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

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' }
  }//供应商
}
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']

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: '消息名称',
      name: 'name',
      required: true,
      get readOnly() {
        return self.st === 3 ? true : false;
      },
      get type() {
        return inputType(self);
      },
    },

    {
      label: '消息类型',
      name: 'type',
      type: 'select',
      required: true,
      get options() {
        return self.options?.MESSAGE_TYPE??[]
      },
      get mode() {
        return self.st === 1 ? 'txt' : '';
      },
    },
    {

      label: '推送方式',
      type: 'select',
      required: true,
      multiple: true,
      maxTagCount: 2,
      get options() {
        return self.options?.MESSAGE_SEND_TYPE??[]
      },
      mode:'multiple',
      get name() {
        return self.st === 1 ? 'sendTypeName' : 'sendType';
      },
    },
    {
      get required() {
        let form = self.form();
        let sendType = form?.getFieldValue('sendType')
        if (form&&sendType) {
          return sendType.includes('5')
        } else {
          return false;
        }

      },

      name: 'qwWebhook',
      label: '企业微信',
      placeholder: '请输入企业微信webhook',
      get itemStyle() {
        return self.st === 1 ? 'display: block;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;':undefined
      },
      tooltip: true,
      labelCol: { span: 6 },
      wrapperCol: { span: 18 },
      get type() {
        return inputType(self);
      },

    },
    {
      required: true,
      name: 'content',
      span: 12,
      labelCol: { span: 3 },
      wrapperCol: { span: 19},
      label: '消息内容',
      itemHeight: 'auto',
      scopedSlots: { customRender: 'content' },
    },
    {
      type: 'row',
      span: 12,
      labelCol: { span: 3 },
      wrapperCol: { span: 21},
      list: [
        {
          style:'display:inline-block',
          name: 'noticeCargoowner',
          readOnly: self.st == 1,
          type: 'check',
          replaceFields: {
            true: 'Y',
            false: "N",
          },
          checkedText: '通知货主',
          value: "N",
        },
        {
          style:'display:inline-block',
          name: 'noticeCarrier',
          readOnly: self.st == 1,
          type: 'check',
          replaceFields: {
            true: 'Y',
            false: "N",
          },
          checkedText: '通知承运商',
          value: "N",
        },
        {
          style:'display:inline-block',

          name: 'noticeConsignee',
          readOnly: self.st == 1,
          type: 'check',
          replaceFields: {
            true: 'Y',
            false: "N",
          },
          checkedText: '通知收货方',
          value: "N",
        },
        {
          style:'display:inline-block',

          name: 'noticeDriver',
          readOnly: self.st == 1,
          type: 'check',
          replaceFields: {
            true: 'Y',
            false: "N",
          },
          checkedText: '通知司机',
          value: "N",
        },
        {
          style:'display:inline-block',
          name: 'noticeShipper',
          readOnly: self.st == 1,
          type: 'check',
          replaceFields: {
            true: 'Y',
            false: "N",
          },
          checkedText: '通知发货方',
          value: "N",
        }

      ],
    },

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

    divider(self, '通知人员'),







  ]
}



