<!--
  @description: 审核招标公告、审核资审公告
  @Modifier: haoFx
  @routerPath: /projectManagement/auditBulletinContent
              /projectManagement/auditInformationBulletinContent
  @date: 2019/11/18-20:52
-->
<template>
  <div>
    <div class="title p0-16 clearfix">
      <!-- 返回 -->
      <div class="title-back pointer" @click="back">
        <i class="iconfont icon-fanhui mr10" />
        {{ bulletinTitle }}审核
      </div>
    </div>
    <div>
      <dl class="projectInfoDetail">
        <dt>
          <p class="projectInfoDetail_icon">
            <i class="iconfont icon-xiangmujibenxinxi" />
          </p>
          基本信息
        </dt>
        <dd>
          <table class="tableData">
            <tr>
              <td>项目名称</td>
              <td>
                {{ formData.tenderName }}
              </td>
              <td>公告标题</td>
              <td>
                {{ formData.title }}
              </td>
            </tr>
            <tr>
              <td>标书获取时间</td>
              <td>
                {{ formData.tenderDocumentReceiveStartTime }}
              </td>
              <td>接收答疑截止时间</td>
              <td>
                {{ formData.acceptAnsweringQuestionsEndTime }}
              </td>
            </tr>
            <tr>
              <td>投标截止时间</td>
              <td>
                {{ formData.submitEndTime }}
              </td>
              <td>开标时间</td>
              <td>
                {{ formData.openBidStartTime }}
              </td>
            </tr>
            <tr>
              <td v-if="formData.openBidEndTime">
                解密时间
              </td>
              <td v-if="formData.openBidEndTime">
                {{ formData.openBidEndTime }}
              </td>
              <td>发布媒介</td>
              <td :colspan="formData.openBidEndTime?'':'3'">
                {{ mediaPartners }}
              </td>
            </tr>
          </table>
        </dd>
      </dl>
    </div>
    <!--公告详情组件-->
    <bulletinPdfDetail />
    <!--操作按鈕 auditStatus 00待审核-->
    <div v-if="$route.query.auditStatus === '00'" class="but_footer">
      <div 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.auditReason"
              :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="confirmLoading" type="primary" @click="verified()">
            审核通过
          </el-button>
          <el-button :loading="confirmLoading" @click="auditFail()">
            审核不通过
          </el-button>
          <el-button @click="back()">
            返 回
          </el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { auditBulletin } from '@/api/bidding/bidBulletin'
/* 混合开发方法-参数字段*/
import { tenderBulletinInitGroupMixin } from './../mixins/tenderBulletinInitGroupMixin'// 字典信息
/* 组件*/
import bulletinPdfDetail from '../tenderBulletin/bulletinPdf-detail'
import { queryTenderBulletinData } from '../../../../api/bidding/bidBulletin'
export default {
  name: 'AuditBulletinOpinion',
  components: {
    bulletinPdfDetail
  },
  mixins: [tenderBulletinInitGroupMixin],
  data() {
    return {
      formData: {
        tenderName: '',
        title: '',
        tenderDocumentReceiveStartTime: '',
        acceptAnsweringQuestionsEndTime: '',
        submitEndTime: '',
        openBidStartTime: '',
        openBidEndTime: '',
        mediaPartners: ''
      },
      confirmLoading: false, // 控制按钮重复点击Loding
      // 审核信息参数
      auditInfoParam: {
        auditStatus: '', // 01-审核通过 ||02-审核不通过
        auditReason: '', // 审核意见
        bulletinId: this.$route.query.bulletinId
      }
    }
  },
  computed: {
    mediaPartners() {
      let list = (this.formData.mediaPartners || '').split(',')
      list = list.filter(item => item !== '00')
      list = list.map(item => {
        const cell = this.mediaPartnersList.find(cell => cell.typecode === item)
        if (cell) {
          return cell.typename
        }
        return ''
      })
      return list.join(',')
    }
  },
  created() {
    this.loadData()
    this.initGroup()
    this.initBulletinType()// 字典信息区分-招标公告/资审公告方法
  },
  methods: {
    // 获取字典方法
    initGroup() {
      const data = ['mediaPartners'] // 招标询价方式
      this.$store.dispatch('getGroupType', data).then(res => {
        Object.keys(res.bidTypeData).forEach((key) => {
          this[key] = res.bidTypeData[key]
        })
      })
    },
    loadData() {
      queryTenderBulletinData({ tenderId: this.$route.query.tenderId, bulletinId: this.$route.query.bulletinId }).then(res => {
        this.formData = res.data
      })
    },
    // 返回
    back() {
      // 同一个页面不同路由
      let path = ''
      if (this.bulletinType === '01') { // 招标公告
        path = '/projectManagement/auditBulletin'
      } else if (this.bulletinType === '21') {
        path = '/projectManagement/auditInformationBulletin'// 资审公告
      }
      this.$router.push({
        path: path
      })
    },
    // 操作审核通过不通过调用接口
    handleAuditBulletin(auditStatus) {
      this.auditInfoParam.auditStatus = auditStatus
      this.confirmLoading = true// btnLoding
      auditBulletin(this.auditInfoParam).then(reponse => {
        this.$message({
          type: 'success',
          message: '审核成功'
        })
        this.back()
        this.confirmLoading = false// btnLoding
      }).catch(() => {
        this.confirmLoading = false// btnLoding
      })
    },
    // 审核通过
    verified() {
      this.$confirm('确认提交?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        this.handleAuditBulletin('01')
      }).catch(() => {
      })
    },
    // 审核不通过
    auditFail() {
      if (this.auditInfoParam.auditReason) {
        this.$confirm('确认提交?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          confirmButtonClass: 'confirmBtn',
          cancelButtonClass: 'cancelBtn',
          type: 'warning'
        }).then(() => {
          this.handleAuditBulletin('02')
        }).catch(() => {
        })
      } else {
        this.$message({
          type: 'warning',
          message: '请输入审核意见'
        })
      }
    }
  }
}
</script>

<style lang="less" scoped>

</style>
