<!--
@name: 待调度-调度(组件化)
@author: 张泽贤
@time: 2022-04-15
-->
<template>
  <p-card class="full-card-panel">
    <a-space slot="title">
      <span><a-icon type="arrow-left" style="color: #1990ff; margin-right: 10px" @click="back" />调度</span>
      <p-button v-action:directionBtns :disabled="spinning" :type="!lineDirection ? 'primary' : 'default'">全部</p-button>
      <p-button v-action:directionBtns :disabled="spinning" :type="lineDirection == 10 ? 'primary' : 'default'">正向</p-button>
      <p-button v-action:directionBtns :disabled="spinning" :type="lineDirection == 20 ? 'primary' : 'default'">逆向</p-button>
    </a-space>

    <a-space slot="extra">
      <a-dropdown-button type="primary" @click="handleSystemGroupClick">
        {{ defaultGroupName ? '"' + defaultGroupName + '"默认' : '暂无默认分组' }}
        <a-radio-group slot="overlay">
          <a-menu class="dropdown-mini-menu" mode="inline">
            <a-sub-menu key="sub1">
              <span slot="title">分组配置</span>
              <a-menu-item v-for="item in options.GROUP_CONFIG" :key="item.groupName">
                <a-checkbox :name="item.groupName" @change="handleMenuClick($event, 'sub1')" :checked="groupName === item.groupName"> {{ item.groupName }}</a-checkbox>
              </a-menu-item>
            </a-sub-menu>
            <a-sub-menu key="sub2">
              <span slot="title">类型条件</span>
              <a-menu-item v-for="item in options.GROUP_DISPATCH_NEW" :key="item.value">
                <a-checkbox :checked="groupDimensionList.includes(item.value)" @change="handleMenuClick($event, 'sub2', item.value)">{{ item.label }}</a-checkbox>
              </a-menu-item>
            </a-sub-menu>
            <a-menu-item style="margin-bottom: 6px; padding-left: 8px">
              <a-space>
                <a-button @click.stop="settingGroupClick">设置</a-button>
                <a-button type="primary" @click.stop="onSystemGroup" :disabled="!groupDimensionList.length && !groupName">确定</a-button>
              </a-space>
            </a-menu-item>
          </a-menu>
        </a-radio-group>
      </a-dropdown-button>

      <p-button type="primary" @click="onSave('dispatch')">调度</p-button>
      <p-button type="primary" @click="onSave('review')">调度并审核</p-button>
    </a-space>
    <p-spin :spinning="spinning">
      <p-form-model ref="ruleForm" :model="form" :rules="rules" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }" class="plg-grid-from">
        <a-row>
          <a-col :span="6">
            <p-form-model-item label="订单数">{{ orderList.length }}</p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item label="总件数">{{ form.actualTotalPcs }}</p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item label="总重量">{{ form.actualTotalWeight }}</p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item label="总体积">{{ form.actualTotalVolume }}</p-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="6">
            <p-form-model-item label="承运方类型" prop="carrierType">
              <p-select v-model="form.carrierType" :options="options.LINE_CARRIER_TYPE" @change="carrierTypeChange" />
            </p-form-model-item>
          </a-col>
          <a-col :span="6" v-action:directionBtns>
            <p-form-model-item label="最早提货时间">
              {{ form.minEstimatedPickupTime }}
            </p-form-model-item>
          </a-col>
          <a-col :span="6" v-action:directionBtns>
            <p-form-model-item label="最晚送达时间">
              {{ form.maxEstimatedDeliveryTime }}
            </p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item label="备注" prop="memo">
              <p-input v-model="form.memo" placeholder="请输入备注" />
            </p-form-model-item>
          </a-col>
        </a-row>
        <a-row v-if="form.carrierType === 2">
          <a-col :span="6">
            <p-form-model-item label="司机" prop="driverName">
              <p-search-modal v-model="form.driverName" v-bind="driverAttr" @ok="(...args) => onFormChange('driver', ...args)" :targetClick="false" @input="onFormInput('driver')" />
            </p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item label="司机手机号" prop="driverPhoneNumber">
              <p-input v-model="form.driverPhoneNumber" />
            </p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item label="送货员" prop="deliverymanName">
              <p-search-modal v-model="form.deliverymanName" v-bind="deliveryAttr" @ok="(...args) => onFormChange('delivery', ...args)" :targetClick="false" @input="onFormInput('delivery')" />
            </p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item label="送货员手机号" prop="deliverymanPhoneNumber">
              <p-input v-model="form.deliverymanPhoneNumber" />
            </p-form-model-item>
          </a-col>
        </a-row>
        <a-row v-if="form.carrierType === 2">
          <a-col :span="6">
            <p-form-model-item label="车辆" prop="vehiclePlateNumber">
              <p-search-modal v-model="form.vehiclePlateNumber" v-bind="carAttr" @change="(...args) => onFormChange('car', ...args)" :targetClick="false" @input="onFormInput('car')" />
            </p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item label="车辆归属" prop="vehicleAscriptionName">
              <p-input v-if="selfCar" :value="form.vehicleAscriptionName" readOnly placeholder="请选择车辆" />
              <p-select v-else v-model="form.vehicleAscription" :options="options.VEHICLE_TYPE" />
            </p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item label="车型" prop="vehicleTypeName">
              <p-search-modal v-model="form.vehicleTypeName" v-bind="$data.$formItems.vehicleTypeAttr" @change="(...args) => onFormChange('vehicleType', ...args)" />
            </p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item label="隶属机构" prop="vehicleAffiliationName">
              <p-search-modal v-model="form.vehicleAffiliationName" v-bind="affiliationAttr" @change="(...args) => onFormChange('affiliation', ...args)" :disabled="disAffiliation" />
            </p-form-model-item>
          </a-col>
        </a-row>
        <a-row v-if="form.carrierType === 2">
          <a-col :span="6">
            <p-form-model-item label="装载率">
              <p-input :value="'体积:' + form.volumeLoadingRate + ',重量:' + form.weightLoadingRate" readOnly placeholder="请选择车辆" />
            </p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item label="车辆类别" prop="vehicleTypeCategoryName">
              <p-input :value="form.vehicleTypeCategoryName" readOnly />
            </p-form-model-item>
          </a-col>
          <a-col
            :span="6"
            v-if="
              ['2', '3'].some((i) => {
                return RELATION_THIRD_SYSTEM.includes(i);
              })
            "
          >
            <p-form-model-item label="容器号" prop="containerName">
              <p-search-modal v-model="form.containerName" v-bind="$data.$formItems.containerAttr" @change="(...args) => onFormChange('container', ...args)" :disabled="!form.vehiclePlateNumber" />
            </p-form-model-item>
          </a-col>
          <a-col :span="6" v-if="RELATION_THIRD_SYSTEM.includes('1')">
            <p-form-model-item label="设备号" prop="vehicleDeviceName">
              <p-search-modal v-model="form.vehicleDeviceName" v-bind="deviceAttr" @change="(...args) => onFormChange('device', ...args)" :disabled="!form.vehiclePlateNumber" />
            </p-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="6" v-if="form.carrierType === 1">
            <p-form-model-item label="承运商编码" prop="carrierCode">
              <p-search-modal v-model="form.carrierCode" v-bind="$data.$formItems.carrierAttr" @change="(...args) => onFormChange('carrier', ...args)" />
            </p-form-model-item>
          </a-col>
          <a-col :span="6" v-if="form.carrierType === 1">
            <p-form-model-item label="承运商名称" prop="carrierName">
              <p-input :value="form.carrierName" readOnly />
            </p-form-model-item>
          </a-col>
          <a-col :span="6">
            <p-form-model-item label="是否过磅">
              <p-switch v-model="form.isWeigh" checkedChildren="是" unCheckedChildren="否" :replaceFields="{ true: 1, false: 0 }" />
            </p-form-model-item>
          </a-col>
        </a-row>
      </p-form-model>
      <a-divider orientation="left">运单信息</a-divider>
      <p-table
        ref="masterTable"
        dragle
        bordered
        :customScrollbar="true"
        :extendedObjectCode="'15'"
        row-key="shipbillId"
        :id="$route.meta.menuId + '_schedule'"
        :scroll="{ x: true, y: 300 }"
        :data-source.sync="loadingBillDetailVO"
        :rowSelectType="false"
        :columns="columns"
        :autoLoad="false"
        :pagination="false"
        :customRow="customRow"
      >
      </p-table>
    </p-spin>
  </p-card>
</template>

<script>
import * as $formItems from '@/blocks/components/searchModalConfig/index';
import { Dispatch, dispatch_review, getCarData } from '../js/api';
import { setSchedulingColumns } from '@/blocks/components/scheduling/js/table/tableConfig.js';

export default {
  props: {
    customRow: {
      type: null,
    },
    defaultGroupName: { type: null },
    groupName: { type: null },
    //方向属性
    lineDirection: {
      type: null,
    },
    orderList: {
      type: Array,
      default: () => [],
    },
    options: {
      type: Object,
      default: () => ({}),
    },
    groupDimensionList: {
      type: Array,
      default: () => [],
    },
    mextendedField_list: {
      type: Array,
      default: () => [],
    },
    shipbillIdList: {
      type: Array,
      default: () => [],
    },
    //承运商策略数据
    carrierStrategyForm: {
      type: Object,
    },
  },
  computed: {
    RELATION_THIRD_SYSTEM() {
      //关联外网系统
      return this.$store.state?.sysParameter?.sysParameter_TMS?.RELATION_THIRD_SYSTEM?.value ?? '';
    },
    driverAttr() {
      let driverAttr = $formItems.driverAttr;
      driverAttr.remoteBefore = (vode, res) => {
        res.data.vehicleTypeId = this.defaultVehicleTypeId;
      };
      driverAttr.tableConfig.rowSelectType = 2;
      return driverAttr;
    },
    deliveryAttr() {
      let deliveryAttr = $formItems.deliveryAttr;
      deliveryAttr.tableConfig.rowSelectType = 2;
      return deliveryAttr;
    },
    carAttr() {
      return Object.assign({ remoteData: { vehicleTypeId: this.defaultVehicleTypeId, driverIds: this.form.driverId ? this.form.driverId.split(',') : [] } }, $formItems.carAttr);
    },
    affiliationAttr() {
      let carrierAttr = $formItems.carrierAttr;
      carrierAttr.targetValueKey = 'name';
      return carrierAttr;
    },
    deviceAttr() {
      let deviceAttr = $formItems.deviceAttr_scanPage;
      deviceAttr.tableConfig.rowSelectType = 2;
      return Object.assign({ remoteData: { vehicleId: this.form.vehicleId } }, deviceAttr);
    },
  },
  data() {
    return {
      selfCar: true,
      columns: setSchedulingColumns(this, this.mextendedField_list),
      s_lineDirection: this.lineDirection,
      spinning: false,
      $formItems,
      loadingBillDetailVO: [],
      defaultVehicleTypeId: null, //车型ID
      form: {
        isWeigh: 0,
        vehicleAscriptionName: '',
        vehicleAscription: '',
        carrierSysFlag: '',
        memo: '',
        minEstimatedPickupTime: '',
        maxEstimatedDeliveryTime: '',
        shipbillNumber: 0,
        actualTotalPcs: 0,
        actualTotalWeight: 0,
        actualTotalVolume: 0,
        totalPcs: '',
        totalVolume: '',
        totalWeight: '',
        carrierType: 1,
        driverId: '',
        driverCode: '',
        driverName: '',
        driverPhoneNumber: '',
        deliverymanId: '',
        deliverymanCode: '',
        deliverymanName: '',
        deliverymanPhoneNumber: '',
        vehicleId: '',
        vehicleCode: '',
        vehiclePlateNumber: '',
        vehicleTypeCode: '',
        vehicleTypeName: '',
        volumeLoadingRate: '',
        weightLoadingRate: '',
        carrierId: '',
        carrierCode: '',
        carrierName: '',
        customerNumber: 0,
        siteNumber: 0,
        containerName: '',
        containerCode: '',
        containerId: '',
      },
      disAffiliation: false,
      rules: {
        carrierType: [{ required: true, message: '承运方类型不能为空', trigger: 'change' }],
        driverName: [{ required: true, message: '司机不能为空', trigger: 'change' }],
        carrierCode: [{ required: true, message: '承运商不能为空', trigger: 'change' }],
        driverPhoneNumber: [{ required: true, trigger: 'blur', type: 'phone' }],
        vehiclePlateNumber: [{ required: true, trigger: 'change', type: 'plateNumber' }],
      },

      //groupDimensionList: [],
    };
  },
  watch: {
    mextendedField_list(v) {
      this.columns = setSchedulingColumns(this, v);
    },
    lineDirection(v) {
      this.s_lineDirection = v;
    },
    carrierStrategyForm(data) {
      this.defaultVehicleTypeId = null;
      if (data) {
        this.defaultVehicleTypeId = data.vehicleTypeId;
        this.form.volumeLoadingRate = data.volume ? parseFloat(this.BigJs(this.form.actualTotalVolume).div(data.volume).times(100)).toFixed(0) + '%' : '';
        this.form.weightLoadingRate = data.weight ? parseFloat(this.BigJs(this.form.actualTotalWeight).div(data.weight).times(100)).toFixed(0) + '%' : '';
        this.form = { ...this.form, ...data };

        if (data.vehiclePlateNumber) {
          this.form.vehiclePlateNumber = data.vehiclePlateNumber;

          return getCarData(this, data.vehiclePlateNumber).then((p) => {
            if (p) {
              for (let key in this.form) {
                if (typeof this.form[key] !== 'undefined' && !this.form[key]) {
                  this.form[key] = p[key];
                }
              }
              this.form.vehicleTypeCategoryName = p.typeCategoryName;
              this.form.vehicleTypeCategory = p.typeCategory;
              this.form.vehicleDeviceName = p.deviceName;
              this.form.vehicleDeviceCode = p.deviceCode;
              // this.form.actualTotalWeight = p.weight;
              // this.form.actualTotalVolume = p.volume;
              this.form.vehicleDeviceId = p.deviceId;
              this.form.vehicleAffiliationName = p.affiliationName;
              this.form.vehicleAffiliationId = p.affiliationId;
              this.form.vehicleAffiliationCode = p.affiliationCode;
              this.form.volumeLoadingRate = p.volume
                ? parseFloat(
                    this.BigJs(this.form.actualTotalVolume || 0)
                      .div(p.volume)
                      .times(100)
                  ).toFixed(0) + '%'
                : '';
              this.form.weightLoadingRate = p.weight
                ? parseFloat(
                    this.BigJs(this.form.actualTotalWeight || 0)
                      .div(p.weight)
                      .times(100)
                  ).toFixed(0) + '%'
                : '';
            }
          });
        }
      }
    },
  },
  mounted() {
    let consigneeUnitNameSet = new Set(),
      consigneeNameSet = new Set();

    this.loadingBillDetailVO = this.orderList.map((item, index) => {
      this.form.actualTotalPcs = parseFloat(this.BigJs(this.form.actualTotalPcs).plus(item.totalPcs || 0));
      this.form.actualTotalWeight = parseFloat(this.BigJs(this.form.actualTotalWeight).plus(item.totalWeight || 0));
      this.form.actualTotalVolume = parseFloat(this.BigJs(this.form.actualTotalVolume).plus(item.totalVolume || 0));
      consigneeUnitNameSet.add(item.consigneeUnitName);
      consigneeNameSet.add(item.consigneeName);
      item.shippingOrder = index + 1;
      return { ...item };
    });

    this.form.shipbillNumber = this.loadingBillDetailVO.length;
    this.form.customerNumber = consigneeUnitNameSet.size;
    this.form.siteNumber = consigneeNameSet.size;
    this.form.totalPcs = this.form.actualTotalPcs;
    this.form.totalVolume = this.form.actualTotalVolume;
    this.form.totalWeight = this.form.actualTotalWeight;
  },
  methods: {
    settingGroupClick() {
      this.$emit('visibleSettingGroup', true);
    },
    handleSystemGroupClick() {
      if (this.defaultGroupName) {
        this.$emit('back', 'packetScheduling', {
          groupDimensionList: [],
          groupConfigName: this.defaultGroupName,
          shipbillIdList: this.shipbillIdList,
          groupNumber: 1,
        });
      } else {
        this.$emit('visibleSettingGroup', true);
      }
    },
    onSystemGroup() {
      this.$emit('back', 'packetScheduling', {
        groupDimensionList: this.groupDimensionList,
        groupConfigName: this.groupName,
        shipbillIdList: this.shipbillIdList,
        groupNumber: 1,
      });
    },
    // 返回
    back() {
      this.defaultVehicleTypeId = null;
      this.$emit('back');
    },
    // 调度、审核
    onSave(method) {
      this.$refs.ruleForm.validate((valid) => {
        if (!valid) return false;
        this.spinning = true;
        const { volumeLoadingRate, weightLoadingRate } = this.form;
        let params = {
          loadingBillDetailVO: this.loadingBillDetailVO.map((item) => {
            return { shipbillId: item.shipbillId };
          }),
          loadingBillHeaderVO: { ...this.form, volumeLoadingRate: volumeLoadingRate, weightLoadingRate: weightLoadingRate },
        };
        switch (method) {
          case 'dispatch':
            Dispatch(params)
              .then((res) => {
                if (res.success) {
                  this.$message.success(res.message);
                  this.back();
                } else {
                  this.$exception(res);
                }
              })
              .finally(() => {
                this.spinning = false;
              });
            break;

          case 'review':
            dispatch_review(params)
              .then((res) => {
                if (res.success) {
                  this.$message.success(res.message);
                  this.defaultVehicleTypeId = null;
                  this.back();
                } else {
                  this.$exception(res);
                }
              })
              .finally(() => {
                this.spinning = false;
              });
            break;
        }
      });
    },

    // 分组调度
    handleMenuClick(event, type, value) {
      this.$emit('menuClick', event, type, value);
    },
    onPacketScheduling() {
      this.$emit('onPacketScheduling', {
        groupDimensionList: this.groupDimensionList,
        shipbillIdList: this.shipbillIdList,
      });
    },

    carrierTypeChange() {
      this.form.vehicleAscriptionName = '';
      this.form.vehicleAscription = '';
      this.form.carrierSysFlag = '';
      this.form.driverId = '';
      this.form.memo = '';
      this.form.driverCode = '';
      this.form.driverName = '';
      this.form.driverPhoneNumber = '';
      this.form.deliverymanId = '';
      this.form.deliverymanCode = '';
      this.form.deliverymanName = '';
      this.form.deliverymanPhoneNumber = '';
      this.form.vehicleId = '';
      this.form.vehicleCode = '';
      this.form.vehiclePlateNumber = '';
      this.form.vehicleTypeCode = '';
      this.form.vehicleTypeName = '';
      this.form.carrierId = '';
      this.form.carrierCode = '';
      this.form.carrierName = '';
      this.form.containerName = '';
      this.form.containerId = '';
      this.form.containerCode = '';
      this.$refs.ruleForm.clearValidate();
    },
    onFormChange(name, ...args) {
      let idList = [],
        codeList = [],
        phoneList = [],
        affiliationIdSet = new Set(),
        affiliationCodeSet = new Set(),
        affiliationNameSet = new Set();
      let vehiclePlateNumber = null;
      args[2].forEach((item) => {
        idList.push(item.id);
        codeList.push(item.code);
        if (name === 'driver' || name === 'delivery') phoneList.push(item.phoneNumber);
        if (name === 'driver') {
          affiliationIdSet.add(item.affiliationId);
          affiliationCodeSet.add(item.affiliationCode);
          affiliationNameSet.add(item.affiliationName);
          this.form.vehiclePlateNumber = vehiclePlateNumber = item.vehiclePlateNumber;
          this.form.vehicleId = item.vehicleId;
          this.form.vehicleCode = item.vehicleCode;
        }
      });
      if (!args[1]) args[2] = [{}];
      if (name === 'driver') {
        this.form.driverId = idList.join(',');
        this.form.driverCode = codeList.join(',');
        this.form.driverName = args[1];
        this.form.driverPhoneNumber = phoneList.join(',');

        if (idList.length === 1 && vehiclePlateNumber) {
          //查询车辆数据
          this.form.vehiclePlateNumber = vehiclePlateNumber;

          getCarData(this, vehiclePlateNumber).then((p) => {
            if (p) {
              if (args[2][0].hasVehicleTypeDriver !== '1') {
                delete p.vehicleTypeCode;
                delete p.vehicleTypeName;
              }
              for (let key in this.form) {
                if (typeof this.form[key] !== 'undefined' && !this.form[key]) {
                  this.form[key] = p[key];
                }
              }
              this.form.vehicleAscriptionName = p.vehicleAscriptionName;
              this.form.vehicleAscription = p.vehicleAscription;
              this.form.vehicleTypeCategoryName = p.typeCategoryName;
              this.form.vehicleTypeCategory = p.typeCategory;
              this.form.vehicleDeviceName = p.deviceName;
              this.form.vehicleDeviceCode = p.deviceCode;
              // this.form.actualTotalWeight = p.weight;
              // this.form.actualTotalVolume = p.volume;
              this.form.volumeLoadingRate = p.volume ? parseFloat(this.BigJs(this.form.actualTotalVolume).div(p.volume).times(100)).toFixed(0) + '%' : '';
              this.form.weightLoadingRate = p.weight ? parseFloat(this.BigJs(this.form.actualTotalWeight).div(p.weight).times(100)).toFixed(0) + '%' : '';
              this.form.vehicleDeviceId = p.deviceId;
              this.form.vehicleAffiliationName = p.affiliationName;
              this.form.vehicleAffiliationId = p.affiliationId;
              this.form.vehicleAffiliationCode = p.affiliationCode;
            }
          });
        }
        // 如果选择的司机里只有一个隶属机构（承运商），回显并且不能编辑；如果有多个，弹窗编辑
        if (affiliationIdSet.size === 1) {
          this.disAffiliation = true;
          this.form.vehicleAffiliationId = [...affiliationIdSet][0];
          this.form.vehicleAffiliationCode = [...affiliationCodeSet][0];
          this.form.vehicleAffiliationName = [...affiliationNameSet][0];
        } else {
          this.disAffiliation = false;
          this.form.vehicleAffiliationId = '';
          this.form.vehicleAffiliationCode = '';
          this.form.vehicleAffiliationName = '';
        }

        // 如果只有一辆车，默认选中
        if (args[2].length === 1) {
          this.form.vehicleId = args[2][0].vehicleId;
          this.form.vehicleCode = args[2][0].vehicleCode;
          this.form.vehiclePlateNumber = args[2][0].vehiclePlateNumber;
          this.form.vehicleTypeCode = args[2][0].vehicleTypeCode;
          this.form.vehicleTypeName = args[2][0].vehicleTypeName;
          this.form.vehicleTypeCategory = args[2][0].vehicleTypeCategory;
          this.form.vehicleTypeCategoryName = args[2][0].vehicleTypeCategoryName;
          this.form.vehicleDeviceId = '';
          this.form.vehicleDeviceCode = '';
          this.form.vehicleDeviceName = '';
          this.form.containerId = '';
          this.form.containerCode = '';
          this.form.containerName = '';
          this.form.volumeLoadingRate = args[2][0].volume ? parseFloat(this.BigJs(this.form.actualTotalVolume).div(args[2][0].volume).times(100)).toFixed(0) + '%' : '';
          this.form.weightLoadingRate = args[2][0].weight ? parseFloat(this.BigJs(this.form.actualTotalWeight).div(args[2][0].weight).times(100)).toFixed(0) + '%' : '';
        }
      } else if (name === 'delivery') {
        this.form.deliverymanId = idList.join(',');
        this.form.deliverymanCode = codeList.join(',');
        this.form.deliverymanName = args[1];
        this.form.deliverymanPhoneNumber = phoneList.join(',');
      } else if (name === 'car') {
        this.selfCar = true;
        this.form.vehicleAscriptionName = args[2][0].vehicleAscriptionName;
        this.form.vehicleAscription = args[2][0].vehicleAscription;
        this.form.vehicleId = args[2][0].id;
        this.form.vehicleCode = args[2][0].code;
        this.form.vehiclePlateNumber = args[2][0].plateNumber;
        this.form.vehicleTypeCode = args[2][0].vehicleTypeCode;
        this.form.vehicleTypeName = args[2][0].vehicleTypeName;
        this.form.vehicleTypeCategory = args[2][0].typeCategory;
        this.form.vehicleTypeCategoryName = args[2][0].typeCategoryName;
        this.form.vehicleDeviceId = args[2][0].deviceId;
        this.form.vehicleDeviceCode = args[2][0].deviceCode;
        this.form.vehicleDeviceName = args[2][0].deviceName;
        this.form.containerId = args[2][0].containerId;
        this.form.containerCode = args[2][0].containerCode;
        this.form.containerName = args[2][0].containerName;

        if (args[1]) {
          this.form.volumeLoadingRate = args[2][0].volume ? parseFloat(this.BigJs(this.form.actualTotalVolume).div(args[2][0].volume).times(100)).toFixed(0) + '%' : '';
          this.form.weightLoadingRate = args[2][0].weight ? parseFloat(this.BigJs(this.form.actualTotalWeight).div(args[2][0].weight).times(100)).toFixed(0) + '%' : '';
        }
      } else if (name === 'carrier') {
        this.form.carrierId = args[2][0].id;
        this.form.carrierCode = args[2][0].code;
        this.form.carrierName = args[2][0].name;
        this.form.carrierSysFlag = args[2][0].carrierSysFlag;
      } else if (name === 'affiliation') {
        this.form.vehicleAffiliationId = args[2][0].id;
        this.form.vehicleAffiliationCode = args[2][0].code;
        this.form.vehicleAffiliationName = args[2][0].name;
      } else if (name === 'device') {
        let idList = [],
          codeList = [],
          nameList = [];
        args[2].forEach((item) => {
          item.deviceId && idList.push(item.deviceId);
          item.deviceCode && codeList.push(item.deviceCode);
          item.deviceName && nameList.push(item.deviceName);
        });
        this.form.vehicleDeviceId = idList.join(',');
        this.form.vehicleDeviceCode = codeList.join(',');
        this.form.vehicleDeviceName = nameList.join(',');
      } else if (name === 'container') {
        let idList = [],
          codeList = [],
          nameList = [];
        args[2].forEach((item) => {
          item.id && idList.push(item.id);
          item.code && codeList.push(item.code);
          item.name && nameList.push(item.name);
        });
        this.form.containerId = idList.join(',');
        this.form.containerCode = codeList.join(',');
        this.form.containerName = nameList.join(',');
      } else if (name === 'vehicleType') {
        this.defaultVehicleTypeId = args[2][0].id;
        this.form.vehicleTypeCode = args[2][0].code;
        this.form.vehicleTypeName = args[2][0].name;
        this.form.vehicleTypeCategory = args[2][0].type;
        this.form.vehicleTypeCategoryName = args[2][0].typeName;
      }
    },

    onFormInput(name) {
      switch (name) {
        case 'driver':
          this.form.driverId = '';
          this.form.driverCode = '';
          break;
        case 'delivery':
          this.form.deliverymanId = '';
          this.form.deliverymanCode = '';
          this.form.deliverymanPhoneNumber = '';
          break;
        case 'car':
          this.selfCar = false;
          this.form.vehicleId = '';
          this.form.vehicleCode = '';
          this.form.vehicleTypeCode = '';
          this.form.vehicleTypeName = '';
          this.form.volumeLoadingRate = '';
          this.form.weightLoadingRate = '';
          this.form.vehicleTypeCategory = '';
          this.form.vehicleTypeCategoryName = '';
          this.form.vehicleDeviceId = '';
          this.form.vehicleDeviceCode = '';
          this.form.vehicleDeviceName = '';
          this.form.containerId = '';
          this.form.containerCode = '';
          this.form.containerName = '';
          break;
      }
    },
  },
};
</script>