<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)" :data="tableData" size="small" border class="com-table">
                    <el-table-column prop="woName" label="工单标题">
                    </el-table-column>
                    <el-table-column prop="ruleName" label="预警规则">
                    </el-table-column>
                    <el-table-column prop="stsDesc" label="状态">
                    </el-table-column>
                  <!--  <el-table-column prop="sts" label="状态">
                    </el-table-column> -->
                    <el-table-column label="操作" width="160px" align="center" fixed="right">
                        <template slot-scope="scope">
                            <el-button size="mini" type="primary" @click="dialogCheck(4,scope.row)">查看</el-button>
                            <el-button size="mini" v-if="scope.row.sts == 0 || scope.row.stsDesc == '打回'" type="primary"
                                @click="dialogCheck(2,scope.row)">处理</el-button>
                            <!-- <el-button size="mini" v-if="scope.row.sts == 2" type="primary"
                                @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>

            <el-dialog title="预警工单处理" :visible.sync="dialogStatus" width="60%" :close-on-press-escape="false"
                :show-close="false" :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 class="dialog-r">
                    <el-form :model="infolist" ref="infolist" style="height: calc(100vh - 180px);overflow-y: scroll;">
                        <div class="info-line">
                            <el-form-item>
                                <span>预警规则</span>
                                <el-input v-model="infolist.ruleName" placeholder="工单标题" disabled></el-input>
                            </el-form-item>
                            <el-form-item>
                                <span>工单标题</span>
                                <el-input v-model="infolist.woName" placeholder="工单标题"></el-input>
                            </el-form-item>
                        </div>
                        <el-form-item class="info-line online">
                            <span>接收人员</span>
                            <deptTreeOnly class="tree" @treeCheck="treeCheckonly"></deptTreeOnly>
                            <div class="tree treeUser">
                                <p>{{treeListonly.leaderAuditName}}</p>
                            </div>
                        </el-form-item>
                        <el-form-item class="info-line online">
                            <span>工单备注</span>
                            <el-input v-model="infolist.replyDesc" placeholder="工单备注"
                                type="textarea" :rows="3"></el-input>
                        </el-form-item>
                       <!-- <div style="padding-left: 80px">
                            <myUpload @uploadBack="uploadBack" :fileInfo="fileInfo" :fileList="fileInfo.fileList"></myUpload>
                        </div> -->
                    </el-form>
                </div>

                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogCli(1)" type="primary">确 定</el-button>
                    <el-button @click="dialogCli(2)">取 消</el-button>
                </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;">
                    <ruleCheck :infolist="infolist" :datalist="datalist" :dialogInfo="dialogInfo" :historySts="historySts"></ruleCheck>

                </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.stsDesc == '打回'">处 理</el-button>
                    <el-button @click="dialoginfoCli(3)">取 消</el-button>
                </div>
            </el-dialog>
        </div>
    </fullscreen>
</template>
<script>
    import mySearch from '../../../components/search'
    import toolList from '../../../components/toolList'
    import uploadDown from '../../../components/uploadDown.vue'
    import deptTree from "../../../components/deptTree.vue"
    import deptTreeOnly from "../../../components/deptTreeOnly.vue"
    import ruleCheck from "./ruleCheck.vue"
    import myUpload from '../../../components/upload'

    export default {
        components: {
            mySearch,
            toolList,
            uploadDown,
            deptTree,
            deptTreeOnly,
            ruleCheck,
            myUpload
        },
        data() {

            return {
                tooltit: '预警工单处理',
                fullscreen: false,
                total: 0,
                pageSize: 1,
                tableData: [],
                dialogStatus: false,
                infolist: {},
                typeOptions: [],
                titname: '',
                disableStatus: false,
                visiblec: [],
                visibleList: [],
                userInfo: {},
                searchList: [{
                        type: 'input',
                        tit: '规则名称',
                        value: '',
                        width: '48%'
                    },
                    {
                        type: 'input',
                        tit: '派发工号',
                        value: '',
                        width: '48%',
                    },
                ],
                params: {},
                datalist: {
                    url: '/sysmgr/noticeatt/downfile',
                    type: 1
                },
                btnsts: 1,
                uploadstatus: false,
                fileInfo: {
                    limit: 10,
                    url: '/market/cwo/upload',
                    fileList: []
                },
                attList: [],
                treeList: [],
                treeListonly: [],
                defaultList: [],
                depttype: 0,
                transfer: false,
                activeName: '1',
                routerList: [{
                    name: '其他人办理',
                    label: '1'
                }, {
                    name: '领导审批',
                    label: '2'
                }],
                dialogInfo:false,
                historySts:false,
            }
        },
        methods: {
            uploadBack(v) {
                this.attList = v;
            },
            treeCheck(v) {
                this.treeList = v;
            },
            treeCheckonly(v) {
                this.treeListonly = v;
            },
            //搜索数据
            searchInfo(v) {
                this.params = {};
                v[0] ? this.params.ruleName = v[0] : '';
                v[1] ? this.params.sendNo = v[1] : '';
                this.getList(this.params, this.pageSize);
            },
            //获取列表
            getList(v, n) {
                this.pageSize = n;
                let _this = this;
                this.$http({
                    url: "/market/alarmCWo/queryAlarmWoPage",
                    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;
                });
            },
            // 分页
            currchange(v) {
                this.pageSize = v;
                this.getList(this.params, this.pageSize);
            },
            //查看 修改 新增
            dialogCheck(v, n) {
                this.btnsts = v;
                this.infolist = Object.assign({}, n); //拷贝
                this.defaultList = [];
                this.treeListonly = {};
                if (v === 2) {
                    this.titname = '回复';
                    this.dialogStatus = true;
                    this.disableStatus = false;
                } else if (v === 4) {
                    this.titname = '查看';
                }
                this.$http({
                    url: "/market/alarmCWo/Cquery",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        woNo: n.woNo
                    },
                }).then((res) => {
                    this.infolist.attList = res.data.attList;
                    this.datalist.attList = res.data.attList;
                    if (v === 4) {
                        this.dialogInfo = true;
                    }
                    this.uploadstatus = true;
                    this.fileInfo.fileList = [];
                    this.treeList = res.data.deptList;
                    this.attList = [];
                    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,
                            });
                        })
                    }
                    if (res.data.deptList) {
                        res.data.deptList.forEach(item => {
                            this.defaultList.push(item.deptCode);
                        })
                    }
                    this.depttype = 1;
                });
            },
            dialoginfoCli(v) {
                if (v == 1) {
                    this.historySts = !this.historySts;
                } else if (v == 2) {
                    this.dialogInfo = false;
                    this.dialogStatus = true;
                    this.historySts = false;
                } else if (v == 3) {
                    this.dialogInfo = false;
                    this.infolist = {};
                    this.fileInfo.fileList = [];
                    this.historySts = false;
                }
            },
            dialogCli(v) {
                if (v === 2) {
                    this.infolist = {};
                    this.dialogStatus = false;
                    this.defaultList = [];
                    this.depttype = 0;
                    return
                }
                let info = {};
                info.woNo = this.infolist.woNo;
                info.woName = this.infolist.woName;
                info.replyDesc = this.infolist.replyDesc;
                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,
                        woNo: this.infolist.woNo
                    });
                }
                info.attList = attList;
                if (this.activeName == '1') {
                    info.sts = "0";
                    info.stsDesc = '待回复';
                    info.receiveName = this.treeListonly.leaderAuditName;
                    info.receiveNo = this.treeListonly.leaderAuditNo;
                    this.submitInfo("/market/alarmCWo/redeploySQaAlarmWo", info);
                } else if (this.activeName == '2') {
                    info.sts = "1";
                    info.stsDesc = "待审核";
                    info.auditName = this.treeListonly.leaderAuditName;
                    info.auditNo = this.treeListonly.leaderAuditNo;
                    this.submitInfo("/market/alarmCWo/replyAlarmWo", 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.infolist = {};
                                _this.dialogStatus = false;
                                _this.getList(this.params, this.pageSize);
                                _this.defaultList = [];
                                _this.depttype = 0;
                            }

                        });
                    }
                })
            },

            //功能栏
            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);
                // console.log(this.userInfo)
                this.infolist = {

                };
            },
            //获取部门
            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.getUser();
            this.getDepot();
        },
        created() {

        }
    }
</script>
<style scoped lang="scss">
    .search {
        margin-bottom: 16px;
    }

    .dialog-footer {
        padding-right: 20px;
        margin-top: 10px;
    }

    .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>
