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) => {
  console.log(self);
  return {
    // 运单
    waybillAttr: {
      modalWidth: 1000,
      label: '试算实验',
      placeholder: '请选择运单',
      targetClick: true,
      targetValueKey: 'id',
      remoteUrl: { url: UPCLOUD_RDC_TMS_BMS_SERVICE + '/shipBill/findList/v1.0', method: 'post' },
      rowKey: 'id',
      // remoteBefore: (vNode, remoteUrl) => {
      //   remoteUrl.data = { appointmentId: self.editData.appointmentId, ...remoteUrl.data }
      // },
      toolBar: {
        labelCol: { span: 8 },
        wrapperCol: { span: 16 },
        items: [
          { type: 'input', name: 'cargoOwnerName', label: '货主' },
          { type: 'input', name: 'orderNo', label: '订单号' },
          { type: 'input', name: 'shipbillNo', label: '运单号' },
          {
            name: 'orderBusinessType',
            label: '业务类型',
            type: 'select',
            get options() {
              return self.options.ORDER_BUSINESS_TYPE
            },
          },
          { type: 'input', name: 'shipperName', label: '发货方' },
          { type: 'input', name: 'consigneeName', label: '收货方' },
          {
            name: 'orderDateStart',
            disabledDate: disabledTime('orderDateEnd'),
            label: '下单开始时间',
            type: 'date',
            showTime: true,
            // format: 'YYYY-MM-DD',
            placeholder: '年/月/日',
            on: {
              openChange(open, form) {
                if (!open) {
                  form.setItemProps('orderDateEnd', { open: true })
                }
              },
            },
          },
          {
            name: 'orderDateEnd',
            label: '下单结束时间',
            disabledDate: disabledTime('orderDateStart'),
            type: 'date',
            showTime: true,
            // format: 'YYYY-MM-DD',
            placeholder: '年/月/日',
            on: {
              openChange(open, form) {
                form.setItemProps('orderDateEnd', { open })
              },
            },
          },
        ],
      },
      tableConfig: {
        rowSelectType: 1,
        scroll: { x: true },
        columns: [
          { width: 120, dataIndex: 'shipbillNo', title: '运单号' },
          { width: 120, dataIndex: 'cargoOwnerName', title: '货主' },
          { width: 120, dataIndex: 'orderNo', title: '订单号' },
          { width: 120, dataIndex: 'wmsOrderNo', title: 'WMS单号' },
          { width: 120, dataIndex: 'orderTypeName', title: '订单类型' },
          { width: 120, dataIndex: 'orderBusinessTypeName', title: '业务类型' },
          { width: 120, dataIndex: 'deliveryMethodTypeName', title: '配送方式' },
          { width: 120, dataIndex: 'transportTypeName', title: '运输模式' },
          { width: 120, dataIndex: 'temperatureRequirementName', title: '温度要求' },
          { width: 120, dataIndex: 'lineName', title: '线路' },
          { width: 120, dataIndex: 'orderDate', title: '订单下单日期' },
          { width: 120, dataIndex: 'estimatedPickupStartTime', title: '预计提货时间' },
          { width: 120, dataIndex: 'estimatedDeliveryStartTime', title: '预计送达时间' },
          { width: 120, dataIndex: 'transportAging', title: '时效' },
          { width: 120, dataIndex: 'shipperTypeName', title: '发货方类型' },
          { width: 120, dataIndex: 'shipperUnitName', title: '发货方单位' },
          { width: 120, dataIndex: 'shipperName', title: '发货方' },
          { width: 120, dataIndex: 'shipperProvinceCityDistrict', title: '始发地' },
          { width: 120, dataIndex: 'shipperContact', title: '联系人' },
          { width: 120, dataIndex: 'shipperPhoneNumber', title: '手机号' },
          { width: 120, dataIndex: 'shipperLandlineNumber', title: '座机号' },
          { width: 120, dataIndex: 'shipperEmail', title: '邮箱' },
          { width: 120, dataIndex: 'shipperAddress', title: '详细地址' },
          { width: 120, dataIndex: 'shipperMemo', title: '备注' },
          { width: 120, dataIndex: 'shipperPositioning', title: '发货方位置' },
          { width: 120, dataIndex: 'consigneeTypeName', title: '收货方类型' },
          { width: 120, dataIndex: 'consigneeUnitName', title: '收货方单位' },
          { width: 120, dataIndex: 'consigneeName', title: '收货方' },
          { width: 120, dataIndex: 'consigneeProvinceCityDistrict', title: '目的地' },
          { width: 120, dataIndex: 'consigneeContact', title: '联系人' },
          { width: 120, dataIndex: 'consigneePhoneNumber', title: '手机号' },
          { width: 120, dataIndex: 'consigneeLandlineNumber', title: '座机号' },
          { width: 120, dataIndex: 'consigneeEmail', title: '邮箱' },
          { width: 120, dataIndex: 'consigneeAddress', title: '详细地址' },
          { width: 120, dataIndex: 'consigneeMemo', title: '备注' },
          { width: 120, dataIndex: 'consigneePositioning', title: '收货方位置' },
          { width: 120, dataIndex: 'totalPcs', title: '总件数' },
          { width: 120, dataIndex: 'totalWeight', title: '总重量' },
          { width: 120, dataIndex: 'totalVolume', title: '总体积' },
          { width: 120, dataIndex: 'packageWholePiece', title: '整件数' },
          { width: 120, dataIndex: 'packageLclPiece', title: '拼箱数' },
          { width: 120, dataIndex: 'packageTotalWeight', title: '包裹总重量' },
          { width: 120, dataIndex: 'packageTotalVolume', title: '包裹总体积' },
        ],
      },
    },
  }
}

