<script>
import { confirmSummary, cancelSummary } from "@/api/purchase/DemandSummary.js";
export default {
  name: "ConfirmBtn",
  props: {
    selectData: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {};
  },
  computed: {
    disabled: {
      get() {
        const { selectData } = this.$props;
        return !selectData.length;
      },
      set() {},
    },
    innerValue: {
      get() {
        const { selectData } = this.$props;
        return selectData;
      },
      set() {},
    },
  },
  methods: {
    // 确认
    async useConfirms() {
      try {
        this.$modal.loading("处理中，请稍后......");
        let { code, msg } = await confirmSummary(this.innerValue);
        if (code == 200) {
          this.$notify.success(msg);
          this.$emit("refresh");
        }
      } catch (error) {
      } finally {
        this.$modal.closeLoading();
      }
    },
    // 取消确认
    async useUnconfirm() {
      try {
        this.$modal.loading("处理中，请稍后......");
        let params = this.innerValue.map((item) => item.demandItemId).join();
        let { code, msg } = await cancelSummary(params);
        if (code == 200) {
          this.$notify.success(msg);
          this.$emit("refresh");
        }
      } catch (error) {
      } finally {
        this.$modal.closeLoading();
      }
    },
  },
  created() {},
};
</script>

<template>
  <el-button-group>
    <el-button
      type="primary"
      :size="$attrs.size"
      :disabled="disabled"
      @click="useConfirms"
      >确 认</el-button
    >
    <el-button :size="$attrs.size" :disabled="disabled" @click="useUnconfirm"
      >取消确认</el-button
    >
  </el-button-group>
</template>
