<!--
 * @Date: 2022-10-17 09:09:15
 * @LastEditors: 陈禹琨 cyk910622@163.com
 * @LastEditTime: 2023-05-06 17:06:50
 * @FilePath: \upcloud-wms-henanyiyao-web\src\views\kzyWMS\inBound\quality\billEditor\components\spotCheck.vue
 * @Description: cyk
-->
<template>
  <div class="detail">
    <p-modal
      title="抽检"
      :visible="value"
      :dialogStyle="{ top: '40px' }"
      :draggable="true"
      :width="'85%'"
      :confirm-loading="confirmLoading"
      @ok="handleOk"
      @cancel="handleCancel"
    >
      <div class="body" @click="errText = ''">
        <p-table-edit-pro
          v-if="value"
          ref="refData"
          size="small"
          rowKey="taskRqcId"
          :scroll="{ x: 1200 }"
          :columns="columns"
          auto-width
          dragle
          :data-source.sync="dataList"
          :hasRowSelectCheck="true"
          :pagination="false"
          :rowSelectType="false"
          :has-row-count="true"
        >
        </p-table-edit-pro>

        <div style="margin-top: 20px; color: red" v-html="errText">{{ errText }}</div>
      </div>
    </p-modal>
  </div>
</template>
<script>
import { packingColumns } from "../config/spotCheck/config";

import { batchAdd } from "../api";

export default {
  component: {},

  props: {
    value: {
      type: Boolean,
      default: false,
    },
    dataList: {
      type: Array,
      default: [],
    },
  },
  data() {
    return {
      confirmLoading: false,
      columns: packingColumns,
      errText: "",
    };
  },
  created() {},
  mounted() {},
  watch: {},
  methods: {
    handleOk(e) {
      this.confirmLoading = true;
      //抽样实际整件数（qcOddCaseActQty）>抽样整件数（qcOddCaseQty）
      //抽样实际零散数（qcOddPieceActQty）>抽样零散数（qcOddPieceQty）
      // this.$emit.visible = false
      let errList = [];
      this.dataList.forEach((tt, i) => {
        console.log("实际抽检件数", tt.qcOddCaseActQty);
        console.log("实际抽检零散数", tt.qcOddPieceActQty);
        console.log("抽检件数", tt.qcOddCaseQty);
        console.log("抽检零散数", tt.qcOddPieceQty);
        console.log("入库件数", tt.oddCaseQty);
        console.log("入库数量", tt.pieceQty);
        console.log("入库零散数", tt.oddPieceQty);

        //           { title: "抽检件数", dataIndex: "qcOddCaseQty", key: "qcOddCaseQty", width: 100, type: "txt" },
        //   { title: "抽检零散数", dataIndex: "qcOddPieceQty", key: "qcOddPieceQty", width: 100, type: "txt" },
        //   { title: "实际抽检件数", dataIndex: "qcOddCaseActQty", key: "qcOddCaseActQty", width: 100, type: "number", min: 0 },
        //   { title: "实际抽检零散数", dataIndex: "qcOddPieceActQty", key: "qcOddPieceActQty", width: 100, type: "number", min: 0 },
        // pieceQty
        // oddCaseQty
        // 质检件数 qcOddCaseActQty
        //抽检件数 qcOddCaseQty
        //质检零散数 qcOddPieceActQty
        //抽检零散数 qcOddPieceQty

        if (+tt.oddPieceQty != 0 && +tt.qcOddPieceActQty == 0) {
          errList.push("第" + (i + 1) + "行:抽样实际整件数、抽样实际零散数必须大于等于整件数、零散数 ");
        }
        if (+tt.oddCaseQty != 0 && +tt.qcOddCaseActQty == 0) {
          errList.push("第" + (i + 1) + "行:抽样实际整件数、抽样实际零散数必须大于等于整件数、零散数 ");
        }

        if (+tt.oddPieceQty >= +tt.qcOddPieceActQty && +tt.oddCaseQty >= +tt.qcOddCaseActQty) {
          //      +tt.qcOddPieceActQty > 0
          //   +tt.qcOddCaseActQty > 0
          this.confirmLoading = false;
        } else {
          this.confirmLoading = false;
          errList.push("第" + (i + 1) + "行:抽样实际整件数、抽样实际零散数必须大于等于整件数、零散数 ");
        }
        // "件数", dataIndex: "caseQty"
        // "零散数", dataIndex: "oddPieceQty"
        // if (+tt.qcOddCaseActQty > +tt.caseQty || +tt.qcOddPieceActQty > +tt.oddPieceQty) {
        //   errList.push("第" + (i + 1) + "行:抽样实际整件数、抽样实际零散数不能大于件数、零散数 ");
        //   this.confirmLoading = false;
        // } else {
        //   this.confirmLoading = false;
        // }
      });
      if (errList.length > 0) {
        this.errText = errList.join("<br/>");
        return;
      } else {
        batchAdd(this.dataList).then((res) => {
          if (!res.success) {
            this.$exception(res);
            return;
          }
          this.$message.success(this.$lang("抽检完成"));
          // this.isSpotCheck = true
          this.$emit("isSpotCheck", true);
          this.$emit("input", false);
        });
      }
    },
    handleCancel(e) {
      this.$emit("input", false);
    },
  },
};
</script>
