<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>
                <span>
                    <el-button type="primary" @click="template" size="medium" v-if="companyFlag == 0">汇报模板设置</el-button>
                    <el-button type="primary" @click="tempDown" size="medium">下发</el-button>
                </span>
            </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="woMonth" label="月份标识">
                    </el-table-column>
                    <el-table-column prop="cityName" label="地市">
                    </el-table-column>
                    <el-table-column prop="woType" label="反馈类型">
                    </el-table-column>
                    <el-table-column prop="opTime" label="提交时间">
                    </el-table-column>
                    <el-table-column prop="dutyName" label="负责人">
                    </el-table-column>

                    <el-table-column label="操作" width="220px" align="center">
                        <template slot-scope="scope">
                            <el-button size="mini" type="primary" @click="dialogCheck(0,scope.row)">查看</el-button>
                            <el-button v-if="scope.row.dutyNo == userInfo.loginNoStr" size="mini" type="primary"
                                @click="dialogCheck(1,scope.row)">填写</el-button>
                            <el-button size="mini" type="primary" @click="guiji(scope.row)">轨迹</el-button>
                            <el-button size="mini" v-if="scope.row.opNo == userInfo.loginNoStr" 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>
        </div>

        <el-dialog title="模板设置" :visible.sync="templateSts" width="800px" :destroy-on-close="true"
            :modal-append-to-body="false" :close-on-click-modal="false" :before-close="closedia">
            <div style="height: 60vh;overflow-y: scroll;">
                <div v-for="(item,index) in templist" class="tempbox">
                    <span>扩展字段{{index}}</span>
                    <span>
                        <el-input v-model="item.colContent" placeholder="扩展字段名" @change="tempchange(item)"></el-input>
                    </span>
                    <span>
                        <el-select clearable v-model="item.colFlag" placeholder="是否启用" @change="tempchange(item)">
                            <el-option v-for="items in colFlagopt" :key="items.id" :label="items.name"
                                :value="items.id">
                            </el-option>
                        </el-select>
                    </span>
                </div>
            </div>
        </el-dialog>

        <el-dialog title="轨迹" :visible.sync="gjsts" width="80%" :destroy-on-close="true" :modal-append-to-body="false"
            :close-on-click-modal="false" :before-close="closedia">
            <div style="height: 50vh;overflow-y: scroll;margin-bottom: 20px;">
                <div class="tempbox2">
                    <span>
                        流程环节
                    </span>
                    <span>
                        处理人
                    </span>
                    <span>
                        处理工号
                    </span>
                    <span>
                        处理时间
                    </span>
                </div>
                <div v-for="(item,index) in gjlist" class="tempbox2">
                    <span>
                        {{item.stepName}}
                    </span>
                    <span>
                        {{item.dealName}}
                    </span>
                    <span>
                        {{item.dealNo}}
                    </span>
                    <span>
                        {{item.dealTime}}
                    </span>
                </div>
            </div>
        </el-dialog>


        <el-dialog title="模板下发" :visible.sync="tempdownSts" width="80%" :destroy-on-close="true"
            :modal-append-to-body="false" :close-on-click-modal="false" :before-close="closedia">
            <div>

                <el-form :model="infolist" ref="infolist" style="height: 52vh;overflow-y: scroll;" :rules="rules">

                    <div>
                        <el-form-item prop="woType" class="info-line online">
                            <span>反馈类型</span>
                            <el-select clearable v-model="infolist.woType">
                                <el-option v-for="items in searchList[2].options" :key="items.dataName"
                                    :label="items.dataName" :value="items.dataName">
                                </el-option>
                            </el-select>
                        </el-form-item>

                        <el-form-item prop="woMonth" class="info-line online">
                            <span>月份标识</span>
                            <el-date-picker v-model="infolist.woMonth" type="month" placeholder="月份标识"
                                :disabled="disableStatus">
                            </el-date-picker>
                        </el-form-item>
                    </div>

                    <el-form-item class="info-line online">
                        <span>负责人</span>
                        <div class="tree treeUser" style="width: 30%;margin-right: 1%;">
                            <p v-for="(item,index) in deptList" :key="index" @click="choseDept(item)">{{item.ou}}</p>
                        </div>
                        <div class="tree treeUser" style="width: 30%;margin-right: 1%;">
                            <p v-for="(item,index) in treeListp" :key="index">
                                <span>{{item.ou}}</span>
                                <span class="p-btn" @click="fzperson(item)">负责人</span>
                                <i @click="deletest(item,index)" class="el-icon-error"></i>
                            </p>
                        </div>
                        <div class="tree treeUser" style="width: 30%;">
                            <p v-for="(item,index) in treeListp" :key="index">{{item.loginNameStr}}</p>
                        </div>
                    </el-form-item>

                </el-form>

                <div slot="footer" style="text-align: right;padding: 20px 0;">
                    <el-button type="primary" @click="tempdownadd">确 定</el-button>
                    <el-button @click="tempdownSts = false">取 消</el-button>
                </div>

            </div>
        </el-dialog>

        <el-dialog title="选择负责人" :visible.sync="dialogStatusp" width="50%" :destroy-on-close="true"
            :modal-append-to-body="false" :close-on-click-modal="false">
            <el-form style="height: 50vh;overflow-y: scroll;">
                <div class="treeUserp">
					<p v-for="(item,index) in treeListponly" :key="index" @click="chofz(item)" v-if="item.loginNameStr">
					    {{item.groupName}} -
					    {{item.loginNameStr}}
					</p>
                </div>
            </el-form>
        </el-dialog>

        <myMessage :messTit='messTit' @closeMessage="closeMessage" :centerDialogVisible="centerDialogVisible"
            v-if="centerDialogVisible"></myMessage>
    </fullscreen>

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

    export default {
        components: {
            mySearch,
            myMessage,
            toolList,
            myUpload,
            uploadDown,
            deptTreeOnly
        },
        data() {
            const woType = (rule, value, callback) => {
                if (!this.infolist.woType) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const woMonth = (rule, value, callback) => {
                if (!this.infolist.woMonth) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            return {
                rules: {
                    woType: [{
                        required: true,
                        trigger: 'change',
                        validator: woType
                    }],
                    woMonth: [{
                        required: true,
                        trigger: 'change',
                        validator: woMonth
                    }],
                },
                searchList: [{
                    type: 'month',
                    tit: '月份标识',
                    value: '',
                    width: '32%'
                }, {
                    type: 'input',
                    tit: '地市名称',
                    value: '',
                    width: '32%'
                }, {
                    type: 'sel',
                    tit: '反馈类型',
                    value: '',
                    width: '32%',
                    options: [{
                        dataCode: '月度反馈',
                        dataName: '月度反馈'
                    }, {
                        dataCode: '临时反馈',
                        dataName: '临时反馈'
                    }, ]
                }],
                tooltit: '台席管理',
                fullscreen: false,
                total: 0,
                pageSize: 1,
                tableData: [{}],
                dialogStatus: false,
                disableStatus: false,
                titname: '',
                infolist: {

                },
                userInfo: {},
                params: {},
                centerDialogVisible: false,
                messTit: '',
                delid: '',
                loading: false,
                loadinged: false,
                templateSts: false,
                templist: [],
                colFlagopt: [{
                    id: '1',
                    name: '是'
                }, {
                    id: '0',
                    name: '否'
                }, ],
                tempdownSts: false,
                deptList: [],
                treeListp: [],
                treeListponly: [],
                dialogStatusp: false,
                companyFlag: '',
                groupId: '',
                gjsts: false,
                gjlist: []
            }
        },
        methods: {
            guiji(n) {
                this.gjsts = true;
                this.$http({
                    url: "/market/cStoreOutWo/queryMkStoreOutWoTraceList",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        woNo: n.woNo,
                    },
                }).then((res) => {
                    this.gjlist = res.data;
                });
            },
            tempdownadd() {
                let param = [];
                let _this = this;
                for (let i = 0; i < this.treeListp.length; i++) {
                    if (this.treeListp[i].loginNoStr) {
                        param.push({
                            dutyNo: this.treeListp[i].loginNoStr,
                            dutyName: this.treeListp[i].loginNameStr,
                            cityId: this.treeListp[i].o,
                            cityName: this.treeListp[i].ou,
                        })
                    }
                }
                if (param.length == 0) {
                    _this.$message({
                        message: '请选择地市及负责人',
                        type: 'error'
                    });
                    return
                }
                this.$refs.infolist.validate(valid => {
                    if (valid) {
                        this.$http({
                            url: "/market/cStoreOutWo/add",
                            method: "post",
                            headers: {
                                "Content-Type": "application/json",
                            },
                            data: {
                                "outWoList": param,
                                "woMonth": this.$formatDate(this.infolist.woMonth, "YYYY-MM"),
                                "woType": this.infolist.woType
                            },
                        }).then((res) => {
                            if (res.data.result === 1) {
                                _this.$message({
                                    message: res.data.desc,
                                    type: 'error'
                                });
                            } else {
                                _this.$message({
                                    message: '成功',
                                    type: 'success'
                                });
                                _this.tempdownSts = false;
                                _this.getList(this.params, this.pageSize);
                            }
                        });
                    }
                })
            },
            chofz(v) {
                this.dialogStatusp = false;
                for (let i = 0; i < this.treeListp.length; i++) {
                    if (this.treeListp[i].o == this.fadept.o) {
                        this.treeListp[i].loginNameStr = v.loginNameStr;
                        this.treeListp[i].loginNoStr = v.loginNoStr;
                    }
                }
            },
            fzperson(v) {
                this.fadept= v;
                this.dialogStatusp = true;
                this.$http({
                    url: "/sysmgr/sysuserinfo/queryList",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        groupId: v.o,
                    },
                }).then((res) => {
                   this.treeListponly = res.data;
                });
                this.$http({
                    url: "/sysmgr/csysdept/queryRegionDeptList",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        parentorgid: v.o,
                    },
                }).then((res) => {
                   res.data.forEach(item=>{
                       this.$http({
                           url: "/sysmgr/sysuserinfo/queryList",
                           method: "post",
                           headers: {
                               "Content-Type": "application/json",
                           },
                           data: {
                               groupId: item.o,
                           },
                       }).then((ress) => {
                          this.treeListponly.push({bumen:item.ou})
                          this.treeListponly=this.treeListponly.concat(ress.data);
                       });
                   })
                });
            },
            deletest(val, index) {
                this.treeListp.splice(index, 1);
            },
            choseDept(v) {
                let x = 'no';
                for (let i = 0; i < this.treeListp.length; i++) {
                    if (this.treeListp[i].o == v.o) {
                        x = i;
                    }
                }
                if (x != 'no') {
                    this.treeListp.splice(x, 1)
                } else {
                    this.treeListp.push(v);
                }
            },
            //下发模板
            tempDown() {
                this.tempdownSts = true;
                if (this.companyFlag == '0') {
                    this.$http({
                        url: "/sysmgr/csysdept/queryRegionDeptList",
                        method: "post",
                        headers: {
                            "Content-Type": "application/json",
                        },
                        data: {},
                    }).then((res) => {
                        this.deptList = res.data[0].children;
                    });
                } else {
                    this.$http({
                        url: "/sysmgr/csysdept/queryChildListByLoginDept",
                        method: "post",
                        headers: {
                            "Content-Type": "application/json",
                        },
                        data: {
                            // parentorgid: this.groupId
                        },
                    }).then((res) => {
                        this.deptList = res.data;
                    });
                }
            },
            //修改模板
            tempchange(v) {
                this.$http({
                    url: "/market/cStoreOutCfg/update",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: v,
                }).then((res) => {

                });
            },
            //查询模板
            template() {
                this.templateSts = true;
                this.$http({
                    url: "/market/cStoreOutCfg/queryList",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {},
                }).then((res) => {
                    this.templist = res.data;
                });
            },
            //搜索数据
            searchInfo(v) {
                this.params = {};
                v[0] ? this.params.woMonth = this.$formatDate(v[0], "YYYY-MM") : '';
                v[1] ? this.params.cityName = v[1] : '';
                v[2] ? this.params.woType = v[2] : '';
                this.getList(this.params, this.pageSize);
            },
            closedia() {
                this.infolist = {};
                this.infodata = [{}];
                this.dialogStatus = false;
                this.templateSts = false;
                this.tempdownSts = false;
                this.gjsts = false;
            },
            //获取列表
            getList(v, n) {
                this.pageSize = n;
                let _this = this;
                this.loading = true;
                this.$http({
                    url: "/market/cStoreOutWo/queryPage",
                    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);
            },
            setabList(n, p) {
                let params = {
                    children: "",
                    name: n,
                    rountPath: p,
                    target: "_self",
                };
                for (let i = 0; i < this.$store.state.tabList.length; i++) {
                    if (this.$store.state.tabList[i].name === params.name) {
                        this.$store.state.tabList[i] = params;
                    }
                }
                let set = new Set([...this.$store.state.tabList, params]);
                set.add(params);
                this.$store.commit("setDefaultActive", params.rountPath);
                this.$store.commit("setTabList", Array.from(set));
            },
            //申请
            dialogCheck(v, n) {
                let id = n.woNo + ',' + v;
                this.$router.push({
                    path: "/stageSeatcheck?id=" + id,
                    query: {
                        id: id
                    }
                });
                this.setabList("台席管理详情", "/stageSeatcheck?id=" + id);
            },
            closeMessage(v) {
                this.centerDialogVisible = false;
                let _this = this;
                if (v === 1) {
                    _this.$http({
                        url: "/market/cStoreOutWo/del",
                        method: "post",
                        headers: {
                            "Content-Type": "application/json",
                        },
                        data: {
                            woNo: 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.centerDialogVisible = true;
                this.messTit = '即将删除此条数据, 是否删除?';
                this.delid = v.woNo;
            },
            //功能栏
            iconCli(v) {
                if (v === 1) {
                    this.getList(this.params, this.pageSize);
                }
                if (v === 2) {
                    this.fullscreen = !this.fullscreen
                }
            },
            getUser() {
                this.userInfo = JSON.parse(window.sessionStorage.userInfo);
                this.$http({
                    url: "/sysmgr/csysuserinfo/queryUserInfoByLoginNo",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {},
                }).then((res) => {
                    this.companyFlag = res.data.companyFlag;
                    this.groupId = res.data.groupId;
                });
            },
        },
        mounted() {
            this.getList({}, 1);
            this.getUser();
        },
        created() {

        }
    }
</script>
<style scoped lang="scss">
    .onetab {
        margin-bottom: 20px;
        padding: 0 20px;
    }

    .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% - 80px);
        }

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

            p {
                overflow: hidden;
                display: flex;
                justify-content: space-between;
            }

            .p-btn {
                width: 50px !important;
                cursor: pointer;
                color: #0074DA;
            }

            span {
                display: inline-block;
                width: calc(100% - 100px);
            }

            .el-icon-error {
                float: right;
                font-size: 20px;
                margin-top: 9px;
                cursor: pointer;
            }
        }

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

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

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

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

    .adv-type {
        margin-top: 20px;
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        // border: 1px solid #ddd;
        border-radius: 5px;
        padding: 20px;
        box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1);

        div {
            width: 33%;
            text-align: center;
            height: 80px;
            overflow: hidden;
            min-width: 100px;
            cursor: pointer;
            padding-top: 10px;
            margin: 10px 0;
        }

        div:hover {
            background: #CFE8FC;
            border-radius: 5px;
        }

        span {
            width: 100%;
            display: inline-block;
            height: 40px;

            // line-height: 40px;
            i {
                color: #0074D9;
                font-size: 36px;
            }
        }
    }

    .tempbox {
        // border: 1px solid #ddd;
        padding: 5px;
        margin-bottom: 10px;

        span {
            display: inline-block;
            width: 40%;
            padding: 0 10px;
        }

        span:first-child {
            width: 20%;
            text-align: center;
        }
    }

    .tempbox2 {

        border: 1px solid #ddd;
        border-bottom: 0;
        span {
            display: inline-block;
            width: 25%;
            padding: 0 10px;
            border-left: 1px solid #ddd;
            padding: 5px;
        }
    }
    .tempbox2:last-child{
        border-bottom: 1px solid #ddd;
    }

    .treeUserp {
        p {
            padding: 5px;
        }

        p:hover {
            background: #01BEF0;
            color: #fff;
            cursor: pointer;
        }
    }
</style>
