<template>
  <div v-if="detail">
    <reviewDetail v-if="detail"
                  :detail="detail" />
    <el-alert style="margin: 20px 0;"
              title="审核意见"
              :closable="false"
              class="alert"
              type="info"
              v-if="detail.status=='AUDITING'">
    </el-alert>
    <el-input v-if="detail.status=='AUDITING'"
              type="textarea"
              :autosize="{ minRows: 2, maxRows: 4 }"
              placeholder="请输入审核意见"
              v-model="remark">
    </el-input>
    <div slot="footer"
         class="dialog-footer"
         v-if="detail.status=='AUDITING'">
      <!-- <el-button @click="$listeners.close">取 消</el-button> -->
      <el-button type="primary"
                 @click="submit(1)"
                 v-if="permission('musicGroupPaymentCalender/auditPass')">审核通过</el-button>
      <el-button type="danger"
                 @click="submit(0)"
                 v-if="permission('musicGroupPaymentCalender/auditRefuse')">驳回</el-button>
      <el-button @click="$emit('close')">关 闭</el-button>
    </div>
    <div slot="footer"
         class="dialog-footer"
         v-else>
      <el-button type="primary"
                 @click="$listeners.close">关闭</el-button>
    </div>
  </div>
</template>
<script>
import { permission } from '@/utils/directivePage'
import Vue from "vue";
import reviewDetail from "./review-detail";
import { auditPass, auditRefuse } from "@/api/auditManager";
export default {
  props: ["detail"],
  components: {
    reviewDetail,
  },
  data () {
    return {
      remark: "",
    };
  },
  methods: {
    async submit (val) {
      if (!this.remark) {
        return this.$message.error("请输入审核意见");
      }
      if (val) {
        try {
          await this.$confirm('是否确认审核通过', '提示', {
            type: 'warning'
          })
          await auditPass({ batchNo: this.detail.batchNo, auditMemo: this.remark }).then((res) => {
            if (res.code == 200) {
              this.$message.success('审核通过')
              this.$emit('close')
            }
          });
        } catch (error) {}
      } else {
        try {
          await this.$confirm('是否确认驳回', '提示', {
            type: 'warning'
          })
          await auditRefuse({ batchNo: this.detail.batchNo, auditMemo: this.remark }).then((res) => {
            if (res.code == 200) {
              this.$message.success('驳回成功')
              this.$emit('close')
            }
          });
        } catch (error) {}
      }
    },
    permission (str) {
      return permission(str)
    }
  },
};
</script>
<style lang="less" scoped>
.dialog-footer {
  margin-top: 20px;
  display: block;
  text-align: right;
}
</style>
