<template>
    <fullscreen :fullscreen.sync="fullscreen" class="container">
        <div class="container-box">
            <toolList @iconCli='iconCli' :tooltit='tooltit'></toolList>
            <div style="overflow: hidden;">
                <el-button style="float: right;margin-top: 10px;" type="primary" @click="dialogCheck(3)">添加</el-button>
               <el-button style="float: right;margin-top: 10px;margin-right: 20px;" type="primary"
                    @click="getStanding(1)" v-if="companyFlag == 0">供应商维护表</el-button>
                <!-- <el-button style="float: right;margin-top: 10px;margin-right: 10px;" type="primary"
                    @click="getStanding(2)">预算及上限</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="woTitle" label="业务名称">
                    </el-table-column>
                    <el-table-column prop="opName" label="申请姓名">
                    </el-table-column>
                    <el-table-column prop="createTime" 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(1,scope.row)">查看</el-button>
                            <el-button size="mini" type="danger" v-if="scope.row.sts != 1"
                                @click="dialogCheck(2,scope.row)">处理</el-button>
                            <el-button size="mini" type="danger"
                                v-if="!scope.row.finishTime&&scope.row.sts==1&&scope.row.opName==userInfo.loginName"
                                @click="delLine(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 prop="woName">
                            <span>工单名称</span>
                            <el-input v-model="infolist.woName" placeholder="工单名称"
                                :disabled="disableStatus">
                            </el-input>
                        </el-form-item>
                        <el-form-item prop="terminal">
                            <span>申请流程</span>
                            <el-select clearable v-model="terminal" placeholder="申请流程" disabled>
                                <el-option v-for="items in options" :key="items.procId" :label="items.procName"
                                    :value="items.procId">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item prop="woTypeCode">
                            <span>媒介类型</span>
                            <el-select clearable v-model="woTypeCode" placeholder="媒介类型"
                                :disabled="disableStatus">
                                <el-option v-for="items in mjopt" :key="items.id" :label="items.name" :value="items.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item prop="supplierName">
                            <span>供应商</span>
                            <el-button type="primary" @click="chosegys" :disabled="disableStatus">选择
                            </el-button>
                            <el-input v-model="suppinfo.supplierName" disabled
                                style="width: calc(100% - 210px);margin-left: 20px;"></el-input>
                        </el-form-item>
                    </div>

                    <div class="info-line" v-if="woTypeCode == 1">
                        <el-form-item>
                            <span>投放单位</span>
                            <el-input v-model="infolist.putUnit" placeholder="投放单位"
                                :disabled="disableStatus">
                            </el-input>
                        </el-form-item>
                        <el-form-item>
                            <span>项目名称</span>
                            <el-input v-model="infolist.projectName" placeholder="项目名称"
                                :disabled="disableStatus">
                            </el-input>
                        </el-form-item>
                        <el-form-item>
                            <span>投放时期</span>
                            <el-input v-model="infolist.putTime" placeholder="投放时期"
                                :disabled="disableStatus">
                            </el-input>
                        </el-form-item>
                        <el-form-item>
                            <span>项目负责人</span>
                            <el-input v-model="infolist.dutyName" placeholder="项目负责人"
                                :disabled="disableStatus">
                            </el-input>
                        </el-form-item>
                        <el-form-item>
                            <span>联系方式</span>
                            <el-input v-model="infolist.dutyTel" placeholder="联系方式"
                                :disabled="disableStatus">
                            </el-input>
                        </el-form-item>
                        <el-form-item>
                            <span>活动编号</span>
                            <el-input v-model="infolist.actNo" placeholder="活动编号"
                                :disabled="disableStatus">
                            </el-input>
                        </el-form-item>
                    </div>

                    <div class="info-line" v-if="woTypeCode == 4">
                        <el-form-item>
                            <span>品牌及内容</span>
                            <el-input v-model="infolist.advContent" placeholder="广告发布品牌及内容"
                                :disabled="disableStatus">
                            </el-input>
                        </el-form-item>
                        <el-form-item>
                            <span>广告版本</span>
                            <el-input v-model="infolist.advVersion" placeholder="广告发布版本"
                                :disabled="disableStatus">
                            </el-input>
                        </el-form-item>
                    </div>

                    <div class="info-line">
                        <el-form-item>
                            <span>税率</span>
                            <el-input v-model="infolist.taxRate" placeholder="税率"
                                :disabled="disableStatus">
                            </el-input>
                        </el-form-item>
                    </div>

                    <myinternet v-if="woTypeCode == 1" :titname='titname' :vision='vision' @backsum="backsum"
                        :infodatas="infodatas" :status="status" :allSumnum="allSum"></myinternet>
                    <television v-if="woTypeCode == 2" :titname='titname' :vision='vision' @backsum="backsum"
                        :infodatas="infodatas" :status="status" :allSumnum="allSum"></television>
                    <paper v-if="woTypeCode == 3" :titname='titname' :vision='vision' @backsum="backsum"
                        :infodatas="infodatas" :status="status" :allSumnum="allSum"></paper>
                    <outdoors v-if="woTypeCode == 4" :titname='titname' :vision='vision' @backsum="backsum"
                        :taxRate="infolist.taxRate" :infodatas="infodatas" :status="status" :allSumnum="allSum"
                        :otherinfo="otherinfo"></outdoors>

                    <div class="info-line" style="clear: both;">
                        <el-form-item>
                            <span>甲方</span>
                            <el-input v-model="infolist.partyA" placeholder="甲方"
                                :disabled="disableStatus">
                            </el-input>
                        </el-form-item>
                        <el-form-item>
                            <span>乙方</span>
                            <el-input v-model="infolist.partyB" placeholder="乙方"
                                :disabled="disableStatus">
                            </el-input>
                        </el-form-item>
                        <el-form-item>
                            <span>日期</span>
                            <el-date-picker :disabled="disableStatus" v-model="infolist.patime"
                                type="date">
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item>
                            <span>日期</span>
                            <el-date-picker :disabled="disableStatus" v-model="infolist.pbtime"
                                type="date">
                            </el-date-picker>
                        </el-form-item>
                    </div>

                    <div style="padding:0 20px 0 120px;margin-bottom: 20px;" v-if="disableStatus">
                        <uploadDown :datalist="datalist" :dialogStatus="uploadstatus"></uploadDown>
                    </div>

                    <div v-if="!disableStatus">
                        <myUpload @uploadBack="uploadBack" :fileInfo="fileInfo" :fileList="fileInfo.fileList">
                        </myUpload>
                    </div>

                    <el-form-item class="info-line online" v-if="visionsts == '2'">
                        <span>审批说明</span>
                        <el-input v-model="remark" placeholder="审批说明" type="textarea" :rows="3"
                            :disabled="titname == '查看'">
                        </el-input>
                    </el-form-item>

                    <div style="margin-bottom: 20px;padding: 0 20px;" v-if="titname != '添加'">
                        <el-table class="com-table" ref="multipleTable" :data="rovaList" tooltip-effect="dark"
                            size="small" border style="width: 100%">
                            <el-table-column prop="taskId" label="编号">
                            </el-table-column>
                            <el-table-column prop="taskName" label="环节">
                            </el-table-column>
                            <el-table-column prop="assigneeName" label="处理人">
                            </el-table-column>
                            <el-table-column prop="assigneeNo" label="处理人工号">
                            </el-table-column>
                            <el-table-column prop="opTime" label="处理时间">
                            </el-table-column>
                            <el-table-column prop="remark" label="备注">
                            </el-table-column>
                        </el-table>
                    </div>
                </el-form>

                <div slot="footer" class="dialog-footer myfooter">
                    <el-button v-if="titname != '查看' && vision == '流程发起'" type="primary" @click="sumzero">确 定
                    </el-button>
                    <el-button v-if="titname != '查看' && vision == '上刊用印'" type="primary" @click="dialogCli(2)">导 出
                    </el-button>
                    <el-button v-if="titname != '查看' && visionsts == '2'" type="primary" @click="sumzero">通 过
                    </el-button>
                    <el-button v-if="titname != '查看' && visionsts == '2'" type="primary" @click="dialogCli(1)">打 回
                    </el-button>
                    <el-button v-if="titname == '添加'" type="primary" @click="sumzero">确 定</el-button>
                    <el-button v-if="titname == '查看'" @click="dialogCli(3)">确 定</el-button>
                    <el-button @click="dialogCli(3)">取 消</el-button>
                </div>
            </div>
        </el-dialog>

        <el-dialog title="供应商" :visible.sync="suppliersts" :destroy-on-close="true" :modal-append-to-body="false"
            :close-on-click-modal="false" :fullscreen="true">
            <el-table :data="suppList" tooltip-effect="dark" style="width: 100%" border height="calc(100vh - 180px)">
                <el-table-column width="55" align="center">
                    <template slot-scope="scope">
                        <el-checkbox v-model="scope.row.sts" @change="boxcho(scope)"></el-checkbox>
                    </template>
                </el-table-column>
                <el-table-column prop="supplierName" label="供应商">
                </el-table-column>
                <el-table-column prop="supplierCode" label="合同编码">
                </el-table-column>
                <el-table-column prop="contractName" label="合同名称">
                </el-table-column>
                <el-table-column prop="frameSum" label="框架总额">
                </el-table-column>
                <el-table-column prop="frameSurplusSum" label="框架剩余总额">
                </el-table-column>
                <el-table-column prop="budgetSum" label="预算总额">
                </el-table-column>
                <el-table-column prop="surplusSum" label="预算剩余额度">
                </el-table-column>
                <el-table-column prop="endTime" label="截止时间">
                </el-table-column>
            </el-table>
            <div class="t-footer" style="text-align: right;margin-top: 20px;">
                <el-button type="primary" @click="suppliercheck(1)">确 定</el-button>
                <el-button @click="suppliercheck(2)">取 消</el-button>
            </div>
        </el-dialog>

        <el-dialog title="选择审批人" :visible.sync="checkexa" width="50%" :destroy-on-close="true"
            :modal-append-to-body="false" :close-on-click-modal="false">
            <div>

                <el-form :model="infolist" ref="infolist">
                    <el-form-item class="info-line online">
                        <span>审批人员</span>
                        <deptTreeOnly class="tree" @treeCheck="treeCheckonly" :defaultList="defaultList"
                            :type="depttype" :closeList="closeList"></deptTreeOnly>
                        <div class="tree treeUser">
                            <p>{{treeListonly.leaderAuditName}}
                                <i v-if="treeListonly.leaderAuditName" @click="deletes()" class="el-icon-error"></i>
                            </p>
                        </div>
                    </el-form-item>
                </el-form>

                <div slot="footer" style="text-align: right;padding-bottom: 20px;">
                    <el-button type="primary" @click="dialogCliadd" v-if="titname == '添加'">确 定</el-button>
                    <el-button type="primary" @click="dialogCli(2)" v-if="vision == '流程发起'||visionsts == 2">确 定
                    </el-button>
                    <el-button @click="checkexa = false">取 消</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'
    import uploadDown from '../../../components/uploadDown.vue'
    import myinternet from './internet.vue'
    import television from './television.vue'
    import paper from './paper.vue'
    import outdoors from './outdoors.vue'
    import deptTreeOnly from "../../../components/deptTreeOnly.vue"

    export default {
        components: {
            mySearch,
            myMessage,
            toolList,
            myUpload,
            uploadDown,
            myinternet,
            television,
            paper,
            outdoors,
            deptTreeOnly
        },
        data() {
            const woName = (rule, value, callback) => {
                if (!this.infolist.woName) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const terminal = (rule, value, callback) => {
                if (!this.terminal) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const woTypeCode = (rule, value, callback) => {
                if (!this.woTypeCode) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const supplierName = (rule, value, callback) => {
                if (!this.suppinfo.supplierName) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            return {
                rules: {
                    woName: [{
                        required: true,
                        trigger: 'blur',
                        validator: woName
                    }],
                    terminal: [{
                        required: true,
                        trigger: 'change',
                        validator: terminal
                    }],
                    woTypeCode: [{
                        required: true,
                        trigger: 'change',
                        validator: woTypeCode
                    }],
                    supplierName: [{
                        required: true,
                        trigger: 'change',
                        validator: supplierName
                    }],
                },
                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: 5,
                    url: '/bpm/api/upload',
                    fileList: []
                },
                rovaList: [],
                vision: '',
                datalist: {
                    url: '/bpm/api/download',
                    type: 1
                },
                uploadstatus: false,
                rovaList: [],
                mydisable: 1,
                opname: '',
                opno: '',
                attList: [],
                options: [],
                terminal: '729291034548674560',
                // terminal: '754971596344848384',//需求发起人流程
                // terminal: '724514662710046720',
                remark: '',
                visionsts: '1',
                woTypeCode: 1,
                mjopt: [{
                    id: 1,
                    name: '互联网'
                }, {
                    id: 2,
                    name: '广播电视'
                }, {
                    id: 3,
                    name: '纸媒'
                }, {
                    id: 4,
                    name: '户外'
                }, ],
                infodatas: [{}, {}],
                suppliersts: false,
                suppList: [],
                suppinfo: {}, //供应商信息
                allSum: 0, //合计总价
                status: false, //组件数据状态
                otherinfo: {},
                companyFlag: 1,
                checkexa: false,
                treeListonly: {},
                defaultList: [],
                closeList: false,
                depttype: 0,
            }
        },
        methods: {
            deletes() {
                this.treeListonly = {};
                this.closeList = !this.closeList;
            },
            treeCheckonly(v) {
                this.treeListonly = v;
            },
            //组件返回数据
            backsum(v, n, x) {
                this.allSum = v;
                this.infodatas = n;
                if (x) {
                    this.otherinfo.advPriceSum = x.advPriceSum;
                    this.otherinfo.advDiscountSum = x.advDiscountSum;
                    this.otherinfo.contractAdvCost = x.contractAdvCost;
                    this.otherinfo.contractAdvTax = x.contractAdvTax;
                    this.otherinfo.otherDiscount = x.otherDiscount;
                }
            },
            //查询供应商
            chosegys() {
                this.suppliersts = true;
                this.$http({
                    url: "/market/cadvLedger/querySupplierList",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                        "page": '{"pageNo":"' + 1 + '","pageSize":"1000"}'
                    },
                    data: {},
                }).then((res) => {
                    res.data.forEach(item => {
                        item.sts = false;
                    })
                    this.suppList = res.data;
                });
            },
            //选择供应商
            boxcho(v) {
                this.suppinfo = v.row;
                this.infolist.partyB = this.suppinfo.supplierName
                for (let i = 0; i < this.suppList.length; i++) {
                    this.suppList[i].sts = false;
                }
                this.suppList[v.$index].sts = true;
            },
            //选择供应商
            suppliercheck(v) {
                if (v == 2) {
                    this.suppinfo = {};
                    this.infolist.partyB = '';
                }
                this.suppliersts = false;
            },
            closedia() {
                this.infolist = {};
                this.attList = [];
                this.fileInfo.fileList = [];
                this.dialogStatus = false;
            },
            //获取列表
            getList(v, n) {
                this.pageSize = n;
                let _this = this;
                this.loading = true;
                v.procName = "广告发布申请流程(省),广告发布申请流程";
                this.$http({
                    url: "/bpm/api/queryToDoAndFinishTaskList",
                    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;
                    this.allSum = 0;
                });
            },
            // 分页
            currchange(v) {
                this.pageSize = v;
                this.getList(this.params, this.pageSize);
            },
            //申请
            dialogCheck(v, n) {
                this.dialogStatus = true;
                let infolist = Object.assign({}, n);
                this.vision = '';
                this.visionsts = '';
                this.infodatas = [{}, {}];
                if (v === 1) {
                    this.titname = '查看';
                    this.disableStatus = true;
                } else if (v === 2) {
                    this.titname = '审批';
                    this.disableStatus = true;
                } else if (v === 3) {
                    this.titname = '添加';
                    this.disableStatus = false;
                    return
                }
                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.terminal = infolist.procId;
                    this.opname = res.data.opName;
                    this.opno = res.data.opNo;
                    this.infolist = JSON.parse(res.data.params.terminalRes);
                    this.infodatas = this.infolist.factoryList; //组件数据
                    this.allSum = this.infolist.allSum; //合计总价
                    this.suppinfo = this.infolist.suppinfo; //供应商
                    this.woTypeCode = this.infolist.woTypeCode * 1; //类型
                    this.otherinfo = this.infolist.otherinfo; //类型
                    this.status = true;
                    this.infolist.procId = infolist.procId;
                    this.infolist.procVersion = infolist.procVersion;
                    this.remark = infolist.remark;
                    this.infolist.stepId = infolist.stepId;
                    this.infolist.taskId = infolist.taskId;
                    this.infolist.taskName = infolist.taskName;
                    this.infolist.opName = infolist.opName;
                    this.infolist.opNo = infolist.opNo;
                    this.infolist.opTime = infolist.opTime;
                    this.infolist.woNo = infolist.woNo;
                    if (res.data.taskList[res.data.taskList.length - 1].taskName == '需求发起') {
                        this.vision = '流程发起';
                        if (this.titname == '审批') {
                            this.disableStatus = false;
                        }
                    }
                    if (res.data.taskList[res.data.taskList.length - 1].taskName == '流程发起') {
                        this.vision = '流程发起';
                        if (this.titname == '审批') {
                            this.disableStatus = false;
                        }
                    } else if (res.data.taskList[res.data.taskList.length - 1].taskName == '三级经理审批') {
                        this.vision = '三级经理审批';
                        this.visionsts = '2';
                    } else if (res.data.taskList[res.data.taskList.length - 1].taskName == '二级经理审批') {
                        this.vision = '二级经理审批';
                        this.visionsts = '2';
                    } else if (res.data.taskList[res.data.taskList.length - 1].taskName == '总经理审批') {
                        this.vision = '总经理审批';
                        this.visionsts = '2';
                    } else if (res.data.taskList[res.data.taskList.length - 1].taskName == '宣传负责人审批') {
                        this.vision = '宣传负责人审批';
                        this.visionsts = '2';
                    } else if (res.data.taskList[res.data.taskList.length - 1].taskName == '上刊用印') {
                        this.vision = '上刊用印';
                    }
                    this.datalist.attList = JSON.parse(res.data.params.attList);
                    this.attList = [];
                    this.fileInfo.fileList = [];
                    this.datalist.attList.forEach(item => {
                        item.id = item.attchFileId;
                        this.fileInfo.fileList.push({
                            name: item.fileName,
                            url: '',
                            id: item.id,
                            attchFileId: item.attchFileId,
                            fileName: item.fileName
                        });
                        this.attList.push({
                            name: item.fileName,
                            url: '',
                            id: item.id,
                            attchFileId: item.attchFileId,
                            fileName: item.fileName
                        });
                    })
                    this.rovaList = res.data.taskList;
                    this.uploadstatus = true;
                });
            },
            //审批
            dialogCli(v, n) {
                this.dialogStatus = false;
                this.status = false;
                if (v === 3) {
                    this.infolist = {};
                    this.attList = [];
                    this.fileInfo.fileList = [];
                    return
                }
                let _this = this;
                this.infolist.opTime = _this.$formatDate(new Date(), "YYYY-MM-DD")
                if (v === 1) {
                    let params = {
                        dealType: '1',
                        dealTypeDesc: '打回',
                        procId: this.infolist.procId,
                        procVersion: this.infolist.procVersion,
                        remark: this.remark,
                        stepId: this.infolist.stepId,
                        taskId: this.infolist.taskId,
                        taskName: this.infolist.taskName,
                        opName: this.infolist.opName,
                        opNo: this.opno,
                        opTime: this.infolist.opTime,
                        params: {
                            procExeCondiVal: '不同意',
                            terminalRes: JSON.stringify(this.infolist),
                            assigneeNo: this.opno,
                            assigneeName: this.opname,
                        },
                        woNo: this.infolist.woNo,
                    }
                    if (n == 1) {
                        this.$http({
                            url: '/bpm/api/submitTask',
                            method: "post",
                            headers: {
                                "Content-Type": "application/json",
                            },
                            data: params,
                        }).then((res) => {
                            if (res.data.result === 1) {
                                _this.$message({
                                    message: res.data.desc,
                                    type: 'error'
                                });
                            } else {
                                _this.closedia();
                                _this.infolist = {};
                                _this.attList = [];
                                _this.fileInfo.fileList = [];
                                _this.getList(this.params, this.pageSize);
                            }
                        });
                    } else {
                        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.remark,
                        stepId: this.infolist.stepId,
                        taskId: this.infolist.taskId,
                        taskName: this.infolist.taskName,
                        opName: this.infolist.opName,
                        opNo: this.opno,
                        opTime: this.infolist.opTime,
                        params: {
                            woType: this.infolist.woType,
                            terminalRes: JSON.stringify(this.infolist),
                        },
                        woNo: this.infolist.woNo,

                    }
                    if (this.vision == '审批' && this.visionsts == '2') {
                        param.params.assigneeNo = this.opno;
                        param.params.assigneeName = this.opname;
                    }
                    if (this.vision == '三级经理审批' || this.vision == '二级经理审批' || this.vision == '宣传负责人审批') {
                        param.params.assigneeNo = this.treeListonly.leaderAuditNo;
                        param.params.assigneeName = this.treeListonly.leaderAuditName;
                    }
                    if (this.vision == '流程发起') {
                        param.params.assigneeNo = this.treeListonly.leaderAuditNo;
                        param.params.assigneeName = this.treeListonly.leaderAuditName;
                        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,
                                opName: this.attList[i].opName,
                                opNo: this.attList[i].opNo,
                                opTime: this.attList[i].opTime,
                                woNo: this.infolist.woNo,
                                attchFileId: this.attList[i].attchFileId,
                            });
                        }
                        param.params.attList = JSON.stringify(attList)
                    }
                    if (this.vision == '上刊用印') {
                        let param = new FormData();
                        param.append("woNo", this.infolist.woNo);
                        this.$http({
                            url: "/market/cAdvPubWo/excelExport",
                            method: "post",
                            headers: {
                                "Content-Type": "application/json",
                            },
                            responseType: "blob",
                            data: param,
                        }).then((response) => {
                            if (window.navigator && window.navigator.msSaveOrOpenBlob) {
                                let blob = new Blob([response.data], {
                                    type: 'application/vnd.ms-excel'
                                })
                                window.navigator.msSaveOrOpenBlob(blob,
                                    new Date().getTime() + '.xlsx')
                            } else {
                                /* 火狐谷歌的文件下载方式 */
                                var blob = new Blob([response.data])
                                var downloadElement = document.createElement('a')
                                var href = window.URL.createObjectURL(blob)
                                downloadElement.href = href
                                downloadElement.download = new Date().getTime() + '.xlsx'
                                document.body.appendChild(downloadElement)
                                downloadElement.click()
                                document.body.removeChild(downloadElement)
                                window.URL.revokeObjectURL(href)
                            }
                        });
                    }
                    this.checkexa = false;
                    this.submitInfo("/bpm/api/submitTask", param);
                }
            },
            //添加
            dialogCliadd(v) {
                let _this = this;
                let info = {};
                info.opTime = _this.$formatDate(new Date(), "YYYY-MM-DD");
                this.infolist.patime ? this.infolist.patime = _this.$formatDate(this.infolist.patime, "YYYY-MM-DD") :
                '';
                this.infolist.pbtime ? this.infolist.pbtime = _this.$formatDate(this.infolist.pbtime, "YYYY-MM-DD") :
                '';
                info.opNo = this.userInfo.loginNo;
                info.opName = this.userInfo.loginName;
                info.woTitle = this.infolist.woName;
                info.params = {};
                info.params.terminalRes = this.infolist;
                let infodatas = [];
                for (let i = 0; i < this.infodatas.length; i++) {
                    infodatas.push(this.infodatas[i])
                }
                info.params.terminalRes.factoryList = infodatas;
                info.params.terminalRes.allSum = this.allSum;
                info.params.terminalRes.woTypeCode = this.woTypeCode;
                info.params.terminalRes.suppinfo = this.suppinfo;
                info.params.terminalRes.otherinfo = this.otherinfo;
                info.procId = this.terminal;
                info.params.assigneeNo = this.treeListonly.leaderAuditNo;
                info.params.assigneeName = this.treeListonly.leaderAuditName;
                for (let i = 0; i < this.options.length; i++) {
                    if (this.terminal == this.options[i].procId) {
                        info.procName = this.options[i].procName;
                        info.procVersion = this.options[i].procVersion;
                    }
                }
                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,
                        opName: this.attList[i].opName,
                        opNo: this.attList[i].opNo,
                        opTime: this.attList[i].opTime,
                        woNo: this.infolist.woNo,
                        attchFileId: this.attList[i].attchFileId,
                    });
                }
                info.params.attList = JSON.stringify(attList)
                info.params.terminalRes = JSON.stringify(info.params.terminalRes);
                this.checkexa = false;
                this.submitInfo("/bpm/api/startProc", info);
            },
            sumzero() {
                this.$refs.infolist.validate(valid => {
                    if (valid) {
                        if (!this.allSum) {
                            this.$message({
                                message: '总价金额不能为0!',
                                type: 'error'
                            });
                            return
                        }
                        // if (this.suppinfo.surplusSum < this.allSum) {
                        if (this.suppinfo.surplusSum < this.otherinfo.contractAdvCost) {
                            this.$message({
                                message: '供应商剩余预算不足!',
                                type: 'error'
                            });
                            return
                        }
                        this.$http({
                            url: "/market/cAdvPubBudget/queryPage",
                            method: "post",
                            headers: {
                                "Content-Type": "application/json",
                                "page": '{"pageNo":"' + 1 + '","pageSize":"1000"}'
                            },
                            data: {},
                        }).then((res) => {
                            // if (res.data.data[0].surplusSum < this.allSum) {
                            if (res.data.data[0].surplusSum < this.otherinfo.contractAdvCost) {
                                this.$message({
                                    message: '地市预算不足!',
                                    type: 'error'
                                });
                                return
                            }
                        });
                        if (this.companyFlag == 0 && this.vision == '总经理审批') {
                            this.treeListonly.leaderAuditNo = 'feixianzong'
                            this.treeListonly.leaderAuditName = '费显宗'
                            this.dialogCli(2);
                        } else if (this.companyFlag == 0 && this.vision == '二级经理审批') {
                            this.treeListonly.leaderAuditNo = 'wangqixia'
                            this.treeListonly.leaderAuditName = '王其侠'
                            this.dialogCli(2);
                        } else {
                            this.checkexa = true
                        }
                    }
                })
            },
            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.closedia();
                                _this.infolist = {};
                                _this.attList = [];
                                _this.fileInfo.fileList = [];
                                _this.getList(this.params, this.pageSize);
                            }

                        });
                    }
                })
            },
            getStanding(v) {
                if (v == 1) {
                    this.$router.push({
                        path: '/advgys',
                    });
                    this.setabList('供应商管理', '/advgys');
                } else {
                    this.$router.push({
                        path: '/advysx',
                    });
                    this.setabList('预算及上限', '/advysx');
                }
            },
            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));
            },
            //流程
            getTermianl() {
                this.$http({
                    url: "/bpm/api/queryBpmProcList",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                        "page": '{"pageNo":"' + 1 + '","pageSize":"100"}'
                    },
                    data: {},
                }).then((res) => {
                    this.options = res.data.data;
                });
            },
            closeMessage(v) {
                this.centerDialogVisible = false;
                let _this = this;
                if (v === 1) {
                    this.dialogCli(1, 1);
                }
            },
            //删除
            delLine(v, n) {
                this.centerDialogVisible = true;
                this.messTit = '即将撤销此条数据, 是否撤销?';
                this.delid = v;
                let infolist = Object.assign({}, n);
                this.vision = '';
                this.visionsts = '';
                this.infodatas = [{}, {}];
                this.$http({
                    url: '/bpm/api/taskInit',
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        woNo: n.woNo
                    },
                }).then((res) => {
                    this.terminal = infolist.procId;
                    this.opname = res.data.opName;
                    this.opno = res.data.opNo;
                    this.infolist = JSON.parse(res.data.params.terminalRes);
                    this.infolist.procId = infolist.procId;
                    this.infolist.procVersion = infolist.procVersion;
                    this.infolist.stepId = res.data.taskList[res.data.taskList.length - 1].stepId;
                    this.infolist.taskId = res.data.taskList[res.data.taskList.length - 1].taskId;
                    this.infolist.taskName = res.data.taskList[res.data.taskList.length - 1].taskName;
                    this.infolist.opName = infolist.opName;
                    this.infolist.opNo = infolist.opNo;
                    this.infolist.opTime = infolist.opTime;
                    this.infolist.woNo = infolist.woNo;
                    this.datalist.attList = JSON.parse(res.data.params.attList);
                    this.remark = '';
                });
            },
            //文件返回值
            uploadBack(v) {
                this.attList = 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.$http({
                    url: "/sysmgr/csysuserinfo/queryUserInfoByLoginNo",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {},
                }).then((res) => {
                    this.companyFlag = res.data.companyFlag;
                });
                 this.$http({
                    url: "/market/cAdvPubWo/isXqfq",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {},
                }).then((res) => {
                    if(res.data.body == 1){
                        this.terminal='754971596344848384'
                    }else{
                        this.terminal='729291034548674560'
                    }
                });
            }
        },
        mounted() {
            this.getList({}, 1);
            this.getUser();
            this.getTermianl();
        },
        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: 100px;
            display: inline-block;
            text-align: left;

            i {
                color: red;
                display: inline-block;
                padding-right: 5px;
            }
        }

        .el-select,
        .el-input {
            width: calc(100% - 120px);
        }
    }

    .online {
        width: 100%;

        .el-select {
            width: calc(100% - 120px);
        }

        span {
            vertical-align: top;
        }

        .el-textarea {
            width: calc(100% - 120px);
        }

        .tree {
            width: calc(50% - 60px);
            display: inline-block;
            margin-right: 20px;
            height: 300px;
            overflow-y: scroll;

            .el-icon-error {
                float: right;
                font-size: 20px;
                margin-top: 9px;
                cursor: pointer;
            }
        }

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

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