import request from '@/utils/request'

import { driverAttr, driverAutoCompleteMethod, deviceAttr_scanPage, carAttr, vehicleTypeAttr, carrierAttr,containerAttr } from '@/blocks/components/searchModalConfig/index'

import { UPCLOUD_RDC_TMS_MAINDATA_SERVICE, UPCLOUD_RDC_TMS_BMS_SERVICE } from '@/config/serviceSettings.js'
const serviceName = UPCLOUD_RDC_TMS_MAINDATA_SERVICE




export const setFromItems = (self) => {
  return [
    driverAutoCompleteMethod(self,  {
      type: 'searchModal',
      name: 'driverName',
      label: '司机姓名',
      required: true,
      subName:['driverCode','driverId'],
      on: {
        change(event, value, form) {
          if (!value) {
            form.setFieldsValue({
              driverId: '',
              driverCode: '',
              driverPhoneNumber: '',
            })
          }
        },
        ok(event, value, dataArr, form) {
          if (dataArr.length > 0) {
            let driverId = [], driverCode = [], driverPhoneNumber = [],_vehiclePlateNumber=[]
            let obj = null
            dataArr.forEach(item => {
              const { id, code, phoneNumber ,vehiclePlateNumber} = item
              driverId.push(id)
              driverCode.push(code)
              driverPhoneNumber.push(phoneNumber)
              _vehiclePlateNumber.push(vehiclePlateNumber)
            });
            form.setFieldsValue({
              ...obj,
              driverId: driverId.join(','),
              driverCode: driverCode.join(','),
              driverPhoneNumber: driverPhoneNumber.join(','),
              vehiclePlateNumber: _vehiclePlateNumber.join(','),
            })
          }
        }
      }
    }
    ),

    {
      name: 'driverPhoneNumber',
      label: '司机电话',
      type: 'input',
      //required: true,
      rules: [
        {
          type: 'phone',
          required: true,
        },
      ],
      validateTrigger: 'blur',
    },
    {
      name: 'vehiclePlateNumber',
      label: '车辆',
      type: 'input',
      validateTrigger: 'blur',
      rules: [
        {
          type: 'plateNumber',
          required: true,
        },
      ],
    },
    {
      subName:['containerBillNos','containerBillNo','vehicleId'],
      name: 'consigneeName',
      label: '原发货方',
      type: 'txt',
     // required: true,
    },
  ];

}
//编辑容器明细
export const setContinerEditColumns = (self) => {

  return [
    {
      dataIndex: '_containerTypeValue',
      type:'txt',
      title: '容器类型',
      on: {
        change: function ({record,value,label}) {
          record.containerType=value
          record.containerTypeName = label
        }
      },
      customColumnProps({ name, value, record, index, props }) {
        record._containerTypeValue=record.containerTypeName
        if (record.id === null) {
          props.type = 'select'
          props.options = self.options.CONTAINER_TYPE;
          props.required = true
          //props.dataIndex = 'containerType'
        }
      },
    },
    {
      dataIndex: 'containerCode',
      title: '容器编码',
      type: 'txt',
      customColumnProps({  name, value, record, index, props}) {
        if (record.id === null) {
          props.type='edit'
          props.required = true
        }
      },



    },
    {
      autoLoad: false,
      align: 'center',
      options:self.options.CONTAINER_ABNORMAL_STATUS,
      dataIndex: 'abnormalStatus',
      type:'select',
      title: '异常标记',
      customColumnProps({  name, value, record, index, props},ref) {
        if (record.id === null) {
          record.abnormalStatus=2
          record.abnormalStatusName='多货'
          props.customRender = ( value, record, index) => {
            return self._c('a-space', {}, [
              self._v(record.abnormalStatusName),
              self._c('a', {
                attrs: {
                    href:'javascript:'
                },
                on: {
                  click: () => {

                    ref.removeRow(record._row_count);

                  }
                }
              },[self._v('删除')])
            ])
          }


        }
      },

    },


  ]
}
