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

var params = null;

export function detailConfig(self) {
  return [
    {
      key: 'one',
      checkedKey: 'main',
      height: 'auto',
      btns: [
        {
          label: '打印',
          click() {
            self.print();
          }
        },
      ],
      list: [
        {
          key: 'main',
          tab: '主要信息',
          item: {
            type: 'p-search-table',
            autoLoad: false,
            rowSelectType: 1,
            rowKey: 'rcvHeaderId',
            config: basicData(self),
            remoteUrl: baseUrl + '/rcvInstockLines/extractRcvH',
            remoteParams: params,
            operators: [],
            doneBefore(response) {
              response.data.list = response.data.list.map(item => {
                return {
                  ...item,
                  ...item.rcvHeadersDTO,
                  ...item.rcvHeadersProfilesDTO
                }
              })
              return response
            },
            selectChange(selectedRowKeys, selectedRows) {
              let ref = self.queryRefFromName('list');
              self.selectedMainItem = selectedRows[0];
              if (selectedRows.length < 1) {
                ref.data = []
                return
              }
              self.handleQuerySubList({ rcvHeaderId: selectedRowKeys[0] }).then(res => {
                res.forEach((t) => {
                  t.warehouseLocatorName = t.whLocatorName
                  t.realWhLocatorId = t.whLocatorId
                  t.realWhLocatorCode = t.whLocatorCode
                });
                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),
            colChange({ record, name, value }) { },
            onClick(selectedRowKeys, selectedRows, data) {},
          }
        }
      ]
    }
  ]
}
