import {SERVICE_CTRL_TOWER, upcloud_base_inventory} from "@/config/serviceSettings";

// 货主
export const getConsignorItems = (changeFun, remoteBeforeFun) => {
  return [
    {
      "hidden": true,
      "type": "input",
      "name": "consignorid",
      "label": "货主ID",
      "value": ""
    },
    {
      "hidden": true,
      "type": "input",
      "name": "consignorcode",
      "label": "货主编码",
      "value": ""
    },
    {
      "type": "searchModal",
      "name": "consignorname",
      "label": "货主名称",
      "title": "货主名称",
      "value": "",
      "rowKey": "companyId",
      "destroyOnClose": true,
      "targetClick": true,
      "targetValueKey": "companyName",
      "labelCol": {
        "span": 8
      },
      "wrapperCol": {
        "span": 16
      },
      "span": 6,
      "remoteUrl": {
        "url": SERVICE_CTRL_TOWER + "/userDataAuth/allDataAuthByUser/?companyType=H",
        "method": "get"
      },
      "required": true,
      "toolBar": {
        "items": []
      },
      "tableConfig": {
        remoteBefore: remoteBeforeFun,
        "columns": [
          {
            "dataIndex": "companyId",
            "title": "货主ID",
            "hidden": true
          },
          {
            "dataIndex": "companyName",
            "title": "货主名称"
          },
          {
            "dataIndex": "companyCode",
            "title": "货主编码"
          }
        ],
        "hasRowSelectCheck": true,
        "rowSelectType": 1
      },
      "on": {
        change: changeFun
      }
    },
  ]
}

// 仓库
export const getBranchItems = changeFun => {
  return [
    {
      "hidden": true,
      "type": "input",
      "name": "dcId",
      "label": "仓配中心Id",
      "value": ""
    },
    {
      "hidden": true,
      "type": "input",
      "name": "branchid",
      "label": "仓库ID",
      "value": ""
    },
    {
      "hidden": true,
      "type": "input",
      "name": "branchcode",
      "label": "仓库编码",
      "value": ""
    },
    {
      "type": "searchModal",
      "name": "branchname",
      "label": "仓库名称",
      "title": "仓库名称",
      "value": "",
      "rowKey": "companyId",
      "destroyOnClose": true,
      "targetClick": true,
      "targetValueKey": "companyName",
      "labelCol": {
        "span": 8
      },
      "wrapperCol": {
        "span": 16
      },
      "span": 6,
      "remoteUrl": {
        "url": SERVICE_CTRL_TOWER + "/userDataAuth/allDataAuthByUser/?companyType=S",
        "method": "get"
      },
      "required": true,
      "toolBar": {
        "items": []
      },
      "tableConfig": {
        "columns": [
          {
            "dataIndex": "companyId",
            "title": "仓库ID",
            "hidden": true
          },
          {
            "dataIndex": "dcId",
            "title": "仓配中心ID",
            "hidden": true
          },
          {
            "dataIndex": "companyName",
            "title": "仓库名称"
          },
          {
            "dataIndex": "companyCode",
            "title": "仓库编码"
          }
        ],
        "hasRowSelectCheck": true,
        "rowSelectType": 1
      },
      "on": {
        change: changeFun
      }
    },
  ]
}

// 批号弹窗
export const getLOTItems = (changeFun, remoteBeforeFun,modalOpenChange) => {
  return [
    {
      "hidden": true,
      "type": "text",
      "name": "locatorId",
      "label": "货位",
      "value": ""
    },
    {
      "hidden": true,
      "type": "text",
      "name": "containerCode",
      "label": "托盘",
      "value": ""
    },
    {
      "type": "searchModal",
      "name": "manufacturerLotNum",
      "label": "批号",
      "title": "批号",
      "value": "",
      "rowKey": "id",
      "destroyOnClose": true,
      "targetClick": true,
      "targetValueKey": "manufacturerLotNum",
      "labelCol": {
        "span": 8
      },
      "wrapperCol": {
        "span": 16
      },
      "span": 6,
      "remoteUrl": {
        "url": upcloud_base_inventory + "/stock/v1/queryStockInfoList",
        "method": "post"
      },
      "required": true,
      "toolBar": {
        "items": [
          {type: 'input', name: 'batchNum', label: '批号', span: 8, value: ''},
          {
            type: 'select',
            name: 'status',
            label: '库存状态',
            options: [
              {label: '合格', value: '1'},
              {label: '不合格', value: '2'},
              {label: '待检', value: '3'},
              {label: '退货', value: '4'}
            ],
            span: 8,
            value: ''
          }
        ]
      },
      "tableConfig": {
        remoteBefore: remoteBeforeFun,
        "columns": [
          {
            "dataIndex": "itemName",
            "title": "商品名称"
          },
          {
            "dataIndex": "manufacturerLotNum",
            "title": "批号"
          },
          {
            "dataIndex": "status",
            "title": "库存状态",
            customRender(text) {
              text = String(text)
              if (text === '1') return '合格'
              if (text === '2') return '不合格'
              if (text === '3') return '待检'
              if (text === '4') return '退货'
              return text
            }
          },
          {
            "dataIndex": "invoicedQuantity",
            "title": "可开票数量"
          }
        ],
        "hasRowSelectCheck": true,
        "rowSelectType": 1
      },
      "on": {
        change: changeFun
      },
      modalOpenChange
    },
  ]
}
