<script>
import { DOCUMENTSRETURN } from "@/api/business/purchase/task";
export default {
  name: "DocumentsReturnDialog",
  props: {
    selectData: {
      type: [Array],
      require: true,
    },
  },
  components: {},
  data() {
    return {
      title: "退回需求",
      visible: false,
      loading: false,
      params: { baskCause: "" },
    };
  },
  computed: {
    disabled: {
      get() {
        return !this.selectData.length;
      },
      set() {},
    },
  },
  watch: {},
  methods: {
    //
    open() {
      this.visible = true;
    },
    //
    hide() {
      this.visible = false;
      this.params.baskCause = "";
    },
    //
    async submit(prop) {
      try {
        // try
        this.loading = true;
        const {
          params: { baskCause },
        } = this;
        const documentIds = prop.map((item) => item.id);
        const { msg, code } = await DOCUMENTSRETURN({
          baskCause,
          documentIds,
        });
        if (code === 200) {
          this.hide();
          this.$emit("success");
          this.$notify.success({ title: msg });
        }
      } catch (err) {
        // catch
      } finally {
        // loading
        this.loading = false;
      }
    },
  },
  created() {},
  mounted() {},
  destroyed() {},
};
</script>

<template>
  <el-button
    v-bind="$attrs"
    v-on="$listeners"
    :disabled="disabled"
    @click="open"
  >
    {{ title }}
    <el-dialog
      :title="title"
      :visible.sync="visible"
      width="25%"
      append-to-body
      @close="hide"
    >
      <div slot="footer" class="dialog-footer">
        <el-button
          :size="$attrs.size"
          :loading="loading"
          @click="visible = false"
          >取 消</el-button
        >
        <el-button
          type="primary"
          :size="$attrs.size"
          :loading="loading"
          @click="submit(selectData)"
          >确 认</el-button
        >
      </div>
      <el-alert
        title="请填写退单原因"
        type="info"
        show-icon
        :closable="false"
        style="margin-bottom: 10px"
      >
      </el-alert>
      <el-form
        :size="$attrs.size"
        :model="params"
        label-width="0px"
        label-position="right"
        style="padding: 0"
      >
        <el-form-item prop="" label="">
          <el-input v-model="params.baskCause"> </el-input>
        </el-form-item>
      </el-form>
    </el-dialog>
  </el-button>
</template>

<style scoped></style>
