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

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

// 回盘任务查询-表格列配置
export const columns = [
  {dataIndex: 'warehouseName', title: '仓库名称', width: 100},
  {dataIndex: 'ownerName', title: '货主名称', width: 100},
  {dataIndex: 'containerNo', title: '托盘号', width: 100},
  {dataIndex: 'itemCode', title: '商品编码', width: 100},
  {dataIndex: 'itemName', title: '商品名称', width: 100},
  {dataIndex: 'qty', title: '数量', width: 100},
  {
    dataIndex: 'status', title: '状态', width: 100,
    customRender(text) {
      text = String(text)
      if (text === '0') return '未回盘'
      if (text === '1') return '已回盘'
      return text
    }
  },
  {dataIndex: 'gmtCreate', title: '日期', width: 100},
  {dataIndex: 'packQty', title: '规格', width: 100},
]
// 回盘任务查询-表格查询条件
export const items = self => {
  return [
    // 仓库
    ...getBranchItems(),
    // 货主
    ...getConsignorItems(),
    {
      type: "date",
      name: "startDate",
      label: "开始日期",
      placeholder: "请输入开始日期",
      value: "",
      format: "YYYY-MM-DD",
      ...grid
    },
    {
      type: "date",
      name: "endDate",
      label: "结束日期",
      placeholder: "请输入开始日期",
      value: "",
      format: "YYYY-MM-DD",
      ...grid
    },
    // 商品
    ...getItemItems(
      () => {
      },
      (res, params) => {
        const values = self.$refs.formTarget.form.getFieldsValue()
        params.data.warehouseId = values.branchid;
        params.data.cargoOwnerId = values.consignorid;
        return params
      },
      () => {
        const values = self.$refs.formTarget.form.getFieldsValue()
        if (!values.branchid) {
          self.$message.warning('请先选择仓库')
          return false
        }
        if (!values.consignorid) {
          self.$message.warning('请先选择货主')
          return false
        }
        return true
      }
    ),
    {type: 'input', name: 'itemCode4', label: '托盘号', value: '', ...grid},
    {type: 'select', name: 'itemCode1', label: '状态', value: '', ...grid},
    {type: 'input', name: 'itemCode2', label: '商品编码', value: '', ...grid},
    {type: 'input', name: 'itemCode3', label: '商品助记码', value: '', ...grid},
    {
      type: 'buttonGroup',
      style: {textAlign: 'center'},
      ...grid,
      options: [
        {value: '查询', icon: 'search', btnType: 'primary', style: 'margin-right:16px', htmlType: 'submit'},
        {
          value: "重置", name: "ccz", icon: "redo", style: 'margin-right:16px',
          on: {
            click(event, form) {
              form.resetFields();
            },
          },
        },
      ]
    }
  ]
}