<!--问卷结果-->
<template>
  <div class="app-container">
    <el-form ref="queryForm" :inline="true" :model="queryParams" label-width="68px" size="small">
      <el-form-item label="提交时间">
        <el-date-picker
          v-model="dateRange"
          end-placeholder="结束日期"
          range-separator="-"
          start-placeholder="开始日期"
          style="width: 240px"
          type="daterange"
          value-format="yyyy-MM-dd"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="tableData">
      <el-table-column label="序号" type="index"></el-table-column>
      <el-table-column label="提交日期" prop="submitTime"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="text" @click="getResult(scope.row.id)">查看结果</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :limit.sync="queryParams.pageSize"
      :page.sync="queryParams.pageNum"
      :total="total"
      @pagination="getList"/>
    <el-dialog title="查看结果" :visible.sync="open" append-to-body width="1200px">
      <el-table :data="result" border>
        <el-table-column label="序号" type="index"></el-table-column>
        <el-table-column label="问题内容" prop="questionContent"></el-table-column>
        <el-table-column label="结果" prop="result"></el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>
<script>
import {getResult, resultPage} from '@/api/liandao/questionnaire.js'

export default {
  name: "QuestionnaireResult",
  created() {
    this.getList()
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        startTime: undefined,
        endTime: undefined,
      },
      //表格数据
      tableData: [],
      // 总数
      total: 0,
      result: [],
      dateRange: [],
      open: false,
    }
  },
  methods: {
    /** 查询数据列表 */
    getList() {
      this.loading = true;
      if (this.dateRange && this.dateRange.length > 0) {
        this.queryParams.startTime = this.dateRange[0]
        this.queryParams.endTime = this.dateRange[1]
      }
      resultPage(this.queryParams).then(resp => {
          if (resp.code == 200) {
            this.tableData = resp.rows;
            this.total = resp.total;
            this.loading = false;
          }
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.startTime = undefined
      this.queryParams.endTime = undefined
      this.dateRange = []
      this.handleQuery();
    },
    getResult(id) {
      getResult(id).then(resp => {
        if (resp.code == 200) {
          this.result = resp.data
          this.open = true
        }
      })
    }
  }
}
</script>
