import {supplierAttr as _supplierAttr, branchAttr as _branchAttr,customerAttr as _customerAttr, categoryAttr as _categoryAttr, itemAttr as _itemAttr } from '@/blocks/components/searchModalConfig/index'
import departmenTree from './departmenTree.js'

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, queryProviderhUrl, consigneeUrl, queryCustomer_consignee_Url, queryProviderh_consignee_Url } from '@/views/TMS/order/orderManage/api.js'
import { UPCLOUD_RDC_TMS_MAINDATA_SERVICE } from '@/config/serviceSettings.js'

/**0=不显示,1=查看,2=新建,3=修改,4=复制 */

let label = ['', '客户','仓库', '供应商']
const url = ['', queryCustomerUrl,queryBranchUrl,UPCLOUD_RDC_TMS_MAINDATA_SERVICE+ '/provider/popup']
// const url2 = ['', , queryCustomer_consignee_Url,queryBranchUrl, queryProviderh_consignee_Url]
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' }
  }//供应商
}
export let CONDITION_TYPE = (self) => {
  return {
    1: {
      placeholder: '请选择',
      get options() {
        return self.options.DELIVERY_METHOD_TYPE
      },
      is: 'p-select',
      title: '配送方式',
      children:null
    },
    2: {
      is: 'p-select',
      placeholder: '请选择',
      get options() {
        return self.options.CONSIGNEE_TYPE
      },
      title: '发货方类型',
      children:searchConfig
    },
    3: {
      placeholder: '请选择',
      get options() {
        return self.options.CONSIGNEE_TYPE
      },
      is: 'p-select',
      title: '收货方类型',
      children: searchConfig
    },
    4: {
      placeholder: '请选择',
      get options() {
        return self.options.ORDER_TYPE
      },
      is: 'p-select',
      title: '订单类型',
      children:null

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

    },

    6: {
      placeholder: '请选择',
      get options() {
        return self.options.TRANSPORT_TYPE
      },
      is: 'p-select',
      title: '运输模式',
      children:null

    },
    7: {
      placeholder: '请选择',
      get options() {
        return self.options.TEMPERATURE_REQUIREMENT
      },
      is: 'p-select',
      title: '温度要求',
      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: {
        columns: [
          { dataIndex: 'cargoOwnerId', title: 'ID', hidden: true },
          { dataIndex: 'cargoOwnerName', title: '货主名称' },
          { dataIndex: 'cargoOwnerCode', title: '货主编码' },
        ],
      },
    },
    9:departmenTree(self),
  }
}


export const setFormItems = (self, expData = []) => {
  let selectedRowKeys = []
  let inputType = (self) => (self.st === 1 ? 'txt' : 'input')
  let e = []
  if (expData.length > 0) {
    expData.forEach((item) => {
      let type = item.type
      Object.defineProperty(item, 'type', {
        get() {
          return self.st === 1 ? 'txt' : type
        },
      })
    })
    e = [divider(self, '扩展信息'), ...expData]
  }
  return [
    divider(self, '基本信息'),

    { name: 'id', label: 'id', hidden: true, value: '' },
    {
      label: '策略名称',
      span:6,
      name: 'strategyName',
      get type() {
        return inputType(self)
      },
      required: true,
      get readOnly() {
        return self.st === 3 ? true : false
      },
    },
    {
      span:6,
      name: 'memo',
      label: '备注',
      get type() {
        return inputType(self)
      },
      value: '',
    },
    divider(self, '满足条件'),
    {
      name: 'strategyCtSaveVOList',
      span:18,
      value: [],
      itemHeight: 'auto',
      scopedSlots: { customRender: 'diy' },
    },
    // {
    //   span: 18,
    //   type: 'txt',
    //   itemHeight: 'auto',
    //   scopedSlots: { customRender: 'alert' },
    // },
    divider(self, '匹配优先级'),
    // {
    //   wrapperCol:{ span: 24 },
    //   itemHeight: 'auto',
    //   scopedSlots: { customRender: 'match' },
    // },


  ]
}

export const getDataSource=()=> {
  return [
    { title: '按行政区域-行政区域', name: 'adminToAdmin', _s: 1 },
    { title: '按行政区域-收货方', name: 'adminToConsignor', _s: 2 },
    { title: '按仓库-行政区域', name: 'branchToAdmin', _s: 3 },
    { title: '按仓库-收货方', name: 'branchToConsignor', _s: 4 },
  ]
}
