import { UPCLOUD_RDC_TMS_BMS_SERVICE } from '@/config/serviceSettings.js'
import myClass from '@/views/BMS/$common/tableConfig/shipbillClass.js'

let consignee = new myClass({ name: '收货方', key: 'consignee' })
let shipper = new myClass({ name: '发货方', key: 'shipper' })

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 + '/settlementManagement/findList', method: 'post' },
      rowKey: 'id',
      remoteBefore: (vNode, remoteUrl) => {
        let expenseNoList = self.dataSource.map(item => item.expenseNo);
        remoteUrl.data = {
          settlementDepartment: self.form.settlementDepartment,
          settlementCompany: self.form.settlementCompany,
          carrierType: self.form.carrierType,
          affiliationName: self.form.carrierType == 2 ? self.form.carrierName : '',
          carrierCode: self.form.carrierType == 1 ? self.form.carrierCode : '',
          expenseNos: expenseNoList,
          ...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: {
        // let expenseNoList = self.dataSource.map(item => item.expenseNo);
        // getCheckboxProps: (record) => {
        //   return {
        //     props: {
        //       disabled: expenseNoList.includes(record.expenseNo)
        //     }
        //   }
        // },
        rowSelectType: 2,
        scroll: { x: true },
        columns: [
          { dataIndex: 'id', title: 'ID', hidden: true, width: 100, },
          {
            dataIndex: 'shipbillNo',
            sorter: (a, b) => {
              if (!a.shipbillNo || !b.shipbillNo) return
              return a.shipbillNo.replace(/[^0-9]/gi, '') - b.shipbillNo.replace(/[^0-9]/gi, '')
            },
            title: '运单号',
            width: 200,
            customRender: (txt, record) => {
              return self._c(
                'a',
                {
                  attrs: {
                    href: 'javascript:void(0)',
                  },
                  on: {
                    click: (event) => {
                      event.stopPropagation()
                      return self.$emit('view', record)
                    },
                  },
                },
                [self._v(txt)]
              )
            },
          },

          {
            dataIndex: 'expenseNo',
            title: '费用单号',
            width: 120,
            sorter: (a, b) => {
              if (!a.orderNo || !b.orderNo) {
                return
              }
              return a.expenseNo.replace(/[^0-9]/gi, '') - b.expenseNo.replace(/[^0-9]/gi, '')
            },
          },
          {
            dataIndex: 'expenseCode',
            title: '费用编码',
            width: 120,

          },
          {
            dataIndex: 'expenseName',
            title: '费用名称',
            width: 120,
            sorter: (a, b) => {
              return a.expenseName.length - b.expenseName.length
            },

          },
          {
            title: '费用科目编码',
            dataIndex: 'expenseAccountCode',
            width: 120,
            sorter: (a, b) => {
              return a.expenseAccountCode.length - b.expenseAccountCode.length
            },
          },
          {
            title: '费用科目名称',
            dataIndex: 'expenseAccountName',
            width: 120,
            sorter: (a, b) => {
              return a.expenseAccountName.length - b.expenseAccountName.length
            },

          },
          {
            title: '费用类型',
            dataIndex: 'expenseTypeName',
            width: 120,
            sorter: (a, b) => {
              return a.expenseType - b.expenseType
            },

          },
          {
            dataIndex: 'taxAmt',
            title: '含税金额',
            width: 120,
            sorter: (a, b) => {
              return a.taxAmt - b.taxAmt
            },

          },
          {
            dataIndex: 'noTaxAmt',
            title: '无税金额',
            width: 120,
            sorter: (a, b) => {
              return a.noTaxAmt - b.noTaxAmt
            },

          },
          {
            dataIndex: 'taxPoint',
            title: '税点',
            width: 100,
            sorter: (a, b) => {
              return a.taxPoint - b.taxPoint
            },

          },
          {
            dataIndex: 'tax',
            title: '税额',
            width: 100,
            sorter: (a, b) => {
              return a.tax - b.tax
            },

          },
          {
            dataIndex: 'expenseStatusName',
            title: '费用状态',
            width: 100,
            sorter: (a, b) => {
              return a.expenseStatus - b.expenseStatus
            },
          },
          {
            dataIndex: 'expenseMemo',
            title: '费用说明',
            width: 100,
            sorter: (a, b) => {
              if (!a.expenseMemo || !b.expenseMemo) {
                return
              }
              return a.expenseMemo.length - b.expenseMemo.length
            },

          },
          {
            dataIndex: 'billingSourceName',
            title: '费用来源',
            width: 100,
            sorter: (a, b) => {
              if (!a.billingSourceName || !b.billingSourceName) {
                return
              }
              return a.billingSourceName.length - b.billingSourceName.length
            },

          },

          {
            dataIndex: 'cargoOwnerName',
            title: '货主',
            width: 120,
            sorter: (a, b) => {
              return a.cargoOwnerName != b.cargoOwnerName
            }
          },
          {
            dataIndex: 'driverName',
            title: '司机名称',
            width: 120,
            sorter: (a, b) => {
              return a.driverName != b.driverName
            }
          },
          {
            dataIndex: 'orderNo',
            title: '订单号',
            width: 120,
            sorter: (a, b) => {
              if (!a.orderNo || !b.orderNo) {
                return
              }
              return a.orderNo.replace(/[^0-9]/gi, '') - b.orderNo.replace(/[^0-9]/gi, '')
            },
          },

          {
            dataIndex: 'settlementCompany',
            title: '结算公司',
            width: 100,
            sorter: (a, b) => {
              return a.settlementCompany - b.settlementCompany
            },
          },
          {
            dataIndex: 'settlementDepartment',
            title: '结算部门',
            width: 100,
            sorter: (a, b) => {
              return a.settlementDepartment - b.settlementDepartment
            },
          },

          {
            dataIndex: 'synchronousStatusName',
            title: '同步状态​',
            width: 100,
            sorter: (a, b) => {
              return a.synchronousStatus - b.synchronousStatus
            },
          },
          {
            width: 100,
            dataIndex: 'synchronousDate',
            title: '同步时间',
            align: 'center',
            sorter: (a, b) => {
              return +new Date(a.synchronousDate) - +new Date(b.synchronousDate)
            },
          },
          {
            width: 100,
            dataIndex: 'synchronousFailReason',
            title: '同步失败原因',
            sorter: (a, b) => {
              return a.synchronousFailReason - b.synchronousFailReason
            },
          },

          {
            width: 100,
            dataIndex: 'billingStatusName',
            title: '计费状态',
            sorter: (a, b) => {
              return a.billingStatus - b.billingStatus
            },
          },
          {
            width: 100,
            dataIndex: 'billingDate',
            title: '计费时间',
            sorter: (a, b) => {
              return +new Date(a.billingDate) - +new Date(b.billingDate)
            },
          },
          {
            width: 100,
            dataIndex: 'billingContract',
            title: '计费合同',
            sorter: (a, b) => {
              return a.billingContract - b.billingContract
            },
          },

          {
            width: 100,
            dataIndex: 'billingPrice',
            title: '计费价格表',
            sorter: (a, b) => {
              return a.billingPrice - b.billingPrice
            },
          },
          {
            width: 100,
            dataIndex: 'billingTypeName',
            title: '计费类别',
            sorter: (a, b) => {
              return a.billingType - b.billingType
            },
          },
          {
            width: 100,
            dataIndex: 'costFailReason',
            title: '计费失败原因',

          },

          {
            width: 100,
            dataIndex: 'settlementStatusName',
            title: '核算状态',
            // customRender: customRender(self, 'TEMPERATURE_REQUIREMENT'),
            sorter: (a, b) => {

              return a.settlementStatus - b.settlementStatus
            },
          },
          {
            width: 100,
            dataIndex: 'settlementDate',
            title: '核算时间',
            sorter: (a, b) => {
              return +new Date(a.settlementDate) - +new Date(b.settlementDate)
            },
          },
          {
            width: 100,
            dataIndex: 'shipBillStatusName',
            title: '运单状态',
            sorter: (a, b) => {
              return a.shipBillStatus - b.shipBillStatus
            },
          },
          {
            width: 100,
            dataIndex: 'abnormalStatusName',
            title: '异常状态',
            sorter: (a, b) => {
              return a.abnormalStatus - b.abnormalStatus
            },
          },
          {
            width: 100,
            dataIndex: 'carrierTypeName',
            title: '承运方类型',
            sorter: (a, b) => {
              return a.carrierType - b.carrierType
            },
          },
          {
            width: 160,
            dataIndex: 'loadingBillNo',
            title: '调度单号',
            sorter: (a, b) => {
            },
          },
          {
            width: 120,
            dataIndex: 'carrierName',
            title: '承运方名称',
            sorter: (a, b) => {

            },
          },
          {
            width: 120,
            dataIndex: 'deliveryName',
            title: '送货员姓名',
            sorter: (a, b) => {
            },
          },
          {
            width: 120,
            dataIndex: 'vehicleCode',
            title: '车牌号',
            sorter: (a, b) => {
              return a.vehicleId - b.vehicleId

            },
          },
          {
            width: 120,
            dataIndex: 'affiliationName',
            title: '隶属机构',
            sorter: (a, b) => {
              return a.affiliationId - b.affiliationId

            },
          },
          {
            width: 120,

            dataIndex: 'wmsOrderNo',
            title: 'WMS单号',
            sorter: (a, b) => {
              if (!a.wmsOrderNo || !b.wmsOrderNo) {
                return
              }
              return a.wmsOrderNo.replace(/[^0-9]/gi, '') - b.wmsOrderNo.replace(/[^0-9]/gi, '')
            },
          },
          {
            width: 100,
            dataIndex: 'orderTypeName',
            title: '订单类型',
            sorter: (a, b) => {
              return a.orderType - b.orderType

            },
          },
          {
            width: 100,
            dataIndex: 'orderBusinessTypeName',
            title: '业务类型',
            sorter: (a, b) => {
              return a.orderBusinessType - b.orderBusinessType

            },
          },
          {
            width: 100,
            dataIndex: 'deliveryPatternName',
            title: '配送方式',
            sorter: (a, b) => {
              return a.deliveryPattern - b.deliveryPattern
            },
          },
          {
            width: 100,
            dataIndex: 'transportTypeName',
            title: '运输模式',
            sorter: (a, b) => {
              return a.transportType - b.transportType

            },
          },
          {
            width: 100,
            dataIndex: 'temperatureRequirementName',
            title: '温度要求',
            width: 120,
            sorter: (a, b) => {
              return a.temperatureRequirement - b.temperatureRequirement
            },
          },

          {
            width: 120,
            dataIndex: 'memo',
            title: '备注',
            sorter: (a, b) => {
              if (!a.memo || !b.memo) {
                return -1
              }
              return a.memo.length - b.memo.length
            },
          },

          {
            width: 150,

            dataIndex: 'orderDate',
            title: '下单时间',
            sorter: (a, b) => {
              return +new Date(a.orderDate) - +new Date(b.orderDate)
            },
          },
          {
            width: 150,
            dataIndex: 'submitDate',
            title: '提交时间',
            sorter: (a, b) => {
              return +new Date(a.submitDate) - +new Date(b.submitDate)
            },
          },
          {
            dataIndex: 'auditDate',
            title: '审核时间',
            width: 150,
            sorter: (a, b) => {
              return +new Date(a.auditDate) - +new Date(b.auditDate)
            },
          },
          {
            dataIndex: 'loadingDate',
            title: '调度时间',
            width: 150,
            sorter: (a, b) => {
              return +new Date(a.loadingDate) - +new Date(b.loadingDate)
            },
          },
          {
            dataIndex: 'loadingAuditDate',
            title: '调度审核时间',
            width: 150,
            sorter: (a, b) => {
              return +new Date(a.loadingAuditDate) - +new Date(b.loadingAuditDate)
            },
          },
          {
            dataIndex: 'loadingStartDate',
            title: '实际启运时间',
            width: 150,
            sorter: (a, b) => {
              return +new Date(a.loadingStartDate) - +new Date(b.loadingStartDate)
            },
          },
          {
            dataIndex: 'deliveryTime',
            title: '实际送达时间',
            width: 150,
            sorter: (a, b) => {
              return +new Date(a.deliveryTime) - +new Date(b.deliveryTime)
            },
          },
          {
            dataIndex: 'receiptTime',
            title: '回单时间',
            width: 150,
            sorter: (a, b) => {
              return +new Date(a.receiptTime) - +new Date(b.receiptTime)
            },
          },
          {
            dataIndex: 'originalBackDate',
            title: '正本回单时间',
            width: 150,
            sorter: (a, b) => {
              return +new Date(a.originalBackDate) - +new Date(b.originalBackDate)
            },
          },
          {
            dataIndex: 'actualTime',
            title: '实际时效',
            width: 80,
            sorter: (a, b) => {
              return a.actualTime - b.actualTime
            },
          },
          {
            dataIndex: 'completionTime',
            title: '完成时间',
            width: 150,
            sorter: (a, b) => {
              return +new Date(a.completionTime) - +new Date(b.completionTime)
            },
          },

          ...consignee.init(self), //收

          ...shipper.init(self), //发
          {
            dataIndex: 'totalPcs',
            title: '总件数',
            width: 100,
            sorter: (a, b) => {
              return a.totalPcs - b.totalPcs
            },
          },
          {
            dataIndex: 'totalWeight',
            title: '总重量',
            width: 100,
            sorter: (a, b) => {
              return a.totalWeight - b.totalWeight
            },
          },
          {
            dataIndex: 'totalVolume',
            title: '总体积',
            width: 100,
            sorter: (a, b) => {
              return a.totalVolume - b.totalVolume
            },
          },
          {
            dataIndex: 'totalPiece',
            title: '整件数',
            width: 100,
            sorter: (a, b) => {
              return a.totalPiece - b.totalPiece
            },
          },
          {
            dataIndex: 'packageLclPiece',
            title: '拼箱数',
            width: 100,
            sorter: (a, b) => {
              return a.packageLclPiece - b.packageLclPiece
            },
          },
          {
            dataIndex: 'packageTotalWeight',
            title: '包裹总重量',
            width: 100,
            sorter: (a, b) => {
              return a.packageTotalWeight - b.packageTotalWeight
            },
          },
          {
            dataIndex: 'packageTotalVolume',
            title: '包裹总体积',
            width: 100,
            sorter: (a, b) => {
              return a.packageTotalVolume - b.packageTotalVolume
            },
          },
          {
            dataIndex: 'sourceName',
            title: '来源',
            width: 100,
            sorter: (a, b) => {
              return a.source - b.source
            },
          },
          {
            dataIndex: 'importBatchNumber',
            title: '导入批次号',
            width: 100,
            sorter: (a, b) => {
              return a.importBatchNumber - b.importBatchNumber
            },
          },
          {
            dataIndex: 'createperson',
            title: '创建人',
            width: 100,
            sorter: (a, b) => {
              return a.createperson.length - b.createperson.length
            },
          },
          {
            dataIndex: 'createtime',
            title: '创建时间',
            width: 150,
            sorter: (a, b) => {
              return +new Date(a.createtime) - +new Date(b.createtime)
            },
          },
          {
            dataIndex: 'updateperson',
            title: '修改人',
            width: 100,
            sorter: (a, b) => {
              return a.updateperson.length - b.updateperson.length
            },
          },
          {
            dataIndex: 'updatetime',
            title: '修改时间',
            width: 150,
            sorter: (a, b) => {
              return +new Date(a.updatetime) - +new Date(b.updatetime)
            },
          },
        ],
      },
    },
  }
}

