<template>
|
<TableLayout :permissions="['business:ywelectricaldata:query']">
|
<el-form ref="searchForm" slot="search-form" :model="searchForm" label-width="100px" inline>
|
<el-form-item label="电表信息" prop="meterKeyword">
|
<el-input
|
v-model="searchForm.meterKeyword"
|
placeholder="请输入电表名称/表号"
|
clearable
|
@keypress.enter.native="search"
|
/>
|
</el-form-item>
|
<el-form-item label="选择房间" prop="roomId">
|
<el-select v-model="searchForm.roomId" clearable filterable placeholder="全部" style="min-width: 200px">
|
<el-option v-for="item in roomOptions" :key="item.id" :label="item.label" :value="item.id"/>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="抄表时间" prop="readTimeRange">
|
<el-date-picker
|
v-model="searchForm.readTimeRange"
|
type="datetimerange"
|
value-format="yyyy-MM-dd HH:mm:ss"
|
range-separator="-"
|
start-placeholder="开始时间"
|
end-placeholder="结束时间"
|
style="width: 360px"
|
/>
|
</el-form-item>
|
<section>
|
<el-button type="primary" icon="el-icon-search" @click="search">查询</el-button>
|
<el-button icon="el-icon-refresh" @click="reset">重置</el-button>
|
</section>
|
</el-form>
|
<template v-slot:table-wrap>
|
<ul class="toolbar">
|
<li>
|
<el-button
|
type="primary"
|
@click="handleReadNow"
|
:loading="isReading"
|
v-permissions="['business:ywelectricaldata:sync']"
|
>立即抄表</el-button>
|
</li>
|
<li>
|
<el-button
|
@click="exportExcel"
|
:loading="isWorking.export"
|
v-permissions="['business:ywelectricaldata:exportExcel']"
|
>导出</el-button>
|
</li>
|
</ul>
|
<el-table v-loading="isWorking.search" :data="tableData.list" stripe>
|
<el-table-column type="selection" width="55"/>
|
<el-table-column prop="address" label="电表地址" min-width="140" align="center" show-overflow-tooltip/>
|
<el-table-column label="电表名称" min-width="140" align="center" show-overflow-tooltip>
|
<template slot-scope="{ row }">{{ row.electricalName || row.name || '-' }}</template>
|
</el-table-column>
|
<el-table-column prop="roomNames" label="绑定房间" min-width="150" align="center" show-overflow-tooltip/>
|
<el-table-column label="结算方式" min-width="100" align="center">
|
<template slot-scope="{ row }">{{ formatJsfs(row.jsfs) }}</template>
|
</el-table-column>
|
<el-table-column label="组合有功总电量" min-width="140" align="center">
|
<template slot-scope="{ row }">{{ formatEnergy(row.zhygzdl) }}</template>
|
</el-table-column>
|
<el-table-column prop="ye" label="账户余额" min-width="100" align="center"/>
|
<el-table-column prop="countnum" label="购电次数" min-width="90" align="center"/>
|
<el-table-column label="抄表时间" min-width="160" align="center">
|
<template slot-scope="{ row }">
|
<span :title="formatDateTime(readTimeValue(row))">{{ formatRelativeTime(readTimeValue(row)) }}</span>
|
</template>
|
</el-table-column>
|
<el-table-column label="状态" min-width="90" align="center">
|
<template>
|
<span class="red">已触发</span>
|
</template>
|
</el-table-column>
|
</el-table>
|
<pagination
|
@size-change="handleSizeChange"
|
@current-change="handlePageChange"
|
:pagination="tableData.pagination"
|
/>
|
</template>
|
</TableLayout>
|
</template>
|
|
<script>
|
import BaseTable from '@/components/base/BaseTable'
|
import TableLayout from '@/layouts/TableLayout'
|
import Pagination from '@/components/common/Pagination'
|
import * as dataApi from '@/api/business/ywelectricaldata'
|
import { tree } from '@/api/project/ywProject'
|
import dayjs from 'dayjs'
|
import relativeTime from 'dayjs/plugin/relativeTime'
|
import 'dayjs/locale/zh-cn'
|
|
dayjs.extend(relativeTime)
|
dayjs.locale('zh-cn')
|
|
export default {
|
name: 'YwElectricalData',
|
extends: BaseTable,
|
components: { TableLayout, Pagination },
|
data () {
|
return {
|
searchForm: {
|
meterKeyword: '',
|
roomId: null,
|
readTimeRange: []
|
},
|
roomOptions: [],
|
isReading: false
|
}
|
},
|
created () {
|
this.api = dataApi
|
this.module = '抄表记录'
|
this.configData['field.id'] = 'id'
|
this.configData['field.main'] = 'address'
|
this.loadRoomOptions()
|
this.search()
|
},
|
methods: {
|
loadRoomOptions () {
|
tree({}).then(res => {
|
this.roomOptions = this.flattenRooms(res || [])
|
}).catch(() => {})
|
},
|
flattenRooms (nodes, prefix) {
|
if (!nodes || !nodes.length) return []
|
let list = []
|
nodes.forEach(node => {
|
const path = prefix ? prefix + '/' + node.name : node.name
|
if (node.lv === 3) {
|
list.push({ id: node.id, label: path })
|
}
|
if (node.projectDataVOList && node.projectDataVOList.length) {
|
list = list.concat(this.flattenRooms(node.projectDataVOList, path))
|
}
|
})
|
return list
|
},
|
buildSearchModel () {
|
const model = {}
|
if (this.searchForm.meterKeyword) {
|
model.meterKeyword = this.searchForm.meterKeyword
|
}
|
if (this.searchForm.roomId != null && this.searchForm.roomId !== '') {
|
model.roomId = this.searchForm.roomId
|
}
|
if (this.searchForm.readTimeRange && this.searchForm.readTimeRange.length === 2) {
|
model.readTimeBegin = this.searchForm.readTimeRange[0]
|
model.readTimeEnd = this.searchForm.readTimeRange[1]
|
}
|
return model
|
},
|
handlePageChange (pageIndex) {
|
this.tableData.pagination.pageIndex = pageIndex || this.tableData.pagination.pageIndex
|
this.isWorking.search = true
|
dataApi.fetchList({
|
page: this.tableData.pagination.pageIndex,
|
capacity: this.tableData.pagination.pageSize,
|
model: this.buildSearchModel(),
|
sorts: this.tableData.sorts
|
})
|
.then(data => {
|
this.tableData.list = data.records
|
this.tableData.pagination.total = data.total
|
})
|
.catch(() => {})
|
.finally(() => { this.isWorking.search = false })
|
},
|
reset () {
|
this.searchForm = {
|
meterKeyword: '',
|
roomId: null,
|
readTimeRange: []
|
}
|
if (this.$refs.searchForm) {
|
this.$refs.searchForm.resetFields()
|
}
|
this.search()
|
},
|
handleReadNow () {
|
this.$dialog.actionConfirm('确认立即从第三方平台同步抄表数据吗?', '操作确认提醒')
|
.then(() => {
|
this.isReading = true
|
dataApi.syncAll({})
|
.then(res => {
|
this.$tip.apiSuccess(res || '抄表同步成功')
|
this.search()
|
})
|
.catch(e => {
|
this.$tip.apiFailed(e)
|
})
|
.finally(() => {
|
this.isReading = false
|
})
|
})
|
.catch(() => {})
|
},
|
formatJsfs (val) {
|
if (val == null || val === '') return '-'
|
const text = String(val).trim().toLowerCase()
|
if (text === 'true' || text === '1') return '预付费'
|
if (text === 'false' || text === '0') return '后付费'
|
return val
|
},
|
formatEnergy (val) {
|
if (val == null || val === '') return '-'
|
const text = String(val)
|
if (text.toLowerCase().indexOf('kwh') >= 0) return text
|
return text + 'kWh'
|
},
|
readTimeValue (row) {
|
return row.addTime || row.createDate
|
},
|
formatDateTime (value) {
|
if (!value) return '-'
|
const d = dayjs(value)
|
return d.isValid() ? d.format('YYYY-MM-DD HH:mm:ss') : value
|
},
|
formatRelativeTime (value) {
|
if (!value) return '-'
|
const d = dayjs(value)
|
if (!d.isValid()) return value
|
const diffHours = dayjs().diff(d, 'hour')
|
if (diffHours >= 24) {
|
return d.format('YYYY-MM-DD HH:mm:ss')
|
}
|
return d.fromNow()
|
}
|
}
|
}
|
</script>
|
|
<style scoped>
|
.red { color: #f56c6c; }
|
</style>
|