<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="woTitle" 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="auditTime" label="审核时间" width="140">
                    </el-table-column>
                    <el-table-column prop="stsDesc" label="状态">
                    </el-table-column>
                    <el-table-column label="操作" width="180px" align="center">
                        <template slot-scope="scope">
                            <el-button size="mini" type="primary" @click="dialogCheck(1,scope.row)">查看</el-button>

                            <el-button v-if="scope.row.sts == 0 && scope.row.leaderAuditNo == userInfo.loginNoStr" size="mini" type="danger"
                                @click="dialogCheck(2,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="dialogStatus" width="50%" :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="height: calc(100vh - 180px);overflow-y: scroll;">
                    <div class="info-line">
                        <el-form-item>
                            <span>任务标题</span>
                            <el-input v-model="infolist.woTitle" placeholder="标题" disabled></el-input>
                        </el-form-item>
                    </div>
                    <el-form-item class="info-line online" v-if="activeName == '1'">
                        <span>接收人员</span>
                        <deptTreeOnly class="tree" @treeCheck="treeCheckonly"
                            :defaultList="defaultList" :type="depttype" :closeList="closeList"></deptTreeOnly>
                        <div class="tree treeUser">
                            <p>{{treeListonly.leaderAuditName}}
                            <i v-if="treeListonly.leaderAuditName" @click="deletes(item,index)"
                                class="el-icon-error"></i></p>
                        </div>
                    </el-form-item>
                    <el-form-item class="info-line online">
                        <span>工单备注</span>
                        <el-input v-model="infolist.dealRemark" placeholder="工单备注" type="textarea" :rows="3">
                        </el-input>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer myfooter">
                    <el-button @click="dialogCli(2)" type="primary" v-if="activeName != '2'">确 定</el-button>
                    <el-button type="primary" @click="dialogCli(3)" v-if="activeName == '2'">通 过</el-button>
                    <el-button type="primary" @click="dialogCli(4)" v-if="activeName == '2'">打 回</el-button>
                    <el-button @click="dialogCli(1)">取 消</el-button>
                </div>
            </div>
        </el-dialog>

        <el-dialog title="查看工单" :visible.sync="dialogInfo" width="70%" :close-on-press-escape="false"
            :show-close="true" :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 :historySts="historySts" :infolist="infolist" :datalist="datalist" :backlist="backlist" :dialogInfo="dialogInfo"></orderCheck>
            </div>
            <div class="dialog-footer myfooter">
                <el-button @click="dialoginfoCli(1)" type="primary">轨 迹</el-button>
                <el-button @click="dialoginfoCli(2)" type="primary" v-if="infolist.sts == '0'&& infolist.leaderAuditNo == userInfo.loginNoStr">处 理</el-button>
                <el-button @click="dialoginfoCli(3)">取 消</el-button>
            </div>
        </el-dialog>


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

    export default {
        components: {
            mySearch,
            myUpload,
            uploadDown,
            toolList,
            deptTree,
            deptTreeOnly,
            orderCheck
        },
        data() {
            const terminalTypeName = (rule, value, callback) => {
                if (!this.infolist.tit) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const brandName = (rule, value, callback) => {
                if (!this.infolist.num) {
                    callback(new Error('不能为空'))
                } else {
                    if (this.infolist.num > 10) {
                        this.infolist.num = 10;
                    }
                    callback()
                }
            }
            const modelType = (rule, value, callback) => {
                if (!this.infolist.time) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            return {
                rules: {
                    terminalTypeName: [{
                        required: true,
                        trigger: 'blur',
                        validator: terminalTypeName
                    }],
                    brandName: [{
                        required: true,
                        trigger: 'blur',
                        validator: brandName
                    }],
                    modelType: [{
                        required: true,
                        trigger: 'blur',
                        validator: modelType
                    }],
                },
                tooltit: '工单审核',
                searchList: [{
                        type: 'input',
                        tit: '工单标题',
                        value: '',
                        width: '32%',
                    },
                    {
                        type: 'date',
                        tit: '开始时间',
                        value: '',
                        width: '32%',
                    },
                    {
                        type: 'date',
                        tit: '结束时间',
                        value: '',
                        width: '32%',
                    },
                    // {
                    //     type: 'sel',
                    //     tit: '工单状态',
                    //     value: '',
                    //     width: '24%',
                    //     options: [{
                    //             dataCode: 1,
                    //             dataName: '待回复',
                    //         },
                    //         {
                    //             dataCode: 2,
                    //             dataName: '已回复',
                    //         }
                    //     ],
                    // },
                ],
                fullscreen: false,
                total: 0,
                pageSize: 1,
                tableData: [{}],
                dialogStatus: false,
                disableStatus: false,
                titname: '终端',
                infolist: {},
                typeOptions: [{
                    dataCode: 1,
                    dataName: 111,
                }],
                userInfo: {},
                params: {},
                infoApply: [],
                fileInfo: {
                    limit: 10,
                    url: '/sysmgr/noticeatt/upload',
                    fileList: []
                },
                datalist: {
                    url: '/sysmgr/noticeatt/downfile',
                    type: 1
                },
                backlist: {
                    url: '/sysmgr/noticeatt/downfile',
                    type: 1
                },
                datalistback: {
                    url: '/sysmgr/noticeatt/downfile',
                    type: 2
                },
                uploadstatus: false,
                visiblec: [],
                attList: [],
                btnctrlStatus: true,
                typelist: [],
                loading: false,
                loadinged: false,
                treeList: [],
                defaultList: [],
                depttype: 0,
                transfer: false,
                treeListonly: {},
                activeName: '2',
                routerList: [{
                    name: '其他人办理',
                    label: '1'
                }, {
                    name: '领导审批',
                    label: '2'
                }, {
                    name: '办理结束',
                    label: '3'
                }, ],
                dialogInfo:false,
                historySts:false,
                closeList:false,
            }
        },
        methods: {
            deletes(val, index) {
                this.treeListonly = {};
                this.closeList = !this.closeList;
            },
            treeCheck(v) {
                this.treeList = v;
            },
            treeCheckonly(v) {
                this.treeListonly = v;
            },
            //搜索数据
            searchInfo(v) {
                this.params = {};
                v[0] ? this.params.woTitle = v[0] : '';
                v[1] ? this.params.sendTimeFrom = this.$formatDate(v[1], "YYYY-MM-DD") : '';
                v[2] ? this.params.sendTimeTo = this.$formatDate(v[2], "YYYY-MM-DD") : '';
                // v[3] ? this.params.modelType = v[3] : '';
                this.getList(this.params, this.pageSize);
            },
            //获取列表
            getList(v, n) {
                this.pageSize = n;
                let _this = this;
                this.tableData = [];
                this.loading = true;
                this.$http({
                    url: "/market/cwo/queryListByTraceApproval",
                    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);
            },
            //申请
            overcheck(v) {
                let _this = this;
                this.$http({
                    url: "/market/cwo/closeWoInfo",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        woNo: v.woNo
                    },
                }).then((res) => {
                    _this.$message({
                        message: '成功',
                        type: 'success'
                    });
                    _this.getList({}, _this.pageSize);
                });
            },
            dialogCheck(v, n) {
                this.defaultList = [];
                if (v == 1) {
                    this.titname = '查看';
                } else if (v == 2) {
                    this.dialogStatus = true;
                    this.titname = '审核';
                    this.disableStatus = false;
                }
                this.$http({
                    url: "/market/cwo/queryInfo",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        woNo: n.woNo,
                    },
                }).then((res) => {
                    this.uploadstatus = true;
                    this.infolist = res.data;
                    this.infolist.id = n.id;
                    this.visiblec = [];
                    this.treeList = res.data.deptList;
                    this.datalist.attList = res.data.attList;
                    this.backlist.attList = res.data.revertAttList;
                    if (v == 1) {
                        this.dialogInfo = true;
                    }
                    this.attList = [];
                    this.fileInfo.fileList = [];
                    if (res.data.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,
                            });
                        })
                    }
                });
            },
            //添加
            dialogCli(v) {
                if (v === 1) {
                    this.infolist = {};
                    this.dialogStatus = false;
                    this.defaultList = [];
                    this.depttype = 0;
                    return
                } else {
                    let params = {
                        woNo: this.infolist.woNo,
                        taskId: this.infolist.taskId,
                        woTitle: this.infolist.woTitle,
                        sts: '4',
                        stsDesc: v === 3 ? '通过' : '打回',
                    }
                    params.leaderAuditName = this.infolist.auditName;
                    params.leaderAuditNo = this.infolist.auditNo;
                    params.dealRemark = this.infolist.dealRemark;
                    params.stepSts = this.activeName;
                    if(this.infolist.auditNo != this.infolist.sendNo){
                        params.sts = '2';
                        params.stsDesc = '待处理';
                    }
                    this.submitInfo("/market/cwo/chkWoInfo", params);
                }
            },
            submitInfo(u, v) {
                let _this = this;
                this.$refs.infolist.validate(valid => {
                    if (valid) {
                        if(this.activeName == '1'){
                            v.sts = "0";
                            v.stsDesc = "待审核";
                            v.leaderAuditName = this.treeListonly.leaderAuditName;
                            v.leaderAuditNo = this.treeListonly.leaderAuditNo;
                            if(!this.treeListonly.leaderAuditName){
                                this.$message({
                                    message: '请选择接单人！',
                                    type: 'error'
                                });
                                return
                            }
                        }else if(this.activeName == '3'){
                            v.sts = "1";
                            v.stsDesc = "已处理";
                        }
                        this.loadinged = true;
                        this.$http({
                            url: u,
                            method: "post",
                            headers: {
                                "Content-Type": "application/json",
                            },
                            data: v,
                        }).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.infolist = {};
                                _this.dialogStatus = false;
                                _this.getList({}, _this.pageSize);
                                _this.defaultList = [];
                                _this.depttype = 0;
                            }

                        })
                    }
                })
            },
            dialoginfoCli(v) {
                if (v == 1) {
                    this.historySts = !this.historySts;
                } else if (v == 2) {
                    this.dialogInfo = false;
                    this.dialogStatus = true;
                    this.historySts = false;
                    this.titname = '修改';
                } else if (v == 3) {
                    this.dialogInfo = false;
                    this.historySts = false;
                    this.infolist = {};
                }
            },
            //文件返回值
            uploadBack(v) {
                this.attList = v;
            },
            //功能栏
            iconCli(v) {
                if (v === 1) {
                    this.getList(this.params, this.pageSize);
                }
                if (v === 2) {
                    this.fullscreen = !this.fullscreen
                }
            },
            getUser() {
                let menus = JSON.parse(window.sessionStorage.menus);
                this.userInfo = JSON.parse(window.sessionStorage.userInfo);
                this.infolist = {
                    opNo: '',
                    opName: '',
                };
                this.infolist.opNo = this.userInfo.loginNo;
                this.infolist.opName = this.userInfo.loginName;

            },
            getType() {
                this.$http({
                    url: "/market/qatype/queryPage",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                        "page": '{"pageNo":"' + 1 + '","pageSize":"100"}'
                    },
                    data: {},
                }).then((res) => {
                    this.typelist = res.data.data;
                });
            },
            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;
                    }
                }
            },
        },
        mounted() {
            this.getList({}, 1);
            this.getUser();
            this.getType();
            if (this.$route.query.id) {
                let params = {
                    woNo: this.$route.query.id + ''
                }
                this.dialogCheck(this.$route.query.type, params);
            }
        },
        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% - 100px);
        }

        .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;
            }
        }
    }
</style>
