


import { carrierAttr, driverAutoCompleteMethod } from '@/blocks/components/searchModalConfig'


export const setUpdateForm = (self) => {
  let driver = driverAutoCompleteMethod(self,
    {
      subName: ['driverId', 'driverCode'],
      name: 'driverName',
      label: '司机姓名',
      disabled: self.carrierType !== 2,
      on: {
        ok(event, value, dataArr, form) {
          if (dataArr.length > 0) {
            let _vehiclePlateNumber = []
            dataArr.forEach(item => {
              const { vehiclePlateNumber } = item
              _vehiclePlateNumber.push(vehiclePlateNumber)
            });
            form.setFieldsValue({
              vehiclePlateNumber: _vehiclePlateNumber.join(','),
            })
          }
        }
      }
    }
  );

  const formItmes = [
    {
      name: 'planTotalPcs',
      label: '计划箱数',
      required: true,
      type: 'number',
    },
    {
      name: 'planTotalVehicleNumber',
      label: '计划车数',
      type: 'number',
      required: true,
      min: 1,
      value: 1
    },
    {
      name: 'planDeliveryDate',
      label: '计划发货日期',
      required: true,
      type: 'date',
      format: 'YYYY-MM-DD HH:mm',
      showTime: true,
      // value: self.moment().format('YYYY-MM-DD HH:mm')
    },
    {
      name: 'isWeigh',
      type: "radio",
      label: '是否过磅',
      value: 0,
      options: [
        { label: "是", value: 1 },
        { label: "否", value: 0 },
      ],
    },
    {
      name: 'carrierType',
      label: '承运商类型',
      required: true,
      type: 'select',
      get options() {
        return self.options.LINE_CARRIER_TYPE
      },
      on: {
        change: function (valeu, label, data, form) {
          self.carrierType = valeu;
          driver.disabled = valeu !== 2;
          form.setFieldsValue({
            carrierId: '',
            carrierCode: '',
            carrierName: '',
            vehiclePlateNumber: '',
            driverId: '', driverCode: '', driverName: '',
          })


        }
      }
    },
    {
      ...carrierAttr,
      label: '承运商',
      targetValueKey: 'name',
      subName: ['carrierId', 'carrierCode'],
      name: 'carrierName',
      type: 'searchModal',
      get disabled() {
        return self.carrierType !== 1
      }
    },
    driver,
    {
      name: 'vehiclePlateNumber',
      label: '车辆',
      type: 'input',
      get disabled() {
        return self.carrierType !== 2
      },
      validateTrigger: 'blur',
      rules: [
        {
          type: 'plateNumber',
          required: false,
        },
      ],
    },
    {
      name: 'transfiniteCommitDate',
      label: '超限提交日期',
      type: 'date',
      format: 'YYYY-MM-DD HH:mm',
      showTime: true,

    },
    {
      name: 'transfiniteDescription',
      label: '超限说明',
      type: 'input',

    },
    {
      name: 'loadingLocation',
      label: '装货地点',
      type: 'input',

    },
    {
      name: 'deliveryDescription',
      label: '待发运情况说明',
      value: '',
      type: 'input',

    }
  ]

  return formItmes

}
