<script>
import { shutDownSummary } from "@/api/purchase/DemandSummary.js";
export default {
  name: "CloseLine",
  props: {
    selectData: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {};
  },
  computed: {
    disabled: {
      get() {
        const { selectData } = this.$props;
        return !selectData.length;
      },
      set() {},
    },
  },
  methods: {
    async useClick() {
      const { selectData } = this.$props;
      let demand = selectData.some((item) => item.demandNum >= 2);
      let ids = selectData.map((item) => item.demandItemId);
      if (demand) {
        this.$modal
          .confirm("选中项有多个需求单位,是否确定关闭?")
          .then(async () => {
            await this.closeItem(ids);
          })
          .catch(() => {});
      } else {
        await this.closeItem(ids);
      }
    },
    // 关闭
    async closeItem(prop) {
      let params = prop.join();
      try {
        let { code, msg } = await shutDownSummary(prop);
        if (code == 200) {
          this.$modal.notifySuccess(msg);
          this.$emit("refresh");
        }
      } catch (error) {}
    },
  },
  created() {},
};
</script>

<template>
  <el-button :size="$attrs.size" :disabled="disabled" @click="useClick"
    >行关闭</el-button
  >
</template>
