<template>
  <div>
    <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>
        <el-button
            class="el-button--small-yh add-customer-btn"
            type="success"
            v-if="goodsForm.status === 0"
            size="small"
            style="margin-right: 70px;"
            @click="submit(true)"
        >提交
        </el-button>
        <el-button
            class="el-button--small-yh add-customer-btn"
            type="success"
            v-if="goodsForm.status === 1"
            size="small"
            style="margin-right: 70px;"
            @click="submit(false)"
        >取消提交
        </el-button>
        <el-button
            class="el-button--small-yh add-customer-btn"
            type="primary"
            :disabled="goodsForm.status === 1 || type"
            size="small"
            @click="editCustomer"
        >保存
        </el-button>
      </div>
    </div>
    <containerTitle
        title="业务类型"
        style="margin-top: 50px"></containerTitle>
    <basic-container>
      <avue-form v-model="goodsForm" :option="goodsOptionFormC" ref="goodsFormE"></avue-form>
    </basic-container>
    <containerTitle title="起止地信息"></containerTitle>
    <basic-container>
      <el-table
          ref="singleTable"
          :data="tableData"
          size="mini"
          :header-cell-style="{color:'#000',background:'#fafafa'}"
          style="width: 100%">
        <el-table-column
            align="center"
            v-if="goodsForm.status !== 1"
            width="40">
          <template slot-scope="scope">
            <el-tooltip className="item" v-if="scope.$index === tableData.length-1" effect="dark" content="增加途径地址"
                        placement="top">
              <el-button type="primary" icon="el-icon-plus" size="mini" circle @click="addAddress"
                         style="margin-right: 1.25rem;"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column
            property="date"
            align="center"
            width="40">
          <template slot-scope="scope">
            <span v-if="scope.$index == 0">
              <el-button type="primary" size="mini" circle>起</el-button>
            </span>
            <span v-else-if="scope.$index === tableData.length-1">
              <el-button type="success" size="mini" circle>止</el-button>
            </span>
            <span v-else>
              <el-button v-if="goodsForm.status === 1" type="warning" size="mini" circle>途</el-button>
              <el-tooltip v-else class="item" effect="dark" content="删除" placement="left">
                  <el-button type="danger" icon="el-icon-delete" size="mini" circle
                             @click="deleteAddress(scope)"></el-button>
              </el-tooltip>
            </span>
          </template>
        </el-table-column>
        <el-table-column
            type="index"
            label="序号"
            align="center"
            width="60">
        </el-table-column>
        <el-table-column
            property="corpId"
            label="发货工厂"
            align="center"
            :render-header="customTitle"
            width="280">
          <template slot-scope="scope">
            <crop-select
                :corpType="'GC'"
                :disabled="goodsForm.status === 1"
                v-model="scope.row.corpId"
                @getCorpData="(row)=>{withAddress(row,scope)}"/>
          </template>
        </el-table-column>
        <el-table-column
            property="province"
            label="省市区"
            align="center"
            width="280">
          <template slot-scope="scope">
            <el-cascader
                size="small"
                style="width: 100%;"
                :key="scope.row.key"
                :disabled="goodsForm.status === 1"
                :props="treeOption"
                v-model="scope.row.region"></el-cascader>
          </template>
        </el-table-column>
        <el-table-column
            property="address"
            align="center"
            :render-header="customTitle"
            label="详细地址">
          <template slot-scope="scope">
            <el-input v-model="scope.row.address" :disabled="goodsForm.status === 1" size="small"
                      placeholder="请输入内容"></el-input>
          </template>
        </el-table-column>
      </el-table>
    </basic-container>
    <containerTitle title="委托信息"></containerTitle>
    <basic-container>
      <avue-form :option="goodsOptionForm" ref="goodsForm" v-model="goodsForm">
        <template slot-scope="scope" slot="corpId">
          <crop-select
              :disabled="goodsForm.status === 1"
              v-model="goodsForm.corpId"
              @getCorpData="getCorpData"
              :corpType="'KH'"
          ></crop-select>
        </template>
        <template slot-scope="scope" slot="station">
          <port-info
              v-model="goodsForm.station"
              :disabled="goodsForm.status === 1"
          />
        </template>
        >
        <template slot-scope="scope" slot="salesman">
          <el-select v-model="goodsForm.salesman" placeholder="请选择">
            <el-option
                v-for="item in salesmanList"
                :key="item.id"
                :label="item.cname"
                :value="item.id">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="agentId">
          <crop-select
              :disabled="goodsForm.status === 1"
              v-model="goodsForm.agentId"
          ></crop-select>
        </template>
        <template slot-scope="scope" slot="polId">
          <port-info
              v-model="goodsForm.polId"
              :disabled="goodsForm.status === 1"
          />
        </template>
        <template slot-scope="scope" slot="podId">
          <port-info
              v-model="goodsForm.podId"
              :disabled="goodsForm.status === 1"
          />
        </template>
      </avue-form>
    </basic-container>
    <containerTitle title="箱信息"></containerTitle>
    <basic-container v-if="goodsForm.status === 0 || !goodsForm.status">
      <avue-crud :data="entrustList"
                 :option="entrustOptionTwo"
                 @row-save="(row,done,loading)=>{rowSave(row,0,done,loading)}"
                 @row-update="rowSave"
                 ref="crudBox"
                 v-if="KeyBox>0"
                 @resetColumn="resetColumnBox"
                 @saveColumn="saveColumnBox"
                 @row-del="rowDel">
        <template slot="headerSerial" slot-scope="{column}">
          <el-tooltip class="item" effect="dark" content="录入明细" placement="top">
            <el-button type="primary" icon="el-icon-circle-plus-outline" circle size="mini"
                       @click="$refs.crudBox.rowCellAdd({arrivalTime:goodsForm.arrivalTime})"></el-button>
          </el-tooltip>
        </template>
        <template slot="ctnTypeHeader" slot-scope="{column}">
          {{ column.label }}<span style="color:#F56C6C">*</span>
        </template>
        <template slot="ctnQuantityHeader" slot-scope="{column}">
          {{ column.label }}<span style="color:#F56C6C">*</span>
        </template>
        <template slot="landWeightHeader" slot-scope="{column}">
          {{ column.label }}<span style="color:#F56C6C">*</span>
        </template>
        <template slot="landAmountDHeader" slot-scope="{column}">
          {{ column.label }}<span style="color:#F56C6C">*</span>
        </template>
        <!--        <template slot="arrivalTimeHeader" slot-scope="{column}">-->
        <!--          {{ column.label }}<span style="color:#F56C6C">*</span>-->
        <!--        </template>-->
      </avue-crud>
    </basic-container>
    <basic-container v-if="goodsForm.status !== 0 && goodsForm.status">
      <avue-crud
          :data="entrustList"
          :option="entrustOptionTwoT"
          ref="crudBoxTwo"
          v-if="KeyBoxTwo>0"
          @resetColumn="resetColumnBoxTwo"
          @saveColumn="saveColumnBoxTwo"
          @row-save="(row,done,loading)=>{rowSaveT(row,0,done,loading)}"
          @row-update="rowSaveT">
        <template slot="fleetId" slot-scope="{ row, index }">
          <crop-select
              v-if="row.$cellEdit"
              v-model="row.fleetId"
              :cropIndex="index"
              @getCorpData="(data)=>{getfleetIdT(data,row)}"
          ></crop-select>
          <span v-else>{{ row.fleetName }}</span>
        </template>
      </avue-crud>
    </basic-container>
    <containerTitle title="车辆信息"></containerTitle>
    <basic-container>
      <avue-crud
          :data="vehicleList"
          ref="crudContact"
          v-if="keyContact>0"
          @resetColumn="resetColumnContact"
          @saveColumn="saveColumnContact"
          :option="vehicleOption">
      </avue-crud>
    </basic-container>
    <containerTitle title="费用明细"></containerTitle>
    <basic-container>
      <el-tabs v-model="activeIndex" @tab-click="handleSelect">
        <el-tab-pane label="应收" name="1"></el-tab-pane>
        <el-tab-pane label="应付" name="2"></el-tab-pane>
      </el-tabs>
      <avue-crud
          v-if="activeIndex === '1'"
          :data="collectionList"
          :option="collectionOption"
          ref="collection"
          @resetColumn="resetColumnCollection"
          @saveColumn="saveColumnCollection"
          @row-save="(row,done,loading)=>{rowSave(row,0,done,loading)}"
          @row-update="rowSave"
          @row-del="makeDel">
        <template slot-scope="{row}" slot="corpId">
          <crop-select
              v-if="row.$cellEdit"
              v-model="row.corpId"
              :disabled="goodsForm.status === 1"
              @getCorpData="(data)=>{getfleetId(data,row)}"
          ></crop-select>
          <span v-else>{{ row.corpName }}</span>
        </template>
        <template slot-scope="{row}" slot="feeId">
          <breakdown-select
              v-if="row.$cellEdit"
              v-model="row.feeId"
              :disabled="goodsForm.status === 1"
              @selectValue="(value) => selectValue(value,row)"
              :configuration="breakConfiguration"
          >
          </breakdown-select>
          <span v-else>{{ row.feeName }}</span>
        </template>
        <template slot-scope="{row,index}" slot="menu">
          <el-button
              type="text"
              size="small"
              :disabled="goodsForm.status === 1"
              :icon="row.$cellEdit?'el-icon-circle-plus-outline':'el-icon-edit'"
              @click="rowCell(row,index)"
          >{{ row.$cellEdit ? '保存' : '编辑' }}
          </el-button>
          <el-button type="text"
                     icon="el-icon-delete"
                     size="small"
                     :disabled="goodsForm.status === 1"
                     @click="$refs.collection.rowDel(row,index)"
          >删除
          </el-button>
        </template>
        <template slot="menuLeft">
          <el-button type="primary" icon="el-icon-plus" :disabled="goodsForm.status === 1" @click="addRowCollection"
                     size="small">录入明细
          </el-button>
        </template>
      </avue-crud>
      <avue-crud
          v-if="activeIndex === '2'"
          :data="paymentList"
          :option="paymentOption"
          ref="payment"
          @resetColumn="resetColumnPayment"
          @saveColumn="saveColumnPayment"
          @row-save="(row,done,loading)=>{rowSave(row,0,done,loading)}"
          @row-update="rowSave"
          @row-del="feeDel"
      >
        <template slot-scope="{row}" slot="corpId">
          <crop-select
              v-if="row.$cellEdit"
              v-model="row.corpId"
              :disabled="goodsForm.status === 1"
              @getCorpData="(data)=>{getfleetId(data,row)}"
          ></crop-select>
          <span v-else>{{ row.corpName }}</span>
        </template>
        <template slot-scope="{row}" slot="feeId">
          <breakdown-select
              v-if="row.$cellEdit"
              v-model="row.feeId"
              :disabled="goodsForm.status === 1"
              @selectValue="(value) => selectValue(value,row)"
              :configuration="breakConfiguration"
          >
          </breakdown-select>
          <span v-else>{{ row.feeName }}</span>
        </template>
        <template slot-scope="{row,index}" slot="menu">
          <el-button
              type="text"
              size="small"
              :disabled="goodsForm.status === 1"
              :icon="row.$cellEdit?'el-icon-circle-plus-outline':'el-icon-edit'"
              @click="paymentRowCell(row,index)"
          >{{ row.$cellEdit ? '保存' : '编辑' }}
          </el-button>
          <el-button type="text"
                     icon="el-icon-delete"
                     size="small"
                     :disabled="goodsForm.status === 1"
                     @click="$refs.payment.rowDel(row,index)"
          >删除
          </el-button>
        </template>
        <template slot="menuLeft">
          <el-button type="primary" icon="el-icon-plus" :disabled="goodsForm.status === 1" @click="addRowPayment"
                     size="small">录入明细
          </el-button>
        </template>
      </avue-crud>
    </basic-container>
    <containerTitle title="上传附件"></containerTitle>
    <c-upload
        typeUpload="CD"
        deleteUrl="/api/blade-client/common-file/remove"
        :data="orderFilesList"
        :disabled="goodsForm.status === 1"
        :enumerationValue="85.6"
    ></c-upload>
  </div>
</template>

<script>
import {getLazyTree} from "@/api/base/region";
import {
  saveDelegationList,
  detailDelegationList,
  removeCollection,
  saveSaveList,
  addressList, cancelSubmission, getCorp, getSalesman
} from "@/api/landTransportation";

export default {
  props: {
    id: {
      type: String
    }
  },
  data() {
    return {
      activeIndex: '1',
      KeyBox: 0,
      KeyBoxTwo: 0,
      type: false,
      goodsForm: {},
      modelKey: 1,
      orderFilesList: [],
      salesmanList: [],
      vehicleList: [],
      breakConfiguration: {
        multipleChoices: false,
        multiple: false,
        disabled: false,
        searchShow: true,
        collapseTags: false,
        clearable: true,
        placeholder: '请点击右边按钮选择',
        dicData: []
      },
      advantageProjectData: [],
      keyContact: 0,
      vehicleOptionTwo: {
        align: 'center',
        menuAlign: 'center',
        refreshBtn: false,
        menu: false,
        index: true,
        stripe: true,
        cellBtn: false,
        addBtn: false,
        cancelBtn: false,
        editBtn: false,
        addRowBtn: false,
        delBtn: false,
        showSummary: true,
        // editBtn:false,
        summaryText: "合计",
        sumColumnList: [
          {
            name: 'landWeight',
            type: 'sum',
            decimals: 2
          }, {
            name: 'landAmountC',
            type: 'sum',
            decimals: 2
          }, {
            name: 'landAmountD',
            type: 'sum',
            decimals: 2
          }, {
            name: 'oneFeeD',
            type: 'sum',
            decimals: 2
          }, {
            name: 'twoFeeD',
            type: 'sum',
            decimals: 2
          }, {
            name: 'threeFeeD',
            type: 'sum',
            decimals: 2
          }, {
            name: 'fourFeeD',
            type: 'sum',
            decimals: 2
          }, {
            name: 'fiveFeeD',
            type: 'sum',
            decimals: 2
          }, {
            name: 'oneFeeC',
            type: 'sum',
            decimals: 2
          }, {
            name: 'twoFeeC',
            type: 'sum',
            decimals: 2
          }, {
            name: 'threeFeeC',
            type: 'sum',
            decimals: 2
          }, {
            name: 'fourFeeC',
            type: 'sum',
            decimals: 2
          }, {
            name: 'fiveFeeC',
            type: 'sum',
            decimals: 2
          }, {
            name: 'landAmountD',
            type: 'sum',
            decimals: 2
          }, {
            name: 'ctnQuantity',
            type: 'sum',
            decimals: 0
          }],
        column: [
          {
            label: '状态',
            width: 100,
            type: 'select',
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=land_order_status",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            dataType: "string",
            prop: 'status'
          }, {
            label: '车队',
            width: 200,
            prop: 'fleetName'
          }, {
            label: '应付陆运费',
            cell: true,
            prop: 'landAmountC'
          }, {
            label: '尺寸箱型',
            width: 100,
            slot: true,
            prop: 'ctnType'
          }, {
            label: '箱量',
            width: 50,
            prop: 'ctnQuantity'
          }, {
            label: '重量',
            width: 160,
            prop: 'landWeight',
            controls: false,
            precision: 2,
            type: 'number'
          }, {
            label: '到厂时间',
            type: "datetime",
            format: 'yyyy-MM-dd HH:mm:ss',
            valueFormat: 'yyyy-MM-dd HH:mm:ss',
            width: 200,
            prop: 'arrivalTime'
          }, {
            label: '车号',
            width: 150,
            prop: 'plateNo'
          }, {
            label: '司机',
            width: 115,
            prop: 'driverName'
          }, {
            label: '电话',
            width: 160,
            prop: 'tel'
          }, {
            label: '单柜运费',
            prop: 'landAmountD'
          }, {
            label: '委托备注',
            width: 245,
            prop: 'remarks'
          }, {
            label: '车队备注',
            width: 245,
            prop: 'fleetRemarks'
          }, {
            label: '司机备注',
            width: 245,
            prop: 'driverRemarks'
          }
        ]
      },
      vehicleOption: {},
      treeOption: {
        label: 'title',
        value: 'id',
        lazy: true,
        lazyLoad(node, resolve) {
          const parentId = node.level === 0 ? '00' : node.data.id;
          getLazyTree(parentId).then(res => {
            resolve(
                res.data.data.map(item => {
                  return {
                    ...item,
                    leaf: !item.hasChildren
                  };
                })
            );
          });
        }
      },
      tableData: [],
      entrustListT: [],
      entrustOptionTwoTBackup: {
        align: 'center',
        menuAlign: 'center',
        index: true,
        cellBtn: true,
        menu: false,
        refreshBtn: false,
        addBtn: false,
        addRowBtn: false,
        delBtn: false,
        showSummary: true,
        summaryText: "合计",
        sumColumnList: [
          {
            name: 'landWeight',
            type: 'sum',
            decimals: 2
          }, {
            name: 'landAmountC',
            type: 'sum',
            decimals: 2
          }, {
            name: 'landAmountD',
            type: 'sum',
            decimals: 2
          }, {
            name: 'oneFeeD',
            type: 'sum',
            decimals: 2
          }, {
            name: 'twoFeeD',
            type: 'sum',
            decimals: 2
          }, {
            name: 'threeFeeD',
            type: 'sum',
            decimals: 2
          }, {
            name: 'fourFeeD',
            type: 'sum',
            decimals: 2
          }, {
            name: 'fiveFeeD',
            type: 'sum',
            decimals: 2
          }, {
            name: 'ctnQuantity',
            type: 'sum',
            decimals: 0
          }],
        column: [{
          label: '尺寸箱型',
          width: 100,
          prop: 'ctnType'
        }, {
          label: '箱量',
          width: 50,
          prop: 'ctnQuantity'
        }, {
          label: '重量',
          width: 160,
          prop: 'landWeight',
          controls: false,
          precision: 2,
          type: 'number'
        }, {
          label: '单柜运费',
          prop: 'landAmountD',
          width: 100,
          precision: 2,
          controls: false,
        }, {
          label: '到厂时间',
          type: "datetime",
          format: 'yyyy-MM-dd HH:mm:ss',
          valueFormat: 'yyyy-MM-dd HH:mm:ss',
          cell: true,
          width: 200,
          prop: 'arrivalTime'
        }, {
          label: '件数',
          width: 100,
          search: true,
          index: 6,
          overHidden: true,
          controls: false,
          prop: 'quantity',
          type: 'number',
          precision:0
        }, {
          label: '包装',
          width: 100,
          search: true,
          index: 7,
          overHidden: true,
          prop: 'packing',
          type: 'select',
          dicUrl: "/api/blade-system/dict-biz/dictionary?code=packaging",
          props: {
            label: "dictValue",
            value: "dictValue"
          },
        }, {
          label: '尺码',
          width: 100,
          search: true,
          index:8,
          overHidden: true,
          prop: 'size',
        }, {
          label: '备注',
          width: 200,
          prop: 'remarks'
        }]
      },
      entrustOptionTwoT: {},
      entrustList: [],
      goodsOptionFormC: {
        menuBtn: false,
        disabled: false,
        span: 8,
        column: [{
          label: '业务类型',
          prop: 'businessType',
          type: 'select',
          dicUrl: "/api/blade-system/dict-biz/dictionary?code=business_type",
          props: {
            label: "dictValue",
            value: "dictValue"
          },
          rules: [{
            required: false,
            message: " ",
            trigger: "blur"
          }]
        }, {
          label: '运输方式',
          prop: 'shippingMode',
          type: 'select',
          dicUrl: "/api/blade-system/dict-biz/dictionary?code=shipping_mode",
          props: {
            label: "dictValue",
            value: "dictValue"
          },
          change: (data) => {
            if (data.value === '集装箱') {
              this.findObject(this.goodsOptionForm.column, "billNo").rules[0].required = true
            } else if (!data.value) {
              this.findObject(this.goodsOptionForm.column, "billNo").rules[0].required = true
            } else {
              this.findObject(this.goodsOptionForm.column, "billNo").rules[0].required = false
            }
          }
        }]
      },
      goodsOptionForm: {
        menuBtn: false,
        disabled: false,
        span: 8,
        column: [{
          label: '客户名称',
          formslot: true,
          prop: 'corpId',
          rules: [{
            required: true,
            message: " ",
            trigger: "change"
          }],
        }, {
          label: '所属公司',
          formslot: true,
          prop: 'belongCompany',
          rules: [{
            required: false,
            message: " ",
            trigger: "blur"
          }],
        }, {
          label: '订单号',
          prop: 'orderNo',
          disabled: true
        }, {
          label: '提单号',
          prop: 'billNo',
          rules: [{
            required: true,
            message: " ",
            trigger: "blur"
          }],
        }, {
          label: '场站',
          prop: 'station',
          rules: [{
            required: false,
            message: " ",
            trigger: "blur"
          }],
        }, {
          label: '到厂时间',
          type: "datetime",
          format: 'yyyy-MM-dd HH:mm:ss',
          valueFormat: 'yyyy-MM-dd HH:mm:ss',
          prop: 'arrivalTime',
          rules: [{
            required: true,
            message: " ",
            trigger: "blur"
          }],
        }, {
          label: '船名航次',
          prop: 'factory',
          rules: [{
            required: false,
            message: " ",
            trigger: "blur"
          }],
        }, {
          label: '货物名称',
          prop: 'goods',
          rules: [{
            required: false,
            message: " ",
            trigger: "blur"
          }],
        }, {
          label: '订舱代理',
          prop: 'agentId'
        }, {
          label: '起运港',
          prop: 'polId'
        }, {
          label: '目的港',
          prop: 'podId'
        }, {
          label: '开船日期',
          prop: 'etd',
          type: 'date'
        }, {
          label: '截关日期',
          prop: 'etc',
          type: 'date'
        }, {
          label: '截单日期',
          prop: 'siCutoffDate',
          type: 'date'
        }, {
          label: '业务员',
          prop: 'salesman',
        }, {
          label: '备注',
          span: 24,
          prop: 'remarks'
        }]
      },
      entrustOptionTwoBackup: {
        align: 'center',
        menuAlign: 'center',
        refreshBtn: false,
        addBtnText: '录入信息',
        index: true,
        indexSlot: true,
        cellBtn: true,
        addBtn: false,
        addRowBtn: false,
        showSummary: true,
        summaryText: "合计",
        sumColumnList: [
          {
            name: 'landWeight',
            type: 'sum',
            decimals: 2
          }, {
            name: 'landAmountD',
            type: 'sum',
            decimals: 2
          }, {
            name: 'oneFeeD',
            type: 'sum',
            decimals: 2
          }, {
            name: 'twoFeeD',
            type: 'sum',
            decimals: 2
          }, {
            name: 'threeFeeD',
            type: 'sum',
            decimals: 2
          }, {
            name: 'fourFeeD',
            type: 'sum',
            decimals: 2
          }, {
            name: 'fiveFeeD',
            type: 'sum',
            decimals: 2
          }, {
            name: 'ctnQuantity',
            type: 'sum',
            decimals: 0
          }],
        column: [{
          // label: '尺寸箱型',
          label: '尺寸箱型',
          cell: true,
          prop: 'ctnType',
          type: 'select',
          width: 100,
          index: 1,
          dicUrl: "/api/blade-system/dict-biz/dictionary?code=boxType",
          props: {
            label: "dictValue",
            value: "dictValue"
          },
        }, {
          label: '箱量',
          cell: true,
          prop: 'ctnQuantity',
          controls: false,
          precision: 0,
          index: 2,
          width: 100,
          maxRows: 999,
          minRows: 1,
          type: 'number'
        }, {
          label: '总重量(吨)',
          cell: true,
          prop: 'landWeight',
          controls: false,
          width: 200,
          index: 3,
          precision: 2,
          type: 'number'
        }, {
          label: '单柜运费',
          cell: true,
          prop: 'landAmountD',
          controls: false,
          width: 200,
          index: 4,
          precision: 2,
          type: 'number'
        }, {
          label: '到厂时间',
          type: "datetime",
          format: 'yyyy-MM-dd HH:mm:ss',
          valueFormat: 'yyyy-MM-dd HH:mm:ss',
          cell: true,
          width: 200,
          index: 5,
          prop: 'arrivalTime'
        }, {
          label: '件数',
          width: 100,
          search: true,
          index: 6,
          overHidden: true,
          controls: false,
          cell: true,
          prop: 'quantity',
          type: 'number',
          precision:0
        }, {
          label: '包装',
          width: 100,
          search: true,
          index: 7,
          overHidden: true,
          cell: true,
          prop: 'packing',
          type: 'select',
          dicUrl: "/api/blade-system/dict-biz/dictionary?code=packaging",
          props: {
            label: "dictValue",
            value: "dictValue"
          },
        }, {
          label: '尺码',
          width: 100,
          search: true,
          index:8,
          overHidden: true,
          cell: true,
          prop: 'size',
        }, {
          label: '备注',
          cell: true,
          index: 9,
          width: 200,
          prop: 'remarks'
        }]
      },
      entrustOptionTwo: {},
      collectionList: [],
      collectionOptionBackup: {
        align: 'center',
        menuAlign: 'center',
        refreshBtn: false,
        index: true,
        cancelBtn: false,
        editBtn: false,
        delBtn: false,
        cellBtn: false,
        addBtn: false,
        addRowBtn: false,
        showSummary: true,
        addBtnText: '录入明细',
        summaryText: "合计",
        sumColumnList: [{
          name: 'price',
          type: 'sum',
          decimals: 2
        }, {
          name: 'amount',
          type: 'sum',
          decimals: 2
        }, {
          name: 'quantity',
          type: 'sum',
          decimals: 0
        }],
        column: [{
          label: '客户名称',
          slot: true,
          width: 200,
          overHidden: true,
          prop: 'corpId'
        }, {
          label: '费用名称',
          slot: true,
          prop: 'feeId'
        }, {
          label: '计价单位',
          cell: true,
          prop: 'unit',
          type: "select",
          dicUrl: "/api/blade-system/dict-biz/dictionary?code=unit",
          props: {
            label: "dictValue",
            value: "dictKey"
          }
        }, {
          label: '数量',
          cell: true,
          prop: 'quantity'
        }, {
          label: '单价',
          cell: true,
          prop: 'price'
        }, {
          label: '金额',
          cell: true,
          prop: 'amount'
        }, {
          // label: '税率(默认6)',
          label: '税率',
          cell: true,
          prop: 'taxRate'
        }, {
          label: '币别',
          cell: true,
          prop: 'currency',
          type: "select",
          dicUrl: "/api/blade-system/dict-biz/dictionary?code=currency",
          props: {
            label: "dictValue",
            value: "dictKey"
          },
        }
        ]
      },
      paymentList: [],
      collectionOption: {},
      paymentOption: {},
      paymentOptionBackup: {
        align: 'center',
        menuAlign: 'center',
        index: true,
        cancelBtn: false,
        refreshBtn: false,
        editBtn: false,
        delBtn: false,
        cellBtn: false,
        addBtn: false,
        addRowBtn: false,
        showSummary: true,
        addBtnText: '录入明细',
        summaryText: "合计",
        sumColumnList: [{
          name: 'price',
          type: 'sum',
          decimals: 2
        }, {
          name: 'amount',
          type: 'sum',
          decimals: 2
        }, {
          name: 'quantity',
          type: 'sum',
          decimals: 0
        }],
        column: [{
          label: '客户名称',
          width: 200,
          slot: true,
          overHidden: true,
          prop: 'corpId'
        }, {
          label: '费用名称',
          slot: true,
          prop: 'feeId'
        }, {
          label: '计价单位',
          cell: true,
          prop: 'unit',
          type: "select",
          dicUrl: "/api/blade-system/dict-biz/dictionary?code=unit",
          props: {
            label: "dictValue",
            value: "dictKey"
          }
        }, {
          label: '数量',
          cell: true,
          prop: 'quantity'
        }, {
          label: '单价',
          cell: true,
          prop: 'price'
        }, {
          label: '金额',
          cell: true,
          prop: 'amount'
        }, {
          // label: '税率(默认6)',
          label: '税率',
          cell: true,
          prop: 'taxRate'
        }, {
          label: '币别',
          cell: true,
          prop: 'currency',
          type: "select",
          dicUrl: "/api/blade-system/dict-biz/dictionary?code=currency",
          props: {
            label: "dictValue",
            value: "dictKey"
          }
        }]
      }
    };
  },
  async created() {
    this.entrustOptionTwo = await this.getColumnData(this.getColumnName(85.1), this.entrustOptionTwoBackup);
    this.KeyBox++
    this.entrustOptionTwoT = await this.getColumnData(this.getColumnName(85.2), this.entrustOptionTwoTBackup);
    this.KeyBoxTwo++
    this.vehicleOption = await this.getColumnData(this.getColumnName(85.3), this.vehicleOptionTwo);
    this.keyContact++
    this.collectionOption = await this.getColumnData(this.getColumnName(85.4), this.collectionOptionBackup);
    this.paymentOption = await this.getColumnData(this.getColumnName(85.5), this.paymentOptionBackup);
    if (this.id) {
      detailDelegationList({id: this.id, kind: '1'}).then(res => {
        this.goodsForm = res.data.data
        this.tableData = res.data.data.orderAddressList
        this.entrustList = res.data.data.itemList
        this.goodsList = res.data.data.itemList
        this.vehicleList = res.data.data.orderItemList
        this.orderFilesList = res.data.data.fileList
        if (res.data.data.orderFeeList.length > 0) {
          res.data.data.orderFeeList.forEach(item => {
            if (item.type == 1) {
              this.collectionList.push(item)
            } else {
              this.paymentList.push(item)
            }
          })
        }
        this.goodsOptionForm.disabled = this.goodsOptionFormC.disabled = this.collectionOption.disabled = this.paymentOption.disabled = this.goodsForm.status === 1
        delete this.goodsForm.orderAddressList
        delete this.goodsForm.itemList
        delete this.goodsForm.orderFeeList
        this.tableData.forEach(item => {
          if (item.region) item.region = item.region.split(',')
        })
      })
    } else {
      this.tableData = [{
        region: [],
        address: ''
      }, {
        region: [],
        address: ''
      }]
      getCorp().then(res => {
        this.goodsForm = {
          corpId: res.data.data ? res.data.data.id : '',
          businessType: "出口",
          shippingMode: "集装箱",
          belongCompany: res.data.data ? res.data.data.belongCompany : ''
        }
        this.salesmanQuery(this.goodsForm.corpId)
      })
      this.entrustList = [{$cellEdit: true}]
    }
  },
  methods: {
    //查询业务员
    salesmanQuery(id) {
      getSalesman({pid: id}).then(res => {
        this.salesmanList = res.data.data
      })
    },
    //自定义列保存
    async saveColumnCollection() {
      /**
       * 已定义全局方法，直接使用，saveColumnData保存列数据方法,参数传值(表格名称，当前表格的option数据)
       * 已定义全局方法，直接使用，getColumnName方法用来获取枚举值，参数根据自己定义的code值获取中文名
       * 一定要执行异步操作，要等接口成功返回，才能执行下一行代码
       */
      const inSave = await this.saveColumnData(this.getColumnName(85.4), this.collectionOption);
      if (inSave) {
        this.$message.success("保存成功");
        //关闭窗口
        this.$refs.collection.$refs.dialogColumn.columnBox = false;
      }
    },
    //自定义列重置
    async resetColumnCollection() {
      this.collectionOption = this.collectionOptionBackup;
      const inSave = await this.delColumnData(this.getColumnName(85.4), this.collectionOptionBackup);
      if (inSave) {
        this.$message.success("重置成功");
        this.$refs.collection.$refs.dialogColumn.columnBox = false;
      }
    },
    //自定义列保存
    async saveColumnPayment() {
      /**
       * 已定义全局方法，直接使用，saveColumnData保存列数据方法,参数传值(表格名称，当前表格的option数据)
       * 已定义全局方法，直接使用，getColumnName方法用来获取枚举值，参数根据自己定义的code值获取中文名
       * 一定要执行异步操作，要等接口成功返回，才能执行下一行代码
       */
      const inSave = await this.saveColumnData(this.getColumnName(85.5), this.paymentOption);
      if (inSave) {
        this.$message.success("保存成功");
        //关闭窗口
        this.$refs.payment.$refs.dialogColumn.columnBox = false;
      }
    },
    //自定义列重置
    async resetColumnPayment() {
      this.paymentOption = this.paymentOptionBackup;
      const inSave = await this.delColumnData(this.getColumnName(85.5), this.paymentOptionBackup);
      if (inSave) {
        this.$message.success("重置成功");
        this.$refs.payment.$refs.dialogColumn.columnBox = false;
      }
    },
    //自定义列保存
    async saveColumnBox() {
      /**
       * 已定义全局方法，直接使用，saveColumnData保存列数据方法,参数传值(表格名称，当前表格的option数据)
       * 已定义全局方法，直接使用，getColumnName方法用来获取枚举值，参数根据自己定义的code值获取中文名
       * 一定要执行异步操作，要等接口成功返回，才能执行下一行代码
       */
      const inSave = await this.saveColumnData(this.getColumnName(85.1), this.entrustOptionTwo);
      if (inSave) {
        this.$message.success("保存成功");
        //关闭窗口
        this.$refs.crudBox.$refs.dialogColumn.columnBox = false;
      }
    },
    //自定义列重置
    async resetColumnBox() {
      this.entrustOptionTwo = this.entrustOptionTwoBackup;
      const inSave = await this.delColumnData(this.getColumnName(85.1), this.entrustOptionTwoBackup);
      if (inSave) {
        this.$message.success("重置成功");
        this.$refs.crudBox.$refs.dialogColumn.columnBox = false;
      }
    },
    //自定义列保存
    async saveColumnBoxTwo() {
      /**
       * 已定义全局方法，直接使用，saveColumnData保存列数据方法,参数传值(表格名称，当前表格的option数据)
       * 已定义全局方法，直接使用，getColumnName方法用来获取枚举值，参数根据自己定义的code值获取中文名
       * 一定要执行异步操作，要等接口成功返回，才能执行下一行代码
       */
      const inSave = await this.saveColumnData(this.getColumnName(85.2), this.entrustOptionTwoT);
      if (inSave) {
        this.$message.success("保存成功");
        //关闭窗口
        this.$refs.crudBoxTwo.$refs.dialogColumn.columnBox = false;
      }
    },
    //自定义列重置
    async resetColumnBoxTwo() {
      this.entrustOptionTwoT = this.entrustOptionTwoTBackup;
      const inSave = await this.delColumnData(this.getColumnName(85.2), this.entrustOptionTwoTBackup);
      if (inSave) {
        this.$message.success("重置成功");
        this.$refs.crudBoxTwo.$refs.dialogColumn.columnBox = false;
      }
    },
    //自定义列保存
    async saveColumnContact() {
      /**
       * 已定义全局方法，直接使用，saveColumnData保存列数据方法,参数传值(表格名称，当前表格的option数据)
       * 已定义全局方法，直接使用，getColumnName方法用来获取枚举值，参数根据自己定义的code值获取中文名
       * 一定要执行异步操作，要等接口成功返回，才能执行下一行代码
       */
      const inSave = await this.saveColumnData(this.getColumnName(85.3), this.vehicleOption);
      if (inSave) {
        this.$message.success("保存成功");
        //关闭窗口
        this.$refs.crudContact.$refs.dialogColumn.columnBox = false;
      }
    },
    //自定义列重置
    async resetColumnContact() {
      this.vehicleOption = this.vehicleOptionTwo;
      const inSave = await this.delColumnData(this.getColumnName(85.3), this.vehicleOptionTwo);
      if (inSave) {
        this.$message.success("重置成功");
        this.$refs.crudContact.$refs.dialogColumn.columnBox = false;
      }
    },
    //刷新数据
    refreshData() {
      detailDelegationList({id: this.id, kind: '1'}).then(res => {
        this.goodsForm = res.data.data
        this.tableData = res.data.data.orderAddressList
        this.entrustList = res.data.data.itemList
        this.goodsList = res.data.data.itemList
        this.vehicleList = res.data.data.orderItemList
        this.orderFilesList = res.data.data.fileList
        if (res.data.data.orderFeeList.length > 0) {
          this.collectionList = []
          this.paymentList = []
          res.data.data.orderFeeList.forEach(item => {
            if (item.type == 1) {
              this.collectionList.push(item)
            } else {
              this.paymentList.push(item)
            }
          })
        }
        this.goodsOptionForm.disabled = this.goodsOptionFormC.disabled = this.collectionOption.disabled = this.paymentOption.disabled = this.goodsForm.status === 1
        delete this.goodsForm.orderAddressList
        delete this.goodsForm.itemList
        delete this.goodsForm.orderFeeList
        this.tableData.forEach(item => {
          if (item.region) item.region = item.region.split(',')
        })
        this.type = false
      })
    },
    //切换收付费
    handleSelect(tab, event) {
      this.activeIndex = tab.name
    },
    //箱信息保存
    rowSaveT(row, index, done, loading) {
      row.$cellEdit = false
      done()
    },
    //箱信息选择车队
    getfleetIdT(data, row) {
      this.$set(row, 'fleetName', data.cname)
    },
    //地址新增
    addAddress() {
      this.tableData.splice(this.tableData.length - 1, 0, {})
    },
    //返回主列表
    backToList() {
      this.goodsForm = {}
      this.$emit('backToList')
    },
    //删除途径地址
    deleteAddress(scope) {
      this.tableData.splice(scope.$index, 1);
    },
    //箱信息保存
    rowSave(row, index, done, loading) {
      row.$cellEdit = false
      done()
    },
    rowCell(row, index) {
      this.$refs.collection.rowCell(row, index)
    },
    paymentRowCell(row, index) {
      this.$refs.payment.rowCell(row, index)
    },
    //箱信息移除
    rowDel(row, index) {
      this.$confirm('此操作将永久删除该单据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.entrustList.splice(index, 1);
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    //保存
    editCustomer() {
      let data = JSON.parse(JSON.stringify(this.tableData))
      data.forEach((item, index) => {
        item.sort = index + 1
        if (item.region !== undefined && item.region.length !== 0) {
          item.region = item.region.join(',')
        } else {
          item.region = ''
        }
      })
      this.type = true
      saveSaveList({
        ...this.goodsForm,
        kind: '1',
        orderAddressList: data,
        fileList: this.orderFilesList,
        itemList: this.entrustList,
        orderFeeList: this.collectionList.concat(this.paymentList)
      }).then(res => {
        this.$message.success('保存成功');
        this.goodsForm = {}
        if (!this.goodsForm.id) {
          this.id = res.data.data
          this.refreshData()
        } else {
          this.refreshData()
        }
      })
    },
    //提交委托
    submit(type) {
      if (type) {
        this.$refs['goodsFormE'].validate((valid, done) => {
          done()
        })
        this.$refs['goodsForm'].validate((valid, done) => {
          done()
        })
        for (let item in this.tableData) {
          if (item < Number(this.tableData.length) - 1) {
            if (!this.tableData[item].corpId) return this.$message.error('请选择第' + Number(Number(item) + 1) + '行发货工厂');
            if (!this.tableData[item].address) return this.$message.error('请输入第' + Number(Number(item) + 1) + '行详细地址');
          }
        }
        for (let item in this.entrustList) {
          if (!this.entrustList[item].ctnType) return this.$message.error('请选择第' + Number(Number(item) + 1) + '行尺寸箱型');
          if (!this.entrustList[item].ctnQuantity) return this.$message.error('请输入第' + Number(Number(item) + 1) + '行箱量');
          if (!this.entrustList[item].landWeight) return this.$message.error('请输入第' + Number(Number(item) + 1) + '行总重量');
          if (!this.entrustList[item].landAmountD) return this.$message.error('请输入第' + Number(Number(item) + 1) + '单柜运费');
        }
        if (this.entrustList.length === 0) return this.$message.error('箱信息不能为空')
        this.$refs['goodsFormE'].validate((valid, doneE) => {
          doneE()
          if (valid) {
            this.$refs['goodsForm'].validate((valid, done) => {
              done();
              if (valid) {
                let data = JSON.parse(JSON.stringify(this.tableData))
                data.forEach((item, index) => {
                  item.sort = index + 1
                  if (item.region.length !== 0) {
                    item.region = item.region.join(',')
                  } else {
                    item.region = ''
                  }
                })
                saveSaveList({
                  ...this.goodsForm,
                  kind: '1',
                  orderAddressList: data,
                  fileList: this.orderFilesList,
                  itemList: this.entrustList,
                  orderFeeList: this.collectionList.concat(this.paymentList)
                }).then(res => {
                  saveDelegationList({
                    id: this.goodsForm.id
                  }).then(res => {
                    this.$message.success('提交成功');
                    this.refreshData()
                  })
                })
              } else {
                return false;
              }
            });
          } else {
            return false;
          }
        })
      } else {
        cancelSubmission({
          id: this.goodsForm.id
        }).then(res => {
          this.$message.success('取消成功');
          this.refreshData()
        })
      }
    },
    //收费新增
    addRowCollection() {
      this.$refs.collection.rowCellAdd({
        currency: '1',
        type: '1',
        $cellEdit: true
      });
    },
    //付费新增
    addRowPayment() {
      this.$refs.payment.rowCellAdd({
        currency: '1',
        type: '2',
        $cellEdit: true
      });
    },
    //选择费用
    selectValue(value, row) {
      this.$set(row, 'feeName', value.cname)
    },
    //选择客户信息触发
    getfleetId(data, row) {
      this.$set(row, 'corpName', data.cname)
    },
    //收款信息移除
    makeDel(row, index) {
      this.$confirm('此操作将永久删除该单据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (row.id) removeCollection(row.id)
        this.collectionList.splice(index, 1);
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    //付款信息移除
    feeDel(row, index) {
      this.$confirm('此操作将永久删除该单据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (row.id) removeCollection(row.id)
        this.paymentList.splice(index, 1);
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    //选择客户名称带出所属公司
    getCorpData(row) {
      this.goodsForm.belongCompany = row.belongCompany
      //查询业务员
      this.salesmanQuery(row.id)
    },
    //选择地址客户带出地址
    withAddress(row, scope) {
      this.tableData[scope.$index].address = ''
      console.log(row)
      if (!scope.row.key) scope.row.key = 0
      this.tableData[scope.$index].corpName = row.cname
      if (row.attn) {
        this.tableData[scope.$index].address = row.attn
      }
      if (row.tel) {
        if (!row.attn) {
          this.tableData[scope.$index].address += row.tel
        } else {
          this.tableData[scope.$index].address += '—' + row.tel
        }
      }
      if (row.storageAddr) {
        if (!row.tel && !row.attn) {
          this.tableData[scope.$index].address += row.storageAddr
        } else {
          this.tableData[scope.$index].address += '—' + row.storageAddr
        }
      }
      if (row.belongtoarea) {
        addressList(row.belongtoarea.split(',')[0]).then(res => {
          this.tableData[scope.$index].region = [res.data.data.provinceCode, res.data.data.parentId, res.data.data.districtCode]
          scope.row.key++
        })
      }
    },
    //自定义表头
    renderHeader(h) {
      return (
          <div>
            <el-tooltip className="item" effect="dark" content="增加途径地址" placement="top">
              <el-button type="primary" icon="el-icon-plus" size="mini" circle onClick={() => this.addAddress()}
                         style="margin-right: 1.25rem;"></el-button>
            </el-tooltip>
          </div>
      )
    },
    //自定义表头
    customTitle(h, {column, $index}) {
      let text = column.label
      return (
          <div>
            {{text}}<span style="color:#F56C6C">*</span>
          </div>
      )
    }
  }
}
</script>
<style scoped>
</style>
