
<!--
 * @Description: 部门经理-审核采购单-中选审核-最低成交价审核
 * @Author: wxy/gmy
 * @routerPath:/procurement/procurementLowestAuditAdd
 * @Date: 2020-07-14 11:55:32
-->
<template>
  <div>
    <div class="title title_border p0-16">
      <i class="iconfont icon-fanhui pointer" @click="back()" />
      中选审核
    </div>
    <procurementResultGoodsAllotComp :goods-data="goodsData" :is-detail="isDetail" />
    <section class="mb16 main">
      <el-form ref="form" :model="auditData" :rules="rules" :inline-message="true">
        <table class="from_table">
          <tr class="singleRow">
            <td>
              <el-form-item label="审核意见" prop="auditReason" />
            </td>
            <td>
              <el-input
                v-model="auditData.auditReason"
                :autosize="{ minRows: 4, maxRows: 4 }"
                type="textarea"
                maxlength="1000"
                show-word-limit
                style="width:100%"
              />
            </td>
          </tr>
        </table>
      </el-form>
    </section>
    <!--操作按钮-->
    <div class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <!-- 审核按钮 -->
          <el-button :loading="confirmLoading" type="primary" @click="auditYetSignUp()">
            审核通过
          </el-button>
          <el-button :loading="confirmLoading" @click="auditNoSignUp('form')">
            审核不通过
          </el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { auditWinningResult } from '@/api/procurement/procurementResult' // 获取行项目信息
/* 组件 */
import procurementResultGoodsAllotComp from '@/views/procurement/procurementResult/procurementResultGoodsAllot/procurementResultGoodsAllotComp'
/* 校验方法*/
import { characters1_auto } from '@/assets/js/validate'
export default {
  name: 'ProcurementWinningLowestAuditAdd',
  components: {
    procurementResultGoodsAllotComp
  },
  data() {
    return {
      confirmLoading: false,
      isDetail: true,
      // 业务参数
      goodsData: {
        tenderId: ''// 项目id
      },
      auditData: {
        auditStatus: '', // 审核表示02驳回,01通过
        auditReason: '', // 审核意见
        winningIds: '' // 审核项目id
      },
      // 校验规则
      rules: {
        auditReason: [
          { required: true, validator: characters1_auto, trigger: 'blur' }
        ] // 审核意见
      }
    }
  },
  created() {
    this.init()// 初始化
  },
  methods: {
    // 初始化
    init() {
      this.goodsData.tenderId = this.$route.params.tenderId // 项目id
    },
    // 保存数据方法
    assestData() {
      const data = {
        winningIds: this.$route.params.winningId, // 中选id
        auditStatus: this.auditData.auditStatus, // 审核字段 01 通过 02 驳回
        auditReason: this.auditData.auditReason // 审核意见
      }
      return data
    },
    // 审核通过
    auditYetSignUp() {
      // 审核通过auditStatus 01
      this.$confirm('确认审核通过吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        this.auditData.auditStatus = '01'
        this.auditWinningResultData()
      }).catch(() => {
        this.confirmLoading = false
      })
    },
    // 审核不通过
    auditNoSignUp(formName) {
      // 审核通过auditStatus 02
      this.auditData.auditStatus = '02'
      this.$refs[formName].validate(valid => {
        if (valid) {
          // 审核通过auditStatus 01
          this.$confirm('确认审核不通过吗？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            confirmButtonClass: 'confirmBtn',
            cancelButtonClass: 'cancelBtn',
            type: 'warning'
          }).then(() => {
            this.auditData.auditStatus = '02'
            this.auditWinningResultData()
          }).catch(() => {
            this.confirmLoading = false
          })
        } else {
          this.confirmLoading = false
        }
      })
    },
    // 封装审核方法
    auditWinningResultData() {
      this.confirmLoading = true
      const data = this.assestData()
      auditWinningResult(data).then(res => {
        this.$message.success({ message: '操作成功' })
        this.confirmLoading = false
        this.$router.push({ path: '/procurement/procurementAuditList' })
      }).catch(() => {
        this.confirmLoading = false
      })
    },
    // 返回按钮
    back() {
      this.$router.push({ path: '/procurement/procurementAuditList' })
    }
  }
}
</script>

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