<template>
    <div class="item-component-wrap">
        <bread-crumb 
        :curmbFirst="curmbFirst" 
        :curmbSecond="curmbSecond">
        </bread-crumb>
        <div class="component-content screenSet" id="screenSet">
            <div class="search-title">查询条件</div>
            <el-row :gutter="30" class="row" type="flex" style="margin-top: 10px;">
                <el-form ref="serchForm" :model="searchParam" label-width="75px" style="width:100%;">
                    <el-col :span="6">
                        <el-form-item label="讨论主题:">
                            <el-input clearable v-model="searchParam.theme" size="mini" placeholder="请输入主题" clearable></el-input>
                        </el-form-item>
                    </el-col>
					
					<el-col :span="6">
					    <el-form-item label="创建人:">
					        <el-input clearable v-model="searchParam.name" size="mini" placeholder="请输入创建人名称" clearable></el-input>
					    </el-form-item>
					</el-col>
					<el-col :span="6">
					    <el-form-item label="分类:">
					        <el-select  v-model="categoryStatus" size="mini" placeholder="请选择分类">
					            <el-option
					            v-for="(item,index) in category"
					            :key="index"
					            :label="item.label"
					            :value="item.value">
					            </el-option>
					        </el-select>
					    </el-form-item>
					</el-col>
                    <el-col :span="6">
                        <el-form-item label="状态:">
                            <el-select clearable v-model="searchParam.status" size="mini" placeholder="请选择发布状态">
                                <el-option
                                v-for="(item,index) in statuSelect"
                                :key="index"
                                :label="item.label"
                                :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col  style="text-align:right;padding:0 30px 15px 0;">
                        <el-button type="primary" size="small" @click="search">查询</el-button>
                        <el-button type="default" size="small" @click="reseat">重置</el-button>
						<el-button type="primary" size="small" @click="creatFun('1')">举报设置</el-button>
						<el-button type="primary" size="small" @click="creatFun('2')">新建讨论组件</el-button>
                    </el-col>
                </el-form>
            </el-row>
            <el-table 
            :data="tableData" 
            style="width: 100%" v-loading="loading">
                <el-table-column prop="id" label="ID编号" min-width="50" align="center"></el-table-column>
				<el-table-column prop="subject" label="讨论主题" min-width="100" align="center"></el-table-column>
                <el-table-column prop="category" label="分类" min-width="50" align="center"></el-table-column>
                <el-table-column prop="remark" label="备注" min-width="100" align="center"></el-table-column>
				<el-table-column prop="createdusername" label="创建人" min-width="50" align="center"></el-table-column>
				<el-table-column prop="modifiedUsername" label="最后修改人" min-width="100" align="center"></el-table-column>
                <el-table-column prop="status" label="状态" min-width="80" align="center">
                    <template slot-scope="scope">
                        <span>{{ scope.row.status | filteFun}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" fixed="right" align="center" min-width="200">
                    <template slot-scope="scope">
                        <el-button type="primary" size="small" @click="edit(scope.row)">编辑</el-button>					<el-button type="primary" v-if="scope.row.status == 3 || scope.row.status == 1" size="small" @click="optFun(scope.row,'发布')">发布</el-button>
						<el-button type="primary" v-if="scope.row.status == 2" size="small" @click="optFun(scope.row,'下线')">下线</el-button>
						<el-button type="primary" size="small" @click="topicManage(scope.row)">话题管理</el-button>
                       
                    </template>
                </el-table-column>
                <div slot="empty">
                    <div class="table-empty">
                        <img src="../../assets/image/no-content1.png" />
                        <p>没有查询到相关结果</p>
                    </div>
                </div>
            </el-table>
            <!-- 分页 -->
            <div class="pagination">
                <el-pagination
                    background
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="searchParam.pageNo"
                    :page-sizes="[15, 30, 50, 100, 200, 500, 700, 1000, 1500, 2000]"
                    :page-size="searchParam.pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="totalRows">
                </el-pagination>
            </div>
        </div>
    </div>
</template>
<script>
import BreadCrumb from '../../components/breadcrumb.vue'
import { doUpload, getFilePath } from "../../utils/qiniu-util"
import { validateWord } from "../../utils/validate.js"
import { mapGetters } from 'vuex'
import { openLoading, closeLoading } from '../../utils/utils'
import * as commonUtil from '../../utils/utils'
let vm = null
export default {
    components: {
        BreadCrumb
    },
    data() {
        return {
            curmbFirst: '组件',
            curmbSecond: '讨论组件',
            searchParam: {
				theme:'',
				type:'',
				name:'',
			
				status: '',
                pageNo: 1,
                pageSize: 15
            },
			category:[
			],
			categoryStatus:'',
            statuSelect: [
                {
                    label: '未发布',
                    value: '1'
                },{
                    label: '已发布',
                    value: '2'
                },{
                    label: '已下架',
                    value: '3'
                }
            ],
            tableData: [],
            totalRows: 0,
			loading:false,
            
        }
        
    },
    computed: {
      ...mapGetters([
            '_token',
            'idType'
      ])
    },
	filters:{
			
		filteFun(index){
			let str = '';
				
			if(index == 1){
				str = '未发布'
			}else if(index == 2){
				str = '已发布'
			}else if(index == 3){
				str = '已下线'
			}
			return str
		}
	},
    created() {
        this.getData()
		//this.sun()
    },
    // 挂载到Dom完成时
    mounted: function() {
        commonUtil.resizeHeight()
    },
    methods: {
        // 列表查询
        search() {
            this.getData()
        },
		
		//获取数据
		getData(){
			let subject = 0,status = 0,name = 0;
			if(this.searchParam.theme != ''){
				subject = this.searchParam.theme
			}
			if(this.searchParam.status != ''){
				status = this.searchParam.status
			}
			if(this.searchParam.name != ''){
				name = this.searchParam.name
			}
			console.log(this.categoryStatus)
			
            this.loading = true;
            let cStatus = this.categoryStatus ? this.categoryStatus : '0'; //'0'表示默认查所有的
			let url = '/interaction/discuss/'+cStatus+'/'+subject+'/'+name+'/'+status+'/'+this.searchParam.pageNo+'/'+this.searchParam.pageSize
			this.GET(url).then((res) => {
			    this.loading = false
			    if( res.code == '000000' ) {
                    console.log( res.data)
					this.tableData = res.data.resp.discuss || []
                    this.totalRows = res.data.resp.count
                    if (res.data.typeList && res.data.typeList.length) {
                        let arr = [];
                        for(let i = 0; i < res.data.typeList.length; i++) {
                            let obj = {};
                            obj.label = res.data.typeList[i];
                            obj.value = res.data.typeList[i];
                            arr.push(obj);
                        }
                        this.category = arr;
                    }
                    
			    }
			})
		},
		
		
		
        // 重置
        reseat() {
            this.searchParam = Object.assign({},{
                theme:'',
                type:'',
                name:'',
                category:'',
                status: '',
                pageNo: 1,
                pageSize: 15
            })
            this.category =[],
            this.categoryStatus= '',
           this.getData()
        },
		creatFun(index){
			if(index == 1){
				this.$router.push({path: '/report-set'})
			}else if(index == 2){
				this.$router.push({path: '/creat-discuss'})
			}
		},
		edit(item){
			this.$router.push({path: '/creat-discuss',query:{id:item.id}})
		},
		
		topicManage(item){
			this.$router.push({path: '/topic-list',query:{id:item.id}})
		},
        
        // 发布、下线
        optFun(row,str) {
			let status = 0;
			if(str == '发布'){
				status = 2
			}else if(str == '下线'){
				status = 3
			}
			
            this.$confirm('确定要'+str+'该讨论吗？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.PUT('/interaction/discuss/release',{id: row.id,status:status}).then((res) => {
                        if(res.code == "000000") {
                            this.$message({
                                type: 'success',
                                message: '操作成功!'
                            });
                            this.getData()
                        }
                    }).catch(function (error) {
                        this.$message.error(error);
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消'
                    })
            })
        },
        handleSizeChange(value) {
            this.searchParam.pageSize = value
            this.getData()
        },
        handleCurrentChange(value) {
            this.searchParam.pageNo = value
			this.getData()
        }
    }
}
</script>
<style lang="scss">
.item-component-wrap {
    .component-content {
        padding: 10px;
        background: #fff;
        // margin: 84px 20px 20px;
        .search-title {
            padding: 10px 12px;
            font-size: 12px;
            color: #449284;
            border-bottom: 1px solid #efefef;
        }
        .create-button {
            padding: 0 0 15px;
            margin-top: 0 !important;
            text-align: right;
        }
        .table-empty {
            img{
                width: 100px;
            }
            p {
                margin-top: -50px;
            }
        }
    }
}
</style>