<!-- 反审 -->
<script>
import { counterApprove } from "@/api/business/purchase/purchase-order";
export default {
  name: "counterApprove",
  props: {
    selectData: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      title: "反 审",
    };
  },
  computed: {
    innerValue: {
      get() {
        return this.$props.selectData;
      },
      set() {},
    },
    disabled: {
      get() {
        if (this.innerValue.length === 1) {
          return false;
        }
        return true;
      },
      set() {},
    },
  },
  methods: {
    async open() {
      let pu = this.innerValue[0];
      let puOrderIds = this.innerValue.map((item) => Number(item.id));
      if (pu.status === "2") {
        // 已审核
        try {
          this.$modal.loading("提交中...");
          let { code, msg } = await counterApprove({ puOrderIds });
          if (code == 200) {
            this.$notify.success({
              message: msg,
            });
            this.$emit("success");
          }
        } catch (error) {
        } finally {
          this.$modal.closeLoading();
        }
      } else {
        this.$notify.warning({
          message: "请选择已审核单据进行反审！",
        });
      }
    },
  },
  created() {},
  mounted() {},
};
</script>

<template>
  <el-button @click="open" v-bind="$attrs" :disabled="disabled">{{
    title
  }}</el-button>
</template>
