<template>
  <el-dialog :visible.sync="visible" title="关闭发货单" width="510px" @closed="$emit('close')">
    <div v-loading="loading">
      <div style="display:flex;align-items:center;margin-left:10px">
        <i class="el-icon-warning"></i>
        <div class="ml20" style="font-size:16px;color:#303133">确认关闭发货单吗？</div>
      </div>
      <div style="margin-left:50px;color:#303133;margin-top:10px">将恢复礼品的库存，若存在销售单请至商城应用查看退款。</div>
      <dm-input class="mt20" type="textarea" placeholder="请输入关闭原因（必填）" :maxlength="50" :rows="5" show-word-limit v-model="reason"></dm-input>
    </div>
    <div slot="footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="handleConfirm">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import fetch from '@/api/performance.js';
const { closeOrder } = fetch;

export default {
  props: {
    data: Object,
  },
  data() {
    return {
      visible: false,
      reason: '',
      loading: false,
    };
  },
  mounted() {
    this.visible = true;
  },
  methods: {
    handleConfirm() {
      if(this.reason) {
        this.loading = true;
        closeOrder({
          deliveryId: this.data.deliveryId,
          desc: this.reason,
        }).finally(() => this.loading = false);
        this.visible = false;
        this.$emit('refresh');
      } else {
        this.$message.warning('请填写关闭原因');
      }
    },
  }
};
</script>

<style lang="scss" scoped>
.el-icon-warning {
  color: #FAAD14;
  font-size: 21px;
}
</style>
