<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 type="primary" @click="dialogCheck(3)" size="medium">添加</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="checkCycle" label="统计周期">
                    </el-table-column>
                    <el-table-column prop="remark" label="考核说明">
                    </el-table-column>
                    <el-table-column prop="cityName" label="考核对象">
                    </el-table-column>
                    <el-table-column prop="opName" label="发起人">
                    </el-table-column>
                    <el-table-column prop="stsDesc" label="状态">
                    </el-table-column>
                    <el-table-column label="操作" width="220px" align="center">
                        <template slot-scope="scope">
                            <el-button size="mini" type="primary" @click="dialogCheck(1,scope.row)">查看</el-button>
                            <el-button size="mini" type="primary" @click="jumpto(scope.row)">处理</el-button>
                            <el-button size="mini" v-if="companyFlag == 0" 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="titname" :visible.sync="dialogStatus" width="50%" :destroy-on-close="true"
            :modal-append-to-body="false" :close-on-click-modal="false" :before-close="closedia" :fullscreen="true">
            <div v-loading="loadinged">
                <el-form :model="infolist" ref="infolist" :rules="rules"
                    style="height: calc(100vh - 180px);overflow-y: scroll;">
                    <div class="info-line">
                        <el-form-item prop="checkCycle">
                            <span>统计周期</span>
                            <el-date-picker v-model="infolist.checkCycle" type="daterange" placeholder="统计周期"
                                :disabled="disableStatus" style="display: inline-flex;width: calc(100% - 120px);">
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item prop="remark">
                            <span>考核说明</span>
                            <el-input v-model="infolist.remark" placeholder="考核说明" :disabled="disableStatus">
                            </el-input>
                        </el-form-item>
                        <el-form-item prop="cityName">
                            <span>考核范围</span>
                            <el-select clearable v-model="infolist.cityName" placeholder="考核范围" :disabled="disableStatus" :multiple="true">
                                <el-option v-for="items in regionopt" :key="items.ou" :label="items.ou"
                                    :value="items.ou">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </div>

                    <div v-if="disableStatus">
                        <uploadDown :datalist="datalist" :dialogStatus="uploadstatus"></uploadDown>
                    </div>
                    <div v-if="!disableStatus" class="info-line online">
                        <span style="width: 80px;">考核内容</span>
                        <myUpload style="margin-bottom:20px;width: calc(100% - 80px);" @uploadBack="uploadBack" :fileInfo="fileInfo" :fileList="fileInfo.fileList">
                        </myUpload>
                    </div>

                    <div v-if="disableStatus">
                        <uploadDown :datalist="datalist1" :dialogStatus="uploadstatus"></uploadDown>
                    </div>
                    <div v-if="!disableStatus" class="info-line online">
                        <span style="width: 80px;">目标值</span>
                        <myUpload style="margin-bottom:20px;width: calc(100% - 80px);" @uploadBack="uploadBack1" :fileInfo="fileInfo1" :fileList="fileInfo1.fileList">
                        </myUpload>
                    </div>

                    <div v-if="disableStatus">
                        <uploadDown :datalist="datalist2" :dialogStatus="uploadstatus"></uploadDown>
                    </div>
                    <div v-if="!disableStatus" class="info-line online">
                        <span style="width: 80px;">厅店得分</span>
                        <myUpload style="margin-bottom:20px;width: calc(100% - 80px);" @uploadBack="uploadBack2" :fileInfo="fileInfo2" :fileList="fileInfo2.fileList">
                        </myUpload>
                    </div>

                </el-form>
                <div slot="footer" style="float: right;margin-top: 20px;">
                    <el-button type="primary" @click="dialogCliadd(2)">确 定</el-button>
                    <el-button @click="dialogCliadd(1)">取 消</el-button>
                </div>
            </div>
        </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 evaName = (rule, value, callback) => {
                if (!this.infolist.evaName) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const evaTime = (rule, value, callback) => {
                if (!this.infolist.evaTime) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const trainNum = (rule, value, callback) => {
                if (!this.infolist.trainNum) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const evaNum = (rule, value, callback) => {
                if (!this.infolist.evaNum) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            return {
                rules: {
                    evaName: [{
                        required: true,
                        trigger: 'blur',
                        validator: evaName
                    }],
                    evaTime: [{
                        required: true,
                        trigger: 'change',
                        validator: evaTime
                    }],
                    trainNum: [{
                        required: true,
                        trigger: 'blur',
                        validator: trainNum
                    }],
                    evaNum: [{
                        required: true,
                        trigger: 'blur',
                        validator: evaNum
                    }],
                },
                searchList: [{
                        type: 'sel',
                        tit: '考核对象',
                        value: '',
                        width: '98%',
                        options:[]
                    }
                ],
                tooltit: '集中考核',
                fullscreen: false,
                total: 0,
                pageSize: 1,
                tableData: [{}],
                dialogStatus: false,
                disableStatus: false,
                titname: '',
                infolist: {
                    evaTime:'',
                },
                userInfo: {},
                params: {},
                centerDialogVisible: false,
                messTit: '',
                delid: '',
                loading: false,
                loadinged: false,
                docType:[],
                contentType:[],
                infodata:[{}],
                infodatat:[{}],
                datalist: {
                    url: '/market/compatt/downfile',
                    type: 1
                },datalist1: {
                    url: '/market/compatt/downfile',
                    type: 1
                },datalist2: {
                    url: '/market/compatt/downfile',
                    type: 1
                },
                uploadstatus: false,
                attList1: [],
                attList2: [],
                attList3: [],
                fileInfo: {
                    limit: 1,
                    url: '/market/cmkAttachInfo/upload',
                    fileList: [],
                    uploadType:'newlyCoop'
                },fileInfo1: {
                    limit: 1,
                    url: '/market/cmkAttachInfo/upload',
                    fileList: [],
                    uploadType:'newlyCoop'
                },fileInfo2: {
                    limit: 1,
                    url: '/market/cmkAttachInfo/upload',
                    fileList: [],
                    uploadType:'newlyCoop'
                },

                regionopt:[],
                companyFlag:'',
            }
        },
        methods: {
            jumpto(v){
                let id = v.id;
                this.$router.push({
                    path: "/foocusAssessH?id=" + id,
                    query: {
                        id: id,
                    }
                });
                this.setabList("集中考核处理", "/foocusAssessH?id=" + id);

            },
            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));
            },
            uploadBack(v) {
                this.attList1 = v;
            },
            uploadBack1(v) {
                this.attList2 = v;
            },
            uploadBack2(v) {
                this.attList3 = v;
            },
            //搜索数据
            searchInfo(v) {
                this.params = {};
                v[0] ? this.params.cityName = v[0] : '';
                this.getList(this.params, this.pageSize);
            },
            closedia() {
                this.infolist = {
                    evaTime:'',
                };
                this.infodata = [{}];
                this.infodatat = [{}];
                this.attList3 = [];
                this.attList1 = [];
                this.attList2 = [];
                this.fileInfo.fileList = [];
                this.fileInfo1.fileList = [];
                this.fileInfo2.fileList = [];
                this.dialogStatus = false;
            },
            //获取列表
            getList(v, n) {
                this.pageSize = n;
                let _this = this;
                this.loading = true;
                this.$http({
                    url: "/market/cStoreScheTrainFocus/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;
                    let x= '';
                    for (let i = 0; i < res.data.data.length; i++) {
                        res.data.data[i].stsDesc = '';
                        this.$http({
                            url: "/market/cStoreScheTrainFocusDetail/queryList",
                            method: "post",
                            headers: {
                                "Content-Type": "application/json",
                            },
                            data: {focusId:res.data.data[i].id},
                        }).then((ress) => {
                            x = '';
                            ress.data.forEach(item=>{
                                x += item.cityName+'~'+item.stsDesc+','
                            })
                            res.data.data[i].stsDesc = x;
                        });
                    }
                    this.tableData = res.data.data;
                });
            },
            // 分页
            currchange(v) {
                this.pageSize = v;
                this.getList(this.params, this.pageSize);
            },
            //申请
            dialogCheck(v, n) {
                this.dialogStatus = true;
                let infolist = Object.assign({}, n);
                if (v === 1) {
                    this.titname = '查看';
                    this.disableStatus = true;
                } else if (v === 2) {
                    this.titname = '修改';
                    this.disableStatus = false;
                } else if (v === 3) {
                    this.titname = '添加';
                    this.disableStatus = false;
                    return
                }
                this.infolist = infolist;
                this.$http({
                    url: "/market/cStoreScheTrainFocus/query",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        id: n.id
                    },
                }).then((res) => {
                    let checkCycle = this.infolist.checkCycle.split('~');
                    this.infolist.checkCycle = [];
                    this.infolist.checkCycle = checkCycle;

                    res.data.attList1.forEach(item => {
                        this.fileInfo.fileList.push({
                            name: item.fileName,
                            url: '',
                            id: item.id,
                            fileCode: item.fileCode,
                            fileName: item.fileName
                        });
                        this.attList1.push({
                            name: item.fileName,
                            url: '',
                            id: item.id,
                            fileCode: item.fileCode,
                            fileName: item.fileName
                        });
                    })
                    res.data.attList2.forEach(item => {
                        this.fileInfo1.fileList.push({
                            name: item.fileName,
                            url: '',
                            id: item.id,
                            fileCode: item.fileCode,
                            fileName: item.fileName
                        });
                        this.attList2.push({
                            name: item.fileName,
                            url: '',
                            id: item.id,
                            fileCode: item.fileCode,
                            fileName: item.fileName
                        });
                    })
                    res.data.attList3.forEach(item => {
                        this.fileInfo2.fileList.push({
                            name: item.fileName,
                            url: '',
                            id: item.id,
                            fileCode: item.fileCode,
                            fileName: item.fileName
                        });
                        this.attList3.push({
                            name: item.fileName,
                            url: '',
                            id: item.id,
                            fileCode: item.fileCode,
                            fileName: item.fileName
                        });
                    })
                    this.datalist.attList = [];
                    this.datalist.attList = res.data.attList1;
                    this.datalist1.attList = [];
                    this.datalist1.attList = res.data.attList2;
                    this.datalist2.attList = [];
                    this.datalist2.attList = res.data.attList3;
                    this.uploadstatus = !this.uploadstatus;
                });
            },
            //添加
            dialogCliadd(v) {
                if (v == 1 || this.titname == '查看') {
                    this.infolist = {

                    };
                    this.infodata = [{}];
                    this.infodatat = [{}];
                    this.attList1 = [];
                    this.attList2 = [];
                    this.attList3 = [];
                    this.fileInfo.fileList = [];
                    this.fileInfo1.fileList = [];
                    this.fileInfo2.fileList = [];
                    this.dialogStatus = false;
                    return
                }
                let _this = this;
                let info = this.infolist;
                info.opTime = _this.$formatDate(new Date(), "YYYY-MM-DD");
                info.opNo = this.userInfo.loginNo;
                info.opName = this.userInfo.loginName;
                let checkCycle1 = this.$formatDate(this.infolist.checkCycle[0], "YYYY-MM-DD");
                let checkCycle2 = this.$formatDate(this.infolist.checkCycle[1], "YYYY-MM-DD");
                info.checkCycle = checkCycle1 + '~' + checkCycle2;

                let cityName = '';
                for (let i = 0; i < this.infolist.cityName.length; i++) {
                    if(i == 0){
                        cityName = this.infolist.cityName[i];
                    }else{
                        cityName = cityName +','+ this.infolist.cityName[i];
                    }
                }
                info.cityName = cityName;

                let attList1 = [];
                for (let i = 0; i < this.attList1.length; i++) {
                    attList1.push({
                        id: this.attList1[i].id,
                        fileCode: this.attList1[i].fileCode,
                        fileName: this.attList1[i].fileName,
                    });
                }
                info.trainFocus1 = attList1;

                let attList2 = [];
                for (let i = 0; i < this.attList2.length; i++) {
                    attList2.push({
                        id: this.attList2[i].id,
                        fileCode: this.attList2[i].fileCode,
                        fileName: this.attList2[i].fileName,
                    });
                }
                info.trainFocus2 = attList2;

                let attList3 = [];
                for (let i = 0; i < this.attList3.length; i++) {
                    attList3.push({
                        id: this.attList3[i].id,
                        fileCode: this.attList3[i].fileCode,
                        fileName: this.attList3[i].fileName,
                    });
                }
                info.trainFocus3 = attList3;

                if (this.titname == '修改') {
                    this.submitInfo("/market/cStoreScheTrainFocus/update", info);
                } else {
                    this.submitInfo("/market/cStoreScheTrainFocus/add", info);
                }
            },

            submitInfo(u, v) {
                let _this = this;
                this.$refs.infolist.validate(valid => {
                    if (valid) {
                        this.$http({
                            url: u,
                            method: "post",
                            headers: {
                                "Content-Type": "application/json",
                            },
                            data: v,
                        }).then((res) => {
                            if (res.data.result === 1) {
                                _this.$message({
                                    message: res.data.desc,
                                    type: 'error'
                                });
                            } else {
                                _this.$message({
                                    message: '成功',
                                    type: 'success'
                                });
                                _this.closedia();
                                _this.infolist = {
                                    evaTime:'',
                                };
                                _this.infodata = [{}];
                                _this.infodatat = [{}];
                                _this.getList(this.params, this.pageSize);
                            }

                        });
                    }
                })
            },
            closeMessage(v) {
                this.centerDialogVisible = false;
                let _this = this;
                if (v === 1) {
                    _this.$http({
                        url: "/market/cStoreScheTrainFocus/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.centerDialogVisible = true;
                this.messTit = '即将删除此条数据, 是否删除?';
                this.delid = v.id;
            },
            //功能栏
            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/csysdept/queryRegionDeptList",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {},
                }).then((res) => {
                    this.regionopt = res.data[0].children;
                    res.data[0].children.forEach(item=>{
                        this.searchList[0].options.push({
                            dataName:item.ou,
                            dataCode:item.ou
                        })
                    })
                });
                this.$http({
                    url: "/sysmgr/csysuserinfo/queryUserInfoByLoginNo",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {},
                }).then((res) => {
                    this.companyFlag = res.data.companyFlag
                });
            },
        },
        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: 100px;
            display: inline-block;
            text-align: left;

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

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

    .online {
        width: 100%;

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

        span {
            vertical-align: top;
        }

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

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

            .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% - 100px);
            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;
            }
        }
    }
</style>
