<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='jumpadd' v-if="(userInfo.cityName==null&&userInfo.countyName==null)||(userInfo.cityName!=null&&userInfo.countyName==null)">添加
                </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%" v-loading="loading">
                    <el-table-column prop="bizName" label="业务名称">
                    </el-table-column>
                    <el-table-column prop="orderCycle" label="下单周期">
                    </el-table-column>
                    <el-table-column prop="opName" label="申请人">
                    </el-table-column>
                    <el-table-column prop="opCom" label="申请人所属公司">
                    </el-table-column>
                    <el-table-column prop="provinceCity" label="申请类型">
                        <template slot-scope="scope">
                            {{provinceCityArr[scope.row.provinceCity-1]}}
                        </template>
                    </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="操作" width="300px" align="center">
                        <template slot-scope="scope">
                            <!-- <el-button size="mini" type="primary" @click="dialogCheck(1,scope.row)">查看</el-button> -->
                            <!-- <el-button size="mini" type="primary" @click="dialogCheck(2,scope.row)">修改</el-button> -->
                            <el-button size="mini" type="primary" @click="jump(2, scope.row)">查看</el-button>
                            <!-- <el-button size="mini" type="primary" @click="jump(1, scope.row)" v-if="loginNoStr == scope.row.nextOpNo && scope.row.woSts == 0">审批</el-button>                             -->
                           <el-button size="mini" type="primary" @click="jump(1, scope.row)" v-if="(loginNoStr == scope.row.nextOpNo && ((scope.row.provinceCity == 1 && scope.row.nextStep != 12) || (scope.row.provinceCity == 2 && scope.row.nextStep != 10) || (scope.row.provinceCity == 3 && scope.row.nextStep != 11))) && (scope.row.sts != 3)">审批</el-button>
                            <el-button size="mini" type="primary" @click="jump(3, scope.row)" v-if="(loginNoStr == scope.row.nextOpNo && ((scope.row.provinceCity == 1 && scope.row.nextStep ==7) || (scope.row.provinceCity == 1 && scope.row.nextStep ==11) || (scope.row.provinceCity == 2 && scope.row.nextStep == 9) || (scope.row.provinceCity == 3 && scope.row.nextStep == 10))) && (scope.row.sts != 3)">子任务列表</el-button>
                            <el-button size="mini" type="danger" @click="delLine(scope.row)" v-if="(loginNoStr == scope.row.opNo && ((scope.row.provinceCity == 1 && scope.row.nextStep <= 7) || (scope.row.provinceCity == 2 && scope.row.nextStep <= 10) || (scope.row.provinceCity == 3 && scope.row.nextStep <= 11)) && (scope.row.sts != 3))">删除</el-button>
                            <el-button size="mini" type="primary" @click="jump(4, scope.row)" v-if="((scope.row.provinceCity == 1 && scope.row.nextStep == 12) || (scope.row.provinceCity == 2 && scope.row.nextStep == 10) || (scope.row.provinceCity == 3 && scope.row.nextStep == 11)) && (scope.row.countrySts == 0 || scope.row.countrySts == 2)">验收</el-button>

                            <!--<el-button size="mini" type="primary" @click="jump(1, scope.row)" v-if="scope.row.sp">审批</el-button>-->
                            <!--<el-button size="mini" type="primary" @click="jump(3, scope.row)" v-if="scope.row.zrw">子任务列表</el-button>-->
                            <!--<el-button size="mini" type="danger" @click="delLine(scope.row)" v-if="scope.row.sc">删除</el-button>-->
                            <!--<el-button size="mini" type="primary" @click="jump(4, scope.row)" v-if="scope.row.yc">验收</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="dialogStatus" width="50%" :destroy-on-close="true"
            :modal-append-to-body="false" :close-on-click-modal="false" :before-close="closedia" :fullscreen="true">
            <div v-loading="loadinged">
                <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.bizName" disabled></el-input>
						</el-form-item>
						<el-form-item>
							<span>使用场景</span>
							<el-input v-model="infoApply.sceneName" disabled></el-input>
						</el-form-item>
						<el-form-item>
						    <span>下单周期</span>
                            <el-input v-model="infolist.orderCycle" disabled></el-input>
						</el-form-item>
						<el-form-item>
							<span>物料类型</span>
							<el-input v-model="infoApply.metirialName" disabled></el-input>
						</el-form-item>
						<el-form-item>
						    <span>预估预算</span>
						    <el-input v-model="infoApply.budget" disabled></el-input>
						</el-form-item>
                    </div>
					<el-form-item class="info-line online">
					    <span>补充说明</span>
					    <el-input v-model="infoApply.explain" disabled type="textarea" :rows="3"></el-input>
					</el-form-item>
					<el-table :data="infoApply.infomaterType" border size="mini">
						<el-table-column prop="type" label="类型">
						</el-table-column>
						<el-table-column prop="allProv" label="全省">
						</el-table-column>
						<el-table-column prop="hrb" label="哈尔滨">
						</el-table-column>
						<el-table-column prop="qqhr" label="齐齐哈尔">
						</el-table-column>
						<el-table-column prop="mdj" label="牡丹江">
						</el-table-column>
						<el-table-column prop="jms" label="佳木斯">
						</el-table-column>
						<el-table-column prop="dq" label="大庆">
						</el-table-column>
						<el-table-column prop="hg" label="鹤岗">
						</el-table-column>
						<el-table-column prop="yc" label="伊春">
						</el-table-column>
						<el-table-column prop="hh" label="黑河">
						</el-table-column>
						<el-table-column prop="jx" label="鸡西">
						</el-table-column>
						<el-table-column prop="sh" label="绥化">
						</el-table-column>
						<el-table-column prop="sys" label="双鸭山">
						</el-table-column>
						<el-table-column prop="qth" label="七台河">
						</el-table-column>
						<el-table-column prop="dxal" label="大兴安岭">
						</el-table-column>
					</el-table>
					<el-table :data="infoApply.supplier" border size="mini" style="margin: 20px 0;">
						<el-table-column prop="name" label="供应商">
						</el-table-column>
						<el-table-column prop="user" label="预算">
						</el-table-column>
						<el-table-column prop="cost" label="剩余">
						</el-table-column>
					</el-table>
					<el-table class="com-table" ref="multipleTable" :data="rovaList" tooltip-effect="dark" size="small"
					    border>
					    <el-table-column prop="procId" label="编号">
					    </el-table-column>
					    <el-table-column prop="taskName" label="环节">
					    </el-table-column>
					    <el-table-column prop="opName" label="处理人">
					    </el-table-column>
					    <el-table-column prop="opNo" label="处理人工号">
					    </el-table-column>
					    <el-table-column prop="createTime" label="处理时间">
					    </el-table-column>
					    <el-table-column prop="remark" label="备注">
					    </el-table-column>
					</el-table>
					<div class="boximgc">
						<div v-for="(item,index) in infoApply.checkList" :key="index">
							<img :src="item.fileBase64">
						</div>
					</div>
                </el-form>

                <div slot="footer" class="dialog-footer myfooter">
                    <el-button type="primary" @click="dialogCli(2)" v-if="titname !== '查看'">确 定</el-button>
                    <el-button @click="dialogCli(1)" v-if="titname === '查看'">确 定</el-button>
                    <el-button @click="dialogCli(1)">取 消</el-button>
                </div>
            </div>
        </el-dialog> -->

        <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"
                >
                    <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 {
                // rules: {
                //     regionName: [{
                //         required: true,
                //         trigger: 'change',
                //         validator: regionName
                //     }],
                //     advTypeDesc: [{
                //         required: true,
                //         trigger: 'change',
                //         validator: advTypeDesc
                //     }],
                // },
                searchList: [
                    {
                        type: 'input',
                        tit: '业务名称',
                        value: '',
                        width: '32%',
                    },
					{
                        type: 'sel',
                        tit: '状态',
                        value: '',
                        width: '32%',
                        options: [
                        {
                            dataCode: "0",
                            dataName: "待审批"
                        },
                        {
                            dataCode: "1",
                            dataName: "待确认"
                        },
                        {
                            dataCode: "2",
                            dataName: "待验收"
                        },
                        {
                            dataCode: "3",
                            dataName: "已完成"
                        }
                    ]
                    },
                    {
                        type: 'date',
                        tit: '申请时间',
                        value: '',
                        width: '32%',
                    },
                ],
                tooltit:'物料申请管理',
                fullscreen: false,
                total: 0,
                pageSize: 1,
                tableData: [],
                dialogStatus: false,
                disableStatus: false,
                titname: '',
                infolist: {},
                userInfo: {},
                params: {},
                centerDialogVisible: false,
                messTit: '',
                delid: '',
                loading:false,
                loadinged:false,
				fileInfo: {
				    limit: 10,
				    url: '/market/cwo/upload',
				    fileList: []
				},
				infoApply:{},
				rovaList:[],
                applicationDialogStatus:false,
                approvalinfolist: {
                    opinionradio: 1
                },
                stsArr: ['待审批','待确认','待验收','已完成'],
                provinceCityArr:['省',"地市","区县"],
                loginNoStr: "",
                cityWoId: "",
            }
        },
        methods: {
			jumpadd(){
				this.$router.push({
				    path: '/materialApplicationadd',
				});
				this.setabList('物料宣传申请','/materialApplicationadd');
			},
            jump(v, n){
                if(v === 1){
                    // this.$router.push("/materialApplicationExa?id=" + n.id + "");
                    this.$router.push({
                                path: '/materialApplicationExa',
                                query: {cityWoId: n.cityWoId, id: n.id, btnS: 1}
                        })

                }else if(v === 2){
                    this.$router.push("/materialApplicationDetail?id="+ n.id + "")
                }else if(v === 3){
                    let jumpParams = {cityWoId: n.cityWoId, countyWoId: n.countryWoId, woId: n.id, pcId: n.provinceCity};

                    sessionStorage.setItem("jumpParams", JSON.stringify(jumpParams))
                    if(n.provinceCity == 1 && n.nextStep ==7){

                        this.$router.push({
                                path: '/subtaskList',
                                // query: { cityWoId: n.cityWoId, countyWoId: n.countryWoId, woId: n.id, }
                                // path: '/subtaskList/:name',
                                // name: 'subtaskList',
                                // params: { cityWoId: n.cityWoId, countyWoId: n.countryWoId, woId: n.id, }
                        })

                    } else if((n.provinceCity == 1 && n.nextStep ==11) || (n.provinceCity == 2 && n.nextStep == 9) || (n.provinceCity == 3 && n.nextStep == 10)){
                        this.$router.push({
                                path: '/acceptanceSituation',
                                // query: { cityWoId: n.cityWoId, countyWoId: n.countryWoId, woId: n.id, pcId: n.provinceCity}

                                // path: '/acceptanceSituation/:name',
                                // name: 'acceptanceSituation',
                                // params: { cityWoId: n.cityWoId, countyWoId: n.countryWoId, woId: n.id, pcId: n.provinceCity}
                            })
                    }
                }else if(v === 4){
                    // this.$router.push("/acceptance?cityWoId="+ n.cityWoId + "&countyWoId=" + n.countryWoId)
                    this.$router.push({
                                path: '/acceptance',
                                query: { cityWoId: n.cityWoId, countyWoId: n.countryWoId, woId: n.id }
                        })
                }
            },
            setabList(n, p) {
            	let params = {
            		children: "",
            		name: n,
            		rountPath: p,
            		target: "_self",
            	};
            	for (let i = 0; i < this.$store.state.tabList.length; i++) {
            		if (this.$store.state.tabList[i].name === params.name) {
            			this.$store.state.tabList[i] = params;
            		}
            	}
            	let set = new Set([...this.$store.state.tabList, params]);
            	set.add(params);
            	this.$store.commit("setDefaultActive", params.rountPath);
            	this.$store.commit("setTabList", Array.from(set));
            },
            closedia() {
                this.infolist = {};
                this.dialogStatus = false;
                this.approvalinfolist = {};
                this.applicationDialogStatus = false;
            },
            //搜索数据
            searchInfo(v) {
                this.params = {};
                v[0] ? this.params.bizName = v[0] : '';
                v[1] ? this.params.sts = v[1] : '';
                let timeFrom = '';
                let timeTo = '';
                if (v[2]){
                    timeFrom = this.$formatDate(v[2],"YYYY-MM-DD")+ ' 00:00:00'
                    timeTo = this.$formatDate(v[2],"YYYY-MM-DD")+ ' 23:59:59'
                }
                timeFrom ? this.params.opTimeFrom = timeFrom : '';
                timeTo ? this.params.opTimeTo = timeTo : '';
                this.getList(this.params, this.pageSize);
            },
            //获取列表
            getList(v, n) {

                this.pageSize = n;
                let _this = this;
                this.loading = true;
                this.tableData = [];
                this.$http({
                    url: "/market/cadvBusiMetirialWo/queryPage",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                        "page": '{"pageNo":"' + n + '","pageSize":"10"}'
                    },
                    data: v,
                }).then((res) => {
                    this.tableData = res.data.body.pageList.data;
                    this.total = res.data.body.pageList.totalRecord;
                    // console.log(this.tableData);
                    this.loading = false;

                });
            },
            // 分页
            currchange(v) {
                this.pageSize = v;
                this.getList(this.params, this.pageSize);
            },
            //申请
            dialogCheck(v, n) {
                this.dialogStatus = true;
                // 审批同意对话框
                this.applicationDialogStatus = 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(this.infolist.params.wo);

					this.rovaList = res.data.taskList;
				});
            },


            //添加
            dialogCli(v) {
                if (v === 1) {
                    this.infolist = {};
                    this.dialogStatus = false;
                    return
                }else if(v===5){
                    if(this.approvalinfolist.opinionradio == 1){
                        this.infolist.opTime = this.$formatDate(new Date(), "YYYY-MM-DD");
                        this.infolist.dealType = '2';
                        this.infolist.dealTypeDesc = this.approvalinfolist.opinion;
                        this.applicationDialogStatus = false;

                        this.submitInfo("/bpm/api/submitTask", this.infolist);
                    }
                }
                 else {
                    this.infolist.opTime = this.$formatDate(new Date(), "YYYY-MM-DD");
                    if (this.titname === '添加') {
                        this.submitInfo("/bpm/api/addBpmPrePlugin");
                    } else if (this.titname === '审批') {
                        this.submitInfo("/bpm/api/updateBpmPrePlugin", v);
                    }
                }
            },
            submitInfo(u) {
                let _this = this;
                //this.$refs.infolist.validate(valid => {
                    //if (valid) {
                        this.loadinged = true;
                        this.$http({
                            url: u,
                            method: "post",
                            headers: {
                                "Content-Type": "application/json",
                            },
                            data: this.infolist,
                        }).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);
                            }

                        });
                    //}
                //})
            },
            closeMessage(v) {
                this.centerDialogVisible = false;
                let _this = this;
                if (v === 1) {
                    _this.$http({
                        url: "/market/cadvBusiMetirialWo/del",
                        method: "post",
                        headers: {
                            "Content-Type": "application/json",
                        },
                        data: {
                            woId: 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) {
                console.log(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);
                this.loginNoStr = this.userInfo.loginNoStr;

            }
        },
        mounted() {
            this.getList({}, 1);
            this.getUser();
        },
        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);
        }
    }
	.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,.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;
	        }
	    }
	}
	.boximgc {
		display: flex;
		flex-wrap: wrap;
		width: 100% !important;
		margin-top: 20px;

		div {
			display: inline-block;
			width: 18% !important;
			margin-right: 2%;
			margin-bottom: 20px;
			overflow: hidden;
			border: 1px solid #ddd;
			border-radius: 3px;
			background: #fff;
			position: relative;
			height: 100px;

			img {
				width: 100%;
				position: absolute;
				top: 0;
				bottom: 0;
				margin: auto;
				// height: 100%;
			}

		}
	}
</style>
