


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


export const setUpdateForm = (self) => {

  let driver = driverAutoCompleteMethod(self,
    {
      subName: ['driverId', 'driverCode','driverPhoneNumber'],
      name: 'driverName',
      label: '司机姓名',
      disabled: self.carrierType !== 2,
      required:self.carrierType == 2,
      on: {
        ok(event, value, dataArr, form) {
          if (dataArr.length > 0) {
            let _vehiclePlateNumber = [],_vehicleCode=[],_vehicleId=[]
            dataArr.forEach(item => {

              const { vehiclePlateNumber,vehicleCode,vehicleId } = item
              _vehiclePlateNumber.push(vehiclePlateNumber)
              _vehicleCode.push(vehicleCode)
              _vehicleId.push(vehicleId)
            });
            form.setFieldsValue({
              vehiclePlateNumber: _vehiclePlateNumber.join(','),
              vehicleCode: _vehicleCode.join(','),
              vehicleId: _vehicleId.join(','),
            })
          }
        }
      }
    }
  );
  Object.defineProperties(driver, {
    disabled: {
      get() {
        return self.carrierType !== 2
      }
    },
    required: {
      get() {
        return self.carrierType == 2
      }
    }
  });
  let car=carAutoCompleteMethod(self,{
    subName: ['vehicleId', 'vehicleCode'],
    ...carAttr,
    targetClick: false,
    name: 'vehiclePlateNumber',
    label: '车辆',
    disabled: self.carrierType !== 2,
    required:self.carrierType == 2,
    validateTrigger: 'blur',
    rules: [
      {
        type: 'plateNumber',
      },
    ]

  },)




  Object.defineProperties(car, {
    disabled: {
      get() {
        return self.carrierType !== 2
      }
    },
    required: {
      get() {
        return self.carrierType == 2
      }
    }
  })
  const formItmes = [
    {
      name: 'productName',
      label: '产品名称',
      hidden: true,
    },
    {
      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
      },
      get required() {
        return self.carrierType == 1
      },
      on: {
        change(event, value, dataArr, form) {
          let obj = { carrierId: '', carrierCode: '' }
          let data = dataArr[0]
          if (data) {
            obj = { carrierId: data.id, carrierCode: data.code }
          }
          form.setFieldsValue(obj)
        },
      },
    },
    driver,
    car,


    {
      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

}
