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",
      isShowBoxBtn: true,
      btns: [
        {
          label: "提取单据",
          click() {
            self.visible = true;
          },
        },
        {
          label: "采集监管码",
          click() {
            if (self.selectedRows.length < 1) {
              self.$message.warning("请勾选需要处理的商品明细");
              return;
            }
            // let flag = self.selectedRows.every(item => item.isRetrospect == 1)
            let list = self.selectedRows.filter(item => item.isRetrospect == 1)
            if (list.length==0) return self.$message.warning("商品无需追溯");
            self.scanTableList = list.map(item => {
              item.rcvHeaderId = item.asnHeaderId
              item.rcvLineId = item.refAsnLineId
              item.srcCode = item.asnAutoBillNum
              item.cargoOwnerId = item.mtlOwnerId
              item.cargoOwnerCode = item.mtlOwnerCode
              item.taskRqcId = item.asnLineId
              item.uploadFlag = '0'
              return item
            })
            console.log(list,'list');
            self.scanVisible = true;
          },
        },
        // { label: '暂存', click() { self.history(); } },
        // { label: '提取暂存订单', click() { self.showHistoryModal = true; } },
        // { label: '异常单提取', click() { self.showExceptionModal = true; } },
        // { label: '修改', click() {} },
        {
          label: "保存",
          click() {
            self.submitData();
          },
        },
        {
          label: "商品快速维护",
          click() {
            self.showMaintain();
          },
          // list: [
          //   { label: '商品快速维护', click() { self.showMaintain() } },
          //   // { label: '商品条码采集', click() { } },
          //   // { label: '差异对照表', click() { } },
          //   // { label: '查询待处理订单', click() { } },
          //   // { label: '导出', click() { } },
          //   // { label: '操作日志', click() { } }
          // ]
        },
      ],
      list: [
        {
          key: "main",
          tab: "主要信息",
          item: { type: "p-grid-form", config: basicData(self) },
        },
        // {
        //   key: "extend",
        //   tab: "次要信息",
        //   item: { type: "p-grid-form", config: extendFormItems },
        // },
        // {
        //   key: 'operate',
        //   tab: '操作信息',
        //   item: { type: 'p-grid-form', config: operateFormItems }
        // }
      ],
    },
    {
      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 || 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 == "whAreaCategory") {
                // 库别添加一个字段
                record.whAreaCategoryCode = value;
              }
              if (key == "conversionRate" && self.businessData == "int") {
                // 英特需求    pieceQty
                record.oddCaseQty = parseInt(record.pieceQty / record.conversionRate);
                record.oddPieceQty = record.pieceQty % record.conversionRate;
                record.qty = (record.pieceQty / record.conversionRate).toFixed(2);
              }
              // 有效期至改变就清空结论
              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);
              // 代管库位
              if (key === "locatorCode") {
                self.hostClick(record, dataSource);
              }
            },
            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.showExpiredDate) && record.showProductionDate > record.showExpiredDate) {
                  self.$message.warn("到期时间必须大于等于生产时间");
                  record.showProductionDate = "";
                  record.batchProductionDate = "";
                }
                if ((key == "showExpiredDate" && record.showProductionDate) && record.showProductionDate > record.showExpiredDate) {
                  self.$message.warn("到期时间必须大于等于生产时间");
                  record.showExpiredDate = "";
                  record.batchExpiredDate = "";
                }
                if ((key == "batchExpiredDate" && record.batchProductionDate) && record.batchProductionDate > record.batchExpiredDate) {
                  self.$message.warn("到期时间必须大于等于生产时间");
                  record.showExpiredDate = "";
                  record.batchExpiredDate = "";
                }
                // 显示生产日期
                if (key == "showProductionDate" && !record.batchProductionDate) {
                  self.$message.warn("日期格式错误！");
                  // 将显示生产日期置空
                  record.batchProductionDate = "";
                  // 将显示生产日期置空
                  record.showProductionDate = "";
                }
                if (key == "showExpiredDate" && !record.batchExpiredDate) {
                  self.$message.warn("日期格式错误！");
                  // 有效期
                  record.batchExpiredDate = "";
                  // 将显示有效期置空
                  record.showExpiredDate = "";
                }
              }
            },
            onSelectRow({ selectedRowKeys, selectedRows }) {
              self.selectedRows = selectedRows;
            },
          },
          btns: [
            // {
            //   label: '异常处理',
            //   click() {
            //     self.exceptionModal()
            //   }
            // },
            {
              label: "删除",
              click() {
                let ref = self.queryRefFromName("list");
                ref.removeSelectedRow();
                let par = self.selectedRows.filter(item=>item.refAsnLineId.includes('-')).map(item=>item.refAsnLineId) || []
                self.deleteCodesByBill(par)
                self.selectedRows = []
              },
            },
          ],
        },
      ],
    },
  ];
}
