<template>
  <div class="midPopUp" v-if="modelValue" @click.stop="handleClose">
    <div class="container" @click.stop>
      <div class="headerTittle">本次绑定详情</div>
      <div class="describeText">绑定数量不足的管号已经过滤</div>
      <el-divider />
      <el-scrollbar>
        <div class="body">
          <el-table border class="seqTable" :data="showData" style="flex: 1">
            <el-table-column label="批次号" prop="batchNo" />
            <el-table-column label="管号" prop="seqNo" />
            <el-table-column label="数量" prop="num" />
          </el-table>
        </div>
      </el-scrollbar>
      <div class="btns">
        <el-button type="primary" @click="submit">绑定</el-button>
        <el-button @click="handleClose">取消</el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { saveBatch } from "@/api/prosteps/wuliaocaiji.ts";
import { includes } from "lodash-es";
import { useProcessStore } from "@/store";
import { useUserStore } from "@/store";
const emits = defineEmits(["update:modelValue", "close", "dataList"]);
const store = useProcessStore();
const store1 = useUserStore();
const props = defineProps({
  modelValue: {
    type: Boolean,
    default: false,
  },
  showInfo: {
    type: Object,
  },
});

//现选中List
const batchNoTableData = inject("batchNoTableData");

const submit = async () => {
  const array = ref([]);
  batchNoTableData.value
    .filter((item) => item.ok == false)
    .forEach((item) => {
      array.value.push({
        itemCode: props.showInfo.materialCode,
        itemModel: props.showInfo.spec,
        itemName: props.showInfo.materialName,
        operationId: store.scanInfo.operationId,
        operationName: store.scanInfo.operationName,
        processId: store.scanInfo.id,
        workOrderCode: store.odersData.workOrderCode,
        trackBy: store1.user.username,
        seqNoList: item.selectSeq,
        batchNo: item.batchNo,
      });
    });
  if (showData.value.length < 1) {
    ElMessage.error("请先绑定物料！");
    return;
  }
  const { code } = await saveBatch(array.value);
  if (code == "200") {
    ElMessage.success("采集成功！");
    handleClose();
    emits("dataList");
    emits("close");
  }
};
const showData = computed(() => {
  const array = ref([]);
  batchNoTableData.value.forEach((el) => {
    if (el.ok == false) {
      el.selectSeq.forEach((item) => {
        if (item.num != 0) {
          array.value.push(item);
        }
      });
    }
  });
  return array.value;
});
const handleClose = () => {
  emits("update:modelValue", false);
};
</script>

<style lang="scss" scoped>
.btns {
  height: 8vh;
  display: flex;
  justify-content: space-evenly;
  align-items: center;
}
.el-divider {
  margin-top: 0;
}
.seqTable {
  border-radius: 16px;
}
.header {
  @include flex;
  width: 100%;
  margin: $p10 0;

  .inputBox {
    width: 75%;
  }
}

.describeText {
  line-height: 25px !important;
}

.infoBox {
  width: 100%;
  height: 200px;
  border-radius: 16px;
  display: flex;
  justify-content: space-between;
  padding: $p20;
  border-radius: 16px;

  .leftInfo {
    display: flex;
    flex-direction: column;
    justify-content: space-between;

    div {
      text-align: left !important;
    }
  }

  .rightBox {
    display: flex;
    flex-direction: column;
    justify-content: space-between;

    .sumBox {
      width: 180px;
      height: 80px;
      padding-bottom: 40px;
      text-align: left;

      .describeText {
        text-align: left;
        line-height: 30px;
      }

      .sum {
        font-size: $f38;
        font-weight: bold;
        line-height: 20px;
      }
    }
  }
}

.body {
  padding: 0 $p20;

  .info {
    width: 100%;
    height: 70px;
    padding: 0 $p20;
    background-color: white;
    border-radius: 16px;
    line-height: 70px;
  }
}
</style>
