Newer
Older
baseResourceFront / src / views / statistics / evaluationAssessment.vue
StephanieGitHub on 2 Jul 2021 4 KB MOD: 后台联调更新
<!--评价统计-->
<template>
  <app-container>
    <search-area @search="fetchData">
      <search-item>
        <el-date-picker
          v-model="timeRange"
          size="small"
          type="daterange"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          clearable/>
      </search-item>
    </search-area>
    <normal-table
      id="dataTable"
      :data="list"
      :head="tableOption.head"
      :pagination="false"
      :query="listQuery"
      :total="total"
      :columns="columns"
      :list-loading="listLoading"
      :options="tableOption.options"
      :tools-option="tableOption.toolsOption"
      @change="changePage">
      <template slot="btns">
        <!--<el-button size="small" class="edit_btn" @click="batchExport">导出</el-button>-->
      </template>
      <template slot="columns">
        <el-table-column label="平均评分" align="center">
          <template slot-scope="scope">
            <el-rate
              v-model="scope.row.avgScore"
              disabled
              show-score
              text-color="#ff9900"
              score-template="{value}"/>
          </template>
        </el-table-column>
        <el-table-column label="详细记录" width="100" align="center">
          <template slot-scope="scope">
            <el-button size="small" type="text" @click="showDetail(scope.row.toiletId, scope.row.toiletName)">详细记录</el-button>
          </template>
        </el-table-column>
      </template>
    </normal-table>
    <evaluation-list-dialog ref="evaluationList"/>
  </app-container>
</template>

<script>
import FileSaver from 'file-saver'
import XLSX from 'xlsx'
import { getToiletEvaluation } from '@/api/sanitation/statistics'
import EvaluationListDialog from './components/evaluationListDialog'
export default {
  name: 'ToiletAssessment',
  components: { EvaluationListDialog },
  data() {
    return {
      timeRange: [], // 按日统计面板中的日期范围
      listQuery: {
        beginDate: '', // 开始时间
        endDate: '' // 结束时间
      }, // 筛选条件
      columns: [
        { text: '公厕编号 ', value: 'toiletName', align: 'center' },
        { text: '公厕 ', value: 'toiletName', align: 'center' },
        // { text: '平均分', value: 'avgScore', align: 'center' },
        { text: '评价记录数', value: 'recordsCount', align: 'center' }
      ], // 显示列
      list: [], // 列表数据
      total: 0, // 数据总数
      listLoading: true, // 列表加载动画
      typeList: [], // 人员类别
      tableOption: {
        head: {
          show: true, // 是否需要标题栏,
          text: '统计结果' // 标题名称
        },
        options: {
          needIndex: false // 是否需要序号列
        },
        toolsOption: {
          selectColumns: false, // 是否需要筛选列
          refresh: false // 是否需要刷新按钮
        }
      } // 表格属性
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    // 获取数据
    fetchData() {
      this.listLoading = true
      if (this.timeRange && this.timeRange.length > 0) {
        this.listQuery.beginDate = this.timeRange[0]
        this.listQuery.endDate = this.timeRange[1]
      } else {
        this.listQuery.beginDate = ''
        this.listQuery.endDate = ''
      }
      getToiletEvaluation(this.listQuery).then(response => {
        // 降序排序
        this.list = response.data.sort((a, b) => {
          return b.avgScore - a.avgScore
        })
        this.total = response.data.length
        this.listLoading = false
      })
    },
    // 评价记录详情列表
    showDetail(id, name) {
      const listQuery = {
        beginDate: this.listQuery.beginDate,
        endDate: this.listQuery.endDate,
        toiletId: id
      }
      this.$refs.evaluationList.initDialog(listQuery, name)
    },
    // 批量导出
    batchExport() {
      const tableName = this.timeRange[0] + '至' + this.timeRange[1] + '公厕评价统计结果.xlsx'
      /* generate workbook object from table */
      var wb = XLSX.utils.table_to_book(document.querySelector('#dataTable'))
      /* get binary string as output */
      var wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' })
      try {
        FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), tableName)
      } catch (e) { if (typeof console !== 'undefined') console.log(e, wbout) }
      return wbout
    },
    // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
    changePage(val) {
      if (val && val.size) {
        this.listQuery.limit = val.size
      }
      if (val && val.page) {
        this.listQuery.offset = val.page
      }
      this.fetchData()
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .edit_btns{
    .edit_btn{
      float:right;
      margin-left:5px;
    }
  }
</style>