<template>
  <div v-loading.fullscreen.lock="fullscreenLoading">
    <div class="customer-head">
      <div class="customer-back">
        <el-button
            type="danger"
            style="border: none;background: none;color: red"
            icon="el-icon-arrow-left"
            @click="backToList"
        >返回列表
        </el-button>
      </div>
      <div>
        <div class="el-button&#45;&#45;small-yh add-customer-btn" v-if="param.paramValue == 1">
          <el-button type="success" size="small" @click="release()" :disabled="form.status !== 0">发布</el-button>
          <el-button type="warning" size="small" @click="toVoid()" :disabled="form.status !== 4">取消发布</el-button>
          <el-button type="primary" size="small" @click="storage()">保存</el-button>
        </div>
        <div class="el-button&#45;&#45;small-yh add-customer-btn" v-else>
          <el-button type="success" size="small" @click="release()" :disabled="form.status !== 3">发布</el-button>
          <el-button type="warning" size="small" @click="pleaseCheck()" :disabled="form.status !== 0">请核</el-button>
          <el-button type="warning" size="small" @click.stop="checkDialog = true,checkData = detailData.check" v-if="checkDisabled">审批</el-button>
          <el-button type="primary" size="small" @click="storage()">保存</el-button>
          <el-dropdown  style="margin-left: 10px">
            <el-button type="primary" size="small">
              业务处理<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="copyNew()" :disabled="!form.id">复制新增</el-dropdown-item>
              <el-dropdown-item @click.native="toVoid()" :disabled="form.status < 4 || !form.status">取消发布</el-dropdown-item>
              <el-dropdown-item @click.native="checkScheduleDialog = true,checkId=form.id" :disabled="form.status < 0 || !form.status">审批流程</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </div>
    </div>
    <trade-card title="基础资料" style="margin-top: 50px">
      <avue-form :option="optionForm" v-model="form" ref="form"></avue-form>
    </trade-card>
    <trade-card title="箱信息">
      <avue-crud ref="crudBox" :key="key" :option="optionBox" :data="dataListBox"
                 @resetColumn="resetColumn('crudBox','optionBox','optionBoxTwo',201.1)"
                 @saveColumn="saveColumn('crudBox','optionBox','optionBoxTwo',201.1)">
        <template slot-scope="{row,index}" slot="menu">
          <el-button
              type="text"
              size="small"
              :icon="row.$cellEdit?'el-icon-circle-plus-outline':'el-icon-edit'"
              @click="edit(row)"
          >{{ row.$cellEdit ? '确 认' : '编 辑' }}
          </el-button>
          <el-button
              type="text"
              size="small"
              icon="el-icon-delete"
              v-if="form.status === 0"
              @click="rowDel(row,index,'box')"
          >删 除
          </el-button>
        </template>
      </avue-crud>
    </trade-card>
    <trade-card title="代理信息">
      <avue-crud ref="crudAgent" :key="key" :option="optionAgent" :data="dataListAgent"
                 @resetColumn="resetColumn('crudAgent','optionAgent','optionAgentTwo',201.2)"
                 @saveColumn="saveColumn('crudAgent','optionAgent','optionAgentTwo',201.2)">
        <template slot-scope="{row,index}" slot="menu">
          <el-button
              type="text"
              size="small"
              :icon="row.$cellEdit?'el-icon-circle-plus-outline':'el-icon-edit'"
              @click="edit(row)"
          >{{ row.$cellEdit ? '确 认' : '编 辑' }}
          </el-button>
          <el-button
              type="text"
              size="small"
              icon="el-icon-delete"
              v-if="form.status === 0"
              @click="rowDel(row,index,'agent')"
          >删 除
          </el-button>
        </template>
        <template slot="menuLeft">
          <el-button
              type="success"
              size="small"
              icon="el-icon-bottom"
              @click="dialogVisible = true"
          >导入
          </el-button>
        </template>
      </avue-crud>
    </trade-card>
    <trade-card title="投标对比">
      <avue-crud ref="crudBid" :key="key" :option="optionBid" :data="dataListBid"
                 @resetColumn="resetColumn('crudBid','optionBid','optionBidTwo',201.3)"
                 @saveColumn="saveColumn('crudBid','optionBid','optionBidTwo',201.3)">
        <template slot-scope="{row,index}" slot="menu">
          <el-button
              type="text"
              size="small"
              :icon="row.$cellEdit?'el-icon-circle-plus-outline':'el-icon-edit'"
              @click="edit(row)"
          >{{ row.$cellEdit ? '确 认' : '编 辑' }}
          </el-button>
          <el-button
              type="text"
              size="small"
              @click="winningTheBid(row,index)"
              v-if="row.status === 5"
          >确认中标
          </el-button>
        </template>
      </avue-crud>
    </trade-card>
    <el-dialog
        v-dialogdrag
        title="导入客户"
        :fullscreen="dialogFull"
        :visible.sync="dialogVisible"
        class="el-dialogDeep"
        append-to-body
        :close-on-click-modal="false"
        width="80%"
    >
      <template slot="title">
        <span class="el-dialog__title">
          <span
              style="display:inline-block;background-color: #3478f5;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px"
          ></span>
          导入客户
        </span>
        <div
            style="float: right"
            class="avue-crud__dialog__menu"
            @click="dialogFull ? (dialogFull = false) : (dialogFull = true)"
        >
          <i class="el-icon-full-screen"></i>
        </div>
      </template>
      <el-row style="height: 0">
        <el-col :span="5">
          <div class="box">
            <el-scrollbar>
              <basic-container>
                <avue-tree
                    :option="treeOption"
                    :data="treeData"
                    @node-click="nodeClick"
                />
              </basic-container>
            </el-scrollbar>
          </div>
        </el-col>
        <el-col :span="19">
          <basic-container>
            <avue-crud
                :option="option"
                :data="dataList"
                ref="crud"
                v-model="form"
                :page.sync="page"
                :before-close="beforeClose"
                @search-change="searchChange"
                @search-reset="searchReset"
                @refresh-change="refreshChange"
                @selection-change="selectionChange"
                @on-load="onLoad"
                @saveColumn="saveColumn('crud','option','option',47)"
                @tree-load="treeLoad"
            >
            </avue-crud>
          </basic-container>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button
            type="primary"
            @click="confirmSelection"
            :disabled="selection.length > 0 ? false : true"
        >确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog
        append-to-body
        title="审批"
        class="el-dialogDeep"
        :visible.sync="checkDialog"
        width="50%"
        :close-on-click-modal="false"
        :destroy-on-close="true"
        :close-on-press-escape="false"
        v-dialog-drag
    >
      <check
          :checkData="checkData"
          :checkDetail="false"
          :idList="[]"
          @choceCheckFun="checkDialog = false"
      >
      </check>
    </el-dialog>
    <el-dialog
        append-to-body
        title="审批进度"
        class="el-dialogDeep"
        :visible.sync="checkScheduleDialog"
        width="40%"
        :close-on-click-modal="false"
        :destroy-on-close="true"
        :close-on-press-escape="false"
        v-dialog-drag
    >
      <check-schedule
          :checkId="checkId"
          :batchNo="batchNo"
          @choceScheduleFun="checkScheduleDialog = false"
      >
      </check-schedule>
    </el-dialog>
  </div>
</template>

<script>
import {
  detailDelegationList,
  saveSaveList,
  boxDelete,
  agentDelete,
  confirmRelease, confirmVoid, confirmPleaseCheck, confirmWinningTheBid,allList,paramList
} from "@/api/bidingDocument/issueTender";
import check from "@/components/check/check";
import checkSchedule from "@/components/check/checkSchedule";
import {dateFormat} from "@/util/date";
import option from "@/components/selectComponent/configuration/mainList.json";
import {customerList, getDeptLazyTree} from "@/api/basicData/customerInformation";
import {customerParameter} from "@/enums/management-type";
import {getDictionary} from "@/api/system/dictbiz";
export default {
  name: "detailsPageEdit",
  components:{
    check,
    checkSchedule
  },
  watch: {
    form: {
      handler(newValue, oldValue) {
        if (this.form.status > 0){
          this.$set(this.optionForm,'disabled',true)
          this.$set(this.optionBox,'addRowBtn',false)
          this.$set(this.optionAgent,'addRowBtn',false)
          this.optionBox.column.forEach(item=>{
            this.$set(item,'disabled',true)
            if (item.prop === "remark"){
              this.$set(item,'disabled',false)
            }
          })
          this.optionAgent.column.forEach(item=>{
            this.$set(item,'disabled',true)
            if (item.prop === "remark"){
              this.$set(item,'disabled',false)
            }
          })
        }else {
          this.$set(this.optionForm,'disabled',false)
          this.findObject(this.optionForm.column, "status").disabled = true
          this.$set(this.optionBox,'disabled',false)
          if (this.optionBox.column){
            this.findObject(this.optionBox.column, "status").disabled = true
          }
          this.$set(this.optionAgent,'disabled',false)
          if (this.optionAgent.column){
            this.findObject(this.optionAgent.column, "status").disabled = true
          }
        }
      }
    }
  },
  data() {
    return {
      dialogVisible:false,
      option:{},
      treeOption: {
        nodeKey: "id",
        lazy: true,
        treeLoad: function (node, resolve) {
          const parentId = node.level === 0 ? 0 : node.data.id;
          getDeptLazyTree({
            parentId: parentId,
            corpType: customerParameter.code
          }).then(res => {
            resolve(
                res.data.data.map(item => {
                  return {
                    ...item,
                    leaf: !item.hasChildren
                  };
                })
            );
          });
        },
        addBtn: false,
        menu: false,
        size: "small",
        props: {
          labelText: "标题",
          label: "title",
          value: "value",
          children: "children"
        }
      },
      dataList:[],
      page: {
        pageSize: 10,
        pagerCount: 5,
        total: 0
      },
      dialogFull: false,
      checkDialog:false,
      checkScheduleDialog:false,
      checkId: '',
      batchNo:'',
      line:'',
      key:0,
      selection:[],
      checkData: {},
      fullscreenLoading: false,
      optionForm: {
        submitBtn: false,
        emptyBtn: false,
        span: 6,
        column: [{
          label: '发布日期',
          prop: 'releaseTime',
          type: "datetime",
          format: 'yyyy-MM-dd HH:mm',
          valueFormat: 'yyyy-MM-dd HH:mm:ss',
          value:dateFormat(new Date, 'yyyy-MM-dd hh:mm:ss'),
          rules: [{
            required: true,
            message: " ",
            trigger: "change"
          }],
        }, {
          label: '截止日期',
          prop: 'deadlineTime',
          type: "datetime",
          format: 'yyyy-MM-dd HH:mm',
          valueFormat: 'yyyy-MM-dd HH:mm:ss',
          rules: [{
            required: true,
            message: " ",
            trigger: "change"
          }],
        }, {
          label: '合同号',
          prop: 'contractNo',
          rules: [{
            required: true,
            message: " ",
            trigger: "change"
          }],
        }, {
          label: '状态',
          disabled:true,
          prop: 'status',
          dataType: "number",
          type: 'select',
          dicUrl: "/api/blade-system/dict-biz/dictionary?code=main_bid_status",
          props: {
            label: "dictValue",
            value: "dictKey"
          }
        }, {
          label: '起运港',
          prop: 'departureHarbor',
          filterable: true,
          type: "select",
          dicUrl: "/api/blade-client/port/allList",
          props: {
            label: "name",
            value: "name"
          },
          rules: [{
            required: true,
            message: " ",
            trigger: "change"
          }],
        }, {
          label: '目的港',
          prop: 'objectiveHarbor',
          filterable: true,
          type: "select",
          dicUrl: "/api/blade-client/port/allList",
          props: {
            label: "name",
            value: "name"
          },
          change:(data)=>{
            allList().then(res=>{
              for (let item of res.data.data){
                if (data.value == item.name){
                  this.line = item.line
                }
              }
            })
          },
          rules: [{
            required: true,
            message: " ",
            trigger: "change"
          }],
        }, {
          label: '起运地',
          prop: 'departureLand',
          filterable: true,
          type: "select",
          dicUrl: "/api/blade-client/port/allList",
          props: {
            label: "name",
            value: "name"
          }
        }, {
          label: '目的地',
          prop: 'objectiveLand',
          filterable: true,
          type: "select",
          dicUrl: "/api/blade-client/port/allList",
          props: {
            label: "name",
            value: "name"
          }
        }, {
          label: '装柜日期',
          prop: 'loadingTime',
          type: "datetime",
          format: 'yyyy-MM-dd HH:mm',
          valueFormat: 'yyyy-MM-dd HH:mm:ss',
          rules: [{
            required: true,
            message: " ",
            trigger: "change"
          }],
        }, {
          label: '是否直航',
          prop: 'directFlight',
          type: 'select',
          dicData: [{
            label: '是',
            value: 1
          }, {
            label: '否',
            value: 0
          }],
          value:1,
          rules: [{
            required: true,
            message: " ",
            trigger: "change"
          }],
        }, {
          label: '转港',
          prop: 'transshipment',
          filterable: true,
          type: "select",
          dicUrl: "/api/blade-client/port/allList",
          props: {
            label: "name",
            value: "name"
          }
        }, {
          label: '运输方式',
          prop: 'transportType',
          type: 'select',
          dicUrl: "/api/blade-system/dict-biz/dictionary?code=mode_transport",
          props: {
            label: "dictValue",
            value: "dictValue"
          },
          value:"海运",
          rules: [{
            required: true,
            message: " ",
            trigger: "change"
          }],
        }, {
          label: '运输条款',
          prop: 'transportClause',
          value: "CY-CY",
          rules: [{
            required: true,
            message: " ",
            trigger: "change"
          }],
        }, {
          label: '件数',
          prop: 'number',
          value:10,
          rules: [{
            required: true,
            message: " ",
            trigger: "change"
          }],
        }, {
          label: '包装',
          prop: 'packing',
          type: 'select',
          dicUrl: "/api/blade-system/dict-biz/dictionary?code=packaging",
          props: {
            label: "dictValue",
            value: "dictValue"
          },
          value:"木箱",
          rules: [{
            required: true,
            message: " ",
            trigger: "change"
          }],
        }, {
          label: '重量(kgs)',
          prop: 'weight',
          value:27000,
          rules: [{
            required: true,
            message: " ",
            trigger: "change"
          }],
        }, {
          label: '尺码(cmb)',
          prop: 'size',
          value:18,
          rules: [{
            required: true,
            message: " ",
            trigger: "change"
          }],
        }, {
          label: '货物信息',
          prop: 'cargoInformation',
          span: 18,
          value: "GLASS",
          rules: [{
            required: true,
            message: " ",
            trigger: "change"
          }],
        }, {
          label: '备注',
          prop: 'remark',
          type: 'textarea',
          span: 24,
        }]
      },
      optionBox:{},
      optionBoxTwo: {
        align: 'center',
        index: true,
        refreshBtn: false,
        addBtn: false,
        addRowBtn: true,
        cellBtn: false,
        editBtn: false,
        delBtn: false,
        column: [{
          label: '箱型',
          prop: 'boxType',
          cell: true,
          type: "select",
          dicUrl: "/api/blade-system/dict-biz/dictionary?code=boxType",
          props: {
            label: "dictValue",
            value: "dictValue"
          },
          index:1,
        }, {
          label: '箱量',
          prop: 'boxAmount',
          cell: true,
          index:2,
        },
          // {
        //   label: '海运费',
        //   prop: 'seaFreight',
        //   cell: true,
        //   index:3,
        // }, {
        //   label: '起运港箱使费',
        //   prop: 'departureHarborFee',
        //   cell: true,
        //   index:4,
        // }, {
        //   label: '目的港箱使费',
        //   prop: 'objectiveHarborFee',
        //   cell: true,
        //   index:5,
        // },
          {
          label: '状态',
          prop: 'status',
          type: 'select',
          dataType: "string",
          dicUrl: "/api/blade-system/dict-biz/dictionary?code=main_bid_status",
          props: {
            label: "dictValue",
            value: "dictKey"
          },
          index:6,
        }, {
          label: '备注',
          prop: 'remark',
          cell: true,
          index:7,
        }]
      },
      optionAgent:{},
      optionAgentTwo: {
        align: 'center',
        index: true,
        refreshBtn: false,
        addBtn: false,
        addRowBtn: true,
        cellBtn: false,
        editBtn: false,
        delBtn: false,
        column: [{
          label: '名称',
          prop: 'agentId',
          filterable:true,
          cell: true,
          dicUrl: '/api/blade-client/corpsdesc/bidingCorpsList',
          type: 'select',
          props: {
            label: "cname",
            value: "id"
          },
          index:1,
        }, {
          label: '联系人',
          prop: 'contacts',
          cell: true,
          index:2,
        }, {
          label: '邮箱',
          prop: 'mailbox',
          cell: true,
          index:3,
        }, {
          label: '电话',
          prop: 'phone',
          cell: true,
          index:4,
        }, {
          label: '状态',
          prop: 'status',
          type: 'select',
          dataType: "string",
          dicUrl: "/api/blade-system/dict-biz/dictionary?code=main_bid_status",
          props: {
            label: "dictValue",
            value: "dictKey"
          },
          index:5,
        }, {
          label: '备注',
          prop: 'remark',
          cell: true,
          index:6,
        }]
      },
      optionBid:{},
      optionBidTwo: {
        align: 'center',
        index:true,
        refreshBtn: false,
        addBtn: false,
        addRowBtn: false,
        cellBtn: false,
        editBtn: false,
        delBtn: false,
        menuWidth:140,
        column: [{
          label: '名称',
          prop: 'contrastName',
          index:1,
        }, {
          label: '船公司',
          prop: 'shippingCompany',
          index:2,
        }, {
          label: '船名',
          prop: 'shipName',
          index:3,
        }, {
          label: '箱型',
          prop: 'boxType',
          type: "select",
          dicUrl: "/api/blade-system/dict-biz/dictionary?code=boxType",
          props: {
            label: "dictValue",
            value: "dictValue"
          },
          index:4,
        }, {
          label: '运费',
          prop: 'seaFreight',
          index:5,
        }, {
          label: '截单时间',
          prop: 'cutOffTime',
          index:6,
        }, {
          label: '截港时间',
          prop: 'harborInterceptionTime',
          index:7,
        }, {
          label: '船期',
          prop: 'shippingDate',
          index:8,
        }, {
          label: '起运港箱使天数',
          prop: 'departureHarborFee',
          index:9,
        }, {
          label: '目的港箱使天数',
          prop: 'objectiveHarborFee',
          index:10,
        }, {
          label: '状态',
          prop: 'status',
          type: 'select',
          dataType: "string",
          dicUrl: "/api/blade-system/dict-biz/dictionary?code=main_bid_status",
          props: {
            label: "dictValue",
            value: "dictKey"
          },
          index:11,
        }, {
          label: '备注',
          prop: 'remark',
          cell: true,
          index:12,
        }]
      },
      form: {},
      dataListBox: [],
      dataListAgent: [],
      dataListBid: [],
      param:{},
      checkDisabled:false
    }
  },
  props: {
    id: {
      type: String
    },
    detailData: {
      type: Object
    }
  },
  async created() {
    paramList({
      paramKey:"release.approval",
      current:1,
      size:10
    }).then(res=>{
      for (let item of res.data.data.records){
        if (item.paramKey === "release.approval"){
          this.param = item
        }
      }
    })
    this.option = await this.getColumnData(this.getColumnName(47), option);
    if (this.id) {
      this.refreshData(this.id)
    }
    if (this.detailData.check) {
      this.checkDisabled = true
      this.batchNo = this.detailData.check.batchNo
    }
    this.optionBox = await this.getColumnData(this.getColumnName(201.1), this.optionBoxTwo);
    this.optionAgent = await this.getColumnData(this.getColumnName(201.2), this.optionAgentTwo);
    this.optionBid = await this.getColumnData(this.getColumnName(201.3), this.optionBidTwo);
    this.key++
  },
  methods: {
    nodeClick(data) {
      this.treeDeptId = data.id;
      this.page.currentPage = 1;
      this.onLoad(this.page);
    },
    //确认导出触发
    confirmSelection() {
      for (let item of this.selection){
        this.dataListAgent.push({
          $cellEdit: true,
          agentId:item.id,
          contacts:item.attn,
          phone:item.tel
        })
      }
      this.selection = [];
      this.dialogVisible = false;
    },
    //点击新增时触发
    beforeClose(done) {
      this.parentId = "";
      const column = this.findObject(this.option.column, "parentId");
      column.value = "";
      column.addDisabled = false;
      done();
    },
    //点击搜索按钮触发
    searchChange(params, done) {
      console.log(params);
      this.treeDeptId = "";
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    //搜索重置按钮触发
    searchReset() {
      this.treeDeptId = "";
      this.onLoad(this.page);
    },
    //刷新触发
    refreshChange() {
      this.page = {
        pageSize: 10,
        pagerCount: 5,
        total: 0
      };
    },
    //选中触发
    selectionChange(selection) {
      this.selection = selection;
    },
    //树桩列点击展开触发
    treeLoad(tree, treeNode, resolve) {
      const parentId = tree.id;
      customerList({
        parentId: parentId,
        corpType: this.corpType ? this.corpType : "KH"
      }).then(res => {
        resolve(res.data.data.records);
      });
    },
    onLoad(page, params = { parentId: 0 }) {
      let queryParams = Object.assign({}, params, {
        size: page.pageSize,
        current: page.currentPage,
        corpsTypeId: this.treeDeptId,
        corpType: this.corpType ? this.corpType : "KH",
        line:this.line
      });
      customerList(queryParams).then(res => {
        this.dataList = res.data.data.records;
        this.page.total = res.data.data.total;
        if (this.page.total) {
          this.option.height = window.innerHeight - 500;
        } else {
          this.option.height = window.innerHeight - 200;
        }
      });
    },
    //自定义列保存
    async saveColumn(ref, option, optionBack, code) {
      /**
       * 已定义全局方法，直接使用，saveColumnData保存列数据方法,参数传值(表格名称，当前表格的option数据)
       * 已定义全局方法，直接使用，getColumnName方法用来获取枚举值，参数根据自己定义的code值获取中文名
       * 一定要执行异步操作，要等接口成功返回，才能执行下一行代码
       */
      const inSave = await this.saveColumnData(this.getColumnName(code), this[option]);
      if (inSave) {
        this.$message.success("保存成功");
        //关闭窗口
        this.$refs[ref].$refs.dialogColumn.columnBox = false;
      }
    },
    //自定义列重置
    async resetColumn(ref, option, optionBack, code) {
      this[option] = this[optionBack];
      const inSave = await this.delColumnData(this.getColumnName(code), this[optionBack]);
      if (inSave) {
        this.$message.success("重置成功");
        if (this.form.status > 0){
          this.$set(this.optionForm,'disabled',true)
          this.$set(this.optionBox,'addRowBtn',false)
          this.$set(this.optionAgent,'addRowBtn',false)
          this.optionBox.column.forEach(item=>{
            this.$set(item,'disabled',true)
            if (item.prop === "remark"){
              this.$set(item,'disabled',false)
            }
          })
          this.optionAgent.column.forEach(item=>{
            this.$set(item,'disabled',true)
            if (item.prop === "remark"){
              this.$set(item,'disabled',false)
            }
          })
        }else {
          this.$set(this.optionForm,'disabled',false)
          this.findObject(this.optionForm.column, "status").disabled = true
          this.$set(this.optionBox,'disabled',false)
          this.findObject(this.optionBox.column, "status").disabled = true
          this.$set(this.optionAgent,'disabled',false)
          this.findObject(this.optionAgent.column, "status").disabled = true
        }
        this.$refs[ref].$refs.dialogColumn.columnBox = false;
      }
    },
    edit(row){
      if (row.$cellEdit){
        this.$set(row,'$cellEdit',false)
      }else {
        this.$set(row,'$cellEdit',true)
      }
    },
    rowDel(row, index, type) {
      this.$confirm('是否确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (type === 'box') {
          if (row.id) {
            boxDelete({id: row.id}).then(res => {
              this.dataListBox.splice(index, 1);
              this.$message({
                type: 'success',
                message: '删除成功!'
              });
            })
          } else {
            this.dataListBox.splice(index, 1);
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
          }
        } else if (type === 'agent') {
          if (row.id) {
            agentDelete({id: row.id}).then(res => {
              this.dataListAgent.splice(index, 1);
              this.$message({
                type: 'success',
                message: '删除成功!'
              });
            })
          } else {
            this.dataListAgent.splice(index, 1);
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
          }
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    backToList() {
      this.$router.push({
        path: '/bidingDocument/issueTender/index'
      });
      this.$emit('backToList', false)
    },
    // 确认中标
    winningTheBid(row,index){
      this.$confirm('是否确认中标?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        confirmWinningTheBid({id:row.id}).then(res=>{
          this.$message({
            type: 'success',
            message: '确认中标!'
          });
          this.refreshData(this.id)
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    // 请核
    pleaseCheck(){
      this.$refs['form'].validate((valid, done) => {
        done()
        if (valid){
          this.$confirm('是否确认请核?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            if (new Date(this.form.deadlineTime) < new Date()) return this.$message.error("截止日期不能小于等于当前日期")
            let form = {
              ...this.form,
              itemsList: this.dataListBox,
              agentList: this.dataListAgent,
              contrastList: this.dataListBid
            }
            this.fullscreenLoading = true
            const loading = this.$loading({
              lock: true,
              text: '发布中',
              spinner: 'el-icon-loading',
              background: 'rgba(255,255,255,0.7)'
            });
            saveSaveList(form).then(res => {
              const data = {
                id: res.data.data.id,
                url: '/bidingDocument/issueTender/index',
                pageStatus: "this.$store.getters.entranceXsStatus"
              }
              confirmPleaseCheck(data).then(res=>{
                this.fullscreenLoading = false
                this.$message({
                  type: 'success',
                  message: '请核成功!'
                });
                loading.close();
                this.refreshData(this.form.id)
              })
            }).catch(()=>{
              loading.close();
              this.fullscreenLoading = false;
            })
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消'
            });
          });
        }else {
          done()
        }
      })
    },
    // 复制新增
    copyNew(){
      this.$confirm('是否确认复制新增?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.form.status = 0
        this.form.id = ''
        this.dataListBid = []
        this.dataListBox.forEach(item => item.id = '')
        this.dataListAgent.forEach(item => item.id = '')
        this.$set(this.optionForm,'disabled',false)
        this.$set(this.optionBox,'addRowBtn',true)
        this.$set(this.optionAgent,'addRowBtn',true)
        this.optionBox.column.forEach(item=>{
          this.$set(item,'disabled',false)
        })
        this.optionAgent.column.forEach(item=>{
          this.$set(item,'disabled',false)
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    // 作废
    toVoid(){
      this.$confirm('是否确认作废?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        confirmVoid({id:this.form.id}).then(res=>{
          this.$message({
            type: 'success',
            message: '作废成功!'
          });
          this.refreshData(this.form.id)
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    // 发布
    release(){
      this.$confirm('是否确认发布?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const loading = this.$loading({
          lock: true,
          text: '发布中',
          spinner: 'el-icon-loading',
          background: 'rgba(255,255,255,0.7)'
        });
        confirmRelease({id:this.form.id}).then(res=>{
          loading.close();
          this.$message({
            type: 'success',
            message: '发布成功!'
          });
          this.refreshData(this.form.id)
        }).catch(()=>{
          loading.close();
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    // 保存
    storage() {
      let form = {
        ...this.form,
        itemsList: this.dataListBox,
        agentList: this.dataListAgent,
        contrastList: this.dataListBid
      }
      this.fullscreenLoading = true
      saveSaveList(form).then(res => {
        this.refreshData(res.data.data.id)
      }).finally(() => {
        this.fullscreenLoading = false
      })
    },
    refreshData(id) {
      let ids = ''
      if (id) {
        ids = id
      } else {
        ids = this.form.id
      }
      this.fullscreenLoading = true
      detailDelegationList({id: ids}).then(res => {
        this.form = res.data.data
        this.dataListBox = this.form.itemsList
        this.dataListAgent = this.form.agentList
        this.dataListBid = this.form.contrastList
        delete this.form.itemsList
        delete this.form.agentList
        delete this.form.contrastList
        this.fullscreenLoading = false
      })
    },
  }
}
</script>

<style scoped lang="scss">
::v-deep .el-form-item {
  margin-bottom: 8px;
}
</style>
