import { csMaindata, csBasic, csOms } from '../../api/serviceSettings.js'
import { SERVICE_PLATFORM_POWER_BASE,UPCLOUD_RDC_TMS_MAINDATA_SERVICE } from '@/config/serviceSettings.js'
import qs from 'qs'


/**
 * 只导出常用的searchModal弹窗配置
 import * as $formItems from '../../common/modules/searchModalConfig/index.js'
 v-bind="$data.$formItems.Attr"
 命名为$formItems 1.为了加大使用难度,避免直接this.Attr修改;2.为了后续使用object.freeze提升性能
 * 未处理回调
 * 特异性弹窗选择以下两种方法
 *   1.在页面下创建./js/form.js 单独配置
 *   2.引入后使用Object.assign({},Attr,customAttr)合并配置
 * */

/**
 * 货主弹窗
 * */



      //      // I-内部员工 C-客户 V-供应商 H-货主 S-承运商
  //  if (userCategory === 'C') return $formItems.customerAttr


  //     if (userCategory === 'V') return $formItems.supplierAttr


  //     if (userCategory === 'H') return $formItems.consignorAttr
  //     if (userCategory === 'S') return $formItems.carrierAttr

      // 用户货主弹窗:
      // /cargo_owner/user/popup
      // {"search":"","pageNum":"1","pageSize":"10"}
      // 用户客户弹窗:
      // /tmsBaseCustomer/user/popup
      // {"search":"","pageNum":"1","pageSize":"10"}

      // {"search":"","pageNum":"1","pageSize":"10"}

      // 用户供应商弹窗:
      // /provider/user/popup

      // {"search":"","pageNum":"1","pageSize":"10"}

      // 用户承运商弹窗:
      // /carrier/popup

      // { "search": "", "pageNum": "1", "pageSize": "10" }

      //      // I-内部员工 C-客户 V-供应商 H-货主 S-承运商
  //  if (userCategory === 'C') return $formItems.customerAttr
  //     if (userCategory === 'V') return $formItems.supplierAttr
  //     if (userCategory === 'H') return $formItems.consignorAttr
  //     if (userCategory === 'S') return $formItems.carrierAttr
      //       用户货主弹窗:
      // /cargo_owner/user/popup
      // {"search":"","pageNum":"1","pageSize":"10"}
      // 用户客户弹窗:
      // /tmsBaseCustomer/user/popup
      // {"search":"","pageNum":"1","pageSize":"10"}

      // {"search":"","pageNum":"1","pageSize":"10"}

      // 用户供应商弹窗:
      // /provider/user/popup

      // {"search":"","pageNum":"1","pageSize":"10"}

      // 用户承运商弹窗:
      // /carrier/popup

      // { "search": "", "pageNum": "1", "pageSize": "10" }


export const consignorAttr = {
  label: '货主',
  placeholder: '请选择货主',
  targetClick: true,
  targetValueKey: 'consignorName',
  remoteUrl: { url: UPCLOUD_RDC_TMS_MAINDATA_SERVICE + '/cargo_owner/user/popup', method: 'post' },
  rowKey: 'id',
  toolBar: {
    items: [
      {
        type: 'input',
        name: 'consignorNoAndName',
        label: '查询条件',
        placeholder: '请输入货主编码/货主名称',
        value: '',
      },
    ],
  },
  tableConfig: {
    columns: [
      { ellipsis: true, dataIndex: 'consignorCode', title: '货主编码' },
      { ellipsis: true, dataIndex: 'consignorName', title: '货主名称' },
    ],
  },
}

/**
 * 客户
 * */
export const customerAttr = {
  label: '客户',
  placeholder: '请选择客户',
  targetClick: true,
  targetValueKey: 'customerName',
  remoteUrl: { url: UPCLOUD_RDC_TMS_MAINDATA_SERVICE + '/tmsBaseCustomer/user/popup', method: 'post' },
  rowKey: 'id',
  toolBar: {
    items: [
      { type: 'input', name: 'customerCode', label: '客户编码', value: '' },
      { type: 'input', name: 'customerName', label: '客户名称', value: '' },
    ],
  },
  tableConfig: {
    columns: [
      { ellipsis: true, dataIndex: 'customerCode', title: '客户编码' },
      { ellipsis: true, dataIndex: 'customerName', title: '客户名称' },
    ],
  },
}
/**
 * 仓库
 * */
export const warehouseAttr = {
  label: '仓库',
  placeholder: '请选择仓库',
  targetClick: true,
  targetValueKey: 'warehouseName',
  remoteUrl: { url: csMaindata + '/warehouse/queryWarehouseCurrency', method: 'post' },
  rowKey: 'id',
  toolBar: {
    items: [
      { type: 'input', name: 'warehouseCode', label: '仓库编码', value: '' },
      { type: 'input', name: 'warehouseName', label: '仓库名称', value: '' },
    ],
  },
  tableConfig: {
    columns: [
      { ellipsis: true, dataIndex: 'warehouseCode', title: '仓库编码' },
      { ellipsis: true, dataIndex: 'warehouseName', title: '仓库名称' },
    ],
  },
}
export const branchAttr = {
  label: '仓库',
  placeholder: '请选择仓库',
  targetClick: true,
  targetValueKey: 'warehouseName',
  remoteUrl: { url: csMaindata + '/voidUrl', method: 'post' },
  rowKey: 'id',
  toolBar: {
    items: [
      { type: 'input', name: 'warehouseCode', label: '仓库编码', value: '' },
      { type: 'input', name: 'warehouseName', label: '仓库名称', value: '' },
    ],
  },
  tableConfig: {
    columns: [
      { ellipsis: true, dataIndex: 'warehouseCode', title: '仓库编码' },
      { ellipsis: true, dataIndex: 'warehouseName', title: '仓库名称' },
    ],
  },
}
/**
 * 商品
 * */
export const itemAttr = {
  label: '商品',
  placeholder: '请选择商品',
  targetClick: true,
  targetValueKey: 'itemName',
  remoteUrl: { url: csMaindata + '/item/queryItemListCurrency', method: 'post' },
  rowKey: 'id',
  toolBar: {
    items: [
      { type: 'input', name: 'itemCode', label: '商品编码', value: '' },
      { type: 'input', name: 'itemName', label: '商品名称', value: '' },
    ],
  },
  tableConfig: {
    columns: [
      { ellipsis: true, dataIndex: 'consignorName', title: '货主' },
      { ellipsis: true, dataIndex: 'itemCode', title: '商品编码' },
      { ellipsis: true, dataIndex: 'itemName', title: '商品名称' },
      { ellipsis: true, dataIndex: 'capacity', title: '商品规格' },
    ],
  },
}
/**
 * 供应商
 * */
export const supplierAttr = {
  label: '供应商',
  placeholder: '请选择供应商',
  targetClick: true,
  targetValueKey: 'supplierName',
  remoteUrl: { url: UPCLOUD_RDC_TMS_MAINDATA_SERVICE + '/provider/user/popup', method: 'post' },
  rowKey: 'id',
  toolBar: {
    items: [
      {
        type: 'input',
        name: 'supplierNoName',
        label: '查询条件',
        placeholder: '请输入供应商编码/供应商名称',
        value: '',
      },
    ],
  },
  tableConfig: {
    columns: [
      { ellipsis: true, dataIndex: 'supplierCode', title: '供应商编码' },
      { ellipsis: true, dataIndex: 'supplierName', title: '供应商名称' },
    ],
  },
}
/**
 * 承运商
 * */
export const carrierAttr = {
  label: '承运商',
  placeholder: '请选择承运商',
  targetClick: true,
  targetValueKey: 'carrierName',
  remoteUrl: { url:UPCLOUD_RDC_TMS_MAINDATA_SERVICE  + '/carrier/user/popup', method: 'post' },
  rowKey: 'id',
  toolBar: {
    items: [
      { type: 'input', name: 'carrierCode', label: '承运商编码', value: '' },
      { type: 'input', name: 'carrierName', label: '承运商名称', value: '' },
    ],
  },
  tableConfig: {
    columns: [
      { ellipsis: true, dataIndex: 'carrierCode', title: '承运商编码' },
      { ellipsis: true, dataIndex: 'carrierName', title: '承运商名称' },
    ]
  },
}

/**
 * 批次批号
 * */
export const lotStockAttr = {
  label: '批次库存',
  targetClick: true,
  remoteUrl: { url: csMaindata + '/voidUrl', method: 'post' },
  rowKey: 'seqId',
  toolBar: {
    items: [
      { type: 'input', name: 'batchNum', label: '批次号', value: '' },
      { type: 'input', name: 'lotNo', label: '批号', value: '' },
    ],
  },
  tableConfig: {
    scroll: { x: true },
    columns: [
      { ellipsis: true, width: 170, dataIndex: 'itemname', title: '商品名称' },
      { ellipsis: true, width: 170, dataIndex: 'itemcode', title: '商品编码' },
      { ellipsis: true, width: 170, dataIndex: 'branchname', title: '仓库' },
      { ellipsis: true, width: 170, dataIndex: 'batchNum', title: '批次号' },
      { ellipsis: true, width: 170, dataIndex: 'lotNo', title: '批号' },
      { ellipsis: true, width: 170, dataIndex: 'productionDate', title: '生产日期' },
      { ellipsis: true, width: 170, dataIndex: 'expiredDate', title: '有效期至' },
    ],
  },
}
/**
 * 查询部门
 * */
export const departmentAttr = {
  label: '部门',
  placeholder: '请选择部门',
  targetClick: true,
  targetValueKey: 'name',
  remoteUrl: {
    url: SERVICE_PLATFORM_POWER_BASE + '/organization/page',
    method: 'get',
  },
  rowKey: 'id',
  toolBar: {
    items: [{ type: 'input', name: 'nameOrCode', label: '查询条件', placeholder: '请输入部门编码/名称', value: '' }],
  },
  tableConfig: {
    columns: [
      { dataIndex: 'code', title: '组织编码' },
      { dataIndex: 'name', title: '组织名称' },
    ],
  },
}
/**
 * 查询用户
 * */
export const personAttr = {
  label: '用户',
  placeholder: '请选择用户',
  targetClick: true,
  targetValueKey: 'nickname',
  remoteUrl: { url: SERVICE_PLATFORM_POWER_BASE + '/userpower/getEnterpriseUsers', method: 'get' },
  rowKey: 'id',
  toolBar: {
    items: [{ type: 'input', name: 'name', label: '查询条件', placeholder: '请输入用户编码/名称', value: '' }],
  },
  tableConfig: {
    columns: [
      { dataIndex: 'nickname', title: '用户名称' },
      { dataIndex: 'username', title: '用户账号' },
    ],
  },
}
/**
 * 查询部门的用户
 *  */
export const departmentPersonAttr = {
  label: '用户',
  placeholder: '请选择用户',
  targetClick: true,
  targetValueKey: 'username',
  remoteUrl: {
    url: SERVICE_PLATFORM_POWER_BASE + '/organization/userlist',
    method: 'post',
    transformRequest: [(data) => qs.stringify(data)],
  },
  rowKey: 'id',
  toolBar: {
    items: [
      { type: 'input', name: 'nameOrNickName', label: '查询条件', placeholder: '请输入用户编码/名称', value: '' },
    ],
  },
  tableConfig: {
    columns: [
      { dataIndex: 'nickname', title: '用户名称' },
      { dataIndex: 'username', title: '用户账号' },
    ],
  },
}
/**
 * 法人
 *  */
export const legalPersonAttr = {
  label: '法人',
  placeholder: '请选择法人',
  targetClick: true,
  targetValueKey: 'name',
  remoteUrl: {
    url: SERVICE_PLATFORM_POWER_BASE + '/corporation/all',
    method: 'get',
  },
  rowKey: 'id',
  toolBar: {
    items: [
      { type: 'input', name: 'name', label: '名称', placeholder: '请输入名称', value: '' },
      { type: 'input', name: 'code', label: '编码', placeholder: '请输入编码', value: '' },
    ],
  },
  tableConfig: {
    columns: [
      { dataIndex: 'name', title: '法人' },
      { dataIndex: 'code', title: '编码' },
    ],
  },
}

/**
 * 库区
 *  */
export const areaAttr = {
  label: '库区',
  placeholder: '请选择库区',
  targetClick: true,
  targetValueKey: 'areaName',
  remoteUrl: {
    url: csBasic + '/area/queryArea',
    method: 'post',
  },
  rowKey: 'id',
  toolBar: {
    items: [
      { type: 'input', name: 'areaName', label: '库区名称', placeholder: '请输入库区名称', value: '' },
      { type: 'input', name: 'areaCode', label: '库区编码', placeholder: '请输入库区编码', value: '' },
    ],
  },
  tableConfig: {
    columns: [
      { dataIndex: 'areaName', title: '库区名称' },
      { dataIndex: 'areaCode', title: '库区编码' },
    ],
  },
}
/**
 * 货位
 *  */
export const locationAttr = {
  label: '货位',
  placeholder: '请选择货位',
  targetClick: true,
  targetValueKey: 'locationCode',
  remoteUrl: {
    url: csBasic + '/location/queryLocation',
    method: 'post',
  },
  rowKey: 'id',
  toolBar: {
    items: [{ type: 'input', name: 'locationCode', label: '货位编码', placeholder: '请输入货位编码', value: '' }],
  },
  tableConfig: {
    columns: [
      { dataIndex: 'locationCode', title: '货位编码' },
      { dataIndex: 'areaName', title: '库区名称' },
      { dataIndex: 'areaCode', title: '库区编码' },
    ],
  },
}

/**
 * 店铺
 *  */
export const storeAttr = {
  label: '店铺',
  placeholder: '请选择店铺',
  targetClick: true,
  targetValueKey: 'name',
  remoteUrl: {
    url: csOms + '/store/query',
    method: 'post',
  },
  rowKey: 'id',
  tableConfig: {
    columns: [
      { dataIndex: 'code', title: '店铺编码' },
      { dataIndex: 'name', title: '店铺名称' },
    ],
  },
}
