renkang
2 天以前 4a99240038013c7d962040e6f8eabd2d72095fd7
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
<template>
  <TableLayout :permissions="['business:ywelectricalwarning: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="请输入电表名称/表号" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item label="报警项" prop="warningDefId">
        <el-select v-model="searchForm.warningDefId" clearable placeholder="全部" style="min-width: 200px">
          <el-option
            v-for="item in warningDefList"
            :key="item.key"
            :label="item.name"
            :value="item.key"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="报警时间" prop="alarmTimeRange">
        <el-date-picker
          v-model="searchForm.alarmTimeRange"
          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="handleSync"
            :loading="isSyncing"
            v-permissions="['business:ywelectricalwarning:sync']"
          >同步</el-button>
        </li>
        <li>
          <el-button
            @click="exportExcel"
            :loading="isWorking.export"
            v-permissions="['business:ywelectricalwarning: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>
        <el-table-column prop="deviceAddress" label="电表地址" min-width="140" align="center" show-overflow-tooltip></el-table-column>
        <el-table-column prop="electricalName" label="电表名称" min-width="140" align="center" show-overflow-tooltip></el-table-column>
        <el-table-column prop="roomNames" label="绑定房间" min-width="120" align="center" show-overflow-tooltip></el-table-column>
        <el-table-column prop="warningName" label="报警项" min-width="160" align="center" show-overflow-tooltip></el-table-column>
        <el-table-column label="触发时间" min-width="120" align="center">
          <template slot-scope="{ row }">
            <span :title="formatDateTime(row.startTime)">{{ formatRelativeTime(row.startTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="msg" label="报警详情" min-width="120" align="center" show-overflow-tooltip></el-table-column>
        <el-table-column prop="warningInfo" label="排查提示" min-width="220" align="center" show-overflow-tooltip></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 dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import 'dayjs/locale/zh-cn'
 
dayjs.extend(relativeTime)
dayjs.locale('zh-cn')
 
export default {
  name: 'YwElectricalWarning',
  extends: BaseTable,
  components: { TableLayout, Pagination },
  data () {
    return {
      searchForm: {
        meterKeyword: '',
        warningDefId: null,
        alarmTimeRange: []
      },
      warningDefList: [],
      isSyncing: false
    }
  },
  created () {
    this.config({
      module: '智能电表报警记录',
      api: '/business/ywelectricalwarning',
      'field.id': 'id',
      'field.main': 'deviceAddress'
    })
    this.loadWarningDefOptions()
    this.search()
  },
  methods: {
    loadWarningDefOptions () {
      this.api.warningDefOptions()
        .then(list => {
          this.warningDefList = list || []
        })
        .catch(() => {})
    },
    buildSearchModel () {
      const model = {
        meterKeyword: this.searchForm.meterKeyword,
        warningDefId: this.searchForm.warningDefId
      }
      if (this.searchForm.alarmTimeRange && this.searchForm.alarmTimeRange.length === 2) {
        model.startTimeBegin = this.searchForm.alarmTimeRange[0]
        model.startTimeEnd = this.searchForm.alarmTimeRange[1]
      }
      return model
    },
    search () {
      this.handlePageChange(1)
    },
    handlePageChange (pageIndex) {
      this.__checkApi()
      this.tableData.pagination.pageIndex = pageIndex || this.tableData.pagination.pageIndex
      this.isWorking.search = true
      this.api.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: '',
        warningDefId: null,
        alarmTimeRange: []
      }
      this.$refs.searchForm && this.$refs.searchForm.resetFields()
      this.search()
    },
    handleSync () {
      this.$dialog.actionConfirm('确认从第三方平台同步电表报警记录吗?', '操作确认提醒')
        .then(() => {
          this.isSyncing = true
          this.api.syncAll({})
            .then(res => {
              this.$tip.apiSuccess(res || '同步成功')
              this.search()
            })
            .catch(e => {
              this.$tip.apiFailed(e)
            })
            .finally(() => {
              this.isSyncing = false
            })
        })
        .catch(() => {})
    },
    formatDateTime (value) {
      if (!value) {
        return '-'
      }
      return dayjs(value).format('YYYY-MM-DD HH:mm:ss')
    },
    formatRelativeTime (value) {
      if (!value) {
        return '-'
      }
      return dayjs(value).fromNow()
    }
  }
}
</script>
 
<style scoped>
.red {
  color: #f56c6c;
}
</style>