import moment from "moment";
import { upcloud_base_wh_control } from "@/config/serviceSettings";
let stockStatusOptions = [
  { label: "合格", value: "0" },
  { label: "不合格", value: "1" },
];
// 商品编码，商品名称，包装单位，包装数，商品大类，
// 生产厂家，产地，是否委托生产，受托生产企业，批准文号，
// 上市许可证持有人，数量，验收结论，处理原因、不足原因、处理措施，
// 质量主管复检结果（一级复检可选择修改，二级复检仅显示），
// 质量主管审核意见（一级复检可录入修改，二级复检仅显示），
// 质量主管复检人员（一级复检显示当前登陆人，不可修改，
// 二级复检仅显示一级复检操作人员），质量主管复检时间（一级复检显示当前日期（年月日时分秒），不可修改，
// 二级复检仅显示一级复检操作时间），
// 质量经理复检结果（一级复检不显示或不可录入，二级复检可选择修改），
// 质量主管审核意见（一级复检不显示或不可录入，二级复检可录入修改），
// 质量经理复检人员（一级复检不显示或不可录入，二级复检显示当前登陆人），
// 质量主管复检时间（一级复检不显示或不可录入，二级复检显示当前日期（年月日时分秒））
export const packingColumns = (self) => {
  console.log(self.businessData, "self.businessDataself.businessData");
  let secondStatus = { hidden: true, title: "库存状态", dataIndex: "secondStatus", key: "secondStatus", width: 120 };

  let qcReSecondStatus = {
    hidden: true,
    title: "质量主管库存状态",
    dataIndex: "qcReSecondStatus",
    key: "qcReSecondStatus",
    width: 120,
  };

  let qcReSecondStatus2 = {
    hidden: true,
    title: "质量经理库存状态",
    dataIndex: "qcReSecondStatus2",
    key: "qcReSecondStatus2",
    width: 120,
  };

  if (self.businessData == "int") {
    secondStatus = {
      type: "select",
      title: "库存状态",
      dataIndex: "secondStatus",
      width: 120,
      value: "",
      autoLoad: true,
      disabled: [{ $value: true }],
      replaceFields: {
        label: "subStatusName",
        value: "subStatusCode",
      },
      remoteUrl: { url: upcloud_base_wh_control + "/relationOwnerStockStatus/list", method: "post" },
    };
    qcReSecondStatus = {
      type: "select",
      dataIndex: "qcReSecondStatus",
      title: "质量主管库存状态",
      destroyOptions: true,
      rules: [
        {
          required: true,
          message: "质量主管库存状态必填！",
          match: [{ key: "times", value: 0 }],
        },
      ],
      value: "",
      remoteUrl: { url: upcloud_base_wh_control + "/relationOwnerStockStatus/list", method: "post" },
      replaceFields: {
        label: "subStatusName",
        value: "subStatusCode",
      },
      disabled: [
        {
          $value: false,
          $match: [
            { key: "times", value: "${!1}", group: 1 },
            { key: "qcReResult", value: "${*}", group: 1 }, //空的时候true
          ],
        },
        { $value: true },
      ],
    };
    qcReSecondStatus2 = {
      type: "select",
      title: "质量经理库存状态",
      dataIndex: "qcReSecondStatus2",
      key: "qcReSecondStatus2",
      width: 120,
      destroyOptions: true,
      rules: [
        {
          required: true,
          message: "质量经理库存状态必填！",
          match: [{ key: "times", value: 1 }],
        },
      ],
      value: "",
      remoteUrl: { url: upcloud_base_wh_control + "/relationOwnerStockStatus/list", method: "post" },
      replaceFields: {
        label: "subStatusName",
        value: "subStatusCode",
      },
      disabled: [
        {
          $value: false,
          $match: [
            { key: "times", value: "${!0}", group: 1 },
            { key: "qcReResult2", value: "${*}", group: 1 }, //空的时候true
          ],
        },
        { $value: true },
      ],
    };
  }

  return [
    { hidden: true, title: "taskRecheckId", dataIndex: "taskRecheckId", key: "taskRecheckId" },
    { 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: "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: "manufacturerLotNum", dataIndex: "manufacturerLotNum", key: "manufacturerLotNum" },
    { 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: "stockStatus", key: "stockStatus", type: "input" },
    { 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: "containerCode", key: "containerCode" },
    { hidden: true, title: "货格", dataIndex: "goodsCaseCode", key: "goodsCaseCode", width: 60 },
    { hidden: true, title: "批次号", dataIndex: "batchNum", key: "batchNum", width: 140 },

    { title: "商品编码", dataIndex: "itemNum", key: "itemNum", width: 120 },
    { hidden: true, title: "商品条码", dataIndex: "itemBarCode", key: "itemBarCode", width: 100 },
    { title: "商品名称", dataIndex: "itemName", key: "itemName", width: 160 },
    { hidden: true, title: "商品分类", dataIndex: "categoryName", key: "categoryName", width: 120 },
    { title: "包装单位", dataIndex: "uom", key: "uom", width: 80 },
    { title: "包装数", dataIndex: "conversionRate", key: "conversionRate", width: 80 },
    { title: "商品大类", dataIndex: "categoryName", key: "categoryName", width: 120 },
    { title: "生产厂家", dataIndex: "manufacturerName", key: "manufacturerName", width: 120 },
    { title: "产地", dataIndex: "productionPlace", key: "productionPlace", width: 80 },
    {
      width: 80,
      title: "是否委托生产",
      dataIndex: "isDelegate",
      key: "isDelegate",
      customRender(text) {
        return text == "1" ? "是" : "否";
      },
    },
    { title: "受托生产企业", dataIndex: "delegationPartyName", key: "delegationPartyName", width: 80 },
    { title: "批准文号", dataIndex: "approvalNumber", key: "approvalNumber", width: 80 },
    { title: "上市许可证持有人", dataIndex: "itemHealthListedLicensor", key: "itemHealthListedLicensor", width: 100 },
    { title: "数量", dataIndex: "pieceQty", key: "pieceQty", width: 100 },
    {
      title: "验收结论",
      dataIndex: "rqcResult",
      key: "rqcResult",
      width: 80,
      value: "",
      customRender(text) {
        let options = [
          // 合格0/不合格1/待处理2/拒绝3
          { value: "0", label: "合格" },
          { value: "1", label: "不合格" },
          { value: "2", label: "待处理" },
          { value: "3", label: "拒收" },
        ];
        return options.find((t) => t.value == text).label;
      },
    },
    {
      ...secondStatus,
      relatedQuery: [
        { key: "rqcResult", target: "status" },
        {
          key: "warehouseId",
          target: "warehouseId",
          transform(val) {
            let refMain = self.queryRefFromName("main");
            let values = refMain.form.getFieldsValue();
            return values.warehouseId;
          },
        },
        {
          key: "cargoOwnerId",
          target: "cargoOwnerId",
          transform(val) {
            let refMain = self.queryRefFromName("main");
            let values = refMain.form.getFieldsValue();
            return values.mtlOwnerId;
          },
        },
      ],
    },
    { hidden: true, title: "复检原因", dataIndex: "qcReReason", key: "qcReReason", width: 120, type: "input" },
    { type: "input", title: "审核意见", dataIndex: "aduitSuggestion", key: "aduitSuggestion", width: 120 },
    {
      /* cusType: 'autoComplete', */ title: "处理原因",
      dataIndex: "handlingReason",
      width: 140,
      /* scopedSlots: { customRender: 'handlingReason' }*/
    },
    {
      /*cusType: 'autoComplete',*/ title: "不足原因",
      dataIndex: "defReason",
      width: 140,
      /*scopedSlots: { customRender: 'defReason' }*/
    },
    {
      /* cusType: 'autoComplete', */ title: "处理措施",
      dataIndex: "handlingMeasure",
      width: 140,
      /* scopedSlots: { customRender: 'handlingMeasure' }*/
    },

    { title: "不足原因补充", dataIndex: "rcvReason3", key: "rcvReason3", width: 100 },
    // 质量主管复检结果（一级复检可选择修改，二级复检仅显示）
    // {

    //   title: "质量主管复检结果", dataIndex: "qcReResult", key: "qcReResult", width: 120, type: "select", required: true,
    //   options: [
    //     // 0合格/1不合格/2待处理/3拒绝
    //     { value: '0', label: '合格' },
    //     { value: '1', label: '不合格' },
    //     // { value: '2', label: '待处理' },
    //   ],
    //   disabled: [
    //     {
    //       $value: true,
    //       $match: [
    //         { key: 'times', value: 1 },
    //       ]
    //     },
    //     { $value: false }
    //   ],
    //   relatedClean: ['qcReSecondStatus',],

    // },
    {
      type: "select",
      title: "质量主管复检结果",
      dataIndex: "qcReResult",
      key: "qcReResult",
      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);
        },
      },
      // relatedClean: ['whAreaCategoryCode'],
      required: true,
    },
    {
      ...qcReSecondStatus,
      width: 140,
      relatedQuery: [
        { key: "qcReResult", target: "status" },
        {
          key: "warehouseId",
          target: "warehouseId",
          transform(val) {
            let refMain = self.queryRefFromName("main");
            let values = refMain.form.getFieldsValue();
            return values.warehouseId;
          },
        },
        {
          key: "cargoOwnerId",
          target: "cargoOwnerId",
          transform(val) {
            let refMain = self.queryRefFromName("main");
            let values = refMain.form.getFieldsValue();
            return values.mtlOwnerId;
          },
        },
      ],
      doneBefore(res, remoteParams) {
        console.log(33333333, res);
        res.list = res.data;
      },
    },
    // 质量主管审核意见（一级复检可录入修改，二级复检仅显示）
    {
      title: "质量主管审核意见",
      dataIndex: "qcReSuggestion",
      key: "qcReSuggestion",
      width: 120,
      type: "input",
      rules: [
        {
          required: true,
          message: "质量主管复检结论为不合格或待处理，质量主管审核意见必填！",
          match: [{ key: "qcReResult", value: "${!0}" }],
        },
      ],
      disabled: [
        {
          $value: true,
          $match: [{ key: "times", value: 1 }],
        },
        { $value: false },
      ],
    },
    // 质量主管复检人员（一级复检显示当前登陆人，不可修改二级复检仅显示一级复检操作人员
    {
      title: "质量主管复检人员",
      dataIndex: "qcReOpcode",
      key: "qcReOpcode",
      width: 120,
      type: "input",
      rules: [
        {
          required: true,
          message: "质量主管复检结论为不合格或待处理，请填写质量主管复检人员！",
          match: [{ key: "qcReResult", value: "${!0}" }],
        },
      ],
      disabled: [
        {
          $value: true,
          $match: [{ key: "times", value: 1 }],
        },
        { $value: false },
      ],
    },
    // （一级复检显示当前日期（年月日时分秒），不可修改二级复检仅显示一级复检操作时间）
    {
      type: "p-date-picker",
      dataIndex: "qcReDate",
      key: "qcReDate",
      title: "质量主管复检时间",
      width: 160,
      value: "",
      format: "YYYY-MM-DD HH:mm:ss",
      showTime: true,
      rules: [
        {
          required: true,
          message: "质量主管复结论为不合格或待处理，请填写质量主管复检时间！",
          match: [{ key: "qcReResult", value: "${!0}" }],
        },
      ],
      disabled: [
        {
          $value: true,
          $match: [{ key: "times", value: 1 }],
        },
        { $value: false },
      ],
    },
    // （一级复检不显示或不可录入，二级复检可选择修改）
    // {
    //   title: "质量经理复检结果", dataIndex: "qcReResult2", key: "qcReResult2", width: 120, type: "select",
    //   options: [
    //     // 0合格/1不合格/2待处理/3拒绝
    //     { value: '0', label: '合格' },
    //     { value: '1', label: '不合格' },
    //   ],
    //   rules: [
    //     {
    //       required: true, message: '质量经理复检,复检结果必填！', match: [
    //         { key: 'times', value: 1 }
    //       ]
    //     }
    //   ],
    //   disabled: [
    //     {
    //       $value: true,
    //       $match: [
    //         { key: 'times', value: 0 },
    //       ]
    //     },
    //     { $value: false }
    //   ],
    // },
    {
      ...qcReSecondStatus2,
      relatedQuery: [
        { key: "qcReResult2", target: "status" },
        {
          key: "warehouseId",
          target: "warehouseId",
          transform(val) {
            let refMain = self.queryRefFromName("main");
            let values = refMain.form.getFieldsValue();
            return values.warehouseId;
          },
        },
        {
          key: "cargoOwnerId",
          target: "cargoOwnerId",
          transform(val) {
            let refMain = self.queryRefFromName("main");
            let values = refMain.form.getFieldsValue();
            return values.mtlOwnerId;
          },
        },
      ],
      doneBefore(res, remoteParams) {
        console.log(33333333, res);
        res.list = res.data;
      },
    },

    // （一级复检不显示或不可录入，二级复检可录入修改）
    // {
    //   title: "质量经理审核意见", dataIndex: "qcReSuggestion2", key: "qcReSuggestion2", width: 120, type: "input",
    //   rules: [
    //     {
    //       required: true, message: '质量经理复检结果结论为不合格，请填写质量经理审核意见！', match: [
    //         { key: 'qcReResult2', value: '1' }
    //       ]
    //     }
    //   ],
    //   disabled: [
    //     {
    //       $value: true,
    //       $match: [
    //         { key: 'times', value: 0 },
    //       ]
    //     },
    //     { $value: false }
    //   ],
    // },
    // （一级复检不显示或不可录入，二级复检显示当前登陆人）
    // {
    //   title: "质量经理复检人员", dataIndex: "qcReOpcode2", key: "qcReOpcode2", width: 120, type: "input",
    //   rules: [
    //     {
    //       required: true, message: '质量经理复检结果结论为不合格，请填写质量经理复检人员！', match: [
    //         { key: 'qcReResult2', value: '1' }
    //       ]
    //     }
    //   ],
    //   disabled: [
    //     {
    //       $value: true,
    //       $match: [
    //         { key: 'times', value: 0 },
    //       ]
    //     },
    //     { $value: false }
    //   ],
    // },
    // （一级复检不显示或不可录入，二级复检显示当前日期（年月日时分秒））
    // {
    //   type: "a-date-picker", dataIndex: "qcReDate2", key: "qcReDate2", title: "质量经理复检时间", width: 160, value: '',
    //   format: 'YYYY-MM-DD HH:mm:ss', showTime: true,
    //   rules: [
    //     {
    //       required: true, message: '质量经理复检结果结论为不合格，请填写质量经理复检时间！', match: [
    //         { key: 'qcReResult2', value: '1' }
    //       ]
    //     }
    //   ],
    //   disabled: [
    //     {
    //       $value: true,
    //       $match: [
    //         { key: 'times', value: 0 },
    //       ]
    //     },
    //     { $value: false }
    //   ],
    // },
  ];
};
