import { basicData } from './basic-data'
import { extendFormItems } from './extend'
// import { operateFormItems } from './operate'
import { packingColumns } from './packing'

export function detailConfig(self) {
  return [
    {
      key: 'one',
      checkedKey: 'main',
      height: '300px',
      btns: [
        { label: '提取单据', click() { self.visible = true; } },
        { label: '暂存', click() { self.history(); } },
        { label: '提取暂存订单', click() { self.showHistoryModal = true; } },
        // { label: '修改', click() {} },
        {
          label: '保存',
          click() {
            self.submitData()
          }
        },
        {
          label: '商品快速维护',
          click() { self.showMaintain() }
        },
      ],
      list: [
        {
          key: 'main',
          tab: '主要信息',
          item: { type: 'p-grid-form', config: basicData }
        },
        {
          key: 'extend',
          tab: '次要信息',
          item: { type: 'p-grid-form', config: extendFormItems }
        },
      ]
    },
    {
      key: 'two',
      checkedKey: 'list',
      list: [
        {
          key: 'list',
          tab: '商品明细',
          item: {
            type: 'p-table-sheet',
            rowKey: 'asnLineId',
            rowSelectType: 2,
            config: packingColumns(self),
            operations: [
              { title: '拆分', click(record, index, dataSource) { self.showSplitBill(record, index, dataSource); } },
              { title: '上传', click(record, index, dataSource) { self.showUploadImgs(record, index, dataSource); }, show(record) { return record.storeTemperature ? record.storeTemperature.indexOf('冷') >= 0 : false; } },
            ],
            colChange({ record, key, value, index, dataSource }) {
              // 显示生产日期
              if (key == 'showProductionDate') {
                self.handleShowProductionDate(record, index, value);
              }
              // 显示有效期至
              if (key == 'showExpiredDate') {
                self.handleShowExpiredDate(record, index, value);
              }
              // 零散
              if (key == 'oddPieceQty') {
                self.handleOddPieceQty(record);
              }
              // 总数量
              if (key == 'oddCaseQty' || key == 'oddPieceQty') {
                self.handlePieceQty(record, dataSource);
              }
              // 收货结论 冷藏品 温度 判断
              if (key == 'stockStatus') {
                self.handleStockStatusTemperature(record);
              }
              // 有效期至改变就清空结论
              if (key == 'batchExpiredDate' && self.businessData == 'kzy') {
                record.stockStatus = ''
              }
              // 批号改变就清空结论
              if (key == 'manufacturerLotNum' && self.businessData == 'kzy') {
                record.stockStatus = ''
              }
            },
            onClick({ index, record, key, dataSource }) {
              if (!record) return;
              self.showStockCount(record.itemId);
            },
            onBlur({ index, record, key, dataSource, value }) {
              //件数、零散数为空，默认给0
              if ((key == 'oddPieceQty' || key == 'oddCaseQty') && !value) {
                console.log(value,'valuevaluevaluevalue');
                record[key] = 0
              }
              //为空不进行校验
              if ((record.showProductionDate == "" || record.showProductionDate == null) && (record.showExpiredDate == "" || record.showExpiredDate == null)) {
                return
              } else {
                // 显示生产日期
                if (key == 'showProductionDate' && !record.batchProductionDate) {
                  self.$message.warn('日期格式错误！');
                  // 将显示生产日期置空
                  record.batchProductionDate = '';
                  // 将显示生产日期置空
                  record.showProductionDate = '';
                }
                if (key == 'showExpiredDate' && !record.batchExpiredDate) {
                  self.$message.warn('日期格式错误！');
                  // 有效期
                  record.batchExpiredDate = '';
                  // 将显示有效期置空
                  record.showExpiredDate = '';
                }
              }
            },
          },
          btns: [
            {
              label: '删除',
              click() {
                let ref = self.queryRefFromName('list')
                ref.removeSelectedRow()
              }
            }
          ]
        }
      ]
    },

  ]
}
