<!--
  @description:采购计划审核
  @Modifier: haofengxian
  @routerPath:
  @date: 2021-11-05 11:53
-->
<template>
  <div class="p0-16">
    <!--标题-->
    <section class="title">
      <i class="iconfont icon-fanhui pointer" @click="back()" />
      采购计划审核
    </section>
    <!--采购计划详情-->
    <procurementPlanIsAuditComp />
    <!--待审核显示-->
    <div v-if="planAuditStatus==='00'" class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <el-button type="primary" @click="onAudit('01')">
            通过
          </el-button>
          <el-button @click="onAudit('02')">
            退回
          </el-button>
        </div>
      </div>
    </div>
    <!--  退回弹框-->
    <procurementPlanAuditSendBackDialog :dialog-back-data="dialogBackData" @onEnters="enters" />
  </div>
</template>

<script>
// api
import { purchasePlanAuditByLeader } from '@/api/procurement/purchasplan'
/* 组件*/
import procurementPlanAuditSendBackDialog from './procurementPlanAuditSendBack-dialog' // 退回弹框
import procurementPlanIsAuditComp from '../purPlanning/procurementPlanIDetailComp'

export default {
  name: 'AuditProcurementPlanContent',
  components: {
    procurementPlanAuditSendBackDialog, // 退回弹框
    procurementPlanIsAuditComp // 计划详情组件
  },
  data() {
    return {
      // 退回弹框
      dialogBackData: {
        dialogVilideBack: false // 退回弹框状态
      },
      planMainId: '', // 采购计划id
      planAuditStatus: '' // 审核状态 00 待审核 01审核通过 02审核不通过
    }
  },
  created() {
    this.planMainId = this.$route.params.planMainId
    this.planAuditStatus = this.$route.params.planAuditStatus
  },
  methods: {
    // 返回按钮
    back() {
      this.$router.push({ path: '/procurement/procurementPlanAuditList' })
    },
    // 通过 01通过 02退回
    onAudit(res) {
      if (res === '02') {
        this.dialogBackData.dialogVilideBack = true
      } else {
        this.$confirm('确认审核通过吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          confirmButtonClass: 'confirmBtn',
          cancelButtonClass: 'cancelBtn',
          type: 'warning'
        }).then(() => {
          this.auditByLeader({ code: res })
        })
      }
    },
    // 审核确认接口请求
    auditByLeader(res) {
      const params = {
        planMainId: this.planMainId,
        auditStatus: res.code,
        auditReason: res.inp
      }
      purchasePlanAuditByLeader(params).then((res) => {
        if (res) {
          this.$router.push({ path: '/procurement/procurementPlanAuditList' })
        }
      })
    },
    // 退回弹框关闭
    enters(res) {
      this.dialogBackData.dialogVilideBack = res.flg
      this.auditByLeader(res)
    }
  }
}
</script>

<style scoped>

</style>
