<template>
    <fullscreen :fullscreen.sync="fullscreen" class="container">
        <div class="container-box">
            <toolList @iconCli='iconCli' :tooltit='tooltit'></toolList>
            <div class="search">
                <el-select v-model="advstatus" @change="advchange">
                    <el-option v-for="items in advopt" :key="items.id" :label="items.name" :value="items.id">
                    </el-option>
                </el-select>
            </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="id" label="工单编号">
                    </el-table-column>
                    <el-table-column prop="advTitle" label="工单标题">
                    </el-table-column>
                    <el-table-column prop="opNo" label="发起人">
                    </el-table-column>
                    <el-table-column prop="opName" label="发起人姓名">
                    </el-table-column>
                    <el-table-column prop="opTime" label="发起时间">
                    </el-table-column>
                    <el-table-column prop="stsDesc" label="状态">
                    </el-table-column>
                    <el-table-column label="操作" width="120px" align="center">
                        <template slot-scope="scope">
                            <el-button size="mini" type="primary" @click="dialogCheck(scope.row,1)">查看</el-button>
                            <!--<el-button size="mini" type="danger" v-if="scope.row.sts==3"-->
                            <el-button size="mini" type="danger" v-if="advstatus == 0 && scope.row.isBtnShow  && scope.row.sts=='0'"
                                @click="dialogCheck(scope.row,2)">审核</el-button>
                            <el-button v-if="userInfo.loginName == scope.row.opName&&scope.row.sts=='3'" size="mini"
                                type="primary" @click="advSure(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="80%" :destroy-on-close="true"
                :modal-append-to-body="false" :close-on-click-modal="false">
                <div>

                    <advert v-if="typestatsu === 2" @closeEdio="closeEdio" :componentInfo="componentInfo"
                        :componentStatus="componentStatus" :changeinfo="changeinfo"></advert>

                </div>
            </el-dialog>

            <el-dialog title="定稿素材" :visible.sync="dialogStatusc" width="50%" :destroy-on-close="true"
                :modal-append-to-body="false" :close-on-click-modal="false">
                <el-form>
                    <el-form-item class="info-line online">
                        <span>素材类型</span>
                        <el-select :popper-append-to-body="false" v-model="advtype" placeholder="素材类型">
                            <el-option v-for="item in typeList" :key="item.dataCode" :label="item.dataName"
                                :value="item.dataCode">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-form>
                <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>

        </div>
    </fullscreen>
</template>
<script>
    import mySearch from "../../../components/search.vue";
    import toolList from "../../../components/toolList.vue";
    import advert from "./components/advert.vue"

    export default {
        components: {
            mySearch,
            toolList,
            advert
        },
        data() {
            return {
                tooltit: '广告管理',
                fullscreen: false,
                total: 0,
                pageSize: 1,
                tableData: [{}],
                dialogStatus: false,
                disableStatus: false,
                infolist: {},
                userInfo: {},
                params: {},
                typestatsu: 1,
                options: [],
                typeopt: [],
                componentInfo: {},
                componentStatus: false,
                dialogStatusc: false,
                loading: false,
                changeinfo: false,
                advstatus: '',
                advopt: [{
                    id: '0',
                    name: '待审批',
                }, {
                    id: '2',
                    name: '定稿',
                }, ],
                btnctrlStatus: false,
                typeList: [],
                advtype: '',
                dgid: '',
                singleTable: {},
                shParam:{},
                // isBtnShow: false,
            }
        },
        methods: {
            //获取列表
            getList(v, n) {
                this.pageSize = n;
                let _this = this;
                this.tableData = [];
                this.loading = true;
                let param = {
                    sts: this.advstatus
                };
                this.$http({
                    url: "/market/cadv/queryPage",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                        "page": '{"pageNo":"' + n + '","pageSize":"10"}'
                    },
                    data: param,
                }).then((res) => {
                    //this.tableData = res.data.data;
                    let data = res.data.data;
                    this.total = res.data.totalRecord;
                    this.loading = false;
                    if(this.advstatus==0){
						data.forEach(item => {
                            item.isBtnShow = false;
                            this.getSts(item)
						});
					}
                    this.tableData = data;
                });
            },
		    async getSts(v){
				await this.$http({
				    url: '/bpm/api/taskInit',
				    method: "post",
				    headers: {
				        "Content-Type": "application/json",
				    },
				    data: {
				        taskId: v.taskId,
				        woNo: v.id
				    },
				}).then((res) => {
                    this.shParam = res.data;
				    if(res.data.taskName == '需求部门'){
                        v.sts = '3'
                        return
                    }
                    if(res.data.assigneeNo == this.userInfo.loginNo){
                        v.sts = '0'
                        v.isBtnShow = true;
                        return
                    }
            
				});
			},
            // 分页
            currchange(v) {
                this.pageSize = v;
                this.getList(this.params, this.pageSize);
            },
            advchange() {
                this.getList(this.params, this.pageSize);
            },
            //处理申请
            dialogCheck(n, v) {
                if (v == 1) {
                    this.changeinfo = false;
                } else {
                    this.changeinfo = true;
                }
                this.typestatsu = 2;
                this.dialogStatus = true;
                let params = {
                    woNo: n.id,
                    taskId: n.taskId
                }
                this.componentInfo = params;
                this.componentStatus = true;
            },
            advSure(v) {
                let _this = this;
                this.dialogStatusc = true;
                this.dgid = v.id;
                this.getSts(v);
            },
            dialogCli(v) {
                let _this = this;

                if (v == 1) {
                    let advTypeName = '';
                    for (let i = 0; i < this.typeList.length; i++) {
                        if (this.typeList[i].dataCode == this.advtype) {
                            advTypeName = this.typeList[i].dataName;
                        }
                    }
                    // let param = {
                    //     woNo: this.dgid,
                    //     advTypeName: advTypeName,
                    //     advType: this.advtype
                    // }
                    let gdParam = {
                        woNo: this.dgid,
                        advTypeName: advTypeName,
                        advType: this.advtype
                    }
                    
                    this.shParam.params.terminalRes = JSON.stringify(Object.assign(JSON.parse(this.shParam.params.terminalRes) , gdParam))
                    
                    let param = this.shParam

                    this.$http({
                        // url: "/market/cadv/mkConfirmAdv",
                        url: "/bpm/api/submitTask",
                        method: "post",
                        headers: {
                            "Content-Type": "application/json",
                        },
                        data: param,
                    }).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);
                        }
                    });
                }
                this.dialogStatusc = false;
                this.advtype = '';
                return
            },
            closeEdio() {
                this.getList(this.params, this.pageSize);
                this.dialogStatus = false;
                this.componentStatus = false;
            },
            gettype() {
                this.$http({
                    url: "/sysmgr/cfgDataDicts/queryMap",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        dictCodePks: 'materType'
                    },
                }).then((res) => {
                    this.typeList = res.data.body.materType;
                });
            },
            //功能栏
            iconCli(v) {
                if (v === 1) {
                    this.getList(this.params, this.pageSize);
                }
                if (v === 2) {
                    this.fullscreen = !this.fullscreen
                }
            },
            ctrlbtn() {
                let v = JSON.parse(window.sessionStorage.childrenMenus);
                for (let i = 0; i < v.length; i++) {
                    if (v[i].jspUrl == this.$route.path && v[i].systemflag == '1') {
                        this.btnctrlStatus = true;
                        return
                    }
                }
            },
        },
        mounted() {
            this.userInfo = JSON.parse(window.sessionStorage.userInfo);
            this.advstatus = this.$route.query.type;
            this.getList({}, 1);
            this.ctrlbtn();
            this.gettype();
        },
        created() {

        }
    }
</script>
<style scoped lang="scss">
    .approval {
        .roval-box {
            padding: 0 20px;
            margin-top: 20px;
            margin-bottom: 10px;

            .el-input {
                width: calc(100% - 200px);
                display: inline-block;
            }

            span {
                display: inline-block;
                width: 80px;
                font-size: 14px;
                margin-right: 20px;

                .el-input {
                    width: 100%;
                    display: inline-block;
                }
            }
        }
    }

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