import API from '../../api/default'

const items = [
  {
    type: "row",
    label: "日期",
    name: "ff",
    span: 6,
    labelCol: {
      span: 4
    },
    wrapperCol: {
      span: 20
    },
    list: [
      {
        type: "date",
        name: "startTime",
        style: {paddingRight: "5px"},
        placeholder: "请输入开始日期",
        value: "",
      },
      {
        style: {paddingLeft: "5px"},
        type: "date",
        name: "endTime",
        placeholder: "请输入结束日期",
        format: "YYYY-MM-DD",
        value: "",
      },
    ],
  },
  {
    type: 'input',
    name: 'warehouseName1',
    label: '移库单号',
  },
  {
    type: 'search',
    name: 'dcName',
    label: '移库员',
    title: '移库员',
    destroyOnClose: true,
    targetClick: true,
    span: 6,
    toolBar: {
      items: [
        {
          type: 'input',
          name: 'dcName',
          label: '移库员名称',
          span: 8,
          value: ''
        }
      ]
    },
    tableConfig: {
      rowKey: 'dcName',
      rowSelectType: 1,
      hasRowSelectCheck: true,
      columns: [{dataIndex: 'dcName', title: '移库员名称', key: 'dcName'}]
    },
    value: '',
    remoteUrl: API.wmsdcPage,
    on: {
      ok(event, value, rowData, form) {
        console.log(rowData, 'rowDatarowData')
      }
    }
  },
  {
    type: 'select',
    name: 'platStatus',
    label: '移库来源',
    value: '移库来源',
    options: [
      {label: '移库开票', value: '移库开票'},
      {label: 'GSP来源', value: 'GSP来源'},
    ]
  },

]
const columns = function (self) {
  return [
    {
      dataIndex: 'itemCode',
      width: 140,
      title: '商品编码',
      type: 'search',
      disabled: true,
      targetValueKey: 'itemName',
      targetClick: true,
      destroyOnClose: true,
      tableConfig: {
        rowKey: 'itemId',
        remoteUrl: (res) => {
          return {
            ...API.whItems
          }
        },
        remoteBefore: (res) => {
          let ref = self.queryRefFromName('baseMtlItemUomConversionsList')
          let refMain = self.queryRefFromName('main')
          // console.log(self.getData())
          let formsVal = refMain.form.getFieldsValue()
          ref.changeRemoteParams(formsVal) // 修改请求参数searchmodal
        },
        columns: [
          {
            dataIndex: 'itemName',
            title: '商品名称',
            key: 'itemName'
          },
          {
            dataIndex: 'itemId',
            title: '商品id',
            key: 'itemId'
          },
          // {
          //   dataIndex: 'itemShortName',
          //   title: '商品简称',
          //   key:'itemShortName'
          // }
        ]
      },
      ok(event, value, rowData, form) {
        console.log(rowData, 'rowDatarowData')
        form.setFieldsValue({
          itemId: rowData[0].itemId,
        })
      },
      change(value, label, options, form) {
        if (!value) {
          form.setFieldsValue({itemId: ''})
        }
      }
    },
    {dataIndex: 'itemId', title: '商品Id', key: 'itemId', hidden: true},
    {dataIndex: 'itemCode1', title: '商品条码', key: 'itemCode1', disabled: true,},
    {dataIndex: 'itemName', title: '商品名称', key: 'itemName', disabled: true},

    {dataIndex: 'code4', title: '包装单位', key: 'code4', disabled: true},
    {dataIndex: 'specification', title: '商品规格', key: 'specification', disabled: true},
    {dataIndex: 'code6', title: '包装数', key: 'code6', disabled: true},
    {dataIndex: 'code7', title: '批号', key: 'code7', disabled: true},
    {dataIndex: 'code8', title: '显示货位', key: 'code8', disabled: true},
    {dataIndex: 'code9', title: '数量', key: 'code9', disabled: true},
    {dataIndex: 'code10', title: '件数', key: 'code10', disabled: true},
    {dataIndex: 'code11', title: '零散数', key: 'code11', disabled: true},
    {dataIndex: 'code12', title: '实际数量', key: 'code12', disabled: true},
    {dataIndex: 'code13', title: '实际件数', key: 'code13', disabled: true},
    {dataIndex: 'code14', title: '实际零散数', key: 'code14', disabled: true},
    {dataIndex: 'code15', title: '移入货位', key: 'code15', disabled: true},
    {dataIndex: 'code16', title: '生产厂家', key: 'code16', disabled: true},
    {dataIndex: 'code17', title: '生产日期', key: 'code17', disabled: true},
    {dataIndex: 'code18', title: '有效期至', key: 'code18', disabled: true},
    {dataIndex: 'code19', title: '单据编号', key: 'code19', disabled: true},
    {dataIndex: 'code20', title: '货主编号', key: 'code20', disabled: true},
    {dataIndex: 'code21', title: '货主名称', key: 'code21', disabled: true},
    {dataIndex: 'code22', title: 'GSP单号', key: 'code22', disabled: true},
    {dataIndex: 'code23', title: 'GSP移库类型', key: 'code23', disabled: true},
  ]
}

const operateFormItems = [
  {
    "type": "input", "name": "itemHealthType", "label": "制单人", "value": "",
    labelCol: {span: 8}, span: 6
  },
  {
    "type": "input", "name": "itemHealthUsage", "label": "修改人", "value": "",
    labelCol: {span: 8}, span: 6
  },
  {
    "type": "input", "name": "itemHealthApprovalNbr", "label": "制单日期", "value": "",
    labelCol: {span: 8}, span: 6
  },
  {
    "type": "input", "name": "itemHealthIndustry", "label": "修改时期", "value": "",
    labelCol: {span: 8}, span: 6
  },
  {
    "type": "input", "name": "itemHealthCommonName", "label": "单据状态", "value": "",
    labelCol: {span: 8}, span: 6
  },
  {
    "type": "input", "name": "itemHealthBuyer", "label": "上传状态", "value": "",
    labelCol: {span: 8}, span: 6
  },
  {
    "type": "input", "name": "itemHealthRegisterNbr", "label": "作业状态", "value": "",
    labelCol: {span: 8}, span: 6
  },
];

export function detailConfig(self) {
  return [
    {
      key: 'one', checkedKey: 'main',
      btns: [
        {
          label: '查询', click() {
          }
        },
        {
          label: '重置', click() {
            let refMain = self.queryRefFromName('main')
            let ref = self.queryRefFromName('baseMtlItemUomConversionsList')
            refMain.form.enableItem(['warehouseName', 'cargoOwnerName'])
            ref.delItems() // 删除附表信息
          }
        },
        {
          label: '打印', click() {

          }
        },
      ],
      list: [
        {
          key: 'main',
          tab: '主要信息',
          btns: [
            // { label: '辅助功能1', click() { } },
          ],
          item: {type: 'p-grid-form', config: items}
        },
        {
          key: 'baseMtlItemHealth',
          tab: '操作信息',
          item: {type: 'p-grid-form', config: operateFormItems}
        },
      ]
    },
    {
      key: 'two', checkedKey: 'baseMtlItemUomConversionsList',
      list: [
        {
          key: 'baseMtlItemUomConversionsList',
          tab: '明细',
          btns: [],
          item: {
            type: 'p-table-edit',
            config: columns(self),
            rowKey: '_row_count',
            rowSelectType: 2,
            colChange({record, name, value}) {
            }
          }
        },
      ]
    },
  ];
}
