Newer
Older
CallCenterFront / src / views / assessResult / components / listDeptResult.vue
yangqianqian on 27 May 2021 8 KB 修复统计图表不显示的问题
<template>
  <div class="app-container">
    <!--筛选条件-->
    <div class="search-div">
      <el-form ref="selectForm" :inline="true" :model="listQuery" class="form-container">
        <el-row>
          <el-form-item class="selectForm-container-item" prop="startTime">
            <el-date-picker
              v-model="dateRange"
              type="daterange"
              range-separator="至"
              value-format="yyyy-MM-dd"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              @change="fetchData"/>
          </el-form-item>
        </el-row>
      </el-form>
    </div>
    <!--查询结果Table显示-->
    <div>
      <el-row class="table-title">
        <el-col :span="6"><div class="title-header"><i class="el-icon-menu"/>数据列表</div></el-col>
        <el-col :span="12" :offset="6" class="edit_btns">
          <el-button class="edit_btn" size="small" @click="batchExport">导出报表</el-button>
        </el-col>
      </el-row>
      <el-table v-loading="listLoading" :data="list" class="table" border @selection-change="handleSelectionChange">
        <!--<el-table-column align="center" type="selection" width="55"/>-->
        <el-table-column :index="indexMethod" label="排名" align="center" type="index" width="85"/>
        <el-table-column v-for="column in columns" :key="column.value" :label="column.text" :width="column.width" :align="column.align" show-overflow-tooltip>
          <template slot-scope="scope">
            <span v-if="column.checkCell" :class="checkCell(scope.row.cell)">{{ scope.row[column.value] }}</span>
            <span v-else>{{ scope.row[column.value] }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="160">
          <template slot-scope="scope">
            <el-button type="text" @click="detail(scope.row)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!--分页-->
    <div class="pagination-container">
      <el-pagination
        v-show="total>listQuery.limit"
        :current-page="listQuery.offset"
        :page-sizes="[20,30,50]"
        :page-size="listQuery.limit"
        :total="total"
        align="center"
        layout="total, sizes, prev, pager, next"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"/>
    </div>
    <result-detail v-show="dialogFormVisible" ref="resultdetail" @watchChild="fetchData"/>
  </div>
</template>

<script>
import { getDeptResultList, getDeptList, batchExport } from '@/api/assessResult'
import resultDetail from '@/views/assessResult/components/resultDetail'
import { getDayTime } from '@/utils/dateutils'

export default {
  name: 'ListDeptResult',
  components: { resultDetail },
  data() {
    return {
      listQuery: {
        startTime: '',
        endTime: '',
        offset: 1,
        limit: 20,
        sort: 'score',
        order: 'desc'
      }, // 筛选条件
      columns: [
        {
          text: '部门',
          value: 'deptName',
          align: 'center'
        },
        {
          text: '部门职能指标',
          value: 'deptscore',
          align: 'center'
        },
        {
          text: '专项指标',
          value: 'specialscore',
          align: 'center'
        },
        {
          text: '经济指标',
          value: 'economyscore',
          align: 'center'
        },
        {
          text: '行政综合指标',
          value: 'totalscore',
          align: 'center',
          width: 360
        },
        {
          text: '综合得分',
          value: 'score',
          align: 'center',
          width: 100
        },
        {
          text: '等级',
          value: 'rank',
          align: 'center',
          width: 100
        }
      ], // 显示列
      dateRange: [],
      list: [], // 列表数据
      total: 0, // 数据总数
      deptList: [], // 权属单位树形下拉菜单
      subDeptList: [], // 权属单位树形下拉菜单
      typeList: [], // 是否显示权属单位下拉
      listLoading: false, // 加载动画
      fullscreenLoading: false, // 全屏加载动画
      editShow: false, // 是否显示编辑框
      detailShow: false, // 是否显示编辑框
      deptShowTop: false,
      dialogFormVisible: false
    }
  },
  watch: {
    dateRange(val) {
      if (val && val.length > 0) {
        this.listQuery.startTime = val[0]
        this.listQuery.endTime = val[1]
      } else {
        this.listQuery.startTime = ''
        this.listQuery.endTime = ''
      }
    }
  },
  mounted() {
    var beginTime = getDayTime(new Date().getTime() - 24 * 30 * 60 * 60 * 1000)
    var endTime = new Date()
    this.dateRange = [beginTime, endTime]
    this.fetchData()
  },
  methods: {
    // 查询数据
    search() {
      this.fetchData(false)
    },
    // 获取数据
    fetchData(isNowPage = true) {
      this.listLoading = true
      if (!isNowPage) { // 是否显示当前页,否则跳转第一页
        this.listQuery.offset = 1
      }
      getDeptResultList(this.listQuery).then(response => {
        this.list = response.data.rows
        this.total = parseInt(response.data.total)
        this.listLoading = false
      })
    },
    fetchDeptList() {
      getDeptList('24').then(response => {
        this.deptList = response.data
        // if (this.deptList) {
        //   this.listQuery.dept = this.deptList[0].id
        //   getDeptList(this.listQuery.dept).then(response => {
        //     this.subDeptList = response.data
        //   })
        // }
      })
    },
    changeDept() {
      if (this.listQuery.dept) {
        getDeptList(this.listQuery.dept).then(response => {
          this.subDeptList = response.data
        })
      }
    },
    detail(row) {
      // this.$router.push({ path: '/resultDetail', query: { checkId: row.id }})
      this.dialogFormVisible = true
      this.$refs.resultdetail.initDialog(this.dialogFormVisible, row)
    },
    // 批量导出
    batchExport() {
      // 全屏加载动画
      const loading = this.$loading({
        lock: true,
        text: '数据处理中,请稍后...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      batchExport(this.listQuery).then(res => {
        loading.close() // 关闭加载动画
        const blob = new Blob([res.data])
        const downloadElement = document.createElement('a')
        const href = window.URL.createObjectURL(blob) // 创建下载的链接
        downloadElement.href = href
        downloadElement.download = `部门考核结果.xlsx` // 下载后文件名
        document.body.appendChild(downloadElement)
        downloadElement.click() // 点击下载
        document.body.removeChild(downloadElement) // 下载完成移除元素
        window.URL.revokeObjectURL(href) // 释放blob对象
      }).catch((res) => {
        loading.close()
      })
    },
    checkCell(value) {
      var cell = parseFloat(value)
      if (cell < 10) {
        return 'warning-state'
      }
    },
    indexMethod(index) {
      return this.listQuery.limit * (this.listQuery.offset - 1) + index + 1
    },
    // 改变页容量
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.fetchData()
    },
    // 改变当前页
    handleCurrentChange(val) {
      this.listQuery.offset = val
      this.fetchData()
    },
    // 多选触发方法
    handleSelectionChange(val) {
      this.multipleSelection = val
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .app-container{
    padding: 10px;
  }
  $tableTitleHeight:46px;
  .table{
    margin-bottom: 20px;
  }
  .pagination-container{
    margin-bottom: 50px;
  }
  .table-title{
    background-color:rgba(243, 243, 243, 1);
    height: $tableTitleHeight;
    .title-header{
      line-height:$tableTitleHeight;
      color: #606266;
      font-size: 15px;
      i{
        margin-left: 5px;
        margin-right: 5px;
      }
    }
  }
  .edit_btns{
    .edit_btn{
      float:right;
      margin:7px 3px;//为了需要居中显示margin-top和bottom要用$tableTitleHeight减去按钮原高度除以2
    }
  }
  .warning-state{
    color:red
  }
</style>