<!--
 * @Description: 详情弹框
 * @Author: Sugar.
 * @Date: 2023-11-24 13:55:00
 * @LastEditors: Sugar.
 * @LastEditTime: 2023-11-24 13:55:00
 * @FilePath: \cattle_webui\src\views\finance\refundMr\dialog\details.vue
 * @Copyright: Copyright (c) 2016~2023 by Sugar., All Rights Reserved.
-->
<template>
  <el-dialog
    title="退款详情"
    :visible.sync="open"
    width="500px"
    append-to-body
    :close-on-click-modal="false"
    @close="cancel"
  >
    <div class="dialog" v-if="form">
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple item-class">退款单号: <span>{{ form.id }}</span></div>
        </el-col>
        <el-col :span="24">
          <div class="grid-content bg-purple item-class">原订单号: <span>{{ form.orderId }}</span></div>
        </el-col>
        <el-col :span="24">
          <div class="grid-content bg-purple item-class">支付单号: <span>{{ form.transactionId }}</span></div>
        </el-col>
        <el-col :span="24">
          <div class="grid-content bg-purple item-class">退款金额: <span>￥{{ form.refundAmount }}</span></div>
        </el-col>
        <el-col :span="24">
          <div class="grid-content bg-purple item-class">退款原因: <span>{{ form.refundReason }}</span></div>
        </el-col>
        <el-col :span="24">
          <div class="grid-content bg-purple item-class">状态: <span>{{ statusList[form.status] }}</span></div>
        </el-col>
        <el-col :span="24">
          <div class="grid-content bg-purple item-class">备注: <span>{{ form.remark }}</span></div>
        </el-col>
        <el-col :span="24" v-if="form.status == 2">
          <div class="grid-content bg-purple item-class">驳回原因: <span style="color: red;">{{ form.errReason }}</span></div>
        </el-col>
      </el-row>
    </div>

    <span slot="footer" class="dialog-footer" v-if="!refund">
      <el-button type="primary" @click="cancel">确定</el-button>
    </span>

    <span slot="footer" class="dialog-footer" v-if="refund">
<!--      <el-button @click="cancel">取消</el-button>-->
      <el-button
        type="danger"
        @click="submitForm(2)"
        v-loading.fullscreen.lock="loading"
        element-loading-text="提交中..."
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.8)"
      >
        <span v-if="loading">提交中...</span>
        <span v-else>驳回退款</span>
      </el-button>
      <el-button
        type="primary"
        @click="submitForm(1)"
        v-loading.fullscreen.lock="loading"
        element-loading-text="提交中..."
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.8)"
      >
        <span v-if="loading">提交中...</span>
        <span v-else>同意退款</span>
      </el-button>
    </span>

  </el-dialog>
</template>

<script>
import { pageList, refundAudit } from '@/api/financeMr/refundMr'
import Editor from "@/components/Editor";
import { saveAndEdit } from '@/api/ticketMr/priceMr'
import isEmpty from 'voca/is_empty'
export default {
  name: "detailsDia",
  components: {
    Editor,
  },
  data() {
    return {
      title: "编辑",
      model: "EDIT",
      open: false,
      loading: false,
      form: {
        id: undefined,
      },
      performerVisible: false,
      performerList: [],
      refund: false,
      statusList: {
        0: '申请中',
        1: '退款成功',
        2: '退款驳回',
        3: '退款中',
        4: '退款失败',
      }
    };
  },
  methods: {
    /**
     * 打开弹框
     * @date 2023-11-22
     * @param {any} obj
     * @returns {any}
     */
    openDialog(title, obj, type) {
      this.open = true;
      this.form = obj;
      if (type){
        this.refund = true
      } else {
        this.refund = false
      }
    },
    inputValidatorEn(value) {
      if(isEmpty(value)) {
        return false
      } else {
        return true
      }
    },
    /**
     * 保存
     * @date 2023-11-22
     * @returns {any}
     */
    submitForm(status) {
      this.$confirm('是否' + ( status == 1 ? '确定' : '驳回' ) + '退款?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if(status == 2){
          this.$prompt('驳回理由', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            inputValidator: this.inputValidatorEn,
            inputErrorMessage: '请输入驳回理由'
          }).then(({ value }) => {
            this.refundAuditApi(status, value);
          }).catch(() => {});
        } else {
          this.refundAuditApi(status, '');
        }
      }).catch(() => {});
    },
    refundAuditApi(status, value) {
      this.loading = true;
      refundAudit({ refundId: this.form.id, status: status, errReason: value})
        .then(response => {
            this.$message.success("操作成功!");
            this.$emit("getList");
            this.cancel();
            this.loading = false;
          }
        ).catch(() => {
        this.loading = false;
      });
    },
    /**
     * 关闭弹框
     * @date 2023-11-22
     * @returns {any}
     */
    cancel() {
      this.open = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.dialog {
  padding: 0 30px;
  max-height: 65vh;
  overflow-y: auto;
}
.dialog {
  padding: 0 30px;
  .upload-btn {
    width: 100px;
    height: 100px;
    background-color: #fbfdff;
    border: dashed 1px #c0ccda;
    border-radius: 5px;
    i {
      font-size: 30px;
      margin-top: 20px;
    }
    &-text {
      margin-top: -10px;
    }
  }
  .avatar {
    cursor: pointer;
  }
  .title-class{
    font-size: 16px;
    font-weight: bold;
    color: black;
    margin-bottom: 20px;
    margin-top: 20px;
  }
  .item-class{
    margin-bottom: 20px;
  }
}
</style>
