import {
  genWorkercodeSearchModal,
  genWarehouseAuthSearchModal,
  genWarehouseAreaSearchModal
} from '../../../SearchModal'
import { remote } from './remote'
import { upcloud_base_wh, upcloud_base_common } from '@/config/serviceSettings'

let grid = { span: 8, labelCol: { span: 8 } }
const extendConfig = {
  mapper: { warehouseAreaCode: 'workarea' }
}

export const formItems = function(self) {
  return [
    ...genWorkercodeSearchModal(
      1,
      true,
      false,
      function(vnode, remote) {
        remote.params.isEnable = 1
        console.log(remote)
        return remote
      },
      null,
      grid,
      {
        mapper: { jobnumber: 'workercode', locname: 'personName' }
      }
    ),
    ...genWarehouseAuthSearchModal(
      1,
      true,
      false,
      null,
      function(rowDate, form) {
        if (rowDate) {
          self.warehouseId = rowDate[0].companyId
        } else {
          self.warehouseId = ''
        }
        self.formWarehouseChange()
        self.disableItem()
      },
      grid
    ),
    // ...genWarehouseAreaSearchModal(1, false, false, self.remoteBefore2, null, grid, extendConfig),
    // {
    //   name: 'packcode',
    //   label: '包装方式',
    //   options: [
    //     { title: '固定', value: '01' },
    //     { title: '灵活', value: '02' }
    //   ],
    //   type: 'select',
    //   ...grid
    // },
    // {
    //   name: 'worktype',
    //   label: '作业类型',
    //   ...remote('was_worktype'),
    //   type: 'select',
    //   ...grid
    // },
    // { type: 'input', name: 'priority', label: '优先级', value: '', ...grid, required: true },
    { type: 'input', name: 'workercode', label: 'jobnumber', value: null, ...grid, hidden: true },
    { type: 'input', name: 'personName', label: '人员名称', value: null, ...grid, hidden: true },
    { type: 'SwitchValue', name: 'isEnable', label: '是否启用', value: 1, ...grid }
  ]
}

export const tableCols1 = [
  { title: '编码', dataIndex: 'dictCode', key: 'dictCode' },
  { title: '名称', dataIndex: 'dictName', key: 'dictName' }
]

export const tableCols2 = [
  { hidden: true, title: 'stationId', dataIndex: 'stationId', key: 'stationId' },
  { title: '工作站编码', dataIndex: 'stationCode', key: 'stationCode' },
  { title: '工作站名称', dataIndex: 'stationName', key: 'stationName' },
  { title: '工作站类型', dataIndex: 'stationType', key: 'stationType' },
  { title: '复核台类别', dataIndex: 'stageGroup', key: 'stageGroup' },
  { title: '复核台类型', dataIndex: 'stageType', key: 'stageType' }
]

export const EditTableColumns = [
  { dataIndex: 'warehouseAreaId', title: 'ID', hidden: true, type: 'txt', ellipsis: true },
  { dataIndex: 'warehouseAreaName', title: '库区名称', type: 'txt', ellipsis: true },
  { dataIndex: 'warehouseAreaCode', title: '库区编码', type: 'txt', ellipsis: true },
  { dataIndex: 'priority', title: '优先级', type: 'number', ellipsis: true, required: true },
  {
    dataIndex: 'packcode',
    ellipsis: true,
    // required: true,
    title: '包装方式',
    options: [
      { title: '固定', value: '01' },
      { title: '灵活', value: '02' }
    ],
    type: 'select'
  },
  {
    dataIndex: 'worktype',
    title: '作业类型',
    ellipsis: true,
    // required: true,
    ...remote('was_worktype'),
    type: 'select'
  },

  {
    title: '操作',
    key: 'operation',
    scopedSlots: { customRender: 'operation' },
    //   fixed: 'right',
    align: 'center'
  }
]
export const AddWorkingGroupTable = {
  items: [
    { type: 'input', name: 'warehouseAreaName', label: '库区名称', value: '' },
    { type: 'input', name: 'warehouseAreaCode', label: '库区编码', value: '' },
    {
      // span: 24,
      type: 'buttonGroup',
      style: { textAlign: 'right' },
      options: [
        {
          value: '查询',
          icon: 'search',
          btnType: 'primary',
          style: 'margin-right:10px',
          htmlType: 'submit'
        },
        {
          value: '重置',
          icon: 'redo',
          on: {
            click: (event, form) => {
              console.log(form)
              form.resetFields()
            }
          }
        }
      ]
    }
  ],
  columns: [
    { dataIndex: 'warehouseAreaId', title: 'ID', hidden: true, type: 'txt', ellipsis: true },
    { dataIndex: 'warehouseAreaName', title: '库区名称', type: 'txt', ellipsis: true },
    { dataIndex: 'warehouseAreaCode', title: '库区编码', type: 'txt', ellipsis: true },
    {
      ellipsis: true,
      dataIndex: 'warehouseAreaType',
      title: '库区类型',
      autoLoad: true,
      remoteUrl: { url: upcloud_base_common + '/dict/listbytype?dicttypeCodes=areatype', method: 'post' },
      replaceFields: {
        value: 'dictCode',
        // value: 'dictName',
        label: 'dictName'
      }
    }
  ]
}

export const EditTableDataremoteUrl = { url: upcloud_base_wh + '/baseWmsWarehouseArea/page2', method: 'get' }
