<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">
          <el-button type="primary" size="small" @click="storage()">保存</el-button>
        </div>
      </div>
    </div>
    <trade-card title="基础资料" style="margin-top: 50px">
      <avue-form :option="optionForm" v-model="form"></avue-form>
    </trade-card>
    <trade-card title="箱信息">
      <avue-crud ref="crudBox" :option="optionBox" :data="dataListBox"></avue-crud>
    </trade-card>
    <trade-card title="代理信息">
      <avue-crud ref="crudAgent" :option="optionAgent" :data="dataListAgent"></avue-crud>
    </trade-card>
    <trade-card title="投标对比">
      <avue-crud ref="crudAgent" :option="optionBid" :data="dataListBid"></avue-crud>
    </trade-card>
  </div>
</template>

<script>
import {detailDelegationList, saveSaveList} from "@/api/bidingDocument/issueTender";

export default {
  name: "detailsPageEdit",
  data(){
    return {
      fullscreenLoading:false,
      optionForm:{
        submitBtn:false,
        emptyBtn:false,
        span:6,
        column:[{
          label:'发布日期',
          prop:'releaseTime',
          type: "datetime",
          format:'yyyy-MM-dd HH:mm:ss',
          valueFormat:'yyyy-MM-dd HH:mm:ss'
        },{
          label:'截止日期',
          prop:'deadlineTime',
          type: "datetime",
          format:'yyyy-MM-dd HH:mm:ss',
          valueFormat:'yyyy-MM-dd HH:mm:ss'
        },{
          label:'合同号',
          prop:'contractNo',
        },{
          label:'状态',
          prop:'status',
          dataType: "string",
          type: 'select',
          dicUrl: "/api/blade-system/dict-biz/dictionary?code=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"
          }
        },{
          label:'目的港',
          prop:'objectiveHarbor',
          filterable: true,
          type: "select",
          dicUrl:"/api/blade-client/port/allList",
          props: {
            label: "name",
            value: "name"
          }
        },{
          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:ss',
          valueFormat:'yyyy-MM-dd HH:mm:ss'
        },{
          label:'是否直航',
          prop:'directFlight',
          type: 'select',
          dicData:[{
            label:'是',
            value:1
          },{
            label:'否',
            value:0
          }]
        },{
          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"
          }
        },{
          label:'运输条款',
          prop:'transportClause',
        },{
          label:'件数',
          prop:'number',
        },{
          label:'包装',
          prop:'packing',
          type: 'select',
          dicUrl: "/api/blade-system/dict-biz/dictionary?code=packaging",
          props: {
            label: "dictValue",
            value: "dictValue"
          }
        },{
          label:'重量(kgs)',
          prop:'weight',
        },{
          label:'尺码(cmb)',
          prop:'size',
        },{
          label:'货物信息',
          prop:'cargoInformation',
          span:18,
        },{
          label:'备注',
          prop:'remark',
          type:'textarea',
          span:24,
        }]
      },
      optionBox:{
        align:'center',
        refreshBtn:false,
        addBtn:false,
        addRowBtn:true,
        cellBtn:true,
        column:[{
          label:'箱型',
          prop: 'boxType',
          cell: true,
        },{
          label:'箱量',
          prop: 'boxAmount',
          cell: true,
        },{
          label:'海运费',
          prop: 'seaFreight',
          cell: true,
        },{
          label:'起运港箱使费',
          prop: 'departureHarborFee',
          cell: true,
        },{
          label:'目的港箱使费',
          prop: 'objectiveHarborFee',
          cell: true,
        },{
          label:'状态',
          prop: 'status',
          type: 'select',
          dataType: "string",
          dicUrl: "/api/blade-system/dict-biz/dictionary?code=bid_status",
          props: {
            label: "dictValue",
            value: "dictKey"
          },
          cell: true,
        },{
          label:'备注',
          prop: 'remark',
          cell: true,
        }]
      },
      optionAgent:{
        align:'center',
        refreshBtn:false,
        addBtn:false,
        addRowBtn:true,
        cellBtn:true,
        column:[{
          label:'名称',
          prop: 'agentName',
          cell: true,
        },{
          label:'联系人',
          prop: 'contacts',
          cell: true,
        },{
          label:'邮箱',
          prop: 'mailbox',
          cell: true,
        },{
          label:'电话',
          prop: 'phone',
          cell: true,
        },{
          label:'状态',
          prop: 'status',
          type: 'select',
          dataType: "string",
          dicUrl: "/api/blade-system/dict-biz/dictionary?code=bid_status",
          props: {
            label: "dictValue",
            value: "dictKey"
          },
          cell: true,
        },{
          label:'备注',
          prop: 'remark',
          cell: true,
        }]
      },
      optionBid:{
        align:'center',
        refreshBtn:false,
        addBtn:false,
        addRowBtn:true,
        cellBtn:true,
        column:[{
          label:'名称',
          prop: 'contrastName',
          cell: true,
        },{
          label:'船公司',
          prop: 'shippingCompany',
          cell: true,
        },{
          label:'船名',
          prop: 'shipName',
          cell: true,
        },{
          label:'箱型',
          prop: 'boxType',
          cell: true,
        },{
          label:'运费',
          prop: 'seaFreight',
          cell: true,
        },{
          label:'起运港箱使费',
          prop: 'departureHarborFee',
          cell: true,
        },{
          label:'目的港箱使费',
          prop: 'objectiveHarborFee',
          cell: true,
        },{
          label:'状态',
          prop: 'status',
          type: 'select',
          dataType: "string",
          dicUrl: "/api/blade-system/dict-biz/dictionary?code=bid_status",
          props: {
            label: "dictValue",
            value: "dictKey"
          },
          cell: true,
        },{
          label:'备注',
          prop: 'remark',
          cell: true,
        }]
      },
      form:{},
      dataListBox:[],
      dataListAgent:[],
      dataListBid:[],
    }
  },
  props: {
    id: {
      type: String
    }
  },
  created() {
    if (this.id){
      this.refreshData(this.id)
    }
  },
  methods:{
    backToList(){
      this.$emit('backToList', false)
    },
    storage(){
      let form = {
        ...this.form,
        itemsList:this.dataListBox,
        agentList:this.dataListAgent,
        contrastList:this.dataListBid
      }
      // this.loading = true;
      saveSaveList(form).then(res=>{
        console.log(res)
        this.refreshData(res.data.data.id)
      })
    },
    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>
