import departmenTree from './departmenTree.js'
import { supplierAttr as _supplierAttr, branchAttr as _branchAttr, customerAttr as _customerAttr, categoryAttr as _categoryAttr, itemAttr as _itemAttr } from '@/blocks/components/searchModalConfig/index'
export const baseColor = {
  color: '#000000',
  background: '#ffffff'
}

_customerAttr.tableConfig.rowSelectType = 2;
_branchAttr.tableConfig.rowSelectType = 2;
_supplierAttr.tableConfig.rowSelectType = 2;

function divider(self, value) {
  return {
    label: '',
    span: 24,
    itemHeight: '60px',
    labelCol: { span: 0 },
    wrapperCol: { span: 24 },
    type: () => {
      return self._c('a-divider', { attrs: { orientation: 'left' } }, [self._v(value)])
    },
  }
}
import { cargo_ownerUrl, queryCustomerUrl, queryBranchUrl } from '@/views/TMS/order/orderManage/api.js'
import { UPCLOUD_RDC_TMS_MAINDATA_SERVICE } from '@/config/serviceSettings.js'
import { _ } from 'core-js'
let searchConfig = {
  0: {
    disabled: true
  },
  1: _.cloneDeep(_customerAttr),//客户
  2: _.cloneDeep(_branchAttr),//仓库
  3: {
    ..._.cloneDeep(_supplierAttr),
    remoteUrl: { url: UPCLOUD_RDC_TMS_MAINDATA_SERVICE + '/provider/popup', method: 'post' }
  }//供应商
}
/**0=不显示,1=查看,2=新建,3=修改,4=复制 */

let label = ['', '客户', '仓库', '供应商']
const url = ['', queryCustomerUrl, queryBranchUrl, UPCLOUD_RDC_TMS_MAINDATA_SERVICE + '/provider/popup']
let itemAttr = _.cloneDeep(_itemAttr)
let categoryAttr = _.cloneDeep(_categoryAttr)
itemAttr.tableConfig.rowSelectType = 2
categoryAttr.tableConfig.rowSelectType = 2

export let CONDITION_TYPE = (self) => {

  return {

    1: {
      placeholder: '请选择',
      get options() {
        return self.options.DELIVERY_METHOD_TYPE
      },
      is: 'p-select',
      title: '配送方式',
      mode: 'multiple',
      children: null
    },
    2: {
      is: 'p-select',
      placeholder: '请选择',
      get options() {
        return self.options.CONSIGNEE_TYPE
      },
      title: '发货方类型',
      mode: 'default',
      children: searchConfig,

    },
    3: {
      placeholder: '请选择',
      get options() {
        return self.options.CONSIGNEE_TYPE
      },
      is: 'p-select',
      title: '收货方类型',
      mode: 'default',
      children: searchConfig,

    },
    4: {
      placeholder: '请选择',
      get options() {
        return self.options.ORDER_TYPE
      },
      is: 'p-select',
      title: '订单类型',
      mode: 'multiple',
      children: null
    },
    5: {
      placeholder: '请选择',
      get options() {
        return self.options.ORDER_BUSINESS_TYPE
      },
      is: 'p-select',
      title: '业务类型',
      mode: 'multiple',
      children: null
    },

    6: {
      placeholder: '请选择',
      get options() {
        return self.options.TRANSPORT_TYPE
      },
      is: 'p-select',
      title: '运输模式',
      mode: 'multiple',
      children: null
    },
    7: {
      placeholder: '请选择',
      get options() {
        return self.options.TEMPERATURE_REQUIREMENT
      },
      is: 'p-select',
      title: '温度要求',
      mode: 'multiple',
      children: null
    },
    8: {
      children: null,
      is: 'p-search-modal',
      title: '货主',
      placeholder: '请选择',
      targetClick: true,
      toolBar: {
        labelCol: { span: 8 },
        wrapperCol: { span: 16 },
        items: [
          {
            type: 'input',
            name: 'cargoOwnerCode',
            label: '货主编码',
            value: '',
          },
          {
            type: 'input',
            name: 'cargoOwnerName',
            label: '货主名称',
            value: '',
          },
        ],
      },
      remoteUrl: {
        url: cargo_ownerUrl,
        method: 'post',
      },
      rowKey: 'cargoOwnerId',
      targetValueKey: 'cargoOwnerName',
      tableConfig: {
        rowSelectType: 2,
        columns: [
          { dataIndex: 'cargoOwnerId', title: 'ID', hidden: true },
          { dataIndex: 'cargoOwnerName', title: '货主名称' },
          { dataIndex: 'cargoOwnerCode', title: '货主编码' },
        ],
      },
    },
    9: departmenTree(self),
    10: {
      ...itemAttr,
      placeholder: '请选择',
      is: 'p-search-modal',
      children: null,
      title: '商品',
    },
    11: {
      ...categoryAttr,
      placeholder: '请选择',
      title: "商品品类",
      is: 'p-search-modal',
      children: null,
    },

    12: {
      ...itemAttr,
      placeholder: '请选择商品',
      is: 'p-search-modal',
      title: "商品件数",
      children: null,
      nodeList: [
        {
          is: 'countExpressions',
          get options() {
            return self.options.CMP_SYMBOL.filter(item => item)
          },
          disabled: false,
          lowerLimit: {
            lowerLimitSymbol: 0,
            lowerLimitValue: null,
            upperLimitSymbol: 0,
            upperLimitValue: null
          }

        }
      ]
    },
    13: {
      ...itemAttr,
      title: "商品重量",
      placeholder: '请选择商品',
      is: 'p-search-modal',
      children: null,
      nodeList: [
        {
          is: 'countExpressions',
          get options() {
            return self.options.CMP_SYMBOL.filter(item => item)
          },
          disabled: false,
          lowerLimit: {
            lowerLimitSymbol: 0,
            lowerLimitValue: null,
            upperLimitSymbol: 0,
            upperLimitValue: null
          }

        }
      ]

    },
    14: {
      title: "商品总件数",
      children: null,
      placeholder: '请选择',
      is: 'countExpressions',
      lowerLimit: {
        lowerLimitSymbol: 0,
        lowerLimitValue: null,
        upperLimitSymbol: 0,
        upperLimitValue: null
      },
      get options() {
        return self.options.CMP_SYMBOL.filter(item => item)
      },
      disabled: false
    },
    15: {
      title: "商品总重量",
      children: null,
      placeholder: '请选择',
      is: 'countExpressions',
      lowerLimit: {
        lowerLimitSymbol: 0,
        lowerLimitValue: null,
        upperLimitSymbol: 0,
        upperLimitValue: null
      },
      get options() {
        return self.options.CMP_SYMBOL.filter(item => item)
      },
      disabled: false
    },
    16: {},
    17: {},
    18: {
      is: 'p-select',
      title: '商品超限',
      mode: 'default',
      placeholder: '请选择',
      children: null,
      get options() {
        return self.options.GOODS_TRANSFINITE_ENABLED
      },

    },

  }
}


export const setFormItems = (self, expData = []) => {
  let selectedRowKeys = []
  let inputType = (self) => (self.st === 1 ? 'txt' : 'input')
  let e = []
  if (expData.length > 0) {

  }
  return [
    divider(self, '基本信息'),
    { name: 'id', label: 'id', hidden: true, value: '' },

    {
      label: '策略名称',
      name: 'name',
      required: true,
      get readOnly() {
        return self.st === 3 ? true : false;
      },
      get type() {
        return inputType(self);
      },
    },

    {
      label: '优先级',
      name: 'priorityLevel',
      required: true,
      min: 1,
      max: 999,
      precision: 0,
      get type() {
        return self.st === 1 ? 'txt' : 'number'
      }
    },
    {
      label: '备注',
      name: 'memo',
      get type() {
        return inputType(self);
      },

    },
    divider(self, '满足条件'),
    {
      name: 'strategyBusinessCntViewDTOS',
      span: 24,
      value: [],
      itemHeight: 'auto',
      scopedSlots: { customRender: 'diy' },
    },


  ]
}

export const setFormItems2 = (self) => {


  return [

    divider(self, '业务规则'),

    {
      get hidden() {
        let form = self.form();
        if (form || self.GOODS_TRANSFINITE_ENABLED) {
          if (form) {
            let strategyBusinessCntViewDTOS = form?.getFieldValue('strategyBusinessCntViewDTOS')??null
            strategyBusinessCntViewDTOS = strategyBusinessCntViewDTOS?.find(item => {
              return item.key == 18
            })
            return !(strategyBusinessCntViewDTOS?.value==1)
          }
        } else {
          return true
        }
      },
      span: 12,
      wrapperCol: { span: 24 },
      type: 'row',
      itemHeight: 'auto',
      list: [
        {
          type: 'check',
          name: 'transfiniteCmtDtSelect',
          get readOnly() {
           return self.st === 1
           },
          style: 'display:inline-block;width:110px',
          replaceFields: {
            true: 1,
            false: 0,
          },
          // wrapperCol: { span: 24 },
          checkedText: '输入超限日期:',
          value: 0,
          //span: 4,
        },
        {
          get readOnly() {
            return self.st === 1
          },
          get mode() {
            return self.st === 1 ? 'txt' : ''
          },
          type: 'select',
          label: '',
          style: 'display:inline-block;width:200px;margin-right:10px',
          placeholder: '请选择',
          name: 'transfiniteCmtDtEnable',
          get options() {
            return self.options.PROCESS_ENABLE
          }
        },
        {
          get readOnly() {
            return self.st === 1
            },
          type: 'check',
          name: 'transfiniteDescriptionSelect',
          replaceFields: {
            true: 1,
            false: 0,
          },
          style: 'display:inline-block;width:110px',
          checkedText: '输入超限说明:',
          value: 0,
          span: 4,
        },
        {
          type: 'select',
          label: '',
          span: 8,
          get readOnly() {
            return self.st === 1
          },
          get mode() {
            return self.st === 1 ? 'txt' : ''
          },
          style: 'display:inline-block;width:200px;margin-right: 10px;',
          //wrapperCol: { span: 22 },
          placeholder: '请选择',
          name: 'transfiniteDescriptionEnable',
          get options() {
            return self.options.PROCESS_ENABLE
          }
        },

        {
          type: 'check',
          name: 'carrierUploadTransfiniteSelect',
          get readOnly() {
            return self.st === 1
          },
            //style: 'display:inline-block',
          replaceFields: {
            true: 1,
            false: 0,
          },
          style: 'display:inline-block;width:140px',
          checkedText: '承运商上传超限证:',
          value: 0,
          span: 4,
        },
        {
          type: 'select',
          label: '',
          span: 8,

          get mode() {
            return self.st === 1 ? 'txt' : ''
          },
          style: 'display:inline-block;width:170px;margin-right: 10px;',
          //wrapperCol: { span: 22 },
          placeholder: '请选择',
          name: 'carrierUploadTransfiniteEnable',
          get options() {
            return self.options.PROCESS_ENABLE
          }
        },

        {
          type: 'check',
          name: 'loadingLocationSelect',
          get readOnly() {
            return self.st === 1
          },

          replaceFields: {
            true: 1,
            false: 0,
          },
          style: 'display:inline-block;width:110px',
          checkedText: '输入装车地点:',
          value: 0,
          span: 4,
        },
        {
          type: 'select',
          label: '',
          span: 8,
          get mode() {
            return self.st === 1 ? 'txt' : ''
          },
          style: 'display:inline-block;width:200px',
          //wrapperCol: { span: 22 },
          placeholder: '请选择',
          name: 'loadingLocationEnable',
          get options() {
            return self.options.PROCESS_ENABLE
          }
        }
      ]
    },


    {
      span: 24,
      wrapperCol: { span: 24 },
      type: 'row',
      itemHeight: 'auto',
      list: [
        {

          type: 'check',
          name: 'deliveryMethodSelect',
          get readOnly() {
            return self.st === 1
          },

          replaceFields: {
            true: 1,
            false: 0,
          },
          checkedText: '指定配送方式:',
          value: 0,
          style: 'display:inline-block;width:110px',

        },
        {
          type: 'select',
          style: 'display:inline-block;width:200px;margin-right:10px',
          placeholder: '请选择',
          label: '',
          get mode() {
            return self.st === 1 ? 'txt' : ''
          },
          name: 'deliveryMethodType',
          get options() {
            return self.options.DELIVERY_METHOD_TYPE
          }
        },
        {
          type: 'check',
          name: 'inventoryCheckSelect',
           get readOnly() {
            return self.st === 1
          },
          replaceFields: {
            true: 1,
            false: 0,
          },

          style: 'display:inline-block;width:110px',
          checkedText: '库存校验:',
          value: 0,
        },

        {
          type: 'select',
          label: '',
          placeholder: '请选择',
          style: 'display:inline-block;width:200px',
          //wrapperCol: { span: 22 },
             get mode() {
            return self.st === 1 ? 'txt' : ''
          },          name: 'inventoryCheckEnable',
          get options() {
            return self.options.PROCESS_ENABLE
          },
        },
      ],
    },
    {
      span: 24,
      wrapperCol: { span: 24 },
      type: 'row',
      itemHeight: 'auto',

      list: [

        {
          type: 'check',
          name: 'applyPcsSelect',
           get readOnly() {
            return self.st === 1
          },
          style: 'display:inline-block;width:110px',
          replaceFields: {
            true: 1,
            false: 0,
          },
          // wrapperCol: { span: 24 },
          checkedText: '输入申请数量:',
          value: 0,
          //span: 4,
        },
        {
          type: 'select',
          label: '',
          style: 'display:inline-block;width:200px;margin-right:10px',
             get mode() {
            return self.st === 1 ? 'txt' : ''
          },          // wrapperCol: { span: 22 },
          placeholder: '请选择',
          name: 'applyPcsEnable',
          get options() {
            return self.options.PROCESS_ENABLE
          }
        },
        {
          type: 'check',
          name: 'departureTemperatureSelect',
           get readOnly() {
            return self.st === 1
          },
          //style: 'display:inline-block',
          replaceFields: {
            true: 1,
            false: 0,
          },
          style: 'display:inline-block;width:110px',
          checkedText: '输入启运温度:',
          value: 0,
          span: 4,
        },
        {
          type: 'select',
          label: '',
          span: 8,
             get mode() {
            return self.st === 1 ? 'txt' : ''
          },          style: 'display:inline-block;width:200px',
          //wrapperCol: { span: 22 },
          placeholder: '请选择',
          name: 'departureTemperatureEnable',
          get options() {
            return self.options.PROCESS_ENABLE
          }
        }
      ]
    },

    {
      span: 24,
      wrapperCol: { span: 24 },
      type: 'row',
      itemHeight: 'auto',
      list: [
        {
          type: 'check',
          name: 'deliveryTemperatureSelect',
           get readOnly() {
            return self.st === 1
          },
          style: 'display:inline-block;width:110px',
          replaceFields: {
            true: 1,
            false: 0,
          },
          checkedText: '输入送达温度:',
          value: 0,
        },
        {
          type: 'select',
          label: '',
             get mode() {
            return self.st === 1 ? 'txt' : ''
          },          style: 'display:inline-block;width:200px;margin-right:10px',
          // wrapperCol: { span: 22 },
          placeholder: '请选择',
          name: 'deliveryTemperatureEnable',
          get options() {
            return self.options.PROCESS_ENABLE
          }
        },


        {
          type: 'check',
          name: 'pricePcdMatchTypeSelect',
           get readOnly() {
            return self.st === 1
          },
          style: 'display:inline-block;width:160px',
          replaceFields: {
            true: 1,
            false: 0,
          },
          checkedText: '价格表省市区匹配方式:',
          value: 0,
        },
        {
          type: 'select',
          label: '',
             get mode() {
            return self.st === 1 ? 'txt' : ''
          },          style: 'display:inline-block;width:200px',
          // wrapperCol: { span: 22 },
          placeholder: '请选择',
          name: 'pricePcdMatchType',
          get options() {
            return self.options.PRICE_PCD_MATCH_TYPE
          }
        }
      ]
    },
    {
      span: 24,
      wrapperCol: { span: 24 },
      type: 'row',
      itemHeight: 'auto',
      list: [
        {
          type: 'check',
          name: 'rtnOrderPicSelect',
           get readOnly() {
            return self.st === 1
          },
          replaceFields: {
            true: 1,
            false: 0,
          },
          checkedText: '回单图片:',
          value: 0,
          style: 'display:inline-block;width:110px',
        },
        {
          type: 'select',
          style: 'display:inline-block;width:200px;margin-right:10px',
          placeholder: '请选择',
          label: '',
             get mode() {
            return self.st === 1 ? 'txt' : ''
          },          name: 'rtnOrderPicEnable',
          get options() {
            return self.options.WHETHER
          }
        },
        {
          type: 'check',
          name: 'rtnOrderPaperSelect',
           get readOnly() {
            return self.st === 1
          },
          replaceFields: {
            true: 1,
            false: 0,
          },
          style: 'display:inline-block;width:110px',
          checkedText: '正本回单:',
          value: 0,
        },
        {
          type: 'select',
          label: '',
          placeholder: '请选择',
          style: 'display:inline-block;width:200px',
             get mode() {
            return self.st === 1 ? 'txt' : ''
          },          name: 'rtnOrderPaperEnable',
          get options() {
            return self.options.WHETHER
          },
        },
      ],
    },
    {
      span: 24,
      wrapperCol: { span: 24 },
      type: 'row',
      itemHeight: 'auto',
      list: [
        {
          type: 'check',
          name: 'rtnOrderDeadlineSelect',
           get readOnly() {
            return self.st === 1
          },
          replaceFields: {
            true: 1,
            false: 0,
          },
          checkedText: '回单期限:',
          value: 0,
          style: 'display:inline-block;width:110px',
        },
        {
          style: 'display:inline-block;width:200px;margin-right:10px',
          label: '',
          name: 'rtnOrderDeadline',
          unit: '天',
          min: 1,
          precision: 0,
          get type() {
            return self.st === 1 ? 'txt' : 'number'
          },
        },
        {
          type: 'check',
          name: 'deliveryDirectionSelect',
           get readOnly() {
            return self.st === 1
          },
          replaceFields: {
            true: 1,
            false: 0,
          },

          style: 'display:inline-block;width:110px',
          checkedText: '指定配送方向:',
          value: 0,
        },
        {
          type: 'select',
          label: '',
          placeholder: '请选择',
          style: 'display:inline-block;width:200px',
             get mode() {
            return self.st === 1 ? 'txt' : ''
          },          name: 'deliveryDirection',
          get options() {
            return self.options.LINE_DIRECTION
          },
        },
      ],
    },
    {
      span: 24,
      wrapperCol: { span: 24 },
      type: 'row',
      itemHeight: 'auto',
      list: [
        {
          type: 'check',
          name: 'recordTagSelect',
           get readOnly() {
            return self.st === 1
          },
          replaceFields: {
            true: 1,
            false: 0,
          },
          checkedText: '记录标记:',
          value: 0,
          style: 'display:inline-block;width:110px',
        },
        {
          // type: 'textarea',
          style: 'display:inline-block;width:520px;margin-right:10px',
          label: '',
             get mode() {
            return self.st === 1 ? 'txt' : ''
          },          name: 'recordTagWord',
          placeholder: '请输入标记术语，支持逗号拼接的多个',
          get type() {
            return self.st === 1 ? 'txt' : 'textarea'
          },
        },
      ]
    },

    {
      type: 'check',
      name: 'colorTagSelect',
       get readOnly() {
            return self.st === 1
          },
      replaceFields: {
        true: 1,
        false: 0,
      },
      style: 'display:inline-block;width:150px',
      checkedText: '颜色标记:',
      value: 0,
    },
    {
      name: 'colorTagBgdColor',
      value: self.colorTagBgdColor,
      label: '背景颜色',
      scopedSlots: { unit: 'colorTagBgdColor' },
      get type() {
        return self.st === 1 ? 'txt' : 'input'
      },
    },
    {
      scopedSlots: { unit: 'colorTagFontColor' },
      name: 'colorTagFontColor',
      label: '字体颜色',
      value: self.colorTagFontColor,
      get type() {
        return self.st === 1 ? 'txt' : 'input'
      }
    }

  ]
}
