<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'>添加
                </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="woNo" label="业务编码">
                    </el-table-column>
                    <el-table-column prop="scence" label="使用场景">
                    </el-table-column>
                    <el-table-column prop="approvalNo" label="申请工号">
                    </el-table-column>
					<el-table-column prop="approvalName" label="申请姓名">
                    </el-table-column>
                    <el-table-column prop="approvalTime" label="申请时间">
                    </el-table-column>
					<el-table-column prop="budget" label="预算金额">
                    </el-table-column>
                    <el-table-column label="操作" width="100px" align="center">
                        <template slot-scope="scope">
                            <el-button size="mini" type="primary" @click="dialogCheck(1,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>
        </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="infoApply.tit" disabled></el-input>
						</el-form-item>
						<el-form-item>
							<span>使用场景</span>
							<el-input v-model="infoApply.scene" disabled></el-input>
						</el-form-item>
						<el-form-item>
						    <span>下单周期</span>
						    <el-date-picker v-model="infoApply.overtime" type="date" disabled></el-date-picker>
						</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>
						<el-form-item v-if="infoApply.infomaterType">
						    <span>剩余成本</span>
						    <el-input v-model="infoApply.infomaterType.sy" 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.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>

        <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: '48%',
                    },
					{
                        type: 'input',
                        tit: '地市名称',
                        value: '',
                        width: '48%',
                    },
                ],
                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:[]
            }
        },
        methods: {
			jumpadd(){
				this.$router.push({
				    path: '/materialApplicationadd',
				});
				this.setabList('物料宣传申请','/materialApplicationadd');
			},
            closedia() {
                this.infolist = {};
                this.dialogStatus = false;
            },
            //搜索数据
            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/cadvMetirialRegionApproval/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;
                    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(this.infolist.params.terminalRes);
					this.rovaList = res.data.taskList;
				});
            },
            //添加
            dialogCli(v) {
                if (v === 1) {
                    this.infolist = {};
                    this.dialogStatus = false;
                    return
                } 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: "/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) {
                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);

            }
        },
        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>
