<!--
  @description: 保证金退还审批
  @Modifier: sunxinman/haofengxian
  @routerPath:fee/bailfeeRefundAudit-detail
  @date: 2020/04/03-15:01
-->
<template>
  <div class="p0-16">
    <section class="title clearfix">
      <!-- 返回 -->
      <div class="title-back pointer" @click="back()">
        <i class="iconfont icon-fanhui mr10" />保证金退还审批
      </div>
    </section>
    <!--项目信息、退款明细组件-->
    <bailfeeRefundDetail :audit-status="$route.params.auditStatus" />
    <template v-if="$route.params.auditStatus === '00'">
      <div class="page-title">
        执行审批 <span class="red-star">说明：以下针对未单条驳回的记录操作。</span>
      </div>
      <table class="tableData">
        <tr class="singleRow">
          <td><span class="red-star">*</span>审批意见</td>
          <td>
            <el-input
              v-model="formDataAudit.operateReason"
              :autosize="{ minRows: 4, maxRows: 4 }"
              type="textarea"
              maxlength="4000"
              show-word-limit
              style="width: 100%"
            />
          </td>
        </tr>
        <tr class="singleRow">
          <td>审批附件</td>
          <td>
            <upload
              ref="upload"
              :data="cashDepositRefundAuditAddData"
              :auto-delete="true"
              :auto-upload="true"
              :limit="1"
              title=""
              file-ref="fileRef"
            />
          </td>
        </tr>
      </table>
    </template>
    <!-- 操作按钮 -->
    <div class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <template v-if="$route.params.auditStatus === '00'">
            <el-button :loading="confirmLoading" type="primary" @click="audit">
              审批通过
            </el-button>
            <el-button :loading="confirmLoading" @click="noAudit">
              审批不通过
            </el-button>
          </template>
          <el-button type="primary" @click="exportAuditDetailList">
            导出【付款审批单】
          </el-button>
          <el-button :loading="confirmLoading" @click="back">
            返 回
          </el-button>
          <!-- <el-button>加签</el-button>
          <el-button>后置加签执行董事</el-button> -->
        </div>
      </div>
    </div>
  </div>
</template>
<script>
/* 接口*/
import { auditPassOrReject, exportAuditDetailList } from '@api/fee/bailfee'
import { cashDepositMixin } from '../mixins/cashDepositMixin'
import { cashDepositGroupMixin } from '../mixins/cashDepositGroupMixin'
/* 组件*/
import upload from '@comp/common/updownload/upload'// 文件上传
import bailfeeRefundDetail from './bailfeeRefund-detail'
import { download } from '@assets/js/utils'// 常用方法

export default {
  name: 'BailfeeRefundAuditDetail',
  components: {
    upload,
    bailfeeRefundDetail
  },
  mixins: [cashDepositMixin, cashDepositGroupMixin],
  data() {
    return {
      confirmLoading: false,
      refundId: this.$route.params.refundId, // 退款主表id
      totalMoney: 0.00, // 退款金额统计
      tableData: [],
      // 项目信息
      formData: {
        packName: '', // 标段名称
        packNo: '', // 标段编号
        tenderName: '', // 项目名称
        tenderNo: ''// 项目编号
      },
      // 审批信息
      formDataAudit: {
        auditStatus: '', // 审批状态  00待审批 01通过 02驳回
        operateReason: '', // 审批意见
        refundIds: ''// 退款主键id
      },
      // 查看退款明细
      dialogDataRefund: {
        dialog: false, // 查看退款明细弹框
        refundDetailId: ''// 退款明细id
      }
    }
  },
  created() {
    this.cashDepositRefundAuditAddData.bizId = this.refundId // 主键id
  },
  methods: {
    // 返回
    back() {
      this.$router.push('/fee/bailfeeRefundAudit-list')
    },
    // 审核通过
    audit() {
      this.$confirm('确认审批通过?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        this.axiosAudit('01')
      }).catch(() => {

      })
    },
    // 审核不通过
    noAudit() {
      this.$confirm('确认审批不通过?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        this.axiosAudit('02')
      }).catch(() => {
      })
    },
    // 退款申请
    axiosAudit(auditStatus) {
      this.formDataAudit.refundIds = this.refundId // 主键id
      this.formDataAudit.auditStatus = auditStatus// 审批状态 01通过 02驳回
      // 审批意见是否为空
      if (this.formDataAudit.operateReason) {
        this.confirmLoading = true
        auditPassOrReject(this.formDataAudit).then(() => {
          this.$message({
            type: 'success',
            message: '提交成功'
          })
          this.back()
          this.confirmLoading = false
        }).catch(() => {
          this.confirmLoading = false
        })
      } else {
        this.$message({
          message: '请输入审批意见',
          type: 'warning'
        })
      }
    },
    // 导出物料
    exportAuditDetailList() {
      const data = {
        packId: this.$route.params.packId,
        refundId: this.$route.params.refundId
      }
      exportAuditDetailList(data).then(res => {
        download(res, '付款审批单.xls')
      })
    }
  }
}
</script>
<style lang="less" scoped>

</style>
