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

const items = [

    {
      type: 'input',
      name: 'fildName',
      label: '单据编号',
      disabled: true,
    },
    {
      type: 'input',
      name: 'fildName1',
      label: '单据日期',
        disabled: true,
    },
    {
      type: 'input',
      name: 'fildName2',
      disabled: true,
      label: '移库来源'
    },
    {
      type: 'input',
      name: 'fildName3',
      disabled: true,
      label: '业主编号'
    },
    {
      type: 'input',
      name: 'fildName4',
      disabled: true,
      label: '业主名称'
    },
    {
      type: 'input',
      name: 'fildName5',
      disabled: true,
      label: '移库员'
    }
  ]
const columns = function (self) {
  return [
    {
      dataIndex: 'itemCode',
      width: 140,
      title: '商品编码',
      type: 'search',
      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,
          })
        },
      required: true
    },
    { dataIndex: 'itemId', title: '商品Id', key: 'itemId', hidden: true  },
    { dataIndex: 'itemName', title: '商品名称', key: 'itemName' },
    { dataIndex: 'specification', title: '商品规格', key: 'specification' },
    { dataIndex: 'fildName1', title: '包装单位', key: 'fildName1' },
    { dataIndex: 'fildName2', title: '包装数量', key: 'fildName2' },
    { dataIndex: 'fildName3', title: '批次号', key: 'fildName3' },

    { dataIndex: 'code4', title: '移出货位ID', key: 'code4', hidden: true },
    {
      dataIndex: 'batchNum',
      width: 140,
      title: '移出货位',
      type: 'search',
      destroyOnClose:true,
      remoteUrl: API.locatorStocks,
      targetValueKey: 'name',
      targetClick: true,
      required: true,
      tableConfig: {
        columns: [
          {
            dataIndex: 'batchNum',
            title: '批次号',
            key: 'batchNum'
          },
          {
            dataIndex: 'batchId',
            title: '批次ID',
            key: 'batchId'
          },
          {
            dataIndex: 'lockReason',
            title: '锁库存原因',
            key: 'lockReason'
          },
        ],
        remoteBefore: (res) => {
          console.log(res,'resresres')
          let ref = self.queryRefFromName('baseMtlItemUomConversionsList')
          console.log(ref)
          let formsVal = ref.getListData()
          console.log(formsVal, 'formsValformsValformsVal')
          ref.changeRemoteParams(formsVal[0]) // 修改请求参数searchmodal
        }
      },
      ok: function () {
        console.log('ok', arguments)
      },
      on: {
        search(val, val1, val2) {
          console.log(val, val1, val2,'val, val1, val2val, val1, val2val, val1, val2')
          
        }
      }
    },
    { dataIndex: 'code2', title: '移出库别', key: 'code2' },
    { dataIndex: 'fildName4', title: '实际数量', key: 'fildName4' },
    { dataIndex: 'fildName5', title: '实际件数', key: 'fildName5' },
    { dataIndex: 'fildName6', title: '实际零散数', key: 'fildName6' },
    
    {
      dataIndex: 'warehouseLocatorCode',
      width: 140,
      title: '计划移入货位',
      type: 'search',
      remoteUrl: API.locatorWHPage,
      targetClick: true,
      targetValueKey: 'warehouseLocatorCode',
      toolBar: {
        items: [
          {
            type: 'input',
            name: 'warehouseLocatorName',
            label: '货位名称',
            span: 6,
            value: ''
          },
          {
            type: 'input',
            name: 'warehouseLocatorCode',
            label: '货位编码',
            span: 6,
            value: ''
          },
          {
            type: 'input',
            name: 'warehouseName',
            label: '仓库名称',
            span: 6,
            value: ''
          }
        ]
      },
      tableConfig: {
        rowKey: 'warehouseLocatorId',
        rowSelectType: 1,
        hasRowSelectCheck: true,
        columns: [
          { dataIndex: 'warehouseLocatorName', title: '货位名称', key: 'warehouseLocatorName' },
          { dataIndex: 'warehouseLocatorCode', title: '货位编码', key: 'warehouseLocatorCode' },
          { dataIndex: 'warehouseLocatorId', title: '货位ID', key: 'warehouseLocatorId' }
        ]
      },
      ok(event, value, rowData, form) {
        form.setFieldsValue({
            warehouseAreaCategory: rowData[0].warehouseAreaCategory,
            warehouseLocatorId: rowData[0].warehouseLocatorId,
        })
      },
      required: true
    },
    { dataIndex: 'warehouseAreaCategory', title: '移入库别', key: 'warehouseAreaCategory' },
    { dataIndex: 'warehouseLocatorId', title: '移入货位ID', key: 'warehouseLocatorId',hidden:true },
    { dataIndex: 'code8', title: '计划数量', key: 'code8', type: 'edit', required: true },
    { dataIndex: 'code9', title: '计划件数', key: 'code9', type: 'edit', required: true },
    { dataIndex: 'code10', title: '计划零散数', key: 'code10', type: 'edit', required: true },
    { dataIndex: 'code11', title: '移库原因', key: 'code11', },
    { dataIndex: 'code12', title: '生产厂家', key: 'code12', type: 'edit' },
    { dataIndex: 'code13', title: 'GSP单号', key: 'code13', type: 'edit' },
    { dataIndex: 'code14', title: 'GSP移库类型', key: 'code14', type: 'edit' },
  ]
}

// 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() {
          }
        },
      ],
      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: [
            {
              label: '新增', click() {
                let ref = self.queryRefFromName('baseMtlItemUomConversionsList')
                // console.log(self.getData())
                ref.addItem() // 新增
                // self.formsVal = formsVal  disabled
            } },
            {
              label: '删除', click() {
                self.$confirm({
                  content: self.$lang('确定删除?'),
                  onOk: () => {
                    let ref = self.queryRefFromName('baseMtlItemUomConversionsList')
                    ref.delSelectedItems()
                  }
                })
            } },
          ],
          item: {
            type: 'p-table-edit',
            config: columns(self),
            rowKey: '_row_count',
            rowSelectType: 2,
            colChange({ record, name, value }) {
            }
          }
        },
      ]
    },
  ];
}
