// import { remote } from './remote'
import { upcloud_base_wh } from "@/config/serviceSettings";
import { genWarehouseAuthSearchModal, genCargoownerAuthSearchModal } from '@/views/kzyWMS/SearchModal'
let grid = {
  labelCol: { span: 10 },
  wrapperCol: { span: 14 },
  span: 8
}

function setWhName(user) {
  let _this = user
  if (!_this.userInfo) return
  const { warehouseId, warehouseCode, warehouseName } = _this.warehouse

  let whName = genWarehouseAuthSearchModal(1, true, false, null, function(rowData, form) {
    if (!rowData) {
      form.setFieldsValue({
        companyId: '',
        companyCode: '',
        companyName: ''
      })
    } else {
      // [integer] 扫描监管码节点：0=拣货 1=外复核
      _this.warehouseId = rowData[0].companyId
      form.setFieldsValue({
        bldgId: '',
        warehouseId: rowData[0].companyId,
        warehouseCode: rowData[0].companyCode,
        warehouseName: rowData[0].companyName
      })
    }
  })

  delete whName[2].labelCol
  delete whName[2].span
  delete whName[2].wrapperCol
  whName[0].value = warehouseId
  whName[1].value = warehouseCode
  whName[2].value = warehouseName
  whName[2].type = 'select'
  whName[2].allowClear = false
  whName[2].options = _this.userInfo.warehouseList //直接从状态里拿数据
  whName[2].replaceFields = { value: 'warehouseId', label: 'warehouseName' }
  whName[2].destroyOptions = false
  whName[2].showSearch = false
  whName[2].labelCol = { span: 10 }
  whName[2].wrapperCol = { span: 14 }
  whName[2].style = { width: '240px' }
  delete whName[2].remoteUrl;
  whName[2].on.change = (...args) => {
    let form = args[3];
    form.setFieldsValue({bldgId:''})
    _this.warehouseId=''
    _this.warehouseId = args[0];
  }

  return whName
}

export const getFromItems = function(_this) {
  
  return [
    {
      type: 'input',
      name: 'operatorCode',
      required: true,
      label: '工号',
      disabled: true,
      value: _this.userInfo.employeeNo
    },
    {
      type: 'input',
      name: 'srcCode',
      label: '订单号',
      value: ''
      // required: true
    },
    // 仓库
    // ...setWhName(_this),
      ...genWarehouseAuthSearchModal(1, true, false, null, null, grid),
    {
      name: 'branchid',
      hidden: true
    },
    {
      labelCol: { span: 10 },
      wrapperCol: { span: 14 },
      style: { width: '240px' },
      type: 'select',
      allowClear: false,
      name: 'bldgId',
      replaceFields: {
        value: 'bldgId',
        label: 'bldgName'
      },
      remoteUrl: {
        url: upcloud_base_wh+'/wmsWhBldg/v1/page'
      },
      remoteParams:_this.bldgIdRemoteParams,
      defaultValueIndex: 0,
      destroyOptions: false,
      label: '建筑物',
      value: '',
      required: true,

    },
    {
      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()
            }
          }
        }
      ]
    }
  ]
}

export const getMinCol = function(_this) {
  return [
    {
      title: '单据编号',
      dataIndex: 'srcCode',
      ellipsis: true
    },
    {
      title: '收货单位(客户)名称',
      dataIndex: 'shipperName',
      width: 270,
      ellipsis: true
    },

    {
      title: '收货地址',
      dataIndex: 'receiveAddress',
      ellipsis: true
    },
    {
      title: '收货方式',
      dataIndex: 'receiveWay',
      ellipsis: true,
      customRender: value => {
        if (_this.deliver_type.length > 0) {
          let dict = _this.deliver_type.find(item => item.dictId == value)
          if (!dict) {
            return '[查无数据]' + value
          }
          return dict.dictName
        }
      }
    },
    {
      title: '物流商名称',
      dataIndex: 'carrierName',
      ellipsis: true
    },
    {
      title: '容器编号',
      dataIndex: 'containerCode',
      ellipsis: true
    },
    {
      title: '拼箱编号',
      dataIndex: 'lclNo',
      ellipsis: true
    },
    {
      title: '订单紧急等级',
      dataIndex: 'priority',
      ellipsis: true
    },
    {
      title: '预定到货日',
      dataIndex: 'attainDate',
      ellipsis: true
    },
    {
      title: '收货单位(客户)编码',
      dataIndex: 'shipperCode',
      ellipsis: true
    },
    {
      title: '运输路线ID',
      dataIndex: 'shipLineId',
      ellipsis: true
    },
    {
      title: '收货单位(客户)类型',
      dataIndex: 'shipperType',
      ellipsis: true
    },
    {
      title: '复核台编码',
      dataIndex: 'stationCode',
      ellipsis: true
    },
    {
      title: '类型',
      dataIndex: 'type',
      ellipsis: true,
      customRender: (text, record) => {
        if (text == '0') {
          return '拼箱码'
        } else if (text == '1') {
          return '整件拣选码'
        }
      }
    },

    {
      title: '复核人工号',
      dataIndex: 'checkerNo',
      ellipsis: true
    },
    {
      title: '复核人名称',
      dataIndex: 'checkerName',
      ellipsis: true
    },
    {
      title: '复核时间',
      dataIndex: 'checkTime',
      width: 150
    },

    // {
    //   title: '条码',
    //   dataIndex: 'barcode',
    //   ellipsis: true
    // },

    // {
    //   title: '状态',
    //   dataIndex: 'printStatus',
    //   ellipsis: true
    // },

    {
      fixed: 'right',
      title: '操作',
      width: 100,
      align: 'center',
      key: 'operation',
      scopedSlots: { customRender: 'operation' }
    }
  ]
}

export const getDetailCol = function(_this) {
  return [
    {
      dataIndex: 'isSupervise',
      ellipsis: true,
      width: '80px',
      title: '是否监管',
      customRender: (text, 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: 'expiredDate',
      ellipsis: true,
      width: '150px',
      title: '有效期至'
    },
    {
      dataIndex: 'manufacturer',
      ellipsis: true,
      width: '200px',
      title: '生产厂家'
    },
    {
      dataIndex: 'manufacturerLotNum',
      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: '商品大类',
    //   hidden: true
    // },
    {
      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,
      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: '商品大类',
    //   hidden: true,
    // },
    {
      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: '箱重量'
    },

  ]
}

export const getLogCol = function(_this) {
  return [
    // {
    //   dataIndex: 'bldgId',
    //   title: '建筑物id'
    // },
    {
      dataIndex: 'bldgName',
      title: '建筑物名称'
    },
    {
      dataIndex: 'photoId',
      title: '照片id'
    },
    {
      dataIndex: 'pickUpDate',
      title: '提货时间'
    },
    {
      dataIndex: 'shipperCard',
      title: '身份证号'
    },
    {
      dataIndex: 'shipperName',
      title: '提货人姓名'
    },
    {
      dataIndex: 'consignorname',
      title: '产品编码'
    },
    {
      dataIndex: 'srcCode',
      title: '提货订单'
    },
    {
      dataIndex: 'status',
      title: '状态',
      hidden: true
    }
  ]
}
