import { basicData } from './basic-data'
import { extendFormItems } from './extend'
import { baseUrl } from "../../../../config/baseUrl";

export function detailConfig(self) {
  return [
    {
      key: 'one',
      checkedKey: 'main',
      height: 'auto',
      btns: [
        {
          label: '上架确认',
          click() {
            self.toShelf();
          }
        },
      ],
      list: [
        {
          key: 'main',
          tab: '主要信息',
          item: {
            type: 'p-search-table',
            autoLoad: false,
            rowSelectType: 1,
            rowKey: 'id',
            config: basicData(self),
            remoteUrl: baseUrl + '/rcvInstockLines/getInstockTaskArea',
            remoteParams: {},
            operators: [],
            doneBefore(response) {
              response.data = response.data.map(t => { var ee = Object.entries(t)[0]; return { id: Math.floor(Math.random() * 100000), bldgName: ee[0], whAreaCode: ee[1] } })
              return response
            },
            selectChange(selectedRowKeys, selectedRows) {
              let ref = self.queryRefFromName('list');
              let mainRef = self.queryRefFromName('main')
              let params = mainRef.$refs.form.form.getFieldsValue()
              params. bldgName = selectedRows[0].bldgName,
              params. whAreaCode = selectedRows[0].whAreaCode,
              params.status = 1,
              self.selectedMainItem = selectedRows[0];
              self.handleQuerySubList(params).then(res => {
                res.forEach((t) => {
                  t.warehouseLocatorName = t.whLocatorName
                  t.realWhLocatorId = t.whLocatorId
                  t.realWhLocatorCode = t.whLocatorCode
                  t.realWhLocatorName = t.warehouseLocatorName
                });
                ref.data = res;
              });
            },
          }
        }
      ]
    },
    {
      key: 'two',
      checkedKey: 'list',
      list: [
        {
          key: 'list',
          tab: '商品明细',
          btns: [
            { label: '差异', click() { self.toErrorBill(); } },
          ],
          item: {
            type: 'p-table-edit',
            rowSelectType: 2,
            rowKey: 'taskId',
            config: extendFormItems(self),
            operations: [
              { title: '拆分', click(record) { self.showSplitBill(record); } }
            ],
            colChange({ record, name, value }) { },
            onClick(selectedRowKeys, selectedRows, data) {

            },
          }
        }
      ]
    }
  ]
}
