let grid = {
  labelCol: { span: 9 },
  wrapperCol: { span: 15 },
  span: 12,
  // 高度
  itemHeight: '50px',
}
var t

import { checkStation, getInboundTasks, getOneInboundTask } from '../api'
import { REGEX_letter } from '@/views/util'

export function formItems(self) {
  return [
    { hidden: true, type: 'input', name: 'taskId', label: 'taskId', value: '' },
    { hidden: true, type: 'input', name: 'packSize', label: 'packSize', value: '' },
    { hidden: true, type: 'input', name: 'planes', label: 'planes', value: '' },
    { hidden: true, type: 'input', name: 'actualAllocation', label: 'actualAllocation', value: '' },
    { hidden: true, type: 'input', name: 'tuiJian', label: 'tuiJian', value: '' },
    { hidden: true, type: 'input', name: 'goodsShelves', label: 'goodsShelves', value: '' },
    { hidden: true, type: 'input', name: 'goodsId', label: 'goodsId', value: '' },
    { hidden: true, type: 'input', name: 'bizPropertyId', label: 'bizPropertyId', value: '' },
    // { hidden: true, type: 'input', name: 'palletNo', label: 'palletNo', value: '', },
    { hidden: true, type: 'input', name: 'abcType', label: 'abcType', value: '' },
    { hidden: true, type: 'input', name: 'locationType', label: 'locationType', value: '' },
    { hidden: true, type: 'input', name: 'itemId', label: 'itemId', value: '' },
    { hidden: true, type: 'input', name: 'goodsId', label: 'goodsId', value: '' },
    { hidden: true, type: 'input', name: 'lotId', label: 'lotId', value: '' },
    { hidden: true, type: 'input', name: 'packId', label: 'packId', value: '' },
    // packId

    { hidden: true, type: 'input', name: 'oldLocationType', label: 'oldLocationType', value: '' },
    { hidden: true, type: 'input', name: 'newLocationType', label: 'newLocationType', value: '' },
    { hidden: true, type: 'input', name: 'ownerId', label: 'ownerId', value: '' },

    { hidden: true, type: 'input', name: 'itemHealthCategory', label: 'itemHealthCategory', value: '' },
    { hidden: true, type: 'input', name: 'singleVolume', label: 'singleVolume', value: '' },
    {
      type: 'input',
      className: 'input-md-red',
      size: 'large',
      required: true,
      name: 'stationNo',
      label: '工作站',
      ...grid,
      value: '',
      on: {
        pressEnter() {
          self.stationNoEnter()
        },
      },
    },
    {
      type: 'input',
      className: 'input-md-red',
      size: 'large',
      name: 'containerNo',
      required: true,
      label: '扫描容器',
      ...grid,
      value: '',
      on: {
        pressEnter() {
          const params = self.$refs.itemForm.form.getFieldsValue()
          self.containerNoEnter()
        },
      },
    },
    {
      type: 'input',
      className: 'input-md-red',
      size: 'large',
      name: 'itemCode',
      required: true,
      label: '商品编码',
      ...grid,
      value: '',
      on: {
        pressEnter() {
          const params = self.$refs.itemForm.form.getFieldsValue()
          self.barCodeEnter()
        },
      },
    },
    // { type: 'input', className: 'input-md', size: 'large', name: 'goodsOwnId', label: '货品编码', ...grid, value: '', },
    {
      type: 'input',
      className: 'input-md',
      size: 'large',
      name: 'pieceBarcode',
      label: '商品条码',
      ...grid,
      value: '',
    },
    {
      type: 'input',
      className: 'input-md',
      size: 'large',
      name: 'itemName',
      label: '商品名称',
      ...{ labelCol: { span: 6 }, wrapperCol: { span: 18 }, span: 24, itemHeight: '50px' },
      value: '',
    },
    {
      type: 'input',
      className: 'input-md',
      size: 'large',
      name: 'manufacturerId',
      label: '生产厂家',
      ...{ labelCol: { span: 6 }, wrapperCol: { span: 18 }, span: 24, itemHeight: '50px' },
      value: '',
    },
    // { type: 'input', className: 'input-md', size: 'large', name: 'itemHealthApprovalNbr', label: '国药准字', ...grid, value: '', },
    { type: 'input', className: 'input-md', size: 'large', name: 'cargoOwnerName', label: '货主', ...grid, value: '' },
    // { type: 'input', className: 'input-md', size: 'large', name: 'taskId', label: '单据编号', ...grid, value: '', },
    { type: 'input', className: 'input-md', size: 'large', name: 'specification', label: '规格', ...grid, value: '' },
    {
      type: 'input',
      className: 'input-md',
      size: 'large',
      name: 'manufacturerLotNum',
      label: '批号',
      ...grid,
      value: '',
    },
    {
      type: 'input',
      className: 'input-md',
      size: 'large',
      name: 'itemHealthCategoryName',
      label: '商品大类',
      ...grid,
      value: '',
    },
    {
      type: 'input',
      className: 'input-md',
      size: 'large',
      name: 'qty',
      label: '数量',
      ...grid,
      value: '',
      size: 'large',
    },
    {
      type: 'input',
      className: 'input-md',
      size: 'large',
      name: 'palletLocation',
      label: '货位编码',
      ...grid,
      value: '',
    },
    { hidden: true, type: 'input', name: 'goodsBigType', label: 'goodsBigType', ...grid, value: '' },
    {
      type: 'number',
      name: 'inQty',
      className: 'input-md-red',
      size: 'large',
      label: '上架数量',
      ...grid,
      required: true,
      value: '',
      size: 'large',
      min: 0,
      disabled: false,
      on: {
        change(p1, p2) {
          const params = self.$refs.itemForm.form.getFieldsValue()
          // .$refs.easyTable.columns
          // const a = self.$refs.itemForm.form
          // console.log(a,'aaaaaa');
          if (p1 > params.qty) {
            self.$message.error(self.$lang('上架数量不能大于数量'))
          }
        },
      },
    },
    { type: 'input', className: 'input-md', size: 'large', name: 'palletNo', label: '货架号', ...grid, value: '' },
    {
      type: 'input',
      className: 'input-md',
      size: 'large',
      name: 'batchProductionDateShow',
      label: '生产日期',
      ...grid,
      value: '',
    },
    {
      type: 'input',
      className: 'input-md',
      size: 'large',
      name: 'batchExpiredDateShow',
      label: '有效期至',
      ...grid,
      value: '',
    },
  ]
}

export const tableColumns = [
  { hidden: true, title: 'id', dataIndex: 'id' },
  { title: '货位号', dataIndex: 'palletLocation' },
  { title: '位面', dataIndex: 'planes' },
  { title: '货主', dataIndex: 'cargoOwnerName' },
  { title: '商品条码', dataIndex: 'itemCode' },
  { title: '商品名称', dataIndex: 'itemName' },
  { title: '批次号', dataIndex: 'manufacturerLotNum' },
  { title: '现存数量', dataIndex: 'qty' },
  // { title: '剩余容积', dataIndex: 'surplusSize', },
  // { title: '商品大类', dataIndex: 'itemHealthCategoryName', },
  // { title: '商品状态', dataIndex: 'goodsStatus', },
  // { title: '剩余数量', dataIndex: 'storeQty', },
  // { title: 'ABC属性', dataIndex: 'abcType', },
]

export const containerColumns = [
  { hidden: true, title: 'taskId', dataIndex: 'taskId' },
  { dataIndex: 'cargoOwnerName', title: '货主', key: 'cargoOwnerName' },
  { dataIndex: 'itemName', title: '商品名称', key: 'itemName' },
  { dataIndex: 'itemCode', title: '商品编码', key: 'itemCode' },
  { dataIndex: 'pieceBarcode', title: '商品条码', key: 'pieceBarcode' },
  { dataIndex: 'itemHealthCategoryName', title: '商品大类', key: 'itemHealthCategoryName' },
  { dataIndex: 'manufacturerLotNum', title: '批号', key: 'manufacturerLotNum' },
  { dataIndex: 'qty', title: '数量', key: 'qty' },

  { dataIndex: 'specification', title: '规格', key: 'specification' },
  // { dataIndex: "goodsStatus", title: "商品状态", key: "goodsStatus" },
  // { dataIndex: "opIdStr", title: "业务类型", key: "opIdStr" },
  { dataIndex: 'containerNo', title: '容器编号', key: 'containerNo' },
  // { dataIndex: "orderNo", title: "单据编号", key: "orderNo" },
  // { dataIndex: "stateDescription", title: "商品大类", key: "stateDescription" },
  // { dataIndex: "serialNo", title: "单据编码", key: "serialNo",width: 250 },
]

export function palletNoItems(self) {
  return [
    // { type: 'input', name: 'palletNo', label: '货架编码', value: '', },
    { type: 'input', name: 'palletLocation', label: '货位号', value: '' },
    {
      type: 'buttonGroup',
      style: { textAlign: 'left' },
      options: [
        {
          value: '查询',
          icon: 'search',
          btnType: 'primary',
          style: 'margin-left:10px',
          htmlType: 'submit',
        },
        // {
        //   value: '自动分配',
        //   // icon: 'redo',
        //   btnType: "primary",
        //   style: 'margin-left:10px',
        //   on: {
        //     click: () => {
        //       self.automatic()
        //     }
        //   }
        // },
        // {
        //   value: '调整确认',
        //   // icon: 'redo',
        //   btnType: "primary",
        //   style: 'margin-left:10px',
        //   on: {
        //     click: () => {
        //       self.adjustment()
        //       // self.$refs.formTarget.form.resetFields()
        //     }
        //   }
        // },
        {
          value: '取消',
          icon: 'redo',
          style: 'margin-left:10px',
          on: {
            click: () => {
              self.visibleAllocation = false
            },
          },
        },
      ],
    },
  ]
}

export function allocationItems(self) {
  return [
    // { hidden: true, type: 'input', name: 'shelveLocation', label: 'shelveLocation', value: '', },
    { type: 'input', name: 'palletNo', label: '货架编码', value: '' },
    { type: 'input', name: 'palletLocation', label: '货位号', value: '' },
    {
      type: 'buttonGroup',
      style: { textAlign: 'left' },
      options: [
        {
          value: '查询',
          icon: 'search',
          btnType: 'primary',
          style: 'margin-left:10px',
          htmlType: 'submit',
        },
        // {
        //   value: '自动分配',
        //   // icon: 'redo',
        //   btnType: "primary",
        //   style: 'margin-left:10px',
        //   on: {
        //     click: () => {
        //       self.automatic()
        //     }
        //   }
        // },
        {
          value: '调整确认',
          // icon: 'redo',
          btnType: 'primary',
          style: 'margin-left:10px',
          on: {
            click: () => {
              self.adjustment()
              // self.$refs.formTarget.form.resetFields()
            },
          },
        },
        {
          value: '取消',
          icon: 'redo',
          style: 'margin-left:10px',
          on: {
            click: () => {
              self.visibleAllocation = false
            },
          },
        },
      ],
    },
  ]
}
export function goodsItems(self) {
  return [
    // { hidden: true, type: 'input', name: 'shelveLocation', label: 'shelveLocation', value: '', },
    { type: 'input', name: 'pieceBarcode', label: '商品条码', value: '' },
    { type: 'input', name: 'itemName', label: '商品名称', value: '' },
    { type: 'input', name: 'manufacturerLotNum', label: '批号', value: '' },
    {
      type: 'buttonGroup',
      style: { textAlign: 'left' },
      options: [
        {
          value: '查询',
          icon: 'search',
          btnType: 'primary',
          style: 'margin-left:10px',
          htmlType: 'submit',
        },
        {
          value: '重置',
          icon: 'redo',
          style: 'margin-left:10px',
          on: {
            click: () => {
              self.$refs.goodsItems.form.resetFields()
            },
          },
        },
      ],
    },
  ]
}
export const allocationColumns = [
  { hidden: true, title: 'shelveLocation', dataIndex: 'shelveLocation' },
  // { dataIndex: "goodsShelveNo", title: "货架编号", key: "goodsShelveNo" },
  // { dataIndex: "shelveLocation", title: "货位编码", key: "shelveLocation" },
  // { dataIndex: "shelfPlane", title: "位面", key: "goodsName" },
  // { dataIndex: "goodsBarcode", title: "现存商品编码", key: "goodsBarcode" },
  // { dataIndex: "lotId", title: "现存商品批号", key: "lotId" },
  // { dataIndex: "goodsOwnerName", title: "货主", key: "goodsOwnerName" },
  // { dataIndex: "qty", title: "现存数量", key: "containerNo" },
  { hidden: true, title: 'id', dataIndex: 'id' },
  { title: '货位号', dataIndex: 'palletLocation' },
  { title: '位面', dataIndex: 'planes' },
  { title: '货主', dataIndex: 'cargoOwnerName' },
  { title: '商品条码', dataIndex: 'itemCode' },
  { title: '商品名称', dataIndex: 'itemName' },
  { title: '批次号', dataIndex: 'manufacturerLotNum' },
  { title: '现存数量', dataIndex: 'qty' },
]

export function taskSchedulingFun(api, params, time) {
  let timeFun = null
  console.log('执行函数')
  var counter = 0
  return function (status, taskFun, params, type) {
    // return new Promise((resolve, reject) => {
    function timing() {
      timeFun = setInterval(() => {
        console.log('执行任务')
        taskFun(params, type)
      }, time)
    }
    counter++
    console.log(counter)
    if (status == 'start') {
      if (!timeFun) {
        console.log('开始任务')
        timing()
      }
    } else if (status == 'end') {
      console.log('结束任务')
      console.log(timeFun)
      if (timeFun) {
        clearInterval(timeFun)
        timeFun = null
        console.log('结束任务')
      }
    }
    // })
  }
}

export function taskSchedulingFun111(api, params, time) {
  let timeFun = null
  console.log('执行函数')
  var counter = 0
  return function (status, taskFun, params, type) {
    // return new Promise((resolve, reject) => {
    function timing() {
      getOneInboundTask
    }
    if (status == 'start') {
      if (!timeFun) {
        console.log('开始任务')
        timing()
      }
    } else if (status == 'end') {
      console.log('结束任务')
      console.log(timeFun)
      if (timeFun) {
        clearInterval(timeFun)
        timeFun = null
        console.log('结束任务')
      }
    }
    // })
  }
}
