<!--
 * @Description: 部门经理-审核采购单-中选审核-综合评估法/经评审的有效最低价法
 * @Author: 2020-07-14 17:18:45
 * @routerPath:/procurement/procurementComprehensiveAuditAdd
 * @Date: 2020-07-08 14:46:16
-->
<template>
  <div class="p0-16">
    <section class="title title_border">
      <i class="iconfont icon-fanhui pointer" @click="back()" />
      中选审核
    </section>
    <div class="page-title">
      1.采购单基本信息
    </div>
    <table class="tableData">
      <tr>
        <td>采购单编号</td>
        <td>{{ projectData.tenderNo }}</td>
        <td>采购单名称</td>
        <td>{{ projectData.tenderName }}</td>
      </tr>
      <tr>
        <td>采购方式</td>
        <td>
          {{ filterDictText(tendermethodList, projectData.tenderMethod) }}
        </td>
        <td>采购单位</td>
        <td>{{ projectData.buyersName }}</td>
      </tr>
    </table>
    <h4 />
    <div class="page-title">
      2.确定成交人
    </div>
    <el-table :data="winningResultInfoList" border class="mb16 tableLimit">
      <el-table-column type="index" label="序号" width="60" align="center" />
      <el-table-column
        header-align="center"
        prop="supplierName"
        min-width="110"
        label="供应商名称"
      />
      <el-table-column
        prop="linker"
        header-align="center"
        min-width="110"
        label="联系人"
      />
      <el-table-column
        prop="linkerTel"
        header-align="center"
        align="center"
        min-width="60"
        label="联系电话"
      />
      <el-table-column
        header-align="center"
        prop="offerTime"
        align="center"
        min-width="120"
        label="报价时间"
      />
      <el-table-column
        header-align="center"
        label="最终报价(元)"
        prop="finalPrice"
        align="center"
        min-width="110"
      />
      <el-table-column
        header-align="center"
        label="排名"
        prop="sort"
        align="center"
        min-width="80"
      />
      <el-table-column
        header-align="center"
        align="center"
        min-width="60"
        label="是否中标"
      >
        <template slot-scope="scope">
          {{ scope.row.isWinBiding === '00' ? '否' : '是' }}
        </template>
      </el-table-column>
    </el-table>
    <div class="page-title">
      3.中选审核
    </div>
    <table class="tableData">
      <tr class="singleRow">
        <td>中选备注</td>
        <td colspan="3">
          {{ remark }}
        </td>
      </tr>
      <!-- <tr class="singleRow">
        <td>评标报告</td>
        <td colspan="3">
          <downloadFile :data=" orderTerms" />
        </td>
      </tr>
      <tr class="singleRow">
        <td>附件</td>
        <td colspan="3">
          <downloadFile :data=" orderTerms" />
        </td>
      </tr> -->
    </table>
    <div class="page-title">
      4.审核意见
    </div>
    <section class="mb16">
      <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="page-title">
      5.审核信息
    </div>
    <section>
      <el-table ref="smallTable" :data="auditInfoList">
        <el-table-column prop="auditTime" label="审核时间" align="center" />
        <el-table-column prop="auditUserRealName" label="审核人" header-align="center" align="center" />
        <el-table-column prop="auditStatus" align="center" label="审核状态" header-align="center">
          <template slot-scope="scope">
            {{ filterDictText(auditStatus, scope.row.auditStatus) }}
          </template>
        </el-table-column>
        <el-table-column prop="auditNotPassReason" align="left" label="审核意见" header-align="center" />
      </el-table>
    </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>
          <!-- <el-button @click="back">
            关闭
          </el-button> -->
        </div>
      </div>
    </div>
  </div>
</template>

<script>
/* api接口*/
import {
  queryBaseProcurementProjectInfo
} from '@/api/procurement/procurementProject'
import { queryBiddingWinningResultInfo, auditBiddingWinningResult } from '@api/procurement/procurementResult.js'
import pagination from '@comp/common/pagination/pagination' // 分页
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'
import { commonMxin } from '@/mixins/commonMxin'
import { orderManagementGroupMixin } from '../mixins/orderManagementGroupMixins'
import { orderManagementMixins } from '../mixins/orderManagementMixins'
/* 公共方法*/
import { filterDictText } from '@/assets/js/utils'// 常用方法
import { characters1_auto } from '@/assets/js/validate'
/* 组件*/
import downloadFile from '@comp/common/updownload/downloadFile'
export default {
  name: 'OrderManagementDetail',
  components: {
    downloadFile,
    pagination // 分页
  },
  mixins: [
    ListMixin,
    commonMxin,
    orderManagementGroupMixin,
    orderManagementMixins
  ],
  data() {
    return {
      confirmLoading: false,
      dictionaryType: ['tendermethod'], // 字典类型
      tendermethodList: [], // 采购方式
      winningResultInfoList: [], // 成交人列表
      remark: '', // 中选备注
      auditInfoList: [], // 审核信息
      auditData: {
        auditStatus: '', // 审核表示02驳回,01通过
        auditReason: '', // 审核意见
        winningIds: '' // 审核项目id
      },
      // 校验规则
      rules: {
        auditReason: [
          { required: true, validator: characters1_auto, trigger: 'blur' }
        ] // 审核意见
      }
    }
  },
  created() {
    // 页面初始
    this.pageInit()
    // 获取订单详情信息
    this.getProjectInfo()
    // 成交人列表
    this.winningResultInfo()
  },
  mounted() {},
  methods: {
    // 字典检索
    filterDictText,
    // 页面初始
    pageInit() {
      // 获取字典信息
      this.$store.dispatch('getGroupType', this.dictionaryType).then((data) => {
        // 遍历key存储相应的数据
        for (const key in data.bidTypeData) {
          /* 是否有数据*/
          if (data.bidTypeData[key]) {
            this[key] = data.bidTypeData[key]
          }
        }
      })
    },
    // 获取订单详情信息
    getProjectInfo() {
      queryBaseProcurementProjectInfo({ tenderId: this.$route.params.tenderId }).then(res => {
        this.projectData = res.data
        this.projectData.orderStatus = this.$route.params.orderStatus
      }).catch(() => {})
    },
    // 成交人列表
    winningResultInfo() {
      const params = {
        packId: this.$route.params.packId
      }
      queryBiddingWinningResultInfo(params).then((res) => {
        this.winningResultInfoList = res.data.winningSupplierList
        this.auditInfoList = res.data.data.resultAuditList
        this.remark = res.data.remark
      })
    },
    // 审核通过
    auditYetSignUp() {
      // 审核通过auditStatus 01
      this.$confirm('确认审核通过吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        this.auditData.auditStatus = '01'
        this.auditBiddingWinningResult()
      }).catch(() => {
        this.confirmLoading = false
        this.loading = 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.auditBiddingWinningResult()
          }).catch(() => {
            this.confirmLoading = false
            this.loading = false
          })
        } else {
          this.confirmLoading = false
        }
      })
    },
    // 保存数据方法
    assestData() {
      const data = {
        winningIds: this.$route.params.winningId, // 中选id
        auditStatus: this.auditData.auditStatus, // 审核字段 01 通过 02 驳回
        auditReason: this.auditData.auditReason // 审核意见
      }
      return data
    },
    // 审核
    auditBiddingWinningResult() {
      this.confirmLoading = true
      auditBiddingWinningResult(this.assestData()).then((res) => {
        this.$message.success({ message: '操作成功' })
        this.confirmLoading = false
        this.back()
      }).catch(() => {
        this.confirmLoading = false
      })
    },
    // 返回按钮
    back() {
      this.$router.push({ path: '/procurement/procurementAuditList' })
    }
  }
}
</script>

<style lang="less" scoped>
.tableData h4 {
  line-height: 40px;
}
</style>

