// 主界面查询表单
import {getBranchItems, getConsignorItems} from "./formItems";

const grid = {
  labelCol: {span: 8}, wrapperCol: {span: 16}, span: 6,
}

export function items(self) {
  return [
    {
      type: 'select', name: 'businessType', label: '业务类型', value: '0', allowClear: false,
      options: [
        {label: '入库', value: '0'},
        {label: '解锁', value: '1'},
      ],
      on: {
        change(value, label) {
          self.$nextTick(() => {
            self.setTableColumns()
          })
        }
      },
      ...grid
    },
    // 仓库
    ...getBranchItems((event, targetName, selectRecords, form) => {
      const selectRecord = selectRecords[0] || {}
      const {companyCode = '', companyName = '', companyId = ''} = selectRecord
      form.setFieldsValue({warehouseCode: companyCode, warehouseName: companyName, warehouseId: companyId})
    }),
    // 货主
    ...getConsignorItems((event, targetName, selectRecords, form) => {
      const selectRecord = selectRecords[0] || {}
      const {companyCode = '', companyName = '', companyId = ''} = selectRecord
      form.setFieldsValue({cargoOwnerCode: companyCode, cargoOwnerName: companyName, cargoOwnerId: companyId})
    }),
    {type: 'input', name: 'itemCode', label: '商品编码', value: '', ...grid},
    {type: 'input', name: 'manufacturerLotNum', label: '批号', value: '', ...grid},
    {
      type: 'select', name: 'stockStatus', label: '库存状态', value: '',
      options: [
        {label: '合格', value: '1'},
        {label: '不合格', value: '2'},
        {label: '退货', value: '3'},
        {label: '待检验', value: '4'},
      ],
      on: {
        change(value, label) {
        }
      },
      ...grid
    },
    {
      type: 'select', name: 'status', label: '状态', value: '',
      options: [
        {label: '待判定', value: '1'},
        {label: '已判定', value: '0'},
      ],
      on: {
        change(value, label) {
        }
      },
      ...grid
    },
    {type: 'input', name: 'contanerCode', label: '货位', value: '', ...grid},
    {
      type: 'buttonGroup',
      span: 24,
      wrapperCol: {span: 16, offset: 8},
      style: 'text-align: right;',
      options: [
        {
          value: '查询',
          icon: 'search',
          btnType: 'primary',
          style: 'margin-left:10px',
          htmlType: 'submit'
        },
        {
          value: '重置',
          icon: 'redo',
          style: 'margin-left:10px',
          on: {
            click: () => {
              self.$refs.formTarget.form.resetFields()
            }
          }
        }
      ]
    }
  ]
}

// 主界面列配置
// 入库
export const tableColumns0 = [
  {title: '质检记录号', dataIndex: 'rqcPassCode'},
  {title: '仓库名称', dataIndex: 'warehouseName'},
  {title: '货主名称', dataIndex: 'cargoOwnerName'},
  {title: '商品编码', dataIndex: 'itemCode'},
  {title: '商品名称', dataIndex: 'itemName'},
  {title: '批号', dataIndex: 'manufacturerLotNum'},
  {title: '库存状态', dataIndex: 'stockStatusName'},
  {title: '状态', dataIndex: 'statusName'},
  {title: '业务类型', dataIndex: 'businessTypeName'},
  {
    title: '上游系统下传', dataIndex: 'isDownload',
    customRender(text) {
      if (text === '0') return '否'
      if (text === '1') return '是'
      return text
    }
  },
  {
    title: '放行单上传情况', dataIndex: 'isUploadPass',
    customRender(text) {
      if (text === '0') return '否'
      if (text === '1') return '是'
      return text
    }
  },
  {
    title: '质检报告单上传情况', dataIndex: 'isUploadQc',
    customRender(text) {
      if (text === '0') return '否'
      if (text === '1') return '是'
      return text
    }
  },
  {title: '创建人', dataIndex: 'creatorName'},
  {title: '创建时间', dataIndex: 'gmtCreate'},
  {title: '最后更新人', dataIndex: 'modifierName'},
  {title: '最后更新时间', dataIndex: 'gmtModified'},
  {
    title: '操作', key: 'operate', align: 'center', fixed: 'right', width: 100,
    scopedSlots: {customRender: 'action'},
  },
]
// 解锁
export const tableColumns1 = [
  {title: '质检记录号', dataIndex: 'rqcPassCode'},
  {title: '仓库名称', dataIndex: 'warehouseName'},
  {title: '货主名称', dataIndex: 'cargoOwnerName'},
  {title: '商品编码', dataIndex: 'itemCode'},
  {title: '商品名称', dataIndex: 'itemName'},
  {title: '批号', dataIndex: 'manufacturerLotNum'},
  {title: '货位', dataIndex: 'locatorCode'},
  {title: '数量', dataIndex: 'pieceQty'},
  {title: '库存状态', dataIndex: 'stockStatusName'},
  {title: '状态', dataIndex: 'statusName'},
  {title: '业务类型', dataIndex: 'businessTypeName'},
  {
    title: '上游系统下传', dataIndex: 'isDownload',
    customRender(text) {
      if (text === '0') return '否'
      if (text === '1') return '是'
      return text
    }
  },
  {
    title: '放行单上传情况', dataIndex: 'isUploadPass',
    customRender(text) {
      if (text === '0') return '否'
      if (text === '1') return '是'
      return text
    }
  },
  {
    title: '质检报告单上传情况', dataIndex: 'isUploadQc',
    customRender(text) {
      if (text === '0') return '否'
      if (text === '1') return '是'
      return text
    }
  },
  {title: '创建人', dataIndex: 'creatorName'},
  {title: '创建时间', dataIndex: 'gmtCreate'},
  {title: '最后更新人', dataIndex: 'modifierName'},
  {title: '最后更新时间', dataIndex: 'gmtModified'},
  {
    title: '操作', key: 'operate', align: 'center', fixed: 'right', width: 100,
    scopedSlots: {customRender: 'action'},
  },
]