<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>
                <el-button class="btn-check" size="medium" type="primary" @click="dialogCheck(1)">添加
                </el-button>
            </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="msgTital" label="上报标题" width="120">
                    </el-table-column>
                    <el-table-column prop="msgTypeName" label="信息分类">
                    </el-table-column>
                    <el-table-column prop="sendNo" label="上报工号">
                    </el-table-column>
                    <el-table-column prop="sendName" label="上报姓名">
                        <template slot-scope="scope">
                            <span>{{$desensitization(scope.row.sendName,1)}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="sendTime" label="上报时间" width="140">
                    </el-table-column>
                    <el-table-column prop="sendDeptName" label="上报部门">
                    </el-table-column>
                    <!--    <el-table-column prop="auditNo" label="审核工号">
                    </el-table-column>
                    <el-table-column prop="auditName" label="审核姓名">
                        <template slot-scope="scope">
                            <span>{{$desensitization(scope.row.auditName,1)}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="auditTime" label="审核时间" width="140">
                    </el-table-column>
                    <el-table-column prop="auditResultRemark" label="审核备注">
                    </el-table-column> -->
                    <el-table-column prop="stsDesc" label="状态">
                    </el-table-column>
                    <!-- <el-table-column prop="sts" label="状态">
                    </el-table-column> -->

                    <el-table-column label="操作" width="160px" align="center">
                        <template slot-scope="scope">
                            <el-button size="mini" type="primary" @click="dialogCheck(2,scope.row)">查看</el-button>
                            <el-button v-if="scope.row.sts == 3 || scope.row.sts == 2" size="mini" type="primary"
                                @click="dialogCheck(3,scope.row)">处理</el-button>
                            <el-button v-if="scope.row.sts == 1" size="mini" type="primary"
                                @click="dialogCheckgd(scope.row)">归档</el-button>
                            <!-- <el-button size="mini" type="danger" @click="delLine(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="titname + '信息上报'" :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" :fullscreen="true">
                <div class="dialog-l">
                    <el-tabs tab-position="left" v-model="activeName">
                        <el-tab-pane v-for="item in routerList" :key="item.label" :name="item.label" :label="item.name">
                        </el-tab-pane>
                    </el-tabs>
                </div>

                <div v-loading="loadinged" class="dialog-r">
                    <el-form :model="infolist" ref="infolist" :rules="rules"
                        style="max-height: calc(100vh - 180px);overflow-y: scroll;">


                        <div class="info-line">
                            <el-form-item prop="msgTital">
                                <span>上报标题</span>
                                <el-input v-model="infolist.msgTital" placeholder="标题" :disabled="disableStatus">
                                </el-input>
                            </el-form-item>
                            <el-form-item prop="msgType">
                                <span>信息分类</span>
                                <el-select @change="changemsgType" v-model="infolist.msgType" placeholder="信息分类"
                                    clearable :disabled="disableStatus">
                                    <el-option v-for="item in typelist" :key="item.id" :label="item.msgType"
                                        :value="item.id">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </div>

                        <el-form-item prop="visiblec" class="info-line online" v-if="activeName == 1">
                            <span>接收人员</span>

                            <deptTreeOnly class="tree" @treeCheck="treeCheckonly"></deptTreeOnly>
                            <div class="tree treeUser">
                                <p>{{treeListonly.leaderAuditName}}</p>
                            </div>
                        </el-form-item>

                        <el-form-item prop="visiblec" class="info-line online" v-if="activeName == 2">
                            <span>接收人员</span>
                            <div class="treedept">
                                <p v-for="item in exaList" :key="item.loginNoStr">
                                    <el-checkbox @change="exachange(item)" v-model="item.sts"
                                        style="margin-right: 10px;"></el-checkbox>{{item.loginNameStr}}
                                </p>
                            </div>
                        </el-form-item>

                        <el-form-item class="info-line online" prop="msgInfo">
                            <span>上报内容</span>
                            <el-input v-model="infolist.msgInfo" placeholder="上报内容" type="textarea" :rows="3"
                                :disabled="disableStatus"></el-input>
                        </el-form-item>

                        <div style="padding-left: 80px" v-if="!disableStatus">
                            <myUpload @uploadBack="uploadBack" :fileInfo="fileInfo" :fileList="fileInfo.fileList">
                            </myUpload>
                        </div>

                    </el-form>
                    <div slot="footer" class="dialog-footer myfooter">
                        <el-button @click="dialogCli(2)" v-if="disableStatus">确 定</el-button>
                        <el-button type="primary" @click="dialogCli(1)" v-if="!disableStatus">确 定</el-button>
                        <el-button @click="dialogCli(2)">取 消</el-button>
                    </div>
                </div>
            </el-dialog>


            <el-dialog title="信息上报查看" :visible.sync="dialogInfo" width="70%" :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" :fullscreen="true">
                <div style="height: calc(100vh - 180px);overflow-y: scroll;">
                    <orderCheck :infolist="infolist" :mini="1"></orderCheck>
                    <div style="padding: 0 30px 0 20px;" v-if="this.attList.length>0">
                        <uploadDown :datalist="datalist" :dialogStatus="uploadstatus"></uploadDown>
                    </div>
                </div>
                <div class="dialog-footer myfooter">
                    <el-button @click="dialoginfoCli(2)" type="primary" v-if="infolist.stsDesc == '打回'">处 理</el-button>
                    <el-button @click="dialoginfoCli(3)">取 消</el-button>
                </div>
            </el-dialog>
            <myMessage :messTit='messTit' @closeMessage="closeMessage" :centerDialogVisible="centerDialogVisible"
                v-if="centerDialogVisible"></myMessage>
        </div>
    </fullscreen>

</template>
<script>
    import myUpload from '../../../components/upload'
    import uploadDown from '../../../components/uploadDown'
    import mySearch from '../../../components/search'
    import toolList from '../../../components/toolList.vue'
    import myMessage from "../../../components/myMessage.vue"
    import deptTreeOnly from "../../../components/deptTreeOnly.vue"
    import orderCheck from "../workOrderManage/orderCheck.vue"


    export default {
        components: {
            myUpload,
            uploadDown,
            mySearch,
            toolList,
            myMessage,
            deptTreeOnly,
            orderCheck
        },
        data() {
            const msgTital = (rule, value, callback) => {
                if (!this.infolist.msgTital) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const msgType = (rule, value, callback) => {
                if (!this.infolist.msgType) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const msgInfo = (rule, value, callback) => {
                if (!this.infolist.msgInfo) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            return {
                rules: {
                    msgTital: [{
                        required: true,
                        trigger: 'blur',
                        validator: msgTital
                    }],
                    msgType: [{
                        required: true,
                        trigger: 'change',
                        validator: msgType
                    }],
                    msgInfo: [{
                        required: true,
                        trigger: 'blur',
                        validator: msgInfo
                    }]
                },
                tooltit: "信息上报管理",
                fullscreen: false,
                total: 0,
                pageSize: 1,
                tableData: [{}],
                dialogStatus: false,
                infolist: {},
                typeOptions: [],
                typelist: [],
                titname: '',
                disableStatus: false,
                fileList: [],
                visiblec: [],
                visibleList: [],
                attList: [],
                fileInfo: {
                    limit: 10,
                    url: '/market/cwo/upload',
                    fileList: []
                },
                datalist: {
                    url: '/sysmgr/noticeatt/downfile',
                    type: 1
                },
                uploadstatus: false,
                userInfo: {},
                searchList: [{
                        type: 'sel',
                        tit: '信息分类',
                        value: '',
                        width: '48%',
                        options: []
                    },
                    {
                        type: 'input',
                        tit: '请输入标题',
                        value: '',
                        width: '48%'
                    },
                ],
                params: {},
                btnctrlStatus: true,
                centerDialogVisible: false,
                messTit: '',
                delid: '',
                loading: false,
                loadinged: false,
                activeName: '1',
                routerList: [{
                    name: '上报',
                    label: '1'
                }, {
                    name: '审批',
                    label: '2'
                }],
                treeListonly: [],
                dialogInfo: false,
                exaList: [],
                exaListt: [],
            }
        },
        methods: {
            treeCheckonly(v) {
                this.treeListonly = v;
            },
            closedia() {
                this.datalist.attList = [];
                this.uploadstatus = false;
                this.fileInfo.fileList = [];
                this.infolist = {};
                this.dialogStatus = false;
            },
            //搜索数据
            searchInfo(v) {
                this.params = {};
                v[0] ? this.params.msgType = v[0] : '';
                v[1] ? this.params.msgTital = v[1] : '';
                // v[2] ? this.params.opTimeTo = v[2] : '';
                this.getList(this.params, this.pageSize);
            },
            //获取列表
            getList(v, n) {
                this.pageSize = n;
                let _this = this;
                this.loading = true;
                this.tableData = [];
                this.$http({
                    url: "/market/cqamsg/queryUpInfo",
                    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;
                });
            },
            // 分页
            currchange(v) {
                this.pageSize = v;
                this.getList(this.params, this.pageSize);
            },
            //查看 修改 新增
            dialogCheck(v, n) {
                this.infolist = {};
                if (v === 1) {
                    this.titname = '新建';
                    this.dialogStatus = true;
                    this.disableStatus = false;
                    this.getUser();
                    return
                } else if (v === 2) {
                    this.titname = '查看';
                    this.dialogInfo = true;
                } else if (v === 3) {
                    this.titname = '修改';
                    this.dialogStatus = true;
                    this.disableStatus = false;
                    this.loadinged = true;
                }
                this.$http({
                    url: "/market/cqamsg/queryInfo",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        id: n.id
                    },
                }).then((res) => {
                    res.data.sendName = this.$desensitization(res.data.sendName, 1);
                    res.data.auditName = this.$desensitization(res.data.auditName, 1);
                    this.infolist = res.data;
                    this.datalist.attList = res.data.attList;
                    this.uploadstatus = true;
                    this.infolist.attList = res.data.attList;
                    this.fileInfo.fileList = [];
                    this.attList = [];
                    res.data.attList.forEach(item => {
                        this.fileInfo.fileList.push({
                            name: item.fileName,
                            url: '',
                            id: item.id,
                            fileName: item.fileName,
                            fileCode: item.fileCode,
                        });
                        this.attList.push({
                            name: item.fileName,
                            url: '',
                            id: item.id,
                            fileName: item.fileName,
                            fileCode: item.fileCode,
                        });
                    })
                    this.loadinged = false;
                });
            },
            dialogCli(v) {
                this.datalist.attList = [];
                this.uploadstatus = false;
                if (v === 2) {
                    this.fileInfo.fileList = [];
                    this.infolist = {};
                    this.dialogStatus = false;
                    return
                }
                this.infolist.sendTime = this.$formatDate(new Date(), 'YYYY-MM-DD HH:mm:ss');
                this.infolist.sendNo = this.userInfo.loginNo;
                this.infolist.sendName = this.userInfo.loginName;
                this.infolist.stepSts = this.activeName;
                if (this.titname === '新建') {
                    this.submitInfo("/market/cqamsg/add", v);
                } else if (this.titname === '修改') {
                    this.submitInfo("/market/cqamsg/update", v);
                }
            },
            submitInfo(u, v) {
                let _this = this;
                this.$refs.infolist.validate(valid => {
                    if (valid) {
                        if (this.activeName == '1') {
                            this.infolist.sts = "1";
                            this.infolist.stsDesc = "已上报";
                            this.infolist.receiveName = this.treeListonly.leaderAuditName;
                            this.infolist.receiveNo = this.treeListonly.leaderAuditNo;
                            if (!this.treeListonly.leaderAuditName) {
                                this.$message({
                                    message: '请选择接单人！',
                                    type: 'error'
                                });
                                return
                            }
                        } else if (this.activeName == '2') {
                            this.infolist.sts = "0";
                            this.infolist.stsDesc = "待审核";
                            this.infolist.auditName = this.treeListonly.leaderAuditName;
                            this.infolist.auditNo = this.treeListonly.leaderAuditNo;
                            if (!this.treeListonly.leaderAuditName) {
                                this.$message({
                                    message: '请选择接单人！',
                                    type: 'error'
                                });
                                return
                            }
                        }
                        let attList = [];
                        for (let i = 0; i < this.attList.length; i++) {
                            attList.push({
                                id: this.attList[i].id,
                                fileCode: this.attList[i].fileCode,
                                fileName: this.attList[i].fileName,
                                opName: this.attList[i].opName,
                                opNo: this.attList[i].opNo,
                                opTime: this.attList[i].opTime,
                                noticeId: this.infolist.noticeId
                            });
                        }
                        this.infolist.attList = attList;
                        this.loadinged = true;
                        this.$http({
                            url: u,
                            method: "post",
                            headers: {
                                "Content-Type": "application/json",
                            },
                            data: this.infolist,
                        }).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.infolist.deptCode = '';
                                _this.dialogStatus = false;
                                _this.getList(this.params, this.pageSize);
                            }

                        });
                    }
                })
            },
            dialogCheckgd(v) {
                let _this = this;
                this.$http({
                    url: '/market/cqamsg/bakDoc',
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {id:v.id},
                }).then((res) => {
                    if (res.data.result === 1) {
                        _this.$message({
                            message: res.data.desc,
                            type: 'error'
                        });
                    } else {
                        _this.$message({
                            message: '成功',
                            type: 'success'
                        });
                        _this.getList(this.params, this.pageSize);
                    }

                });
            },
            closeMessage(v) {
                let _this = this;
                this.centerDialogVisible = false;
                if (v === 1) {
                    _this.$http({
                        url: "/market/qamsg/del",
                        method: "post",
                        headers: {
                            "Content-Type": "application/json",
                        },
                        data: {
                            id: this.delid
                        }
                    }).then((res) => {
                        if (res.data.result === 1) {
                            _this.$message({
                                message: res.data.desc,
                                type: 'error'
                            });
                        } else {
                            _this.$message({
                                message: '删除成功',
                                type: 'success'
                            });
                            _this.getList(this.params, this.pageSize);
                        }
                    });
                }
            },
            //删除
            delLine(v) {
                this.delid = v.id;
                this.centerDialogVisible = true;
                this.messTit = '即将删除此条数据, 是否删除?';
            },
            changemsgType() {
                for (let i = 0; i < this.typelist.length; i++) {
                    if (this.infolist.msgType === this.typelist[i].id) {
                        this.infolist.msgTypeName = this.typelist[i].msgType;
                    }
                }
            },
            //文件返回值
            uploadBack(v) {
                this.attList = v;
            },
            //功能栏
            iconCli(v) {
                if (v === 1) {
                    this.getList(this.params, this.pageSize);
                }
                if (v === 2) {
                    this.fullscreen = !this.fullscreen
                }
            },
            //获取人员
            getDepot() {
                this.$http({
                    url: "/sysmgr/csysuserinfo/queryOwnDeptUserListByLoginNo",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {},
                }).then((res) => {
                    this.exaList = res.data;
                    this.exaListt = Object.assign({}, res.data);
                });
            },
            ctrlbtn(v) {
                for (let i = 0; i < v.length; i++) {
                    if (v[i].children.length > 0) {
                        this.ctrlbtn(v[i].children);
                    } else {
                        if (v[i].rountPath === this.$route.path && v[i].systemflag === '1') {
                            this.btnctrlStatus = false;
                            return
                        }
                    }
                }
            },
            getUser() {
                let menus = JSON.parse(window.sessionStorage.menus);
                this.ctrlbtn(menus);
                this.userInfo = JSON.parse(window.sessionStorage.userInfo);
                this.infolist = {};
                this.infolist.sendNo = this.userInfo.loginNo;
                this.infolist.sendName = this.userInfo.loginName;
            },
            getType() {
                this.$http({
                    url: "/market/qatype/queryPage",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                        "page": '{"pageNo":"' + 1 + '","pageSize":"100"}'
                    },
                    data: {
                        sts: 0
                    },
                }).then((res) => {
                    this.typelist = res.data.data;
                    let list = [];
                    res.data.data.forEach(item => {
                        list.push({
                            dataCode: item.id,
                            dataName: item.msgType,
                        })
                    })
                    this.searchList[0].options = list;
                });
            },
            dialoginfoCli(v) {
                if (v == 1) {

                } else if (v == 2) {
                    this.dialogInfo = false;
                    this.dialogStatus = true;
                    this.titname = '修改';
                } else if (v == 3) {
                    this.dialogInfo = false;
                    this.infolist = {};
                }
            },
            exachange(v) {
                for (let i = 0; i < this.exaList.length; i++) {
                    this.exaList[i].sts = false;
                    if (this.exaList[i].id == v.id) {
                        this.exaList[i].sts = true;
                        let opt = {
                            leaderAuditNo: this.exaList[i].loginNoStr,
                            leaderAuditName: this.exaList[i].loginNameStr,
                            displayname: this.exaList[i].groupName
                        }
                        this.treeListonly = opt;
                    }
                }
                this.$forceUpdate();
            }
        },
        mounted() {
            this.getList(this.params, this.pageSize);
            this.getDepot();
            this.getType();
            this.getUser();
        },
        created() {

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

    .tab-long {
        height: 22px;
        float: left;
        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);
        }
    }

    .online {
        width: 100%;

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

        span {
            vertical-align: top;
        }

        .el-textarea {
            width: calc(100% - 100px);
        }

        .tree {
            width: calc(50% - 60px);
            display: inline-block;
            margin-right: 20px;
            height: 300px;
            overflow-y: scroll;
        }

        .treeUser {
            margin: 0;
            border: 1px solid #ddd;

            p {
                background: #f4f4f4;
                padding: 0 20px;
                margin-bottom: 5px;
            }
        }

        .treeUserb {
            width: calc(100% - 100px);
            border: 1px solid #ddd;
            background: #f4f4f4;
            border-radius: 3px;
            height: auto;
            overflow: hidden;

            p {
                display: inline-block;
                padding: 0 20px;
                margin-bottom: 5px;
            }
        }

        .treedept {
            width: calc(100% - 100px);
            // display: inline-block;
            margin-right: 20px;
            border: 1px solid #ddd;
            border-radius: 3px;
            padding: 0 20px;

            p {
                display: inline-block;
                margin-right: 20px;
            }
        }
    }
</style>
