import store from '@/store'
import moment from 'moment'
import {
  genWarehouseAuthSearchModal,
  genBldgSearchModal,
  genCargoownerAuthSearchModal
} from '@/views/kzyWMS/SearchModal'

import { upcloud_base_wh } from '@/config/serviceSettings'
const grid = { span: 8, labelCol: { span: 6 } }
let warehouseId = store.state.user.warehouse.warehouseId
const items = [
  // 仓库
  ...genWarehouseAuthSearchModal(
    1,
    true,
    false,
    null,
    function(rowData, form) {
      if (!rowData) {
        warehouseId = ''
      } else {
        warehouseId = rowData[0].companyId
      }
    },
    grid
  ),
  // 货主(与账户权限关联)
  ...genCargoownerAuthSearchModal(
    1,
    true,
    false,
    function(vn, p) {
      console.log('remoteBefore参数回调：', vn, p)
    },
    null,
    grid
  ),
  {
    type: 'searchModal',
    name: 'bldgName',
    label: '源建筑物',
    // required: true,
    remoteUrl: { url: upcloud_base_wh + '/wmsWhBldg/v1/page', method: 'get' },
    rowKey: 'bldgId',
    targetValueKey: 'bldgName',
    ...grid,
    toolBar: {
      items: [
        {
          type: 'input',
          name: 'bldgName',
          label: '建筑物名称',
          value: ''
        },
        {
          type: 'input',
          name: 'bldgCode',
          label: '建筑物编号',
          value: ''
        }
      ]
    },
    tableConfig: {
      remoteBefore: (res, remoteParams) => {
        remoteParams.params = {
          ...remoteParams.params,
          warehouseId: warehouseId
        }
        return remoteParams
      },
      columns: [
        {
          dataIndex: 'bldgName',
          title: '建筑物名称'
        },
        {
          dataIndex: 'bldgCode',
          title: '建筑物编号'
        }
      ]
    },
    on: {
      ok(event, value, rowData, form) {
        form.setFieldsValue({
          srcBldgCode: `${rowData[0].bldgCode}`
        })
      }
    }
  },
  {
    type: 'searchModal',
    name: 'destBldgName',
    label: '目标建筑物',
    // required: true,
    remoteUrl: { url: upcloud_base_wh + '/wmsWhBldg/v1/page', method: 'get' },
    rowKey: 'bldgId',
    targetValueKey: 'bldgName',
    ...grid,
    toolBar: {
      items: [
        {
          type: 'input',
          name: 'bldgName',
          label: '建筑物名称',
          value: ''
        },
        {
          type: 'input',
          name: 'bldgCode',
          label: '建筑物编号',
          value: ''
        }
      ]
    },
    tableConfig: {
      remoteBefore: (res, remoteParams) => {
        remoteParams.params = {
          ...remoteParams.params,
          warehouseId: warehouseId
        }
        return remoteParams
      },
      columns: [
        { dataIndex: 'bldgName', title: '建筑物名称' },
        { dataIndex: 'bldgCode', title: '建筑物编号' }
      ]
    },
    on: {
      ok(event, value, rowData, form) {
        form.setFieldsValue({
          destBldgCode: `${rowData[0].bldgCode}`
        })
      }
    }
  },
  { type: 'input', name: 'srcBldgCode', hidden: true, label: '源建筑物编码', value: '', ...grid },
  { type: 'input', name: 'destBldgCode', hidden: true, label: '目标建筑物编码', value: '', ...grid },
  { type: 'input', name: 'itemName', label: '商品名称', value: '', ...grid },
  { type: 'input', name: 'itemCode', label: '商品编码', value: '', ...grid },
  // {type: 'input',name: 'itemCode',label: '商品编码',value: '',...grid},
  { type: 'input', name: 'srcCode', label: '订单编号', value: '', ...grid },
  {
    type: 'select',
    name: 'status',
    label: '状态',
    value: '',
    options: [
      // 0:新生成 1:下架 2:上架
      { label: '新生成', value: '0' },
      { label: '下架', value: '1' },
      { label: '上架', value: '2' }
    ],
    ...grid
  },
  {
    type: 'select',
    name: 'moveType',
    label: '补货类型',
    value: '',
    options: [
      // 补货类型 1主动补货 2紧急补货 3波次补货 4被动补货
      { label: '主动补货', value: '1' },
      { label: '紧急补货', value: '2' },
      { label: '波次补货', value: '3' },
      { label: '被动补货', value: '4' }
    ],
    ...grid
  },
  {
    type: 'date',
    name: 'startTime',
    label: '开始日期',
    placeholder: '请输入开始日期',
    format: 'YYYY-MM-DD 00:00:00',
    value: moment().format('YYYY-MM-DD 00:00:00'),
    ...grid
  },
  {
    type: 'date',
    name: 'endTime',
    label: '结束日期',
    placeholder: '请输入结束日期',
    format: 'YYYY-MM-DD 23:59:59',
    value: moment().format('YYYY-MM-DD 23:59:59'),
    ...grid
  },
  {
    ...grid,
    type: 'buttonGroup',
    style: { textAlign: 'center' },
    options: [
      { value: '查询', icon: 'search', btnType: 'primary', style: 'margin-right:16px', htmlType: 'submit' },
      {
        value: '重置',
        name: 'ccz',
        icon: 'redo',
        on: {
          click(event, form) {
            form.resetFields()
            form.setFieldsValue({
              warehouseName: '',
              warehouseId: ''
            })
          }
        }
      }
    ]
  }
]

const columns = [
  // { dataIndex: 'consignorname', title: '货主名称' },
  { dataIndex: 'srcCode', title: '订单编号' },
  //   { dataIndex: 'waveId', title: '波次编号' },
  { dataIndex: 'itemName', title: '商品名称' },
  { dataIndex: 'itemCode', title: '商品编码' },
  { dataIndex: 'pieceQty', title: '数量' },
  { dataIndex: 'caseqty', title: '件数' },
  { dataIndex: 'conversionRate', title: '包装数量' },
  { dataIndex: 'uom', title: '单位' },
  { dataIndex: 'pieceUom', title: '最小单位' },
  { dataIndex: 'specification', title: '规格' },
  { dataIndex: 'srcWarehouseAreaCode', title: '源库区' },
  { dataIndex: 'srcLocatorCode', title: '源货位' },
  { dataIndex: 'destWarehouseAreaCode', title: '目标库区' },
  { dataIndex: 'destLocatorCode', title: '目标货位' },
  { dataIndex: 'manufacturerLotNum', title: '批号' },
  {
    dataIndex: 'status',
    title: '状态',
    customRender: text => {
      // 0:新生成 1:下架 2:上架
      switch (text) {
        case '0':
          return '新生成'
          break
        case '1':
          return '下架'
          break
        case '2':
          return '上架'
          break
      }
    }
  }, // 0-未开始 1-进行中 2-已完成
  {
    dataIndex: 'moveType',
    title: '补货类型',
    customRender: (text, rows, index) => {
      switch (text) {
        case '1':
          return '主动补货'
          break
        case '2':
          return '紧急补货'
          break
        case '3':
          return '波次补货'
          break
        case '4':
          return '被动补货'
          break
      }
    }
  }, // 1主动补货 2紧急补货 3波次补货 4被动补货
  { dataIndex: 'contactName', title: '联系人' },
  { dataIndex: 'srcBldgCode', title: '源建筑物编号' },
  { dataIndex: 'destBldgCode', title: '目标建筑物编号' },
  { dataIndex: 'gmtCreate', title: '创建时间' }
]
export { items, columns }
