import {getConsignorItems, getBranchItems} from "./formItems";

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

// 主界面查询表单
export function items(self) {
  return [
    {
      type: 'select', name: 'type', label: '查询维度', required: true, value: '',
      options: [
        {label: '托盘', value: '1'},
        {label: '监管码', value: '2'},
      ],
      on: {
        change(value, label) {
          self.masterColumns = self.masterColumns.map(_ => {
            return _.dataIndex === 'supervisionCode' && value === '2' ? {..._, hidden: true} : {..._, hidden: false}
          })
        }
      },
      ...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: 'input', name: 'contanerCode', label: '托盘', value: '', ...grid},
    {type: 'input', name: 'supervisionCode', label: '监管码', value: '', ...grid},
    {
      type: 'buttonGroup',
      wrapperCol: {span: 16, offset: 8},
      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 masterColumns = [
  {title: '仓配中心', dataIndex: 'dcCode', width: 120},
  {title: '仓库', dataIndex: 'warehouseName', width: 120},
  {title: '货主', dataIndex: 'cargoOwnerName', width: 120},
  {title: '下传批次号', dataIndex: 'downloadBatchNumber', width: 120},
  {title: '托盘号', dataIndex: 'contanerCode', width: 120},
  {title: '监管码', dataIndex: 'supervisionCode', width: 120, hidden: false}, // 监管码
  {title: '商品id', dataIndex: 'itemId', width: 120},
  {title: '商品编号', dataIndex: 'itemCode', width: 120},
  {title: '数量', dataIndex: 'pieceQty', width: 120},
  {title: '状态', dataIndex: 'statusName', width: 120},
  {title: '批号', dataIndex: 'manufacturerLotNum', width: 120},
  {title: '生产日期', dataIndex: 'productionDate', width: 120},
  {
    dataIndex: 'operation',
    key: 'operation',
    title: '操作',
    width: 120,
    align: 'center',
    fixed: 'right',
    scopedSlots: {customRender: 'action'}
  }
]