import { basicData } from './basic-data'
import { extendFormItems, extendFormItems2 } from './extend'
import { baseUrl } from '../../../../config/baseUrl'
import {
  addItems,
  querySubList,
  querySubList2,
  querySubList3,
  querySubList4,
  querySubList5,
  querySubList6,
  taskSplit,
  doException,
  getLocationType
} from '../../api'

export function detailConfig(self) {
  return [
    {
      key: 'one',
      checkedKey: 'main',
      // height: '400px',
      btns: [
        // {
        //   label: '上架',
        //   click() {
        //     self.toShelf();
        //   }
        // },
      ],
      list: [
        {
          key: 'main',
          tab: '主要信息',
          item: {
            type: 'p-search-table',
            autoLoad: false,
            rowSelectType: 1,
            rowKey: 'rcvHeaderId',
            config: basicData(self),
            remoteUrl: baseUrl + '/report/v1.0/getReportHeader',
            remoteParams: {},
            operators: [],
            scroll: {y: 200},
            doneBefore(response) {
              response.data.list = response.data.list.map(item => {
                return {
                  ...item,
                  ...item.rcvHeadersDTO,
                  ...item.rcvHeadersProfilesDTO
                }
              })
              return response
            },
            selectChange(selectedRowKeys, selectedRows) {
              const list = self.$refs.detail.aList[1].checkedKey
              let postFun = null
              switch (list) {
                case 'list':
                  postFun = querySubList
                  break
                case 'list2':
                  postFun = querySubList2
                  break
                case 'list3':
                  postFun = querySubList3
                  break
                case 'list4':
                  postFun = querySubList4
                  break
                case 'list5':
                  postFun = querySubList5
                  break
                case 'list6':
                  postFun = querySubList6
                  break

                default:
                  break
              }
              let ref = self.queryRefFromName(list)
              self.selectedMainItem = selectedRows[0]
              self.handleQuerySubList({ rcvHeaderId: selectedRowKeys[0], pageNum: 1, pageSize: 500 }, list, postFun).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: 'taskRejectedId',
            config: extendFormItems(self),
            operations: [
              // { title: '拆分', click(record) { self.showSplitBill(record); } }
            ],
            colChange({ record, name, value }) {},
            onClick(selectedRowKeys, selectedRows, data) {
            }
          }
        },
        {
          key: 'list2',
          tab: '上架报表明细',
          btns: [
            // { label: '差异', click() { self.toErrorBill(); } },
          ],
          item: {
            type: 'p-table-edit',
            rowSelectType: 2,
            rowKey: 'taskRejectedId',
            config: extendFormItems2(self),
            operations: [
              // { title: '拆分', click(record) { self.showSplitBill(record); } }
            ],
            colChange({ record, name, value }) {},
            onClick(selectedRowKeys, selectedRows, data) {
              
            }
          }
        },
        {
          key: 'list3',
          tab: '收货报表明细',
          btns: [
            // { label: '差异', click() { self.toErrorBill(); } },
          ],
          item: {
            type: 'p-table-edit',
            rowSelectType: 2,
            rowKey: 'taskRejectedId',
            config: extendFormItems(self),
            operations: [
              // { title: '拆分', click(record) { self.showSplitBill(record); } }
            ],
            colChange({ record, name, value }) {},
            onClick(selectedRowKeys, selectedRows, data) {
            }
          }
        },
        {
          key: 'list4',
          tab: '拒收报表明细',
          btns: [
            // { label: '差异', click() { self.toErrorBill(); } },
          ],
          item: {
            type: 'p-table-edit',
            rowSelectType: 2,
            rowKey: 'taskRejectedId',
            config: extendFormItems(self),
            operations: [
              // { title: '拆分', click(record) { self.showSplitBill(record); } }
            ],
            colChange({ record, name, value }) {},
            onClick(selectedRowKeys, selectedRows, data) {
            }
          }
        },
        {
          key: 'list5',
          tab: '质检报表明细',
          btns: [
            // { label: '差异', click() { self.toErrorBill(); } },
          ],
          item: {
            type: 'p-table-edit',
            rowSelectType: 2,
            rowKey: 'taskRejectedId',
            config: extendFormItems(self),
            operations: [
              // { title: '拆分', click(record) { self.showSplitBill(record); } }
            ],
            colChange({ record, name, value }) {},
            onClick(selectedRowKeys, selectedRows, data) {
            }
          }
        },
        {
          key: 'list6',
          tab: '复检报表明细',
          btns: [
            // { label: '差异', click() { self.toErrorBill(); } },
          ],
          item: {
            type: 'p-table-edit',
            rowSelectType: 2,
            rowKey: 'taskRejectedId',
            config: extendFormItems(self),
            operations: [
              // { title: '拆分', click(record) { self.showSplitBill(record); } }
            ],
            colChange({ record, name, value }) {},
            onClick(selectedRowKeys, selectedRows, data) {
            }
          }
        }
      ]
    }
  ]
}
