<template>

    <fullscreen :fullscreen.sync="fullscreen" class="container">

        <div class="container-box">
            <toolList @iconCli='iconCli' :tooltit='tooltit'></toolList>
            <div class="search">
                <mySearch :searchList="searchList" @searchInfo="searchInfo"></mySearch>
            </div>
            <div class="tabbox">
                <el-table height="calc(100% - 40px)" class="com-table" ref="multipleTable" :data="tableData"
                    tooltip-effect="dark" size="small" border style="width: 100%" v-loading="loading">
                    <el-table-column prop="knowledgeTitle" label="标题">
                    </el-table-column>
                    <el-table-column label="发布工号">
                        <template slot-scope="scope">
                            <span class="">{{scope.row.opNo}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="发布姓名">
                        <template slot-scope="scope">
                            <span>{{$desensitization(scope.row.opName,1)}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="pubDeptName" label="发布部门">
                    </el-table-column>
                    <el-table-column prop="pubTypeName" label="发布类型">
                    </el-table-column>
                    <el-table-column prop="pubTime" label="发布时间">
                    </el-table-column>
                    <el-table-column prop="stsDesc" label="状态">
                    </el-table-column>

                    <el-table-column label="操作" width="100px" align="center">
                        <template slot-scope="scope">
                            <el-button size="mini" v-if="scope.row.sts == 2" :disabled="!btnctrlStatus" type="danger"
                                @click="dialogCheck(scope.row)">审核</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination class="pageBox" @current-change="currchange" layout="prev, pager, next" background
                    :total="total">
                </el-pagination>
            </div>

            <el-dialog title="审核知识" :visible.sync="dialogStatus" width="50%" :close-on-press-escape="false"
                :show-close="true" :before-close="closedia" :destroy-on-close="true" :modal-append-to-body="false"
                :close-on-click-modal="false">
                <div v-loading="loadinged">
                    <el-form style="height: 50vh;overflow-y: scroll;" :model="infolist" ref="infolist" :rules="rules">
                        <div class="info-line">
                            <el-form-item>
                                <span>标题</span>
                                <el-input v-model="infolist.knowledgeTitle" disabled></el-input>
                            </el-form-item>
                            <el-form-item>
                                <span>发布类型</span>
                                <el-input v-model="infolist.pubTypeName" disabled></el-input>
                            </el-form-item>
                            <el-form-item>
                                <span>发布姓名</span>
                                <el-input v-model="infolist.opName" disabled></el-input>
                            </el-form-item>
                            <el-form-item>
                                <span>发布工号</span>
                                <el-input v-model="infolist.opNo" disabled></el-input>
                            </el-form-item>
                        </div>
                        <el-form-item class="info-line online">
                            <span>发布部门</span>
                            <el-input v-model="infolist.pubDeptName" disabled></el-input>
                        </el-form-item>
                        <el-form-item class="info-line online">
                            <span>可见部门</span>
                            <deptTree class="tree" @treeCheck="treeCheck" :defaultList="defaultList" :type="depttype"></deptTree>
                        </el-form-item>
                        <el-form-item class="info-line online">
                            <span>备注</span>
                            <el-input v-model="infolist.auditDesc" placeholder="备注" type="textarea" :rows="3">
                            </el-input>
                        </el-form-item>
                        <div style="padding:0 20px 10px 100px">
                            <uploadDown :datalist="datalist" :dialogStatus="uploadstatus"></uploadDown>
                        </div>
                    </el-form>
                    <div class="dialog-footer myfooter">
                        <el-button type="primary" @click="dialogCli(1)">通 过</el-button>
                        <el-button type="primary" @click="dialogCli(3)">打 回</el-button>
                        <el-button @click="dialogCli(2)">取 消</el-button>
                    </div>
                </div>
            </el-dialog>
        </div>
    </fullscreen>

</template>
<script>
    import myUpload from '../../../components/upload'
    import uploadDown from '../../../components/uploadDown'
    import mySearch from '../../../components/search'
    import toolList from '../../../components/toolList'
    import deptTree from '../../../components/deptTree.vue'

    export default {
        components: {
            myUpload,
            uploadDown,
            mySearch,
            toolList,
            deptTree
        },
        data() {
            const knowledgeTitle = (rule, value, callback) => {
                if (!this.infolist.knowledgeTitle) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const opName = (rule, value, callback) => {
                if (!this.infolist.opName) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const pubType = (rule, value, callback) => {
                if (!this.infolist.pubType) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const opNo = (rule, value, callback) => {
                if (!this.infolist.opNo) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            return {
                rules: {
                    opNo: [{
                        required: true,
                        trigger: 'blur',
                        validator: opNo
                    }],
                    pubType: [{
                        required: true,
                        trigger: 'change',
                        validator: pubType
                    }],
                    opName: [{
                        required: true,
                        trigger: 'blur',
                        validator: opName
                    }],
                    knowledgeTitle: [{
                        required: true,
                        trigger: 'blur',
                        validator: knowledgeTitle
                    }],
                },
                tooltit: '知识库审核',
                fileInfo: {
                    limit: 5,
                    url: '/market/cknowledgeatt/upload',
                    fileList: []
                },
                fullscreen: false,
                total: 0,
                pageSize: 1,
                knowledge: {
                    type: {
                        value: '',
                        options: []
                    },
                    startime: null,
                    endtime: null,
                },
                tableData: [],
                dialogStatus: false,
                infolist: {},
                titname: '',
                disableStatus: false,
                fileList: [],
                visiblec: '',
                visibleList: [],
                attList: [],
                datalist: {
                    url: '/market/compatt/downfile',
                    type: 1
                },
                uploadstatus: false,
                userInfo: {},
                searchList: [{
                        type: 'sel',
                        tit: '发布类型',
                        value: '',
                        width: '19%',
                        options: []
                    },
                    {
                        type: 'input',
                        tit: '发布标题',
                        value: '',
                        width: '19%',
                    },
                    {
                        type: 'date',
                        tit: '开始时间',
                        value: '',
                        width: '19%',
                    },
                    {
                        type: 'date',
                        tit: '结束时间',
                        value: '',
                        width: '19%',
                    },
                    {
                        type: 'input',
                        tit: '关键字',
                        value: '',
                        width: '19%',
                    },
                ],
                params: {},
                centerDialogVisible: false,
                messTit: '',
                delid: '',
                loading: false,
                loadinged: false,
                btnctrlStatus: false,
                treeList: [],
                defaultList:[],
                depttype:0,
            }
        },
        methods: {
            treeCheck(v){
                this.treeList = v;
            },
            closedia() {
                this.infolist = {};
                this.dialogStatus = false;
                this.fileInfo.fileList = [];
                this.defaultList = [];
                this.depttype = 0;
            },
            //搜索数据
            searchInfo(v) {
                this.params = {};
                v[0] ? this.params.pubType = v[0] : '';
                v[1] ? this.params.knowledgeTitle = v[1] : '';
                v[2] ? this.params.opTimeFrom = this.$formatDate(v[2], "YYYY-MM-DD") : '';
                v[3] ? this.params.opTimeTo = this.$formatDate(v[3], "YYYY-MM-DD") : '';
                if (v[4]) {
                    this.params = {};
                    this.params.keyWord = v[4]
                }
                this.getList(this.params, this.pageSize);
            },
            //获取列表
            getList(v, n) {
                this.pageSize = n;
                let _this = this;
                this.loading = true;
                this.tableData = [];
                this.$http({
                    url: "/market/cknowledge/queryChkPage",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                        "page": '{"pageNo":"' + n + '","pageSize":"10"}'
                    },
                    data: v,
                }).then((res) => {
                    this.tableData = res.data.data;
                    this.total = res.data.totalRecord;
                    this.loading = false;
                });
            },
            //字典
            getListype(v) {
                this.$http({
                    url: "/market/mkKnowledgePubMsgType/queryList",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        dictCode: 'pubType'
                    },
                }).then((res) => {
                    let listopt = [];
                    res.data.forEach(item => {
                        listopt.push({
                            dataCode: item.id,
                            dataName: item.pubType,
                        })
                    })
                    this.searchList[0].options = listopt;
                    this.knowledge.type.options = listopt;
                });
            },
            //功能栏
            iconCli(v) {
                if (v === 1) {
                    this.getList(this.params, this.pageSize);
                }
                if (v === 2) {
                    this.fullscreen = !this.fullscreen
                }
            },
            // 分页
            currchange(v) {
                this.pageSize = v;
                this.getList(this.params, this.pageSize);
            },
            //查看 修改 新增
            dialogCheck(v) {
                this.dialogStatus = true;
                this.visiblec = '';
                this.infolist = {};
                this.$http({
                    url: "/market/cknowledge/queryInfo",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        id: v.id
                    },
                }).then((res) => {
                    res.data.opName = this.$desensitization(res.data.opName,1);
                    this.datalist.attList = res.data.attList;
                    this.uploadstatus = true;
                    this.infolist = res.data;
                    this.fileInfo.fileList = [];
                    this.attList = this.infolist.attList;
                    this.treeList = this.infolist.visibleList;
                    this.defaultList = [];
                    res.data.attList.forEach(item => {
                        this.fileInfo.fileList.push({
                            name: item.fileName,
                            url: '',
                            id: item.id,
                            fileName: item.fileName,
                            fileCode: item.fileCode,
                            opName: item.opName,
                            opNo: item.opNo,
                            opTime: item.opTime,
                        });
                    })
                    res.data.visibleList.forEach(item => {
                        this.defaultList.push(item.deptId);
                    })
                    this.depttype = 2;
                    this.loadinged = false;
                });
            },
            //添加 修改
            dialogCli(v) {
                this.uploadstatus = false;
                this.datalist.attList = [];
                this.fileInfo.fileList = [];
                if (v === 2) {
                    this.getUser();
                    this.dialogStatus = false;
                    this.defaultList = [];
                    this.depttype = 0;
                    return
                }
                this.infolist.sts = v;
                v == 1 ? this.infolist.stsDesc = "通过" : this.infolist.stsDesc = "打回";
                this.infolist.auditNo = this.userInfo.loginNo;
                this.infolist.auditName = this.userInfo.loginName;
                this.infolist.auditTime = this.$formatDate(new Date(), "YYYY-MM-DD");
                this.submitInfo("/market/cknowledge/update", v);
            },
            submitInfo(u, v) {
                let _this = this;
                this.loadinged = true;
                this.$http({
                    url: u,
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        knowledge: this.infolist,
                        attList: this.attList,
                        visibleList: this.treeList
                    },
                }).then((res) => {
                    this.loadinged = false;
                    if (res.data.result === 1) {
                        _this.$message({
                            message: res.data.desc,
                            type: 'error'
                        });
                    } else {
                        _this.$message({
                            message: '成功',
                            type: 'success'
                        });
                        _this.fileInfo.fileList = [];
                        _this.infolist = {};
                        _this.dialogStatus = false;
                        _this.getList(_this.params, _this.pageSize);
                        _this.defaultList = [];
                        _this.depttype = 0;
                    }
                })
            },
            ctrlbtn() {
                let v = JSON.parse(window.sessionStorage.childrenMenus);
                for (let i = 0; i < v.length; i++) {
                    if (v[i].jspUrl == this.$route.path && v[i].systemflag == '1') {
                        this.btnctrlStatus = true;
                        return
                    }
                }
            },
            getUser() {
                this.userInfo = JSON.parse(window.sessionStorage.userInfo);
            }
        },
        mounted() {
            this.getList(this.params, this.pageSize);
            this.getListype();
            this.ctrlbtn();
        },
        created() {

        }
    }
</script>
<style scoped lang="scss">
    @import "../../../assets/style";

    .iconfont {
        font-size: 42px;
    }

    .icon-excel {
        color: #67DB63;
    }

    .icon-word {
        color: #FF654E;
    }

    .icon-ppt {
        color: #FF8943;
    }

    .icon-wenjian {
        color: #ccc;
    }

    .el-icon-picture {
        font-size: 36px;
        color: #ccc;
        background: #fff;
        padding: 4px 2px;
        margin-bottom: 2px;
    }

    .back-box {
        margin-top: 20px;
        background: #F2F2F2;
        padding: 20px;

        div {
            display: inline-block;
            text-align: center;
            margin-right: 20px;
            cursor: pointer;

            span {
                display: block;
                width: 80px;
                overflow: hidden;
                padding-top: 10px;
                margin: 0 10px;
                overflow: hidden;
                text-overflow: ellipsis;
                display: -webkit-box;
                /* 将对象作为弹性伸缩盒子模型显示 */
                -webkit-line-clamp: 1;
                /* 控制最多显示几行 */
                -webkit-box-orient: vertical;
                /* 设置或检索伸缩盒对象的子元素的排列方式 */
            }
        }
    }

    .titbox {
        div {
            float: right;

            i {
                font-size: 22px;
                margin-left: 20px;
                cursor: pointer;
            }
        }
    }

    .tabbox {
        margin-top: 15px;
    }

    .pageBox {
        text-align: right;
        margin-top: 10px;
    }

    .info-line {
        width: 100%;
        display: block;
        padding-left: 20px;

        div {
            width: 50%;
            display: inline-block;
        }

        span {
            width: 80px;
            display: inline-block;
            text-align: left;

            i {
                color: red;
                display: inline-block;
                padding-right: 5px;
            }
        }

        .el-select,
        .el-input {
            width: calc(100% - 100px);
        }
        .tree{
            width: calc(100% - 100px);
        }
    }

    .online {
        width: 100%;

        .el-select {
            width: calc(100% - 100px);
        }
        span {
            vertical-align: top;
        }

        .el-textarea {
            width: calc(100% - 100px);
        }
    }
</style>
