<script>
import { rebacktWork } from "@/api/purchase/workSpace.js";
export default {
  name: "OpenOrClose",
  dicts: ["oa_templete_id"],
  props: {
    selectData: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      // title: "撤回",
      title: "作废",
      loading: false,
    };
  },
  computed: {
    disabled: {
      get() {
        const { selectData } = this;
        if (selectData.length < 1) {
          return true;
        }
        return false;
      },
      set() {},
    },
  },
  methods: {
    //收回
    async useClick() {
      try {
        this.$modal.loading("收回中...");
        let row = this.selectData[0];
        let params = {
          billCode: row.code,
          fdId: row.flowId,
          fdTemplateId: this.dict.type.oa_templete_id.find((item) => {
            return item.label == "采购需求单";
          }).value,
          billMaker: row.createBy,
        };

        let { code, msg } = await rebacktWork(params);
        if (code === 200) {
          this.$notify.success(msg);
          this.$emit("success");
        }
      } catch (error) {
      } finally {
        this.$modal.closeLoading();
      }
    },
  },
  created() {},
};
</script>

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