import { remote } from './remote'
import { genWarehouseAuthSearchModal, genBldgSearchModal } from '@/views/kzyWMS/SearchModal'
import store from '@/store'
import { upcloud_base_common, upcloud_base_inventory } from "@/config/serviceSettings";
const HCitems = function (_this) {
  return [
    {
      type: 'number',
      name: 'redQty',
      required: true,
      label: '红冲数量',
      rules: [{
        type: "number",
        message: "请输入正整数",
        validator: (rule, value, cb) => {
          var reg = /^([1-9]\d*|[0]{1,1})$/;
          if (!reg.test(value)) {
            cb(true);
          }
          cb();
        },
      }],
    },
    {
      type: 'textarea',
      name: 'reason',
      required: true,
      label: '红冲原因'
    },
    {
      type: 'select',
      name: 'redDoMethod',
      label: '红冲处理方式',
      required: true,
      value: '1',
      options: [
        { title: '入库盘点', value: '1' },
      ]
    },
  ]
  
}
const items = function(_this) {
  let warehouseId = store.state.user.warehouse.warehouseId
  return [
    {
      type: 'input',
      name: 'operatorCode',
      required: true,
      label: '工号'
    },
    {
      type: 'input',
      name: 'srcBillCode',
      label: '订单号'
    },
    {
      type: 'input',
      name: 'barcode',
      label: '条形编码'
    },
    // 仓库
    ...genWarehouseAuthSearchModal(
      1,
      true,
      false,
      null,
      function(rowData, form) {
        form.setFieldsValue({ bldgName: '', bldgId: '' })
        if (!rowData) {
          warehouseId = null
          form.setFieldsValue({
            companyId: '',
            companyCode: '',
            companyName: ''
          })
        } else {
          // [integer] 扫描监管码节点：0=拣货 1=外复核
          _this.$emit('update:warehouseId', rowData[0].companyId)
          warehouseId = rowData[0].companyId
          form.setFieldsValue({
            warehouseId: rowData[0].companyId,
            warehouseCode: rowData[0].companyCode,
            warehouseName: rowData[0].companyName
          })
        }
      },
      { span: 8, labelCol: { span: 8 } }
    ),
    // 建筑物
    ...genBldgSearchModal(
      1,
      true,
      false,
      function(vn, p) {
        p.params.warehouseId = warehouseId
        return p
      },
      null,
      { span: 8, labelCol: { span: 8 } }
    ),
    {
      type: "select",
      name: "billtypeGroup",
      label: "订单类型",
      value: "",
      autoLoad: true,
      remoteUrl: { url: upcloud_base_common + "/dict/listbytype?dicttypeCodes=billtypeGroup", method: "post" },
      replaceFields: { value: "dictCode", label: "dictName" },
      ...{ span: 8, labelCol: { span: 8 } }
    },
    // {
    //   type: 'input',
    //   name: 'containerCode',
    //   required: true,
    //   label: '容器号'
    // },
    {
      type: 'buttonGroup',
      style: { textAlign: 'center' },
      options: [
        {
          value: '查询',
          icon: 'search',
          btnType: 'primary',
          style: 'margin-right:10px',
          htmlType: 'submit'
        },
        {
          value: '重置',
          name: 'ccz',
          icon: 'redo',
          on: {
            click(event, form) {
              form.resetFields()
            }
          }
        }
      ]
    }
  ]
}

const columns = [
  {
    title: '是否集货完成',
    dataIndex: 'allInPlace',
    hidden: true,
    customRender: (text, record) => {
      if (text == true) return '是'
      if (text == false) return '否'
      return ''
    }
  },
  {
    title: '复核人名称',
    dataIndex: 'checkerName'
  },
  {
    title: '单据编号',
    ellipsis: true,
    dataIndex: 'srcCode',
    width: '200px'
  },
  {
    title: '出库单类型',
    ellipsis: true,
    dataIndex: 'billType',
    width: '200px'
  },
  {
    title: '收货单位(客户)名称',
    ellipsis: true,
    dataIndex: 'shipperName',
    width: '200px'
  },
  {
    title: '收货地址',
    ellipsis: true,
    dataIndex: 'receiveAddress',
    width: '200px'
  },
  {
    title: '容器编号',
    dataIndex: 'containerCode'
  },
  {
    title: '送货方式',
    dataIndex: 'arrivalMode'
  },
  {
    title: '销售员',
    dataIndex: 'salespersonName',
    ellipsis: true
  },
  {
    title: '业务员部门',
    dataIndex: 'saleBranchname'
  },
  {
    title: '工号',
    dataIndex: 'operatorCode'
  },
  {
    title: '开票员',
    dataIndex: 'createby'
  },
  {
    title: '账期类型',
    dataIndex: 'paymentType'
  },
  {
    title: '客户地址',
    dataIndex: 'customerAddress',
    width: '200px',
    ellipsis: true
  },
  {
    title: '备注',
    dataIndex: 'remark'
  },
  {
    title: 'ERP单据编号',
    dataIndex: 'erpSrcCode',
    width: '200px',
    ellipsis: true
  },
  {
    dataIndex: 'receiveWay',
    title: '收货方式',
    ...remote('pub_workstage_delivertype')
  },
  {
    title: '物流商名称',
    dataIndex: 'carrierName'
  },
  {
    title: '拼箱编号',
    dataIndex: 'lclNo'
  },
  // {
  //   title: '状态',
  //   dataIndex: 'printStatus'
  // },
  {
    title: '订单紧急等级',
    dataIndex: 'priority'
  },

  // {
  //   title: '收货方式',
  //   dataIndex: 'receiveWay'
  // },

  {
    title: '预定到货日',
    dataIndex: 'attainDate'
  },
  {
    title: '收货单位(客户)编码',
    dataIndex: 'shipperCode'
  },
  {
    title: '运输路线ID',
    dataIndex: 'shipLineId'
  },

  {
    title: '收货单位(客户)类型',
    dataIndex: 'shipperType'
  },
  {
    title: '复核台编码',
    dataIndex: 'stationCode'
  },
  {
    title: '类型',
    dataIndex: 'type',
    customRender: (text, record) => {
      if (text == '0') return '拼箱码'
      if (text == '1') return '整件拣选码'
    }
  },
  {
    title: '复核人工号',
    dataIndex: 'checkerNo'
  },
  {
    title: '复核时间',
    dataIndex: 'checkTime'
  },
  // todo
  {
    title: '是否冲红',
    dataIndex: 'char1'
  },
  {
    dataIndex: "action",
    title: "操作",
    scopedSlots: { customRender: "action" },
    width: 120,
    align: "center",
    fixed: "right",
  },
]

const columns3 = [
  {
    title: '单据编号',
    ellipsis: true,
    width: '200px',
    dataIndex: 'srcCode'
  },

  {
    title: '收货单位(客户)名称',
    ellipsis: true,
    dataIndex: 'shipperName',
    width: '200px'
  },

  {
    title: '收货地址',
    ellipsis: true,
    dataIndex: 'receiveAddress',
    width: '200px'
  },
  {
    title: '送货方式',
    dataIndex: 'arrivalMode'
  },
  {
    title: '销售员',
    dataIndex: 'salespersonName'
  },
  {
    title: '业务员部门',
    dataIndex: 'saleBranchname'
  },
  {
    title: '开票员',
    dataIndex: 'createby'
  },
  {
    title: '账期类型',
    dataIndex: 'paymentType'
  },
  {
    title: '客户地址',
    dataIndex: 'customerAddress',
    width: '200px',
    ellipsis: true
  },
  {
    title: '备注',
    dataIndex: 'remark'
  },
  {
    title: 'ERP单据编号',
    dataIndex: 'erpSrcCode',
    width: '200px',
    ellipsis: true
  },
  {
    dataIndex: 'receiveWay',
    title: '收货方式',
    ...remote('pub_workstage_delivertype')
  },
  {
    title: '物流商名称',
    dataIndex: 'carrierName'
  },
  {
    title: '货主名称',
    dataIndex: 'consignorName'
  },
  {
    title: '仓库名称',
    dataIndex: 'warehouseName'
  },
  {
    title: '仓库编码',
    dataIndex: 'warehouseCode'
  },
  {
    title: '运输路线名称',
    dataIndex: 'lineCode'
  }
  // {
  //   title: '容器编号',
  //   dataIndex: 'containerCode'
  // },
  // {
  //   title: '拼箱编号',
  //   dataIndex: 'lclNo'
  // },
  // {
  //   title: '状态',
  //   dataIndex: 'printStatus'
  // },
  // {
  //   title: '订单紧急等级',
  //   dataIndex: 'priority'
  // },

  // {
  //   title: '收货方式',
  //   dataIndex: 'receiveWay'
  // },

  // {
  //   title: '预定到货日',
  //   dataIndex: 'attainDate'
  // },
  // {
  //   title: '收货单位(客户)编码',
  //   dataIndex: 'shipperCode'
  // },
  // {
  //   title: '运输路线ID',
  //   dataIndex: 'shipLineId'
  // },

  // {
  //   title: '收货单位(客户)类型',
  //   dataIndex: 'shipperType'
  // },
  // {
  //   title: '复核台编码',
  //   dataIndex: 'stationCode'
  // },
  // {
  //   title: '类型',
  //   dataIndex: 'type',
  //   customRender: (text, record) => {
  //     // console.log(record)
  //     if (text == '0') {
  //       return '拼箱码'
  //     } else if (text == '1') {
  //       return '整件拣选码'
  //     }
  //   }
  // },
  // {
  //   title: '复核人工号',
  //   dataIndex: 'checkerNo'
  // },
  // {
  //   title: '复核人名称',
  //   dataIndex: 'checkerName'
  // },
  // {
  //   title: '复核时间',
  //   dataIndex: 'checkTime'
  // }
]
const singleColumns = [
  // {
  //   title: '序号',
  //   dataIndex: 'index',
  //   key: 'index',
  //   scopedSlots: { customRender: 'index' }
  // },
  // {
  //   dataIndex: 'srcCode',
  //   width: '150px',
  //   title: 'srcCode',
  //   hidden: true,
  // },
  {
    dataIndex: 'isSupervise',
    ellipsis: true,
    width: '80px',
    title: '是否监管',
    customRender: (text, record) => {
      // console.log(record)
      if (text == '0') {
        return '否'
      } else if (text == '1') {
        return '是'
      }
    }
  },
  {
    dataIndex: 'itemCode',
    ellipsis: true,
    width: '150px',
    title: '商品编码'
  },
  {
    dataIndex: 'itemName',
    ellipsis: true,
    width: '200px',
    title: '商品名称'
  },
  {
    dataIndex: 'itemSpecs',
    ellipsis: true,
    width: '150px',
    title: '商品规格'
  },
  {
    dataIndex: 'barcode',
    ellipsis: true,
    width: '150px',
    title: '条码'
  },
  {
    dataIndex: 'conversionRate',
    ellipsis: true,
    width: '150px',
    title: '单位因子'
  },
  {
    dataIndex: 'oddPieceQty',
    ellipsis: true,
    width: '150px',
    title: ' 实际零散数'
  },
  {
    dataIndex: 'qty',
    ellipsis: true,
    width: '150px',
    title: '实际数量'
  },
  {
    dataIndex: 'uomQty',
    ellipsis: true,
    width: '150px',
    title: '实际件数'
  },
  {
    dataIndex: 'locatorCode',
    ellipsis: true,
    width: '150px',
    title: '库位编码'
  },
  {
    dataIndex: 'batchNum',
    ellipsis: true,
    width: '150px',
    title: '批次号'
  },
  {
    dataIndex: 'businessType',
    ellipsis: true,
    width: '150px',
    title: '业务类型',
    customRender: (text, record) => {
      // console.log(record)
      if (text == '0') {
        return '入库'
      } else if (text == '1') {
        return '出库'
      } else if (text == '2') {
        return '库内'
      }
    }
  },
  {
    dataIndex: 'consignorCode',
    ellipsis: true,
    width: '150px',
    title: '货主编码'
  },
  {
    dataIndex: 'consignorName',
    ellipsis: true,
    width: '200px',
    title: '货主名称'
  },
  // {
  //   dataIndex: 'itemHealthSuperviseflag',
  //   ellipsis: true,
  //   width: '150px',
  //   title: '是否监管',
  //   customRender:text=>text=='1'?'是':'否',
  // },
  {
    dataIndex: 'expiredDate',
    ellipsis: true,
    width: '150px',
    title: '有效期至'
  },
  {
    dataIndex: 'manufacturer',
    ellipsis: true,
    width: '200px',
    title: '生产厂家'
  },
  {
    dataIndex: 'manufacturerLotNum',
    ellipsis: true,
    width: '150px',
    title: '批号'
  },
//   {
//     dataIndex: 'maxSu',
//     ellipsis: true,
//     width: '150px',
//     title: '大包装数'
//   },
//   {
//     dataIndex: 'middleSu',
//     ellipsis: true,
//     width: '150px',
//     title: '中包装数'
//   },
//   {
//     dataIndex: 'minSu',
//     ellipsis: true,
//     width: '150px',
//     title: '小包装数'
//   },
//   {
//     dataIndex: 'outerAskDate',
//     ellipsis: true,
//     width: '150px',
//     title: '外复核索取时间'
//   },
  {
    dataIndex: 'pickOddPieceQty',
    ellipsis: true,
    width: '150px',
    title: '拣货零散数量'
  },
  {
    dataIndex: 'pickQty',
    ellipsis: true,
    width: '150px',
    title: '拣货数量'
  },
  {
    dataIndex: 'itemHealthCategoryCode',
    ellipsis: true,
    width: '150px',
    title: '商品大类'
  },
  {
    dataIndex: 'pickUomQty',
    ellipsis: true,
    width: '150px',
    title: '拣货件数'
  },
  {
    dataIndex: 'pickerName',
    ellipsis: true,
    width: '150px',
    title: '拣选员名称'
  },
  {
    dataIndex: 'productionDate',
    ellipsis: true,
    width: '150px',
    title: '生产日期'
  },
  {
    dataIndex: 'shipperName',
    ellipsis: true,
    width: '200px',
    title: '收货单位'
  },
  {
    dataIndex: 'srcCode',
    ellipsis: true,
    hidden: true,
    width: '150px',
    title: '来源订单编号'
  },
  {
    dataIndex: 'stage',
    ellipsis: true,
    width: '150px',
    title: '扫码阶段',
    customRender: (text, record) => {
      // console.log(record)
      if (text == '0') {
        return '入库质检'
      } else if (text == '1') {
        return 'PC拣货'
      } else if (text == '2') {
        return 'PC内复核'
      } else if (text == '3') {
        return 'PC外复核'
      } else if (text == '4') {
        return '补录'
      } else if (text == '5') {
        return 'PDA拣货'
      } else if (text == '6') {
        return 'PDA内复核'
      } else if (text == '7') {
        return 'PDA外复核'
      }
    }
  },
  {
    dataIndex: 'uom',
    ellipsis: true,
    width: '150px',
    title: '单位'
  },
  {
    dataIndex: 'warehouseAreaCode',
    ellipsis: true,
    width: '150px',
    title: '库区编码'
  },
  {
    dataIndex: 'itemHealthIsDouble',
    ellipsis: true,
    width: '100px',
    title: '是否双人复核',
    customRender: (text, record) => {
      // console.log(record)
      if (text == '0') {
        return '否'
      } else if (text == '1') {
        return '是'
      }
    }
  },
  {
    dataIndex: 'itemHealthApprovalNbr',
    ellipsis: true,
    width: '150px',
    title: '批准文号'
  },
  {
    dataIndex: 'isCaseOrPiece',
    ellipsis: true,
    width: '100px',
    title: '整散标志',
    customRender: (text, record) => {
      // console.log(record)
      if (text == '0') {
        return '整散合一'
      } else if (text == '1') {
        return '整散分离'
      }
    }
  },
  {
    dataIndex: 'itemIsValuable',
    ellipsis: true,
    width: '100px',
    title: '是否贵重商品'
  },
  {
    dataIndex: 'itemIsFragile',
    ellipsis: true,
    width: '100px',
    title: '是否易碎'
  },
  {
    dataIndex: 'isBacteria',
    ellipsis: true,
    width: '100px',
    title: '是否无菌',
    customRender: (text, record) => {
      // console.log(record)
      if (text == '0') {
        return '否'
      } else if (text == '1') {
        return '是'
      }
    }
  },
  {
    dataIndex: 'isDelegate',
    ellipsis: true,
    width: '100px',
    title: '是否委托生产',
    customRender: (text, record) => {
      // console.log(record)
      if (text == '0') {
        return '否'
      } else if (text == '1') {
        return '是'
      }
    }
  },
  {
    dataIndex: 'isHosted',
    ellipsis: true,
    width: '100px',
    title: '商品是否代管',
    customRender: (text, record) => {
      // console.log(record)
      if (text == '0') {
        return '否'
      } else if (text == '1') {
        return '是'
      }
    }
  },
  {
    dataIndex: 'itemAssistantCode',
    ellipsis: true,
    width: '100px',
    title: '助记码'
  },
  {
    dataIndex: 'cargoOwnerCode',
    ellipsis: true,
    width: '100px',
    title: '货主编码'
  },
  {
    dataIndex: 'itemHealthCategory',
    ellipsis: true,
    width: '100px',
    title: '商品大类'
  },
  {
    dataIndex: 'manufacturerName ',
    ellipsis: true,
    width: '150px',
    title: '生产厂家'
  },
  {
    dataIndex: 'countryOriginId',
    ellipsis: true,
    width: '150px',
    title: '产地'
  },
  {
    dataIndex: 'itemHealthListedLicensor',
    ellipsis: true,
    width: '150px',
    title: '上市许可持有人'
  },
  {
    dataIndex: 'itemHealthProduceLicense',
    ellipsis: true,
    width: '150px',
    title: '生产企业许可证号'
  },
  {
    dataIndex: 'itemHealthRegisterNbr',
    ellipsis: true,
    width: '150px',
    title: '注册证号'
  },
  {
    dataIndex: 'caseConversionRate',
    ellipsis: true,
    width: '100px',
    title: '包装数量'
  },
  {
    dataIndex: 'itemHealthRecordNbr',
    ellipsis: true,
    width: '100px',
    title: '备案号'
  },
  {
    dataIndex: 'volume',
    ellipsis: true,
    width: '100px',
    title: '箱体积'
  },
  {
    dataIndex: 'weight',
    ellipsis: true,
    width: '100px',
    title: '箱重量'
  },
  {
    dataIndex: 'action',
    title: '操作',
    scopedSlots: { customRender: 'action' },
    width: 140,
    fixed: 'right'
  }
]

export { items, columns, columns3, singleColumns, HCitems }
