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

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

// 主界面查询表单
export function items(self) {
  return [
    // 仓库
    ...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: 'batchNum', label: '商品批号', value: '', ...grid},
    {type: 'input', name: 'itemCode', label: '商品编码', value: '', ...grid},
    {type: 'input', name: 'itemAssistantCode', 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()
            }
          }
        }
      ]
    }
  ]
}
