Newer
Older
baseResourceFront / src / views / dataUpload / dataUploadList.vue
yangqianqian on 23 Mar 2021 13 KB 修改UI
<!--数据上传列表-->
<template>
  <div class="app-container">
    <!--筛选条件-->
    <div class="search-div">
      <div class="search-left">
        <el-form ref="selectForm" :inline="true" :model="listQuery" size="small" class="form-container">
          <el-row>
            <el-col :span="4">
              <el-form-item class="selectForm-container-item">
                <el-input v-model.trim="listQuery.name" placeholder="姓名" clearable/>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item class="selectForm-container-item">
                <el-select v-model="listQuery.sex" placeholder="性别" clearable>
                  <el-option v-for="item in sexList" :key="item.value" :label="item.name" :value="item.value"/>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item class="selectForm-container-item">
                <el-select v-model="listQuery.nation" placeholder="民族" clearable>
                  <el-option v-for="item in nationTypeList" :key="item.value" :label="item.name" :value="item.value"/>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item class="selectForm-container-item">
                <el-select v-model="listQuery.cardType" placeholder="证件类型" clearable>
                  <el-option v-for="item in cardTypeList" :key="item.value" :label="item.name" :value="item.value"/>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item class="selectForm-container-item">
                <el-input v-model.trim="listQuery.idCardNo" placeholder="证件号码" clearable/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="4">
              <el-form-item class="selectForm-container-item">
                <el-select v-model="listQuery.collReason" placeholder="采集原因" clearable>
                  <el-option v-for="item in personTypeList" :key="item.value" :label="item.name" :value="item.value"/>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item class="selectForm-container-item">
                <dept-select v-model="listQuery.stId" :need-top="false" placeholder="采集站点"/>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item class="selectForm-container-item">
                <el-select v-model="listQuery.flgUpload" placeholder="上传状态" clearable>
                  <el-option v-for="item in uploadStatusList" :key="item.value" :label="item.name" :value="item.value"/>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="9">
              <el-form-item class="selectForm-container-item" prop="startTime">
                <el-date-picker
                  v-model="timeRange"
                  type="datetimerange"
                  range-separator="至"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  start-placeholder="创建开始时间"
                  end-placeholder="创建结束时间"/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="search-right">
        <el-button class="filter-item" type="primary" icon="el-icon-search" size="small" @click="search">搜索</el-button>
        <el-button class="filter-item" type="warning" icon="el-icon-delete" size="small" @click="clearInput">重置</el-button>
      </div>
      <div class="clearfloat"/>
    </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 v-if="hasPerm('/upload/batchUpload')" class="edit_btn" size="small" @click="batchUpload">批量上传</el-button>
        </el-col>
      </el-row>
      <el-table v-loading="listLoading" :data="list" class="table" size="small" border @selection-change="handleSelectionChange">
        <el-table-column v-if="hasPerm('/upload/batchUpload')" align="center" type="selection" width="40"/>
        <el-table-column :index="indexMethod" label="#" align="center" type="index" />
        <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>{{ scope.row[column.value] }}</span>
            <span v-if="column.ext">{{ scope.row.ext[column.value] }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="130">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click.stop="goDetail(scope.row)">详情</el-button>
            <el-button v-if="hasPerm('/upload/uploadOne') && scope.row.flgUpload=='0'" type="text" size="small" @click.stop="uploadOne(scope.row)">上传</el-button>
            <el-button v-if="hasPerm('/upload/uploadOne') && scope.row.flgUpload=='2'" type="text" size="small" @click.stop="uploadOne(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>
    <upload-detail ref="uploaddetail"/>
  </div>
</template>
<script>
import DeptSelect from '@/components/DeptSelect'
import { getWaitUploadList, uploadOneData, uploadBatchData } from '@/api/system/dataupload'
import { getSexType, getPersonType, getCardType, getNationType } from '@/api/system/allDict'
import UploadDetail from './components/uploadDetail'
export default {
  name: 'DataUploadList',
  components: { UploadDetail, DeptSelect },
  data() {
    return {
      listQuery: {
        name: '', // 姓名
        sex: '', // 性别
        nation: '', // 民族
        collReason: '', // 采集原因
        cardType: '', // 证件类型
        idCardNo: '', // 证件号码
        stId: '', // 采集站点
        startTime: '', // 开始时间
        endTime: '', // 结束时间
        offset: 1,
        limit: 20,
        sort: '',
        order: ''
      }, // 筛选条件
      columns: [
        {
          text: '姓名',
          value: 'name',
          align: 'center'
        },
        {
          text: '性别',
          value: 'sexName',
          align: 'center',
          width: 45
        },
        {
          text: '民族',
          value: 'nationName',
          width: 50,
          align: 'center'
        },
        {
          text: '采集原因',
          value: 'collReasonName',
          align: 'center'
        },
        {
          text: '证件类型',
          value: 'cardTypeName',
          align: 'center',
          width: 80
        },
        {
          text: '证件号码',
          value: 'idCardNo',
          align: 'center'
        },
        {
          text: '户籍地址',
          value: 'residenceAddr',
          align: 'center'
        },
        {
          text: '上传状态',
          value: 'flgUploadName',
          align: 'center'
        },
        {
          text: '采集站点',
          value: 'stationName',
          align: 'center'
        },
        {
          text: '采集人',
          value: 'collName',
          align: 'center'
        },
        {
          text: '创建时间',
          value: 'createTime',
          width: 120,
          align: 'center'
        }
      ], // 显示列
      list: [], // 列表数据
      total: 0, // 数据总数
      sexList: [], // 性别列表
      nationTypeList: [], // 民族列表
      personTypeList: [], // 人员类别列表
      cardTypeList: [], // 证件类别列表
      uploadStatusList: [{ value: '0', name: '未上传' }, { value: '2', name: '上传失败' }],
      timeRange: [], // 时间范围
      multipleSelection: [], // 多选选中项
      listLoading: true, // 加载动画
      fullscreenLoading: false // 全屏加载动画
    }
  },
  watch: {
    // 当时间范围变化时,填充listQuery时间
    timeRange(val) {
      if (val && val.length > 0) {
        this.listQuery.startTime = val[0]
        this.listQuery.endTime = val[1]
      } else {
        this.listQuery.startTime = ''
        this.listQuery.endTime = ''
      }
    }
  },
  created() {
    this.fetchSexType()// 获取性别列表
    this.fetchNationType()// 获取性别列表
    this.fetchPersonType() // 获取人员类别列表
    this.fetchCardType() // 获取证件类型列表
    this.fetchData()// 获取数据
  },
  activated() {
    this.fetchData(false)
  },
  methods: {
    // 判断是否有选中的项
    checkSelection() {
      if (this.multipleSelection.length === 0) {
        return false
      } else {
        return true
      }
    },
    // 单个上传
    uploadOne(row) {
      const params = {
        irId: row.irId
      }
      this.$confirm(
        '确定上传数据吗?',
        '确认操作',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        uploadOneData(params).then(response => {
          if (response.code === 200) {
            this.$message.success('上传成功')
            this.fetchData(false)
          }
        })
      })
    },
    // 批量上传
    batchUpload() {
      if (this.checkSelection()) {
        const irIds = []
        this.multipleSelection.forEach(function(value, index) {
          irIds.push(value.irId)
        })
        this.$confirm(
          '确定要将所选数据全部上传吗?',
          '确认操作',
          {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }
        ).then(() => {
          uploadBatchData(irIds).then(response => {
            if (response.code === 200) {
              this.$message.success('上传成功')
              this.fetchData(false)
            }
          })
        })
      } else {
        this.$message.error('至少选中一项')
      }
    },
    // 查看详情
    goDetail(row, column, event) {
      this.$router.push({ path: '/uploadDetail', query: { id: row.id, sId: row.sId }})
    },
    // 查询数据
    search() {
      this.fetchData(false)
    },
    // 获取列表
    fetchData(isNowPage = true) {
      this.listLoading = true
      if (!isNowPage) { // 是否显示当前页,否则跳转第一页
        this.listQuery.offset = 1
      }
      getWaitUploadList(this.listQuery).then(response => {
        if (response.code === 200) {
          this.list = response.data.rows
          this.total = parseInt(response.data.total)
        } else {
          this.$message.error(response.message)
        }
        this.listLoading = false
      })
    },
    // 获取性别
    fetchSexType() {
      getSexType().then(response => {
        this.sexList = response.data
      })
    },
    // 获取民族
    fetchNationType() {
      getNationType().then(response => {
        this.nationTypeList = response.data
      })
    },
    // 获取人员类型列表
    fetchPersonType() {
      getPersonType().then(response => {
        this.personTypeList = response.data
      })
    },
    // 获取证件类型列表
    fetchCardType() {
      getCardType().then(response => {
        this.cardTypeList = response.data
      })
    },
    clearInput() {
      this.listQuery = {
        name: '', // 姓名
        sex: '', // 性别
        nation: '', // 民族
        collReason: '', // 采集原因
        cardType: '', // 证件类型
        idCardNo: '', // 证件号码
        stId: '', // 采集站点
        startTime: '', // 开始时间
        endTime: '', // 结束时间
        offset: 1,
        limit: 20,
        sort: '',
        order: ''
      }
      this.timeRange = []
      this.fetchData(false)
    },
    // 序号计算
    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>
  $tableTitleHeight:46px;
  .app-container{
    margin-bottom:20px
  }
  .table{
    margin-bottom: 20px;
  }
  .small-row-class{
    height: 15px;
  }
  .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
    }
  }
</style>
<style rel="stylesheet/scss" lang="scss">
  .small-row-class td{
    padding:2px 0px;
  }
</style>