import {carrierAttr,itemAttr, branchAttr, supplierAttr, consigneeAttr, consignorAutoComplete, consignorAttr, driverAutoCompleteMethod } from '@/blocks/components/searchModalConfig';
// import departmenTree from '@/blocks/components/formConfig/departmenTree.js'
import { UPCLOUD_RDC_TMS_BUSINESS_SERVICE } from '@/config/serviceSettings.js'

export default (self) => {
  // const _departmenTree = departmenTree(self)
  // _departmenTree[2].required = false;
  return {
    mode: "button",
    remoteUrl: { url: UPCLOUD_RDC_TMS_BUSINESS_SERVICE + '/transport_plan_bill/pending_plan_page', method: 'post' },
    rowKey: 'id',
    modalWidth: "70%",
    type: "primary",
    title:'订单列表',
    modalConfig: {
      bodyStyle: {
        height:'592px'
      }
    },
    toolBar: {
      span:6,
      labelCol: { span: 8 },
      wrapperCol: { span: 16 },
      items: [
        { name: 'orderNo', label: '订单号', type: 'input' },
        { name: 'shipbillNo', label: '运单号', type: 'input' },
        {
          name: 'orderBusinessType',
          label: '业务类型',
          type: 'select',
          get options() {
            return self.options.ORDER_BUSINESS_TYPE
          },
        },
        {
          name: 'planDeliveryStartDate_planDeliveryEndDate',
          label: '计划发运日期',
          type: 'a-range-picker',
          format: 'YYYY-MM-DD',
          valueFormat: 'YYYY-MM-DD',
          placeholder: ['开始时间', '结束时间'],


        },
        {
          ...carrierAttr,
          targetClick:false,
          targetValueKey:'name',
          name: 'carrierName',
          label: '承运商',
          type: 'searchModal'
        },
        { name: 'planBillNo', label: '计划单号', type: 'input' },
        {
          name: 'createStartTime_createEndTime',
          label: '制单日期',
          type: 'a-range-picker',
          format: 'YYYY-MM-DD',
          valueFormat: 'YYYY-MM-DD',
          placeholder: ['开始时间', '结束时间'],


        },

        // {
        //   name: 'consigneeType', label: '收货方类型', type: 'select',
        //   get options() {
        //     return self.options.CONSIGNEE_TYPE
        //   },
        // },



        { name: 'loadingLocation', label: '装货地点', type: 'input' },

        {
          ...itemAttr,
          targetClick: false,
          targetValueKey: 'itemName',
          name: 'itemName',
          label: '商品名称',
          type: 'searchModal',
          on: {
            input(event, form) {
              form.setFieldsValue({ itemCode: '' })
            },
            change(event, value, dataArr, form) {
              let obj = { itemCode: '' }
              let data = Array.isArray(dataArr) ? dataArr[0] : null;
              if (data) {
                obj.itemCode = data.itemCode

              }
              form.setFieldsValue(obj)
            }
          }
        },



        consignorAutoComplete(self, { name: 'cargoOwnerName', label: '货主' }),
        // ..._departmenTree,


        {
          name: 'consigneeType', label: '收货方类型', type: 'select',
          get options() {
            return self.options.CONSIGNEE_TYPE
          },
        },
        {
          ...consigneeAttr,
          tableConfig: {
            ...consigneeAttr.tableConfig,
            rowSelectType: 2
          },
          targetClick: false,
          remoteBefore(node, res, form) {
            let consigneeType = form.getFieldValue('consigneeType');
            let obj = { 1: consigneeAttr.remoteUrl, 2: branchAttr.remoteUrl, 3: supplierAttr.remoteUrl }
            if (obj[consigneeType]) {
              res.url = obj[consigneeType].url
            } else {
              res.url = null
              self.$message.warning('请选择收货方类型');

            }
          },
          name: 'consigneeName',
          label: '收货方',
          type: 'searchModal'
        },
      ],
    },
    tableConfig: {
      rowKey: 'shipbillDetailId',
      rowSelectType:2,
      scroll: { x: true, y: 360 },
      columns: [
        {
          dataIndex: 'shipbillNo',
          title: '运单号',
          sorter: (a, b) => a.shipbillNo?.localeCompare(b.shipbillNo),
          width: 160
        },
        {
          dataIndex: 'orderNo',
          title: '订单号',
          sorter: (a, b) => a.orderNo?.localeCompare(b.orderNo),
          width: 160
        },
        {
          dataIndex: 'cargoOwnerName',
          title: '货主',
          sorter: (a, b) => a.cargoOwnerId?.localeCompare(b.cargoOwnerId),
          width: 100
        },
        {
          dataIndex: 'carrierName',
          title: '承运商',
          sorter: (a, b) => a.carrierName?.localeCompare(b.carrierName),
          width: 120
        },
        {
          dataIndex: 'consigneeName',
          title: '收货方',
          sorter: (a, b) => a.consigneeId?.localeCompare(b.consigneeId),
          width: 100
        },
        {
          dataIndex: 'itemCode',
          title: '商品编码',
          sorter: (a, b) => a.itemCode?.localeCompare(b.itemCode),
          width: 120
        },
        {
          dataIndex: 'itemName',
          title: '商品名称',
          sorter: (a, b) => a.itemName?.localeCompare(b.itemName),
          width: 160
        },
        {
          dataIndex: 'loadingLocation',
          title: '装货地点',
          sorter: (a, b) => a.loadingLocation?.localeCompare(b.loadingLocation),
          width: 120
        },
        {
          dataIndex: 'planDeliveryDate',
          title: '计划发货日期',
          sorter: (a, b) => +new Date(a.planDeliveryDate) - +new Date(b.planDeliveryDate),
          width: 140
        },
        {
          dataIndex: 'branchName',
          title: '仓库',
          sorter: (a, b) => a.branchName?.localeCompare(b.branchName),
          width: 100
        },
        {
          dataIndex: 'pcs',
          title: '计划箱数',
          alert: 'center',
          sorter: (a, b) => a.pcs - b.pcs,
          width: 100
        },
        {
          dataIndex: 'isTransfiniteName;',
          title: '是否超限',
          sorter: (a, b) => a.isTransfinite - b.isTransfinite
        }
      ],
    },
  }
}