import { UPCLOUD_RDC_TMS_BMS_SERVICE } from '@/config/serviceSettings.js'


function disabledTime(name) {
  return function (endValue, form) {
    let startValue = form.getFieldValue(name)
    if (!startValue || !endValue) {
      return false
    }
    return new Date(startValue).valueOf() >= endValue.valueOf()
  }
}

export const setQueryFormItmes = (self) => {
  return {
    // 运单
    waybillAttr: {
      modalWidth: 1000,
      label: '运单',
      placeholder: '请选择运单',
      targetClick: true,
      targetValueKey: 'id',
      remoteUrl: { url: UPCLOUD_RDC_TMS_BMS_SERVICE + '/driverFeeSettlement/page', method: 'post' },
      rowKey: 'id',
      remoteBefore: (vNode, remoteUrl) => {
        let excludeFeeIdList = self.dataSource.map(item => item.id);
        remoteUrl.data = {
          excludeFeeIdList,
          ...remoteUrl.data,
        }
      },
      toolBar: {
        labelCol: { span: 8 },
        wrapperCol: { span: 16 },
        items: [
          { type: 'input', name: 'cargoOwnerName', label: '货主' },
          { type: 'input', name: 'carrierName', label: '承运商' },
          { type: 'input', name: 'driverName', label: '司机' },
          { type: 'input', name: 'vehiclePlateNumber', label: '车牌号' },
          { type: 'input', name: 'loadingBillNo', label: '派车单号' },
          {
            name: 'startDate',
            disabledDate: disabledTime('endDate'),
            label: '下单开始时间',
            type: 'date',
            showTime: true,
            // format: 'YYYY-MM-DD',
            placeholder: '年/月/日',
            on: {
              openChange(open, form) {
                if (!open) {
                  form.setItemProps('endDate', { open: true })
                }
              },
            },
          },
          {
            name: 'endDate',
            label: '下单结束时间',
            disabledDate: disabledTime('startDate'),
            type: 'date',
            showTime: true,
            // format: 'YYYY-MM-DD',
            placeholder: '年/月/日',
            on: {
              openChange(open, form) {
                form.setItemProps('endDate', { open })
              },
            },
          },
        ],
      },
      tableConfig: {
        rowSelectType: 2,
        scroll: { x: true },
        columns: [],
      },
    },
  }
}

