<!-- 行关闭 -->
<script>
import orderApi from "@/api/business/purchase/purchase-order";
export default {
  name: "itemClose",
  props: {
    selectData: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      title: "行关闭",
    };
  },
  computed: {
    innerValue: {
      get() {
        return this.$props.selectData;
      },
      set() {},
    },
  },
  methods: {
    async open() {
      let { innerValue } = this;

      let data = innerValue.find((item) => item.isPayment === "Y");

      if (!data) {
        this.$confirm("是否继续此操作?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(async () => {
            try {
              let puOrderIds = innerValue.map((order) => Number(order.id));

              let { code } = await orderApi.itemClose({
                puOrderIds,
              });

              if (code === 200) {
                this.$emit("submit");
                this.$notify.success({
                  message: msg,
                });
              }
            } catch (error) {}
          })
          .catch(() => {});
      } else {
        this.$notify.warning({
          message: "存在已经完成关闭的行",
        });
      }
    },
  },
  created() {},
};
</script>
<template>
  <el-button :size="$attrs.size" @click="open">{{ title }}</el-button>
</template>
