<!-- 行关闭 -->
<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() {},
    },
    disabled: {
      get() {
        let { innerValue } = this;

        if (innerValue.length > 0) {
          return false;
        }
        return true;
      },
      set() {},
    },
  },
  methods: {
    async open() {
      let { innerValue } = this;

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

      if (!data && innerValue.length) {
        this.$prompt("请输入关闭原因", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          inputPattern: /\s*\S+?/,
          inputErrorMessage: "关闭原因不能为空",
        })
          .then(async ({ value }) => {
            try {
              let puOrderIds = innerValue.map((order) => Number(order.id));

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

              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" :disabled="disabled">{{
    title
  }}</el-button>
</template>
