import { genCloumnContainer } from "../../../../config/genColumnContainer";
import moment from "moment";
import { upcloud_base_common, upcloud_base_wh_control, upcloud_base_wh, upcloud_base_wh_inbound, upcloud_base_strategy } from "@/config/serviceSettings";
import request from "@/utils/request";

import { genContainerSearchModal } from "../../../../../SearchModal";
// import { getOption } from "../../../../config/whAreaCategory"
let whAreaCategoryCodeList = [
  { label: "立体库", value: "LTK" },
  { label: "整件库", value: "ZJK" },
  { label: "零货库", value: "LHK" },
  { label: "直调库", value: "ZDK" },
  { label: "整散合一库", value: "HYK" },
  { label: "待处理库", value: "CLK" },
  { label: "代管库", value: "DGK" },
  { label: "越库区", value: "YKQ" },
  { label: "退货库", value: "THK" },
  { label: "冷库", value: "LK" },
  { label: "AGV库", value: "AGVK" },
  { label: "AGV托盘库", value: "AGVZ" },
  { label: "AGV货架库", value: "AGVL" },
  { label: "密集库", value: "MJK" },
  { label: "备货库", value: "BHK" },
  { label: "不合格库", value: "NHK" },
  { label: "盘点库", value: "PDK" },
  { label: "整散合一库", value: "HYK" },
  { label: "调整库", value: "ADJ" },
  { label: "直通库", value: "ZTK" },
  { label: "高架库", value: "GJK" },
  { label: "中药库", value: "ZYK" },
  { label: "物料库", value: "WLK" },
  { label: "AGV食品库", value: "AGVSP" },
  { label: "AGV器械库", value: "AGVQX" },
  { label: "AGV中药", value: "AGVZY" },
];
let cacheWhAreaCategory = {};
let stockStatusOptions = [
  { label: "合格", value: "0" },
  { label: "不合格", value: "1" },
  { label: "待处理", value: "2" },
  { label: "拒收", value: "3" },
];
function recommendRoom(parameter) {
  return request({
    method: "post",
    url: upcloud_base_wh_inbound + "/rqcLines/recommendRoom",
    data: parameter,
  });
}

function getContainers(parameter) {
  return request({
    method: "post",
    url: upcloud_base_wh + "/container/getPageList",
    data: parameter,
  });
}
export const packingColumns = function (self) {
  let stockStatusConfig = {
    type: "select",
    title: "质量状态收货结论",
    dataIndex: "stockStatus",
    key: "stockStatus",
    options: [...stockStatusOptions],
    on: {
      dropdownVisibleChange({ record, index, columnItem }) {
        setTimeout(() => {
          console.log(self.stockStatusOptions);
          const options = self.stockStatusOptions;
          columnItem.options.splice(0, columnItem.options.length, ...options);
        }, 20);
      },
      async change(value) {
        let record = value.record;
        let dataSource = "1";
        let category = "RcvAreaCategoryChoose";
        let { categoryName, warehouseId, mtlOwnerId, enterpriseId, oddPieceQty, oddCaseQty, stockStatus, isAgv } = record;
        console.log(arguments);
        // let res = await self.strategyExecuteFun({
        //   dataSource,
        //   categoryName,
        //   warehouseId,
        //   mtlOwnerId,
        //   category,
        //   enterpriseId,
        //   oddPieceQty,
        //   oddCaseQty,
        //   stockStatus,
        //   isAgv,
        // });
        // console.log(res);
        // let o = self.getwhAreaCategoryCode(res, record);
        // console.log(o, o.includes(record.whAreaCategoryCode));
        // if (record.whAreaCategoryCode && !o.includes(record.whAreaCategoryCode)) {
        //   self.$message.warning("当前行数量发生变化,请重新选择库别!");
        //   record.whAreaCategoryCode = null;
        // }
      },
    },
    disabled: [
      {
        $value: true,
        $match: [{ key: "sourceType", value: "复检" }],
      },
      { $value: false },
    ],
    // relatedClean: ['whAreaCategoryCode'],
    required: true,
  };

  return [
    { hidden: true, title: "taskRqcId", dataIndex: "taskRqcId", key: "taskRqcId" },
    { hidden: true, title: "receiveQty", dataIndex: "receiveQty", key: "receiveQty" },
    { hidden: true, title: "itemId", dataIndex: "itemId", key: "itemId" },
    { hidden: true, title: "batchId", dataIndex: "batchId", key: "batchId" },
    { hidden: true, title: "mtlOwnerId", dataIndex: "mtlOwnerId", key: "mtlOwnerId" },
    { hidden: true, title: "mtlOwnerName", dataIndex: "mtlOwnerName", key: "mtlOwnerName" },
    { hidden: true, title: "warehouseId", dataIndex: "warehouseId", key: "warehouseId" },
    { hidden: true, title: "rcvHeaderId", dataIndex: "rcvHeaderId", key: "rcvHeaderId" },
    { hidden: true, title: "asnHeaderId", dataIndex: "asnHeaderId", key: "asnHeaderId" },
    { hidden: true, title: "srcAutoBillNum", dataIndex: "srcAutoBillNum", key: "srcAutoBillNum" },
    { hidden: true, title: "srcLineId", dataIndex: "srcLineId", key: "srcLineId" },
    { hidden: true, title: "srcBillTyp", dataIndex: "srcBillTyp", key: "srcBillTyp" },
    { hidden: true, title: "srcHeaderId", dataIndex: "srcHeaderId", key: "srcHeaderId" },
    { hidden: true, title: "asnLineId", dataIndex: "asnLineId", key: "asnLineId" },
    {
      hidden: true,
      title: "双人业务类型(0:正常 1：双人验收，默认正常)",
      dataIndex: "itemHealthIsDouble",
      key: "itemHealthIsDouble",
    },
    { hidden: true, title: "rcvLineId", dataIndex: "rcvLineId", key: "rcvLineId" },
    { hidden: true, title: "categoryId", dataIndex: "categoryId", key: "categoryId" },
    { hidden: true, title: "piecePriceTe", dataIndex: "piecePriceTe", key: "piecePriceTe" },
    { hidden: true, title: "piecePriceTi", dataIndex: "piecePriceTi", key: "piecePriceTi" },
    { hidden: true, title: "商品助记码", dataIndex: "itemZjm", key: "itemZjm" },
    { hidden: true, title: "单位助记码", dataIndex: "shipperZjm", key: "shipperZjm" },
    { hidden: true, title: "质检次数", dataIndex: "times", key: "times" },
    { hidden: true, title: "入库类型", dataIndex: "rcvType", key: "rcvType" },
    { hidden: true, title: "stockStatus", dataIndex: "stockStatus", key: "stockStatus" }, //上游结论

    {
      title: "是否追溯",
      dataIndex: "isSupervise",
      key: "isSupervise",
      width: 120,
      customRender(text) {
        text == 0 && (text = "无");
        text == 1 && (text = "监管码");
        text == 2 && (text = "序列号");
        return text;
      },
    },
    // {
    //   title: "验收温度",
    //   dataIndex: "rqcTemperature",
    //   key: "rqcTemperature",
    //   width: 120,
    //   type: "input",
    //   rules: [
    //     {
    //       required: true, message: '结论为拒收，请输入处理原因！', match: [
    //         { key: 'qcResult1', value: '${!3}' }
    //       ]
    //     }
    //   ]
    // },
    //   { title: "库房编号", dataIndex: "warehouseRoomCodes", key: "warehouseRoomCodes", width: 120, },
    { title: "商品编号", dataIndex: "itemNum", key: "itemNum", width: 120 },
    { hidden: true, title: "商品条码", dataIndex: "itemBarCode", key: "itemBarCode", width: 100 },
    { title: "商品名称", dataIndex: "itemName", key: "itemName", width: 160 },
    {
      title: "批号",
      dataIndex: "manufacturerLotNum",
      key: "manufacturerLotNum",
      width: 120,
      type: "input",

      rules: [
        {
          required: true,
          message: "请输入批号",
          match: [
            { key: "stockStatus", value: "0" },
            { key: "stockStatus", value: "1" },
            { key: "stockStatus", value: "2" },
          ],
        },
      ],
    },
    {
      title: "显示生产日期",
      dataIndex: "showProductionDate",
      key: "showProductionDate",
      width: 120,
      type: "input",
      rules: [
        {
          required: true,
          message: "请输入显示生产日期！",
          match: [
            { key: "stockStatus", value: "0" },
            { key: "stockStatus", value: "1" },
            { key: "stockStatus", value: "2" },
          ],
        },
      ],
    },
    {
      title: "显示有效期至",
      dataIndex: "showExpiredDate",
      key: "showExpiredDate",
      width: 120,
      type: "input",
      rules: [
        {
          required: true,
          message: "请输入显示有效期至！",
          match: [
            { key: "stockStatus", value: "0" },
            { key: "stockStatus", value: "1" },
            { key: "stockStatus", value: "2" },
          ],
        },
      ],
    },
    { title: "生产日期", dataIndex: "batchProductionDate", key: "batchProductionDate", width: 120 },
    { title: "有效期至", dataIndex: "batchExpiredDate", key: "batchExpiredDate", width: 120 },
    { title: "商品规格", dataIndex: "specification", key: "specification", width: 120 },
    { title: "商品大类", dataIndex: "categoryName", key: "categoryName", width: 120 },
    { title: "生产厂家", dataIndex: "manufacturerName", key: "manufacturerName", width: 120 },
    { title: "产地", dataIndex: "productionPlace", key: "productionPlace", width: 60 },
    {
      hidden: true,
      title: "是否受托生产",
      dataIndex: "isDelegate",
      key: "isDelegate",
      width: 120,
      customRender(text) {
        return text == "1" ? "是" : "否";
      },
    },
    { hidden: true, title: "受托生产企业", dataIndex: "delegationPartyName", key: "delegationPartyName", width: 120 },
    { title: "批准文号", dataIndex: "approvalNumber", key: "approvalNumber", width: 120 },
    { title: "上市许可持有人", dataIndex: "itemHealthListedLicensor", key: "itemHealthListedLicensor", width: 120 },
    { title: "注册证号", dataIndex: "itemHealthRegisterNbr", key: "itemHealthRegisterNbr", width: 120 },
    { title: "生产企业许可证号", dataIndex: "itemHealthProduceLicense", key: "itemHealthProduceLicense", width: 120 },

    { title: "包装单位", dataIndex: "uom", key: "uom", width: 120 },
    { title: "包装数", dataIndex: "conversionRate", key: "conversionRate", width: 120 },
    { title: "件数", dataIndex: "caseQty", key: "caseQty", width: 80 },
    { title: "零散数", dataIndex: "oddPieceQty", key: "oddPieceQty", width: 80 },
    { title: "数量", dataIndex: "pieceQty", key: "pieceQty", width: 120 },
    { hidden: true, title: "建筑物", dataIndex: "bldgId", key: "bldgId", width: 120 },
    { hidden: true, title: "建筑物", dataIndex: "bldgCode", key: "bldgCode", width: 120 },
    //   { title: "建筑物", dataIndex: "bldgName", key: "bldgName", width: 120, },
    { hidden: true, title: "判断报告单", dataIndex: "rqcReportNoNew", key: "rqcReportNoNew", width: 120 },
    {
      type: "input",
      width: 120,
      title: "质检报告单号",
      dataIndex: "rqcReportNo",
      key: "rqcReportNo",
      disabled: [
        {
          $value: true,
          $match: [{ key: "rqcReportNoNew", value: "${*}" }],
        },
        { $value: false },
      ],
      on: {
        blur({ value, index, record, dataSource }) {
          console.log(value, index, record, dataSource, "datadatadatadata");
          return;
          // let ref = self.queryRefFromName('list');
          // let record = ref.clickTest;
          // let data = ref.data
          // data.forEach((t) => {
          //   if (t.manufacturerLotNum === record.manufacturerLotNum) {
          //     t.rqcReportNo = record.rqcReportNo
          //   }

          // })
        },
      },
    },

    // { title: "容器编号", dataIndex: "containerCode", key: "containerCode", width: 120, type: "input" },
    // genCloumnContainer(self),
    { title: "源拆分单", dataIndex: "sourceSplit", key: "sourceSplit", width: 120 },
    {
      ...genContainerSearchModal(2, false, false, null, null),
      remoteUrl: { url: upcloud_base_wh + "/container/getPageList", method: "post" },
      title: "容器号",
      dataIndex: "containerCode",
      key: "containerCode",
      targetValueKey: "containerCode",
      required: false,
      rowKey: "containerId",
      width: 150,
      targetClick: false,
      relatedQuery: [
        { key: "warehouseId", target: "warehouseId" },
        { key: "containerStatus", target: "containerStatus", default: "10" },
      ],
      disabled: [
        {
          $value: true,
          $match: [{ key: "sourceSplit", value: "1" }],
        },
        { $value: false },
      ],
      on: {
        blur({ value, index, record }) {
          let code = value || "";
          code = code.trim();
          if (!code) return;
          getContainers({
            pageSize: 1000,
            containerStatus: "10",
            containerCode: code,
            warehouseId: self.mainlist[0].warehouseId,
          }).then((res) => {
            if (!res.success) {
              this.$exception(res);
              record.containerCode = "";
              return;
            }
            if (!Array.isArray(res.data.list) || res.data.list.length === 0) {
              record.containerCode = "";
              self.$message.warn("容器不存在或已占有");
              return;
            }
            //根据输入的值匹配接口返回值，如果没有匹配到一模一样的值就取返回的第一个值赋给当前容器号
            if (res.data.list.every((tt) => tt.containerCode != code)) {
              let item = res.data.list[0];
              record.containerCode = item.containerCode;
            }
          });
        },
      },
    },

    stockStatusConfig,
    {
      type: "select",
      title: "库别",
      dataIndex: "whAreaCategoryCode",
      key: "whAreaCategoryCode",
      width: 100,
      autoLoad: true,
      required: true,
      allowClear: true,
      destroyOptions: true,
      remoteUrl: { url: upcloud_base_strategy + "/strategy/v1/execute", method: "get" },
      relatedQuery: [
        // categoryName
        // dataSource
        { key: "dataSource", target: "dataSource", default: "1" },
        { key: "categoryId", target: "categoryId" },
        { key: "warehouseId", target: "warehouseId" },
        { key: "mtlOwnerId", target: "cargoOwnerId" },
        { key: "category", target: "category", default: "RcvAreaCategoryChoose" },
        { key: "enterpriseId", target: "enterpriseId", transform: () => self.$store.state.user.info.enterpriseId },
        { key: "oddPieceQty", target: "oddPieceQty" },
        { key: "oddCaseQty", target: "oddCaseQty" },
        // { key: "stockStatus1", target: "stockStatus1" },
        { key: "stockStatus", target: "stockStatus" },
        // { key: "isCaseOrPiece", target: "isCaseOrPiece" },
        // { key: "categoryGroup", target: "categoryGroup" },
        { key: "isAgv", target: "isAgv" },
        { key: "storeTemperature", target: "storeTemperature" },
      ],
      remoteBefore(vNode, params) {
        //   const {dataSource ,categoryName} = params.params;

        // 缓存入参
        cacheWhAreaCategory = params.params;
        console.log(cacheWhAreaCategory);
        return params;
      },
      doneBefore(res) {
        console.log(arguments);
        console.log(res);
        // if (!res.success) {
        //   self.$message.error("件数、零散数、收货结论、质量状态不能为空!");
        //   return { success: true, data: [] };
        // }
        try {
          const params = cacheWhAreaCategory;
          const matchObj = {
            oddPieceQty: String(params.oddPieceQty),
            oddCaseQty: String(params.oddCaseQty),
            stockStatus: String(params.stockStatus),
            categoryId: String(params.categoryId),
            dataSource: String(params.dataSource),
            isAgv: String(params.isAgv),
            storeTemperature: String(params.storeTemperature),
          };
          console.log(matchObj);
          let hitRule = res.data.rules.find((rule) => {
            const { matchFactors } = rule;
            if (matchFactors.length === 0) return false;
            return rule.matchFactors.every((matchFactor) => {
              const { fieldName, matchType, value } = matchFactor;
              if (matchType === "equal") {
                return matchObj[fieldName] === value;
              }
              if (matchType === "in") {
                return value.split(",").includes(matchObj[fieldName]);
              }
              if (matchType === "gt") {
                return matchObj[fieldName] > value;
              }
              if (matchType === "lt") {
                return matchObj[fieldName] < value;
              }
            });
          });
          console.log("hitRule", hitRule);
          if (!hitRule) {
            console.error("没有命中的规则");
            return { success: true, data: [] };
          }
          //   let options = hitRule.searchFactors.map((_) => {
          //     const label = whAreaCategoryCodeList.find((item) => item.value === _.value)?.label || _.value;
          //     return { label, value: _.value };
          //   });

          let value = hitRule.searchFactors.map((_) => _.value)[0].split(",");
          console.log(value);
          let options = value.map((i) => {
            const label = whAreaCategoryCodeList.find((v) => {
              if (v.value == i) {
                return v.label;
              } else {
                return null;
              }
            });
            return { label: label.label, value: i };
          });

          console.log("options", options);
          return { success: true, data: options };
        } catch (e) {
          return { success: true, data: [] };
        }
      },
      disabled: [
        {
          $value: true,
          $match: [
            { key: "rcvType", value: "1" },
            {
              key: "categoryCodeFromRcvFlag",
              value: "1",
              group: 1,
            },
          ],
        },
        { $value: false },
      ],
      options: whAreaCategoryCodeList,
    },
    // {
    //   type: "select",
    //   title: "库存状态",
    //   dataIndex: "secondStatus",
    //   key: "secondStatus",
    //   width: 120,
    //   value: "",
    //   required: true,
    //   destroyOptions: true,
    //   remoteUrl: { url: upcloud_base_wh_control + "/relationOwnerStockStatus/list", method: "post" },
    //   autoLoad: true,

    //   //传参
    //   relatedQuery: [
    //     { key: "warehouseId", target: "warehouseId" },
    //     { key: "mtlOwnerId", target: "cargoOwnerId" },
    //     { key: "qcResult1", target: "status" },
    //   ],
    //   replaceFields: {
    //     value: "subStatusCode",
    //     label: "subStatusName",
    //   },
    // },
    {
      type: "select",
      title: "处理原因",
      dataIndex: "handlingReason",
      width: 140,
      allowClear: true,
      // scopedSlots: { customRender: 'handlingReason' }
      autoLoad: true,
      remoteUrl: { url: upcloud_base_common + "/dict/listbytype?dicttypeCodes=rcv_billd_rcvreason1", method: "post" },
      replaceFields: {
        // value: 'dictCode',
        value: "dictName",
        label: "dictName",
      },
      rules: [
        {
          required: true,
          message: "结论为拒收或待处理，请输入处理原因！",
          match: [
            { key: "stockStatus", value: "2" },
            { key: "qcResult1", value: "2" },
            { key: "qcResult1", value: "3" },
          ],
        },
      ],
    },
    {
      type: "select",
      title: "不足原因",
      dataIndex: "defReason",
      width: 140,
      allowClear: true,
      // scopedSlots: { customRender: 'defReason' }
      autoLoad: true,
      remoteUrl: { url: upcloud_base_common + "/dict/listbytype?dicttypeCodes=rcv_billd_rcvreason2", method: "post" },
      replaceFields: {
        // value: 'dictCode',
        value: "dictName",
        label: "dictName",
      },
      rules: [
        {
          required: true,
          message: "结论为拒收或待处理，请输入不足原因！",
          match: [
            { key: "stockStatus", value: "2" },
            { key: "qcResult1", value: "2" },
            { key: "qcResult1", value: "3" },
          ],
        },
      ],
    },
    {
      type: "select",
      title: "处理措施",
      dataIndex: "handlingMeasure",
      width: 140,
      allowClear: true,
      // scopedSlots: { customRender: 'handlingMeasure' }
      autoLoad: true,
      remoteUrl: { url: upcloud_base_common + "/dict/listbytype?dicttypeCodes=rcv_handle_measure", method: "post" },
      replaceFields: {
        // value: 'dictCode',
        value: "dictName",
        label: "dictName",
      },
      rules: [
        {
          required: true,
          message: "结论为拒收或待处理，请输入处理措施！",
          match: [
            { key: "stockStatus", value: "2" },
            { key: "qcResult1", value: "2" },
            { key: "qcResult1", value: "3" },
          ],
        },
      ],
    },
    {
      type: "select",
      title: "退货类型",
      dataIndex: "returnType",
      width: 140,
      allowClear: true,
      // scopedSlots: { customRender: 'returnType' }
      autoLoad: true,
      remoteUrl: { url: upcloud_base_common + "/dict/listbytype?dicttypeCodes=rcv_return_type", method: "post" },
      replaceFields: {
        // value: 'dictCode',
        value: "dictName",
        label: "dictName",
      },
    },
    { title: "退货说明", dataIndex: "returnExplain", key: "returnExplain", width: 120, type: "input" },
    { width: 80, title: "含税单价", dataIndex: "piecePriceTi", key: "piecePriceTi" },
    { hidden: true, width: 80, title: "不含税单价", dataIndex: "piecePriceTe", key: "piecePriceTe" },
    { title: "处理意见", dataIndex: "handlingSuggestion", key: "handlingSuggestion", width: 120 },
    {
      title: "是否已复检",
      dataIndex: "isRechecked",
      key: "isRechecked",
      width: 120,
      customRender(text) {
        return text == "1" ? "是" : "否";
      },
    },
    {
      title: "复检结果",
      dataIndex: "reCheckResult",
      key: "reCheckResult",
      width: 120,
      customRender(text) {
        let text2 = "";
        if (text == "1") {
          text2 = "不合格";
        } else if (text == "0") {
          text2 = "合格";
        } else {
          text2 = "";
        }
        return text2;
      },
    },
    // (0:正常 1：双人验收，默认正常)
    {
      title: "是否双人验收",
      dataIndex: "itemHealthIsDouble",
      key: "itemHealthIsDouble",
      width: 120,
      customRender(text) {
        return text == "1" ? "是" : "否";
      },
    },
    { title: "存储分类", dataIndex: "itemHealthStoreCategory", key: "itemHealthStoreCategory", width: 100 },
    { title: "存储条件", dataIndex: "storeTemperature", key: "storeTemperature", width: 120 },
    {
      title: "是否进口",
      dataIndex: "itemIsImported",
      key: "itemIsImported",
      width: 120,
      customRender(text) {
        return text == "1" ? "是" : "否";
      },
    },
    {
      width: 80,
      title: "是否标准器械",
      dataIndex: "isInstrument",
      key: "isInstrument",
      customRender(text) {
        return text == "1" ? "是" : "否";
      },
    },

    {
      type: "input",
      title: "isAgv",
      dataIndex: "isAgv",
      hidden: true,
    },
    { title: "单据类型", dataIndex: "rcvType", key: "rcvType", width: 120 },
    { title: "来源数据", dataIndex: "sourceType", key: "sourceType", width: 120 },
    { hidden: true, title: "要货部门", dataIndex: "needDept", key: "needDept", width: 120 },
    { hidden: true, title: "收货员", dataIndex: "rcvUser", key: "rcvUser", width: 60 },
    { hidden: true, title: "有效期天数", dataIndex: "shelfLifeDays", key: "shelfLifeDays", width: 80 },
    { hidden: true, title: "asn备注", dataIndex: "asnLineRemark", key: "asnLineRemark", width: 100 },
    { hidden: true, title: "备注", dataIndex: "lineRemark", key: "lineRemark", width: 100, type: "input" },
    { hidden: true, title: "单位包装数量", dataIndex: "qty", key: "qty", width: 80 },
    { hidden: true, title: "质检件数", dataIndex: "qcOddCaseActQty", key: "qcOddCaseActQty", width: 100 },
    { hidden: true, title: "质检零散数", dataIndex: "qcOddPieceActQty", key: "qcOddPieceActQty", width: 100 },
    { hidden: true, title: "质检人1", dataIndex: "qcOpcode1", key: "qcOpcode1", width: 120 },
    { hidden: true, title: "质检人2", dataIndex: "qcOpcode2", key: "qcOpcode2", width: 120 },
    { hidden: true, title: "批次号", dataIndex: "batchNum", key: "batchNum", width: 120 },
    { hidden: true, title: "供应商批号", dataIndex: "vendorBatchNum", key: "vendorBatchNum", width: 150 },
  ];
};

function getOption(record, main, whAreaCategoryCodeList, caseQty) {
  let newOptions = null;
  var tempData = null;
  //销售退回有效期至超过当前日期，库别默认退货库
  tempData = new Date(record.batchExpiredDate);
  if (tempData < new Date()) {
    if (main.rcvType == "2") {
      newOptions = whAreaCategoryCodeList.filter((t) => {
        if (t.value == "THK") return true;
        else return false;
      });
    }
  }
  //代管类型只能入代管库
  else if (main.rcvType == "8" || main.rcvType == "9") {
    console.log(main.rcvType, "main.rcvType");
    newOptions = whAreaCategoryCodeList.filter((t) => {
      if (t.value == "DGK") return true;
      else return false;
    });
  }
  // 10.整散合一库 只能入整散合一的商品，即整散合一的商品默认并且只能入整散合一库
  else if (record.itemHealthStoreCategory.indexOf("合一") >= 0) {
    newOptions = whAreaCategoryCodeList.filter((t) => {
      //不再限制越库区
      if (main.rcvType == "7" && (t.value == "ZDK" || t.value == "YKQ")) {
        return true;
      }
      if (main.rcvType == "6" && t.value == "YKQ") {
        return true;
      }
      if (t.value == "HYK" || t.value == "YKQ") return true;
      else return false;
    });
  }
  // 其它组合
  else {
    //
    //整件caseQty;
    let oddPieceQty = +record.oddPieceQty || 0; //零散
    newOptions = whAreaCategoryCodeList.filter((t) => {
      //特殊单据直调、越库 需单独判断是否整散分开
      // 1.整件库 只能入整散分开的整件
      //不再限制越库区
      if (main.rcvType == "7" && caseQty > 0 && oddPieceQty == 0 && (t.value == "ZJK" || t.value == "ZDK" || t.value == "YKQ")) {
        return true;
      }
      if (main.rcvType == "6" && caseQty > 0 && oddPieceQty == 0 && (t.value == "ZJK" || t.value == "YKQ")) {
        return true;
      }
      // 2.零货库 只能入整散分开的
      if (main.rcvType == "7" && caseQty == 0 && oddPieceQty > 0 && (t.value == "LHK" || t.value == "ZDK" || t.value == "YKQ")) {
        return true;
      }
      if (main.rcvType == "6" && caseQty == 0 && oddPieceQty > 0 && (t.value == "LHK" || t.value == "YKQ")) {
        return true;
      }

      // 14.其他订单判断是否整散，再选择库别
      if (caseQty > 0 && oddPieceQty == 0 && (t.value == "ZJK" || t.value == "YKQ")) {
        return true;
      }
      if (caseQty == 0 && oddPieceQty > 0 && (t.value == "LHK" || t.value == "YKQ")) {
        return true;
      }
      // if ((main.rcvType == '6' || main.rcvType == '1' || main.rcvType == '2') && t.value == 'YKQ') { return true; }
      // 11.待处理库 收货结论为不合格的才可以入待处理库
      if (record.qcResult1 == "1" && t.value == "CLK") {
        return true;
      }
      if (t.value == "YKQ") return true;
      return false;
    });
  }
  return newOptions;
}

/*

setTimeout(() => {
let ref = self.queryRefFromName('list');
let record = ref.clickTest;
let index = ref.data.findIndex(t => t == record);
let main = self.detailData.main;
let item = ref.aColumns.find(t => t.key == 'whAreaCategory')
// 3.直调库 只能订单类型是直调的选，即订单类型是直调的默认并且只能入直调库
if (main.rcvType == '7') {
  item.options.forEach(t => {
    if (t.value == 'ZDK') {
      t.disabled = false;
    } else {
      t.disabled = true;
    }
  });
}
// 13.代管库 只能订单类型是代管的才可以入到代管库，即订单类型是代管的默认并且只能入代管库
else if (main.rcvType == '8') {
  item.options.forEach(t => {
    if (t.value == 'DGK') {
      t.disabled = false;
    } else {
      t.disabled = true;
    }
  });
}
// 10.整散合一库 只能入整散合一的商品，即整散合一的商品默认并且只能入整散合一库
else if (record.itemHealthStoreCategory.indexOf('合一') >= 0) {
  item.options.forEach(t => {
    if (t.value == 'HYK') {
      t.disabled = false;
    } else {
      t.disabled = true;
    }
  });
}
// 其它组合
else {
  //
  let caseQty = +record.caseQty || 0;
  let oddPieceQty = +record.oddPieceQty || 0;
  item.options.forEach(t => {
    t.disabled = true;
    // 1.整件库 只能入整散分开的整件
    if (caseQty > 0 && oddPieceQty == 0 && t.value == 'ZJK') {
      t.disabled = false;
    }
    // 2.零货库 只能入整散分开的
    if (caseQty == 0 && oddPieceQty > 0 && t.value == 'LHK') {
      t.disabled = false;
    }
    // 14.越库区 订单标识有越库的默认到越库区，正常入库和销售退回订单也可以选择，其他不行
    if ((main.rcvType == '6' || main.rcvType == '1' || main.rcvType == '2') && t.value == 'YKQ') {
      t.disabled = false;
    }
    // 11.待处理库 收货结论为不合格的才可以入待处理库
    if (record.qcResult1 == '1' && t.value == 'CLK') {
      t.disabled = false;
    }
  });
}
item.open = open;
if (open == false) return;
let a = () => {
  let drops = document.getElementsByClassName('xxx-xxx-xxx');
  if (drops.length == 0) {
    setTimeout(() => {
      a();
    }, 20);
  } else {
    setTimeout(() => {
      for (let i = 0; i < drops.length; i++) {
        drops[i].style.display = 'none';
      }
      let div = ref.$refs.easyTable.$el.getElementsByClassName('whAreaCategory' + index);
      let id = div[0].children[0].getAttribute('aria-controls');
      document.getElementById(id).parentElement.style.display = 'block';
    }, 20);
  }
}
a();
}, 20);

*/

// ref.aColumns.forEach((t) => {
//   if (t.key == 'whAreaCategoryCode') {
//     if (!whAreaCategoryCodeList) whAreaCategoryCodeList = t.options;
//     t.options.forEach(tt => {
//       tt.disabled = true;
//       // 3.直调库 只能订单类型是直调的选，即订单类型是直调的默认并且只能入直调库
//       if (main.rcvType == '7' && tt.value == 'ZDK') {
//         tt.disabled = false;
//       }
//       // 13.代管库 只能订单类型是代管的才可以入到代管库，即订单类型是代管的默认并且只能入代管库
//       else if (main.rcvType == '8' && tt.value == 'DGK') {
//         tt.disabled = false;
//       }
//       // 10.整散合一库 只能入整散合一的商品，即整散合一的商品默认并且只能入整散合一库
//       else if (record.itemHealthStoreCategory.indexOf('合一') >= 0 && tt.value == 'HYK') {
//         tt.disabled = false;
//
//       }
//       // 其它组合
//       else {
//
//         let caseQty = +record.caseQty || 0;
//         let oddPieceQty = +record.oddPieceQty || 0;
//         // 1.整件库 只能入整散分开的整件
//         if (caseQty > 0 && oddPieceQty == 0 && tt.value == 'ZJK') {
//           tt.disabled = false;
//         }
//         // 2.零货库 只能入整散分开的
//         if (caseQty == 0 && oddPieceQty > 0 && tt.value == 'LHK') {
//           tt.disabled = false;
//         }
//         // 14.越库区 订单标识有越库的默认到越库区，正常入库和销售退回订单也可以选择，其他不行
//         if ((main.rcvType == '6' || main.rcvType == '1' || main.rcvType == '2') && tt.value == 'YKQ') {
//           tt.disabled = false;
//         }
//         // 11.待处理库 收货结论为不合格的才可以入待处理库
//         if (record.qcResult1 == '1' && tt.value == 'CLK') {
//           tt.disabled = false;
//         }
//       }
//     });
//     t.open = open;
//   }
// })
