<!--
  @description:不合格供应商加入/移除审核
  @Modifier:qrf
  @routerPath:
  @date:2020/9/17-14:27
-->
<template>
  <div class="p0-16">
    <section class="clearfix">
      <!-- 返回 -->
      <div class="title title_border" @click="back()">
        <i class="iconfont icon-fanhui mr10" />{{ headTitle }}
      </div>
    </section>
    <div>
      <table class="tableData mb10 main">
        <tr>
          <td>供应商名称</td>
          <td>{{ rowReviewInfo.supplierName }}</td>
          <td>{{ statusOrOpinion }}</td>
          <!-- 不合格供应商（加入）：处罚意见；（移除）：当前状态-->
          <td>{{ statusOrOpinionValue }}</td>
        </tr>
        <tr>
          <td>淘汰原因</td>
          <!-- 不合格供应商淘汰原因-->
          <td colspan="3">
            {{ filterDictText(freezingReasonsList, rowReviewInfo.freezingReasons) }}
          </td>
        </tr>
        <tr>
          <td>{{ TimeOrRemarks }}</td>
          <!-- 不合格供应商（加入）：处罚时间；（移除）：移除原因-->
          <td colspan="3">
            {{ TimeOrRemarksValue }}
          </td>
        </tr>
        <tr>
          <td>事件说明</td>
          <td colspan="3">
            {{ rowReviewInfo.remarks }}
          </td>
        </tr>
        <tr>
          <td>附件</td>
          <td colspan="3">
            <downloadFile :data="upLoadData" />
          </td>
        </tr>
      </table>
      <!--操作按钮-->
      <div class="but_footer">
        <div>
          <div class="page-title">
            审核意见
          </div>
          <el-form ref="auditInfoParam" :model="auditInfoParam">
            <el-form-item ref="auditReason" prop="auditReason">
              <el-input
                v-model="auditInfoParam.auditOpinion"
                :rows="4"
                type="textarea"
                placeholder="请填写审核意见"
                maxlength="200"
                show-word-limit
              />
            </el-form-item>
          </el-form>
        </div>
        <div class="but_footer-h">
          <div class="but_footer-but">
            <el-button :loading="confirmLoading" type="primary" @click="handleAudit('01')">
              审批通过
            </el-button>
            <el-button :loading="confirmLoading" @click="handleAudit('02')">
              审批不通过
            </el-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
/* api*/
import { queryBlacklistAuditInfo, updateAuditBlacklistInfo } from '@/api/supplier/supplierUnqualified.js'
/* 组件*/
import downloadFile from '@comp/common/updownload/downloadFile' // 获取附件信息 下载组件
/* 公共方法*/
import { filterDictText } from '@/assets/js/utils'
import { supplierGroupMixin } from '@/views/supplier/mixins/supplierGroupMixin.js'

export default {
  name: 'ReviewUnqualifiedDetail',
  components: {
    downloadFile // 文件下载
  },
  mixins: [supplierGroupMixin],
  data() {
    return {
      headTitle: '',
      statusOrOpinion: '', // 加入：处罚意见（ 01:暂停合格供应商资格 02:取消合格供应商资格）；移除：当前状态
      TimeOrRemarks: '', // 加入：处罚时间期限；移除：移除原因
      statusOrOpinionValue: '', // 加入：处罚意见（ 01:暂停合格供应商资格 02:取消合格供应商资格）；移除：当前状态
      TimeOrRemarksValue: '', // 加入：处罚时间期限；移除：移除原因
      confirmLoading: false,
      blacklistType: '', // 黑名单类型 01加入；02移除
      bizId: this.$route.params.id,
      dialog: false, // 弹窗状态 false 关闭 true 打开
      // 审核信息参数
      auditInfoParam: {
        auditFlag: '', // 01-审核通过 ||02-审核不通过
        auditOpinion: '', // 审核意见,
        ids: [this.$route.query.bizId]// 供应商departInfoId
      },
      uploadData: {
        bizId: '', // 业务主键Id
        fileType: 'save_blackList_Attr'// 文件类型
      },
      rowReviewInfo: {}
    }
  },
  created() {
    this.loadData()
  },
  methods: {
    filterDictText,
    // 获取数据
    loadData() {
      this.reviewSupplierDetail(this.bizId) // 获取订单详情
    },
    // 获取不合格供应商详情
    reviewSupplierDetail(id) {
      queryBlacklistAuditInfo(id).then(res => {
        this.rowReviewInfo = res.data.data
        this.uploadData.bizId = this.rowReviewInfo.bizId
        if (this.$route.params.bizType === '03') {
          this.headTitle = '不合格供应商（加入）'
          this.statusOrOpinion = '处罚意见'
          this.TimeOrRemarks = '处罚时间期限（月）'
          this.blacklistType = '01'
          this.statusOrOpinionValue = this.rowReviewInfo.punishIdea // 处罚意见
          this.statusOrOpinionValue = this.rowReviewInfo.punishTime // 处罚时间
        } else {
          this.headTitle = '不合格供应商（移除黑名单）'
          this.statusOrOpinion = '当前状态'
          this.statusOrOpinionValue = '移除黑名单'
          this.TimeOrRemarks = '移除原因'
          this.blacklistType = '02'
          this.TimeOrRemarksValue = this.rowReviewInfo.punishIdea // 移除原因
        }
      }).catch(() => {
      })
    },
    // 返回
    back() {
      this.$router.push({
        path: '/supperManagement/supplierAuditList'
      })
    },
    // 审核通过/不通过
    handleAudit(auditStatus) {
      console.log(this.rowReviewInfo)
      const params = {
        auditReason: this.auditInfoParam.auditOpinion, // 审批意见
        auditUser: this.rowReviewInfo.auditUser, // 审批人
        auditStatus: auditStatus, // 审批状态 02驳回,01通过
        ids: this.rowReviewInfo.id, // 黑名单id
        blacklistType: this.blacklistType
      }
      if (auditStatus === '01') {
        this.$confirm('是否确认通过?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          confirmButtonClass: 'confirmBtn',
          cancelButtonClass: 'cancelBtn',
          type: 'warning'
        }).then(() => {
          updateAuditBlacklistInfo(params).then(res => {
            this.$message.success(res.header.msg)
            this.$router.push('/supperManagement/supplierAuditList')
            this.$emit('loadData', {
              pageNo: 1,
              pageSize: 10
            })
          }).catch(() => {
          })
        }).catch(() => {
        })
      } else {
        this.$confirm('是否确认不通过?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          confirmButtonClass: 'confirmBtn',
          cancelButtonClass: 'cancelBtn',
          type: 'warning'
        }).then(() => {
          updateAuditBlacklistInfo(params).then(res => {
            this.$message.success(res.header.msg)
            this.$router.push('/supperManagement/supplierAuditList')
            this.$emit('loadData', {
              pageNo: 1,
              pageSize: 10
            })
          }).catch(() => {
          })
        }).catch(() => {
        })
      }
    }
  }
}
</script>
<style lang="less" scoped>

</style>
