<script>
import { deleteApplies } from "@/api/requisition/basic";
export default {
  name: "PiLiangShanChu",
  props: {
    selectData: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      title: "批量删除",
    };
  },
  computed: {
    disabled: {
      get() {
        let { selectData } = this.$props;

        if (selectData.length > 0) {
          return false;
        }
        return true;
      },
      set() {},
    },
  },
  methods: {
    async onClick() {
      // 单据状态：0-自由态；3-已驳回；9-已回退
      let delStatus = ["0", "3", "9"];
      let { selectData } = this.$props;
      let del = selectData.filter(
        (item) => delStatus.findIndex((d) => d == item.status) === -1
      );
      if (del.length > 0) {
        return this.$notify.warning({
          message: "不允许删除非[自由态、已驳回、已退回]的单据！",
        });
      }

      this.$confirm("确认批量删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          try {
            this.$modal.loading("处理中...");
            let ids = selectData.map((item) => item.id);
            console.log(ids, "ids");
            let { code, msg } = await deleteApplies({ ids });
            if (code == 200) {
              this.$notify.success({ message: msg });
              this.$emit("success");
            }
          } catch (error) {
          } finally {
            this.$modal.closeLoading();
          }
        })
        .catch(() => {
          // this.$emit("success");
        });
    },
  },
  created() {},
};
</script>
<template>
  <el-button @click="onClick" :disabled="disabled" :size="$attrs.size">
    {{ title }}
  </el-button>
</template>
