<!--
  @description: 供应商申报材料-初审审核
  @Modifier:肖文龙
  @routerPath:/supplierDeclaration/editorDeclaration-detail
  @date: 2020/2/21-15:41
-->
<template>
  <div>
    <section class="title p0-16 clearfix">
      <!-- 返回 -->
      <div class="title-back pointer" @click="back()">
        <i class="iconfont icon-fanhui mr10" />{{ title }}
      </div>
    </section>
    <!-- 审报材料-预览组件 -->
    <editorDeclarationDetail />
    <!--操作按鈕-->
    <div class="but_footer">
      <div v-if="isAuditReason" class="p0-16">
        <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="btnLoding" type="primary" @click="passOpen()">-->
          <el-button :loading="btnLoding" type="primary" @click="verified()">
            审核通过
          </el-button>
          <el-button :loading="btnLoding" @click="auditFail()">
            审核不通过
          </el-button>
          <el-button @click="back()">
            返 回
          </el-button>
        </div>
      </div>
    </div>
    <!--供应商入库申请表-弹框-->
    <storageApplicationFormAdd ref="editorDeclarationPassed" :apply-data="applyData" @call-back="back" />
  </div>
</template>
<script>
/* api */
import { auditDepartInfo } from '@api/supplier/supplierBaseInfo' // 入库审核

import { queryDeclarationInfo } from '@api/supplier/declaraTionrecord' // 申请信息

import { changeSupplierInfoAudit } from '@/api/supplier/supplierChange' // 变更审核
import { updateAuditDeclarationInfo } from '@/api/supplier/declaraTionrecord'
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { supplierGroupMixin } from '@/views/supplier/mixins/supplierGroupMixin.js'
/* 组件 */
import storageApplicationFormAdd from '@/views/supplier/editorDeclaration/storageApplicationFrom/storageApplicationFormAdd-dialog.vue' // 供应商入库申请表
import editorDeclarationDetail from './../editorDeclarationContent/editorDeclaration-detail'// 审报材料-预览组件

export default {
  name: 'EditorDeclarationDetail',
  components: {
    editorDeclarationDetail, // 审报材料-预览组件
    storageApplicationFormAdd // 申报审核通过-供应商入库申请表-弹框
  },
  mixins: [ListMixin, supplierGroupMixin],
  data() {
    return {
      // 审核-入库申请弹窗数据
      applyData: {
        id: '', // 调查报告
        isNewSupplier: null, // 是否是新供应商
        nvestigationMethod: '', // 调查方式
        reason: null, // 推荐理由
        supplyScopeId: '' // 申报供应范围
      },
      btnLoding: false, // 按钮Loding
      bizType: this.$route.params.bizType, // 审核类型
      title: '', // 标题
      isAuditReason: true, // 审核意见
      // 审核信息参数
      auditInfoParam: {
        auditFlag: '', // 01-审核通过 ||02-审核不通过
        auditOpinion: '', // 审核意见,
        ids: this.$route.params.bizId // 供应商departInfoId
      }
    }
  },
  created() {
    this.loadData() // 初始化数据
  },
  methods: {
    // 初始化数据
    loadData() {
      if (this.bizType === '00') {
        this.title = '供应商入库审核'
        this.isAuditReason = true
      } else if (this.bizType === '01') {
        this.title = '供应商申报'
        this.isAuditReason = true
      } else if (this.bizType === '02') {
        this.title = '申报材料变更'
        this.isAuditReason = true
      }
    },
    // 操作审核通过不通过调用接口
    auditProject() {
      this.btnLoding = true // 按钮Loding
      if (this.bizType === '02') {
        this.auditInfoParam.departId = this.$route.params.departId
        changeSupplierInfoAudit(this.auditInfoParam).then(reponse => {
          this.$message({
            type: 'success',
            message: '审核成功'
          })
          this.btnLoding = false // 按钮Loding
          this.back()// 返回
        }).catch(() => {
          this.btnLoding = false // 按钮Loding
        })
      } else if (this.bizType === '01') {
        updateAuditDeclarationInfo(this.auditInfoParam).then(reponse => {
          this.$message({
            type: 'success',
            message: '审核成功'
          })
          this.btnLoding = false // 按钮Loding
          this.back()// 返回
        }).catch(() => {
          this.btnLoding = false // 按钮Loding
        })
      } else {
        auditDepartInfo(this.auditInfoParam).then(reponse => {
          this.$message({
            type: 'success',
            message: '审核成功'
          })
          this.btnLoding = false // 按钮Loding
          this.back()// 返回
        }).catch(() => {
          this.btnLoding = false // 按钮Loding
        })
      }
    },
    // 审核通过
    verified() {
      if (this.bizType === '01') {
        // this.passOpen()
        if (this.auditInfoParam.auditOpinion) {
          this.$confirm('确认提交?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            confirmButtonClass: 'confirmBtn',
            cancelButtonClass: 'cancelBtn',
            type: 'warning'
          }).then(() => {
            updateAuditDeclarationInfo({
              id: this.$route.params.bizId, // 主键id
              ids: this.$route.params.bizId, // 主键id
              auditOpinion: this.auditInfoParam.auditOpinion, // 审核意见
              auditStatus: '01', // 审核状态
              supplierId: this.$route.params.supplierId,
              departId: this.$route.params.departId
            }).then(res => {
              this.$message({
                message: '审核提交成功',
                type: 'success'
              })
              this.auditInfoParam.auditFlag = '01' // 审核通过
              this.auditProject()
            })
          }).catch(() => {
          })
        } else {
          this.$message({
            type: 'warning',
            message: '请输入审核意见'
          })
        }
      } else {
        this.$confirm('确认提交?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          confirmButtonClass: 'confirmBtn',
          cancelButtonClass: 'cancelBtn',
          type: 'warning'
        }).then(() => {
          this.auditInfoParam.auditFlag = '01' // 审核通过
          this.auditProject()
        }).catch(() => {
        })
      }
    },
    // 审核不通过
    auditFail() {
      if (this.auditInfoParam.auditOpinion) {
        this.$confirm('确认审核不通过?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          confirmButtonClass: 'confirmBtn',
          cancelButtonClass: 'cancelBtn',
          type: 'warning'
        }).then(({ value }) => {
          this.auditInfoParam.auditFlag = '02' // 审核不通过
          this.auditProject()
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消提交'
          })
        })
      } else {
        this.$message({
          type: 'warning',
          message: '请输入审核意见'
        })
      }
    },
    // 审核-入库申请弹窗数据请求
    queryDeclarationInfo() {
      const id = this.auditInfoParam.ids
      queryDeclarationInfo(id).then((res) => {
        this.applyData = res.data.data
      })
    },
    // 申报审核通过弹框
    passOpen() {
      // 审核-入库申请弹窗数据请求
      this.queryDeclarationInfo()
      // 调用子组件方法打开申报审核弹窗
      this.$refs.editorDeclarationPassed.openDialog()
    },
    // 返回
    back() {
      // path supplierAuditList 供应商审核；supplierOurCompanyAudit-list 供应商本单位审核
      const path = this.$route.meta.path
      if (path === 'supplierAuditList') {
        this.$router.push({
          path: '/supperManagement/supplierAuditList'
        })
      } else if (path === 'supplierOurCompanyAudit-list') {
        this.$router.push({
          path: '/supperManagement/supplierOurCompanyAudit-list'
        })
      }
    }
  }
}
</script>

<style lang="less" scoped>
// 申报图片
.supper_auditStatus{
  position: absolute;
  top: 10px;
  right:100px;

}
</style>
