<template>
    <fullscreen :fullscreen.sync="fullscreen" class="container">
        <div class="container-box">
            <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="cityName" label="地市名称">
                    </el-table-column>
                    <el-table-column prop="nextOpName" label="接口人">
                    </el-table-column>
                    <el-table-column prop="provinceOpName" label="分发人">
                    </el-table-column>
                    <el-table-column prop="optime" label="分发时间">
                    </el-table-column>
                    <el-table-column prop="sts" label="子任务状态">
                        <template slot-scope="scope">
                            {{stsArr[scope.row.sts]}}
                        </template>
                    </el-table-column>
                    
                    <el-table-column label="操作" align="center">
                        <template slot-scope="scope">
                            <el-button
                                size="mini"
                                type="primary"
                                @click="jump(1, scope.row)" v-if="scope.row.sts == 3 || scope.row.sts == 4 || scope.row.sts == 6"
                                >确认结果</el-button
                            >
                            <el-button
                                size="mini"
                                type="primary"
                                @click="jump(2, scope.row)"  v-if="scope.row.sts == 4 || scope.row.sts == 6"
                                >验收情况</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="applicationDialogStatus"
            width="30%"
            :destroy-on-close="true"
            :modal-append-to-body="false"
            :close-on-click-modal="false"
            :before-close="closedia"
        >
            <div v-loading="loadinged">
                <el-form
                    :model="approvalinfolist"
                    ref="approvalinfolist"
                    :rules="rules"
                >
                    <el-form-item class="info-line online" style="margin-left: 10%">
                        <el-radio-group v-model="approvalinfolist.opinionradio">
                            <el-radio :label="1">同意</el-radio>
                            <el-radio :label="2">打回</el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item class="info-line online" style="text-align: center">
                        <el-input
                            v-model="approvalinfolist.opinion"
                            placeholder="审批意见"
                            type="textarea"
                            :rows="2"
                        ></el-input>
                    </el-form-item>
                </el-form>

                <div slot="footer" class="dialog-footer myfooter">
                    <el-button @click="dialogCli(4)">取 消</el-button>
                    <el-button type="primary" @click="dialogCli(5)">确 定</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";

export default {
    components: {
        mySearch,
        myMessage,
        toolList,
        myUpload
    },
    data() {
        const regionName = (rule, value, callback) => {
            if (!this.infolist.regionName) {
                callback(new Error("不能为空"));
            } else {
                callback();
            }
        };
        const advTypeDesc = (rule, value, callback) => {
            if (!this.infolist.advTypeDesc) {
                callback(new Error("不能为空"));
            } else {
                callback();
            }
        };
        return {
            loginNo: JSON.parse(sessionStorage.userInfo).loginNo,
            rules: {
                regionName: [
                    {
                        required: true,
                        trigger: "change",
                        validator: regionName
                    }
                ],
                advTypeDesc: [
                    {
                        required: true,
                        trigger: "change",
                        validator: advTypeDesc
                    }
                ]
            },
            searchList: [
                // {
                //     type: 'input',
                //     tit: '物料名称',
                //     value: '',
                //     width: '48%',
                // },
                {
                    type: "sel",
                    tit: "物料类别",
                    value: "",
                    width: "98%",
                    options: []
                }
                // {
                //     type: 'input',
                //     tit: '地市名称',
                //     value: '',
                //     width: '98%',
                // },
            ],
            tooltit: "物料申请审核",
            fullscreen: false,
            total: 0,
            pageSize: 1,
            tableData: [],
            dialogStatus: false,
            disableStatus: false,
            applicationDialogStatus: false,
            titname: "",
            infolist: {},
            approvalinfolist: {
                opinionradio: 1
            },
            userInfo: {},
            params: {},
            centerDialogVisible: false,
            messTit: "",
            delid: "",
            loading: false,
            loadinged: false,
            fileInfo: {
                limit: 10,
                url: "/market/cwo/upload",
                fileList: []
            },
            infoApply: {},
            rovaList: [],
            woNoArr: [],
            // stsArr: ['待审批','通过','驳回','待验收','已结束'],
            stsArr: ['待确认', '通过', '驳回', '待验收', '已结束', '验收驳回', '待审批'],
        };
    },
    methods: {
        jump(v, n){
                if(v === 1){
                    // this.$router.push("/materialApplicationExa?id="+ n.id + "")
                    // this.$router.push({
                    //             path: '/materialApplicationExa',
                    //             query: {id: this.params.woId }
                    //     })
                    this.$router.push({
                                path: '/materialApplicationExa',
                                query: {id: this.params.woId, btnS: 2, cityWoId: n.id}
                        })

                }else if(v === 2){
                    // this.$router.push("/acceptanceSituation?id="+ n.id + "")
                    this.$router.push({
                        path: '/acceptanceSituation',
                        query: {cityWoId: n.id}
                        // query: { cityWoId: this.params.cityWoId, countyWoId: this.params.countyWoId, woId: this.params.woId }
                    })
                    // this.$router.push({
                    //     path: '/acceptanceSituation',
                    //     name: 'acceptanceSituation',
                    //     params: { cityWoId: this.params.cityWoId, countyWoId: this.params.countyWoId, woId: this.params.woId }
                    // })
                }
            },
        closedia() {
        },
        // //搜索数据
        // searchInfo(v) {
        //     this.params = {};
        //     // v[0] ? this.params.metirialName = v[0] : '';
        //     v[0] ? (this.params.regionName = v[0]) : "";
        //     this.getList(this.params, this.pageSize);
        // },
        //获取列表
        getList(v, n) {
            this.pageSize = n;
            let _this = this;
            this.loading = true;
            this.tableData = [];
            this.$http({
                url:
                    "/market/advSubtask/queryPage",                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
                method: "post",
                headers: {
                    "Content-Type": "application/json",
                    page: '{"pageNo":"' + n + '","pageSize":"10"}'
                },
                data: v
            }).then(res => {
                this.tableData = res.data.body.cityList;
                this.loading = false;
            });
        },
        // 分页
        currchange(v) {
            this.pageSize = v;
            this.getList(this.params, this.pageSize);
        },
        //申请
        dialogCheck(v, n) {            
            this.dialogStatus = true;
            this.infolist = Object.assign({}, n);
            if (v === 1) {
                this.titname = "查看";
                this.disableStatus = true;
            } else if (v === 2) {
                this.titname = "修改";
                this.disableStatus = false;
            }
            
            // this.$http({
            //     url: "/bpm/api/taskInit",
            //     method: "post",
            //     headers: {
            //         "Content-Type": "application/json"
            //     },
            //     data: {
            //         woNo: n.woNo
            //     }
            // }).then(res => {

            //     this.infolist = Object.assign({}, res.data);
            //     this.infoApply = JSON.parse(res.data.params.terminalRes);
            //     this.rovaList = res.data.taskList;
            // });
        },
        //添加
        dialogCli(v) {
            this.dialogStatus = false;
            if (v === 3) {
                return;
            }
            let _this = this;
            this.infolist.opTime = _this.$formatDate(new Date(), "YYYY-MM-DD");
            this.infolist.opNo = this.userInfo.loginNo;
            this.infolist.opName = this.userInfo.loginName;
            if (v === 1) {
                let params = {
                    dealType: "1",
                    dealTypeDesc: "打回",
                    procId: this.infolist.procId,
                    procVersion: this.infolist.procVersion,
                    remark: this.infolist.remark,
                    stepId: this.infolist.stepId,
                    taskId: this.infolist.taskId,
                    taskName: this.infolist.taskName,
                    opName: this.infolist.opName,
                    opNo: this.infolist.opNo,
                    opTime: this.infolist.opTime,
                    params: {
                        procExeCondiVal: "不同意",
                        terminalRes: JSON.stringify(this.infoApply)
                    },
                    woNo: this.infolist.woNo
                };
                this.submitInfo("/bpm/api/submitTask", params);
            } else if (v === 2) {
                let param = {
                    dealType: "0",
                    dealTypeDesc: "提交",
                    procId: this.infolist.procId,
                    procVersion: this.infolist.procVersion,
                    remark: this.infolist.remark,
                    stepId: this.infolist.stepId,
                    taskId: this.infolist.taskId,
                    taskName: this.infolist.taskName,
                    opName: this.infolist.opName,
                    opNo: this.infolist.opNo,
                    opTime: this.infolist.opTime,
                    params: {
                        terminalRes: JSON.stringify(this.infoApply)
                    },
                    woNo: this.infolist.woNo
                };
                this.submitInfo("/bpm/api/submitTask", param);
            }else if(v === 4){
                this.applicationDialogStatus = false;
            }else if(v === 5){//审批确定
                this.applicationDialogStatus = false
                if(this.approvalinfolist.opinionradio == 1){
                        let param = {
                        dealType: "0",
                        dealTypeDesc: "提交",
                        procId: this.infolist.procId,
                        procVersion: this.infolist.procVersion,
                        remark: this.infolist.remark,
                        stepId: this.infolist.stepId,
                        taskId: this.infolist.taskId,
                        taskName: this.infolist.taskName,
                        opName: this.infolist.opName,
                        opNo: this.infolist.opNo,
                        opTime: this.infolist.opTime,
                        params: {
                            terminalRes: JSON.stringify(this.multipleSelection)
                        },
                        woNo: this.infolist.woNo,
                        approvalAgreement: this.approvalinfolist.opinion
                    };
                }
                
            }
        },
        submitInfo(u, v) {
            let _this = this;
            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.getList(this.params, this.pageSize);
                }
            });
        },
        closeMessage(v) {
            this.centerDialogVisible = false;
            let _this = this;
            if (v === 1) {
                _this
                    .$http({
                        url: "/bpm/api/deleteBpmPrePlugin",
                        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;
        },
        //文件返回值
        uploadBack(v) {
        },
        //功能栏
        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);
        }
    },
     mounted() {

        // if (JSON.stringify(this.$route.params) != "{}") {
        //     this.params.cityWoId = this.$route.params.cityWoId;
        //     this.params.countyWoId = this.$route.params.countyWoId;
        //     this.params.woId = this.$route.params.woId;
        // }

        // if (JSON.stringify(this.$route.query) != "{}") {
        //     this.params.cityWoId = this.$route.query.cityWoId;
        //     this.params.countyWoId = this.$route.query.countyWoId;
        //     this.params.woId = this.$route.query.woId;
        // }
        this.getList(this.params, 1);
        this.getUser();
        let jumpParams = JSON.parse(sessionStorage.getItem("jumpParams"))
        this.params.cityWoId = jumpParams.cityWoId;
        this.params.countyWoId = jumpParams.countyWoId;
        this.params.woId = jumpParams.woId;
    },
    watch: {
        $route() {
            this.getList(this.params, 1);
        }
    },
};
</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);
    }
}
.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, 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;
        }
    }
}
.section2 {
    display: flex;
    align-items: center;
    margin: 40px 0;
    button {
        margin-bottom: 0 !important;
    }
    h3 {
        margin-right: 40px;
    }
}
</style>
