<!--
  @description: 投标人提出问题列表
  @Modifier: haoFx/肖文龙
  @routerPath:/bidding/projectDrive/clarification/clarificationQuestionList
  @date: 2020/3/13-14:11
  isCanOperate: true可以操作 false不可以查看只有查看权限
-->
<template>
  <section>
    <el-button
      v-if="tenderBase.isCanOperate"
      type="primary"
      class="mb10"
      @click="addeClarification"
    >
      回复
    </el-button>
    <div>
      <el-table
        v-loading="loading"
        :data="tableData"

        width="100%"
        @selection-change="selectionChange"
      >
        <el-table-column
          type="selection"
          align="center"
          width="50"
        />
        <el-table-column
          type="index"
          label="序号"
          width="60px"
          align="center"
        />
        <el-table-column
          header-align="center"
          label="标段编号"
          prop="packNos"
          align="left"
          min-width="200"
        />
        <el-table-column
          label="问题提交单位"
          header-align="center"
          prop="supplierName"
          min-width="230"
        />
        <el-table-column
          prop="submitQuestionTime"
          align="center"
          label="问题提出时间"
          width="160"
        />
        <el-table-column
          label="问题描述"
          header-align="center"
          prop="questionDescribe"
          min-width="230"
        />
        <el-table-column
          label="状态"
          prop="questionStatus"
          align="center"
          width="100"
        >
          <template slot-scope="scope">
            <span v-for="(item,index) in bidderStatusList" v-if="scope.row.questionStatus===item.typecode" :key="index">
              {{ item.typename }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          label="回复数"
          header-align="center"
          prop="replyNumber"
          width="60"
        />
        <el-table-column
          header-align="center"
          label="操作"
          align="right"
          width="120"
        >
          <template slot-scope="scope">
            <!--登录用户有权限则显示-->
            <el-link
              v-if="tenderBase.isCanOperate"
              type="primary"
              @click.stop="replyClarify(scope.row)"
            >
              [回复]
            </el-link>
            <el-link
              type="primary"
              @click.stop="preview(scope.row)"
            >
              [查看]
            </el-link>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="paginationData" @change="loadData" />
    </div>
  </section>
</template>

<script>
/* 接口*/
import { listClarificationQuestionPages, dealWithQuestionDetailCheckStatus } from '@/api/bidding/bidClarification'// 澄清
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { clarificationGroupMixin } from '../mixins/clarificationGroupMixin'// 澄清质疑-字典信息
export default {
  name: 'ClarificationQuestionList',
  components: {
    pagination// 分页
  },
  mixins: [ListMixin, clarificationGroupMixin],
  data() {
    return {
      tenderBase: this.$store.getters.tenderBase, // 项目信息
      loading: true,
      tableData: [], // 列表数据
      selectionData: []// 已选的数据
    }
  },
  created() {
    // 获取列表信息
    this.loadData()
  },
  methods: {
    // 获取数据
    loadData() {
      const params = {
        tenderId: this.$store.getters.tenderBase.tenderId,
        pageNo: this.paginationData.pageNo,
        pageSize: this.paginationData.pageSize
      }
      listClarificationQuestionPages(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        this.paginationData.total = response.data.total
        for (let i = 0; i < this.tableData.length; i++) {
          // 问题提出时间
          if (this.tableData[i].submitQuestionTime) {
            this.tableData[i].submitQuestionTime = this.$Moment(this.tableData[i].submitQuestionTime).format(this.momentDateTime)
          }
        }
      }).catch(() => {

      })
    },
    // 选择 投标人提出的问题
    selectionChange(val) {
      this.selectionData = val
    },
    /*
    * 回复澄清-存储相应的参数
    * row 如果是单个回复有参数 否则无参数
    * */
    setClarification(row) {
      const data = {
        questionDetailIdList: [], // 问题详情集合Id
        questionIdList: []// 问题Id集合
      }
      if (row) { // 单个回复
        data.questionDetailIdList.push(row.questionDetailId)
        data.questionIdList.push(row.questionId)
      } else { // 批量回复
        // 循环-取相应的Id
        this.selectionData.map(item => {
          data.questionDetailIdList.push(item.questionDetailId)
          data.questionIdList.push(item.questionId)
        })
      }
      // session-存储
      sessionStorage.setItem('setClarification', JSON.stringify(data))
    },
    // 新增回复澄清
    addeClarification() {
      if (this.selectionData.length > 0) {
        this.setClarification()// // 回复澄清-存储相应的参数
        // rrouter-跳转
        this.$router.push({
          path: '/bidding/projectDrive/clarificationQuestionReply/clarificationQuestionAdd',
          query: {
            ...this.$route.query,
            clarificationId: ''// 澄清Id
          }
        })
      } else {
        this.$message({
          message: '请选择投标人提出的问题！',
          type: 'warning'
        })
      }
    },
    // 回复澄清
    replyClarify(row) {
      this.setClarification(row)// // 回复澄清-存储相应的参数
      this.$router.push({
        path: '/bidding/projectDrive/clarificationQuestionReply/clarificationQuestionAdd',
        query: {
          ...this.$route.query,
          clarificationId: row.clarificationId// 澄清Id
        }
      })
    },
    // 查看
    preview(row) {
      if (row.questionStatus === '00') { // 未查看
        dealWithQuestionDetailCheckStatus(row.questionDetailId).then(res => {
          this.$router.push({
            path: '/bidding/projectDrive/clarificationQuestionReply/clarificationPdfDetail',
            query: {
              ...this.$route.query,
              questionId: row.questionId// 澄清问题Id
            }
          })
        })
      } else {
        this.$router.push({
          path: '/bidding/projectDrive/clarificationQuestionReply/clarificationPdfDetail',
          query: {
            ...this.$route.query,
            questionId: row.questionId// 澄清问题Id
          }
        })
      }
    }
  }
}
</script>

<style scoped lang="less">

</style>
