Newer
Older
smartwell_front / src / views / wellManage / listLine.vue
wangxitong on 23 May 2024 13 KB 新增功能
<template>
  <app-container>
    <search-area size="small" @search="search">
      <search-item>
        <el-input v-model.trim="listQuery.keywords" size="small" placeholder="管线编号/位置" clearable />
      </search-item>
      <search-item>
        <el-select v-model="listQuery.pipelineType" size="small" style="width: 140px" placeholder="选择管线类型" clearable>
          <el-option
            v-for="item in lineTypeList"
            :key="item.value"
            :label="item.name"
            :value="item.value"
          />
        </el-select>
      </search-item>
      <search-item>
        <el-select v-model="listQuery.material" size="small" style="width: 140px" placeholder="材质" clearable>
          <el-option label="PE" value="PE"/>
          <el-option label="钢管" value="钢管"/>
          <el-option label="无缝钢管" value="无缝钢管"/>
<!--            v-for="item in lineTypeList"-->
<!--            :key="item.value"-->
<!--            :label="item.name"-->
<!--            :value="item.value"-->
<!--          />-->
        </el-select>
<!--        <el-input v-model.trim="listQuery.material" size="small" style="width: 140px" placeholder="材质" clearable />-->
      </search-item>
      <span style="position: relative;top: 3px;margin-right: 10px;color: #666666;font-size: 15px;">管径范围</span>
      <search-item>
        <el-input-number v-model="listQuery.pipeDiameter1" clearable size="small" :min="0" :max="listQuery.pipeDiameter2===''?100000000:listQuery.pipeDiameter2" label="最小值"/>
      </search-item>
      <span style="position: relative;top: 3px;margin: 0 5px;color: #666666;font-size: 15px;">~</span>
      <search-item>
        <el-input-number v-model="listQuery.pipeDiameter2" clearable size="small" :min="listQuery.pipeDiameter1" :max="1000000" label="最大值"/>
      </search-item>
      <span style="position: relative;top: 3px;margin: 0 10px;color: #666666;font-size: 15px;">建设年代</span>
      <search-item>
        <el-date-picker
          style="width: 120px"
          v-model="listQuery.beginTime"
          size="small"
          value-format="yyyy"
          type="year"
          :picker-options="startDatePicker(listQuery.endTime,1,true)"
          placeholder="开始年代"
        />
      </search-item>
      <span style="position: relative;top: 3px;margin: 0 5px;color: #666666;font-size: 15px;">~</span>
      <search-item>
        <el-date-picker
          style="width: 120px"
          v-model="listQuery.endTime"
          size="small"
          value-format="yyyy"
          type="year"
          :picker-options="endDatePicker(listQuery.beginTime,1,true)"
          placeholder="结束年代"
        />
      </search-item>
      <search-item>
        <dept-select v-model="listQuery.deptid" :need-top="deptShowTop" dept-type="03" placeholder="选择权属单位" />
      </search-item>
    </search-area>
    <!--查询结果Table显示-->
    <normal-table
      ref="normalTable"
      :data="list"
      :total="total"
      :query="listQuery"
      :list-loading="listLoading"
      :options="options"
      size="small"
      @change="changePage"
      @selectionChange="handleSelectionChange"
    >
      <template slot="btns">
        <el-button v-if="hasPerm('/well/add')" size="small" @click="add">
          新增
        </el-button>
        <el-button v-if="hasPerm('/well/delete')" size="small" @click="del">
          删除
        </el-button>
        <el-button :disabled="total===0" size="small" @click="batchExport">
          导出记录
        </el-button>
        <download-template :filename="filename" />
        <el-upload
          :limit="1"
          :show-file-list="false"
          :http-request="uploadFile"
          :file-list="fileList"
          action="string"
          accept=".xls,.xlsx"
          class="upload-btn"
        >
          <el-button slot="trigger" size="small">
            批量导入
          </el-button>
        </el-upload>
      </template>
      <template slot="preColumns">
        <el-table-column align="center" type="selection" width="55" />
      </template>
      <template slot="columns">
        <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 :class="column.class">{{ 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" size="small" @click="detail(scope.row)">
              详情
            </el-button>
            <el-button type="text" size="small" @click="edit(scope.row)">
              编辑
            </el-button>
          </template>
        </el-table-column>
      </template>
    </normal-table>
    <!--编辑-->
    <edit-line ref="editline" @watchChild="fetchData" />
  </app-container>
</template>

<script>
import { getLineListPage, delLines, batchImportLine, batchExportLine } from '@/api/well/well'
import DeptSelect from '@/components/DeptSelect'
import DownloadTemplate from '@/components/DownloadTemplate/index'
import { getDictByCode } from '@/api/system/dict'
import EditLine from "@/views/wellManage/editLine";
import dayjs from "dayjs";

export default {
  name: 'ListWell',
  components: {EditLine, DownloadTemplate, DeptSelect },
  data() {
    return {
      listQuery: {
        keywords: '',
        material: '',
        pipelineType: '',
        pipeDiameter1: '',
        pipeDiameter2: '',
        beginTime: '',
        endTime: '',
        deptid: '',
        offset: 1,
        limit: 20
      }, // 筛选条件
      timeRange: [], // 时间范围
      columns: [
        { text: '管线编号', value: 'pipelineCode', align: 'center' },
        { text: '管线类型', value: 'pipelineTypeName', align: 'center' },
        { text: '管径(mm)', value: 'pipeDiameter', align: 'center' },
        { text: '材质', value: 'material', align: 'center' },
        { text: '埋设方式', value: 'buryMode', align: 'center' },
        { text: '管线位置', value: 'pipelinePosition', align: 'center' },
        { text: '建设年代', value: 'constructEra', align: 'center' },
        { text: '权属单位', value: 'deptName', align: 'center' },
        { text: '起始经度', value: 'startLongitude', align: 'center' },
        { text: '起始纬度', value: 'startLatitude', align: 'center' },
        { text: '起始地面高(mm)', value: 'startGroundHeight', align: 'center' },
        { text: '起始埋深(m)', value: 'startBuryDeep', align: 'center' },
        { text: '起始管顶高(mm)', value: 'startPipecrownHeight', align: 'center' },
        { text: '终止经度', value: 'endLongitude', align: 'center' },
        { text: '终止纬度', value: 'endLatitude', align: 'center' },
        { text: '终止地面高(mm)', value: 'endGroundHeight', align: 'center' },
        { text: '终止埋深(m)', value: 'endBuryDeep', align: 'center' },
        { text: '终止管顶高(mm)', value: 'endPipecrownHeight', align: 'center' },
        { text: '设计压力(MPa)', value: 'designPressure', align: 'center' },
        { text: '瞬时流量(m³)', value: 'instantaneousFlow', align: 'center' },
      ], // 显示列
      multipleSelection: [], // 多选选中项
      list: [], // 列表数据
      total: 0, // 数据总数
      showWellType: true, // 是否显示点位类型下拉
      lineTypeList: [], // 点位类型列表
      deptShowTop: false, // 权属单位下拉是否显示顶级
      listLoading: true, // 加载动画
      fullscreenLoading: false, // 全屏加载动画
      editShow: false, // 是否显示编辑框
      detailShow: false, // 是否显示详情框
      filename: 'pipeline_template.xlsx',
      fileList: [],
      options: {
        needIndex: true, // 是否需要序号列
        border: true // 是否需要上方边框
      },
    }
  },
  created() {
    this.fetchLineType()// 获取井列表
    this.fetchData()// 获取数据
  },
  activated() {
    console.log('activated')
    this.fetchData()// 获取数据
  },
  methods: {
    startDatePicker(endTime,type,today=true) {
      let endDayEnd = dayjs(endTime).format("YYYY");
      return {
        disabledDate:(time)=> {
          if(type == 1){ // 禁用之前
            if(endTime){
              return new Date(time).getFullYear() > new Date(endDayEnd).getFullYear()
            }
          }
        }
      }
    },
    // 参数:同 startDatePicker 对应传入开始时间 startTime
    endDatePicker(startTime,type,today=true) {
      let startDayStart = dayjs(startTime).format("YYYY");
      return {
        disabledDate:(time)=> {
          if(type == 1){
            if (startTime) { // 禁用之前
              return new Date(time).getFullYear() < new Date(startDayStart).getFullYear()
            }
          }
        }
      }
    },
    // 处理时间
    handleDateTime() {
      if (this.timeRange && this.timeRange.length > 0) {
        this.listQuery.beginTime = this.timeRange[0]
        this.listQuery.endTime = this.timeRange[1]
      } else {
        this.listQuery.beginTime = ''
        this.listQuery.endTime = ''
      }
    },
    checkSelection() {
      if (this.multipleSelection.length === 0) {
        return false
      } else {
        return true
      }
    },
    // 新增井
    add() {
      this.dialogFormVisible = true
      this.editShow = true
      this.$refs.editline.initDialog('create', {})
    },
    // 编辑井信息
    edit(row) {
      this.dialogFormVisible = true
      this.editShow = true
      this.$refs.editline.initDialog('update', row)
    },
    // 打开详情对话框
    detail(row) {
      this.dialogFormVisible = true
      this.editShow = true
      this.$refs.editline.initDialog('detail', row)
    },
    // 删除井
    del() {
      if (this.checkSelection()) {
        const wellIds = []
        this.multipleSelection.forEach(function(value, index) {
          wellIds.push(value.id)
        })
        this.$confirm(
          '确定要删除所选管线吗?',
          '确认操作',
          {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }
        ).then(() => {
          delLines(wellIds).then(response => {
            if (response.code === 200) {
              this.$message.success('删除成功')
              this.fetchData()
            }
          })
        })
      } else {
        this.$message.error('至少选中一项')
      }
    },
    // 批量导入井
    uploadFile(param) {
      console.log('uploadFile')
      // 判断文件大小是否符合要求
      const _file = param.file
      const isLt5M = _file.size / 1024 / 1024 < 5
      if (!isLt5M) {
        this.$message.error('请上传5M以下的excel文件')
        return false
      }
      // 全屏加载动画
      const loading = this.$loading({
        lock: true,
        text: '导入中,请稍后...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      // 发起导入请求
      batchImportLine(_file).then(res => {
        loading.close() // 关闭加载动画
        if (res.code === 200) {
          this.$message.success('导入成功')
          this.fileList = []
          this.fetchData()
        } else {
          this.$message.error(res.message)
        }
      }).catch(() => {
        loading.close()
      })
      this.fileList = []
    },
    // 批量导出
    batchExport() {
      // 全屏加载动画
      const loading = this.$loading({
        lock: true,
        text: '下载中,请稍后...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      const _this = this
      const config = {
        // 获取下载进度
        onDownloadProgress(progressEvent) {
          console.log(progressEvent)
          var percent = parseInt(100 * (progressEvent.loaded / progressEvent.total))
          console.log('percent:' + percent, 'total:' + progressEvent.total)
          // 渲染dom
          _this.$nextTick(() => {
            _this.percent = percent
          })
        }
      }
      batchExportLine(this.listQuery, config).then(res => {
        loading.close() // 关闭加载动画
        console.log('download===', res)
        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()
      })
    },
    // 查询数据
    search() {
      this.fetchData(false)
    },
    // 获取井数据
    fetchData(isNowPage = true) {
      this.listLoading = true
      if (!isNowPage) { // 是否显示当前页,否则跳转第一页
        this.listQuery.offset = 1
      }
      getLineListPage(this.listQuery).then(response => {
        console.log(response)
        this.list = response.data.rows
        this.total = parseInt(response.data.total)
        this.listLoading = false
      })
    },
    // 获取管线类型
    fetchLineType() {
      getDictByCode('lineType').then(response => {
        this.lineTypeList = response.data
      })
    },
    // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
    changePage(val) {
      if (val && val.size) {
        this.listQuery.limit = val.size
      }
      if (val && val.page) {
        this.listQuery.offset = val.page
      }
      this.fetchData()
    },
    // 多选触发方法
    handleSelectionChange(val) {
      this.multipleSelection = val
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>

</style>