<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%">
                    <el-table-column prop="woName" label="工单标题">
                    </el-table-column>
                    <el-table-column prop="ruleName" 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="派发时间">
                    </el-table-column>
                    <el-table-column prop="stsDesc" 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 size="mini" v-if="scope.row.sts == 6" type="primary" @click="dialogCheck(3,scope.row)">处理</el-button>
                            <el-button size="mini" v-if="scope.row.stsDesc == '打回'" type="primary" @click="dialogCheck(3,scope.row)">修改</el-button>
                            <!-- <el-button size="mini" v-if="scope.row.sts == 2" type="danger" @click="delLine(scope.row)">删除</el-button> -->
                            <el-button size="mini" type="primary" v-if="scope.row.stsDesc == '通过'" >归档</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" :destroy-on-close="true" :modal-append-to-body="false" :close-on-click-modal="false" :fullscreen="true">
                <el-form :model="infolist" ref="infolist" :rules="rules" style="height: calc(100vh - 180px);overflow-y: scroll;">

                    <el-form-item class="info-line online">
                        <span>预警规则</span>
                        <el-select v-model="infolist.ruleId" placeholder="预警规则" clearable disabled
                            @change="verifall(1)">
                            <el-option v-for="item in warnopt" :key="item.id" :label="item.ruleName" :value="item.id">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <div class="info-line">
                        <el-form-item >
                            <span>工单标题</span>
                            <el-input v-model="infolist.woName" placeholder="工单标题" :disabled="disableStatus"></el-input>
                        </el-form-item>
                        <el-form-item >
                            <span>反馈时间</span>
                            <el-date-picker v-model="infolist.replyTime" type="date" placeholder="要求反馈时间" :disabled="disableStatus">
                            </el-date-picker>
                        </el-form-item>
                    </div>
                    <div class="info-line" v-if="disableStatus">
                        <el-form-item>
                            <span>派发人</span>
                            <el-input v-model="infolist.sendName" placeholder="" disabled></el-input>
                        </el-form-item>
                        <el-form-item>
                            <span>派发时间</span>
                            <el-input v-model="infolist.sendTime" placeholder="派发时间" disabled></el-input>
                        </el-form-item>
                    </div>
                    <el-form-item class="info-line online" v-if="!disableStatus">
                        <span>接收部门</span>
                        <deptTree v-if="!disableStatus" class="tree" @treeCheck="treeCheck"></deptTree>
                        <div :class="!disableStatus?'tree treeUser':'tree treeUserb'">
                            <p v-for="item in treeList" :key="item.receiveNo">{{item.receiveName}}</p>
                        </div>
                    </el-form-item>
                    <el-form-item class="info-line online">
                        <span>任务描述</span>
                        <el-input v-model="infolist.description" :disabled="disableStatus" placeholder="任务描述" type="textarea" :rows="3"></el-input>
                    </el-form-item>
                    <div style="padding-left: 80px" v-if="!disableStatus">
                        <myUpload @uploadBack="uploadBack" :fileInfo="fileInfo" :fileList="fileInfo.fileList"></myUpload>
                    </div>
                    <div style="padding-left: 100px;padding-right: 20px;" v-if="disableStatus">
                        <!-- <uploadDown :datalist="datalist" :dialogStatus="uploadstatus"></uploadDown> -->
                    </div>

                    <div class="tabbox" style="padding: 0 20px;">
                        <el-table class="com-table" ref="multipleTable" :data="tableSmall" tooltip-effect="dark" size="mini"
                            border style="width: 100%">
                            <el-table-column prop="woId" label="工单号">
                            </el-table-column>
                            <el-table-column prop="regionName" label="地市">
                            </el-table-column>
                            <el-table-column prop="overtime" label="是否超时">
                            </el-table-column>
                            <el-table-column prop="description" label="内容">
                                <template slot-scope="scope">
                                    <el-tooltip class="item" effect="light" :content="scope.row.description" placement="bottom">
                                        <span class="tab-long">{{scope.row.description}}</span>
                                    </el-tooltip>
                                </template>
                            </el-table-column>
                        </el-table>
                        <el-pagination class="pageBox" @current-change="currchanges" layout="prev, pager, next" background
                            :total="totals">
                        </el-pagination>
                    </div>

                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogCli(1)" type="primary" v-if="btnsts !== 2">确 定</el-button>
                    <el-button @click="dialogCli(2)" v-if="btnsts === 2">确 定</el-button>
                    <el-button @click="dialogCli(2)">取 消</el-button>
                </div>
            </el-dialog>
        </div>
    </fullscreen>
</template>
<script>
    import myUpload from '../../../components/upload'
    import uploadDown from '../../../components/uploadDown'
    import mySearch from '../../../components/search'
    import toolList from '../../../components/toolList'
    import deptTree from "../../../components/deptTreeUser.vue"

    export default {
        components: {
            myUpload,
            uploadDown,
            mySearch,
            toolList,
            deptTree
        },
        data() {
            const woTitle = (rule, value, callback) => {
                if (!this.infolist.woTitle) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const requireTime = (rule, value, callback) => {
                if (!this.infolist.requireTime) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            return {
                rules: {
                    woTitle: [{
                        required: true,
                        trigger: 'blur',
                        validator: woTitle
                    }],
                    requireTime: [{
                        required: true,
                        trigger: 'change',
                        validator: requireTime
                    }]
                },
                tooltit: '预警工单派发',
                fullscreen: false,
                total: 0,
                totals: 0,
                pageSize: 1,
                pageSizes: 1,
                tableData: [],
                tableSmall: [],
                dialogStatus: false,
                infolist: {},
                typeOptions: [],
                titname: '',
                disableStatus: false,
                fileList: [],
                visiblec: [],
                visiblecw: '',
                visiblecwname: '',
                visibleList: [],
                attList: [],
                fileInfo: {
                    limit: 10,
                    url: '/market/cwo/upload',
                    fileList: []
                },
                datalist: {
                    url: '/sysmgr/noticeatt/downfile',
                    type: 1
                },
                uploadstatus: false,
                userInfo: {},
                searchList: [{
                        type: 'input',
                        tit: '请输入标题',
                        value: '',
                        width: '48%'
                    },
                    {
                        type: 'input',
                        tit: '发起人',
                        value: '',
                        width: '48%',
                    },
                ],
                params: {},
                btnsts:1,
                warnopt:[],
                treeList: [],
                defaultList:[],
                depttype:0,
                stabId:''
            }
        },
        methods: {
            treeCheck(v){
                this.treeList = v;
            },
            //搜索数据
            searchInfo(v) {
                this.params = {};
                v[0] ? this.params.woName = v[0] : '';
                v[1] ? this.params.sendName = v[1] : '';
                this.getList(this.params, this.pageSize);
            },
            //获取列表
            getList(v, n) {
                this.pageSize = n;
                let _this = this;
                this.$http({
                    url: "/market/alarmCWo/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;
                });
            },
            getListsmall(v, n) {
                let _this = this;
                this.$http({
                    url: "/market/alarmWoDesc/queryPage",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                        "page": '{"pageNo":"' + n + '","pageSize":"10"}'
                    },
                    data: {woId:v},
                }).then((res) => {
                    this.tableSmall = res.data.data;
                    this.totals = res.data.totalRecord;
                });
            },
            // 分页
            currchange(v) {
                this.pageSize = v;
                this.getList(this.params, this.pageSize);
            },
            currchanges(v) {
                this.pageSizes = v;
                this.getListsmall(this.stabId, this.pageSizes);
            },
            //查看 修改 新增
            dialogCheck(v, n) {
                this.dialogStatus = true;
                this.disableStatus = false;
                this.btnsts = v;
                this.visiblec = [];
                this.defaultList = [];
                this.infolist = Object.assign({}, n); //拷贝
                this.infolist.sendName = this.$desensitization(this.infolist.sendName,1);
                if (v === 1) {
                    this.titname = '新建';
                    this.depttype = 1;
                    this.getUser();
                    return
                } else if (v === 2) {
                    this.titname = '查看';
                    this.disableStatus = true;
                } else if (v === 3) {
                    this.titname = '修改';
                }
                this.$http({
                    url: "/market/alarmCWo/Cquery",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        woNo: n.woNo
                    },
                }).then((res) => {
                    this.datalist.attList = res.data.attList;
                    this.uploadstatus = true;
                    // this.infolist = res.data;
                    this.fileInfo.fileList = [];
                    this.attList = [];
                    this.treeList = res.data.deptList;
                    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,
                                opName: item.opName,
                                opNo: item.opNo,
                                opTime: item.opTime,
                            });
                            this.attList.push({
                                name: item.fileName,
                                url: '',
                                id: item.id,
                                fileName: item.fileName,
                                fileCode: item.fileCode,
                                opName: item.opName,
                                opNo: item.opNo,
                                opTime: item.opTime,
                            });
                        })
                    }
                    if (res.data.deptList) {
                        res.data.deptList.forEach(item => {
                            this.defaultList.push(item.deptCode);
                        })
                    }
                    this.depttype = 1;
                });
                this.stabId = n.woNo;
                this.getListsmall(n.woNo,1);
            },
            dialogCli(v) {
                this.datalist.attList = [];
                this.uploadstatus = false;
                if (v === 2) {
                    this.fileInfo.fileList = [];
                    this.infolist = {};
                    this.infolist.deptCode = '';
                    this.dialogStatus = false;
                    this.defaultList = [];
                    this.depttype = 0;
                    return
                }
                this.infolist.sendNo = this.userInfo.loginNo;
                this.infolist.sendName = this.userInfo.loginName;
                this.infolist.sendTime = this.$formatDate(new Date(), "YYYY-MM-DD");
                if (this.titname === '新建') {
                    this.submitInfo("/market/alarmCWo/add", v);
                } else if (this.titname === '修改') {
                    this.submitInfo("/market/alarmCWo/Cupdate", v);
                }
            },
            submitInfo(u, v) {
                let _this = this;
                this.$refs.infolist.validate(valid => {
                    if (valid) {
                        this.infolist.sts = "0";
                        this.infolist.stsDesc = "待审核";
                        if (v === 3) {
                            this.infolist.sts = "3";
                            this.infolist.stsDesc = "已召回";
                        }
                        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,
                            });
                        }
                        this.infolist.attList = attList;
                        this.infolist.deptList = this.treeList;
                        this.$http({
                            url: u,
                            method: "post",
                            headers: {
                                "Content-Type": "application/json",
                            },
                            data: this.infolist
                        }).then((res) => {
                            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);
                                _this.defaultList = [];
                                _this.depttype = 0;
                            }

                        });
                    }
                })
            },
            //删除
            delLine(v) {
                let _this = this;
                this.$confirm('即将删除此条数据, 是否删除?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    _this.$http({
                        url: "/market/alarmCWo/del",
                        method: "post",
                        headers: {
                            "Content-Type": "application/json",
                        },
                        data: {
                            woNo: v.woNo
                        }
                    }).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);
                        }
                    });
                })
            },
            //处理所需数据
            verifall(v) {
                if(v === 1){
                    for (let j = 0; j < this.warnopt.length; j++) {
                        if (this.warnopt[j].id === this.infolist.ruleId) {
                            this.infolist.ruleName = this.warnopt[j].ruleName;
                        }
                    }
                }
            },
            //文件返回值
            uploadBack(v) {
                this.attList = v;
                console.log(this.attList)
            },
            //功能栏
            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.infolist = {

                };
            },
            //获取列表
            getwarn() {
                this.$http({
                    url: "/market/alarm/queryList",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {},
                }).then((res) => {
                    this.warnopt = res.data;
                });
            },
            //获取部门
            getDepot() {
                this.$http({
                    url: "/sysmgr/sysdept/queryList",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {},
                }).then((res) => {
                    this.typeOptions = res.data;
                });
            },
        },
        mounted() {
            this.getList(this.params, this.pageSize);
            this.getwarn();
            this.getUser();
            this.getDepot();
        },
        created() {

        }
    }
</script>
<style scoped lang="scss">
    .tab-long {
        height: 22px;
        float: left;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        /* 将对象作为弹性伸缩盒子模型显示 */
        -webkit-line-clamp: 1;
        /* 控制最多显示几行 */
        -webkit-box-orient: vertical;
        /* 设置或检索伸缩盒对象的子元素的排列方式 */
    }
    .dialog-footer{
        padding-right: 20px;
        margin-top: 10px;
    }
    .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;
            }
        }
    }
</style>
