doum
9 天以前 0201c32312f6478b2bde706607c8c6338e9e1d06
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<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>