<!--
  @description: 采购人/代理机构-委托代理合同审核-详情
  @author: 肖文龙
  @routerPath:/consignContract/ConsignContractAuditDetail
  @date： 2019-11-28 16:58:18
-->
<template>
  <div class="main">
    <consignContractDetail />
    <div class="p0-16">
      <div class="page-title">
        审批信息
      </div>
      <el-form ref="form" :model="formData">
        <el-form-item ref="tradeMeans" label="" prop="tradeMeans">
          <el-input
            v-model="formData.auditOpinion"
            :autosize="{ minRows: 4, maxRows: 4 }"
            type="textarea"
            style="width: 100%"
          />
        </el-form-item>
      </el-form>
    </div>
    <!--操作按钮-->
    <div class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <el-button type="primary" @click="submitForm('form', '02')">
            审核通过
          </el-button>
          <el-button @click="submitForm('form', '03')">
            审核不通过
          </el-button>
          <el-button @click="back">
            返 回
          </el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { auditConstractById, getContract } from '@/api/purchasePlan/taskplan'
import consignContractDetail from '@/views/purchasePlan/consignContract/consignContractManage/consignContract/consignContract-detail'
export default {
  name: 'ConsignContractAuditDetail',
  components: {
    consignContractDetail
  },
  data() {
    return {
      formData: {
        auditOpinion: ''
      }
    }
  },
  mounted() {
    const id = this.$route.params.id ? this.$route.params.id : ''
    if (id) {
      getContract(id).then(res => {
        this.formData = res.data
        this.formData.id = id
        this.formData.userId = this.$store.getters.info.id
        this.formData.contractId = id
      })
    }
  },
  methods: {
    // 提交审批
    submitForm(formName, status) {
      this.formData.auditUserId = this.$store.getters.info.userName
      this.formData.contractStatus = status
      let text = ''
      if (status === '02') {
        text = '确认审批通过？'
      } else {
        text = '确认审批不通过？'
      }
      this.$confirm(text, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        if (status === '03' && !this.formData.auditOpinion) {
          this.$message({
            type: 'warning',
            message: '请输入审核意见'
          })
          return false
        }
        this.handleAuditProject()
      }).catch(() => {
      })
    },
    // 操作审核通过不通过调用接口
    handleAuditProject() {
      auditConstractById(this.formData).then(response => {
        this.$message({
          message: '提交成功',
          type: 'success'
        })
        this.$router.push({
          path: '/consignContract/consignContractAuditList'
        })
      }).catch(() => {
      })
    },
    // 返回
    back() {
      this.$router.history.go(-1)
    }
  }
}
</script>

<style lang="less" scoped>
</style>
