index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="20">
  4. <el-col :span="4" :xs="24">
  5. <div class="head-container">
  6. <el-input v-model="areaName" placeholder="请输入服务区名称" clearable size="small" prefix-icon="el-icon-search"
  7. style="margin-bottom: 20px" />
  8. </div>
  9. <div class="head-container">
  10. <el-tree :data="areaOptions" :props="defaultProps" :expand-on-click-node="false" :filter-node-method="filterNode" ref="tree"
  11. node-key="id" default-expand-all highlight-current @node-click="handleNodeClick" />
  12. </div>
  13. </el-col>
  14. <el-col :span="20" :xs="24">
  15. <el-tabs v-model="activeTab" @tab-click="handleTabChange">
  16. <el-tab-pane label="电表抄报" name="first">
  17. </el-tab-pane>
  18. <el-tab-pane label="水表抄报" name="second">
  19. </el-tab-pane>
  20. </el-tabs>
  21. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
  22. <el-form-item label="设备代码" prop="deviceCode">
  23. <el-input v-model="queryParams.deviceCode" placeholder="请输入设备代码" clearable @keyup.enter.native="handleQuery" />
  24. </el-form-item>
  25. <el-form-item>
  26. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  27. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  28. </el-form-item>
  29. </el-form>
  30. <el-table v-loading="loading" :data="deviceList">
  31. <el-table-column label="计量对象" align="left" prop="objName" width="300px">
  32. <template slot-scope="scope">
  33. <span>{{ "(" + getObjTypeName(scope.row.objType) + ")"+ scope.row.objName }}</span>
  34. </template>
  35. </el-table-column>
  36. <el-table-column label="设备代码" align="center" prop="deviceCode" />
  37. <el-table-column label="计量标签" align="center" prop="objTag">
  38. <template slot-scope="scope">
  39. <span>{{ getObjTagName(scope.row.objTag) }}</span>
  40. </template>
  41. </el-table-column>
  42. <el-table-column label="抄表周期" align="center" prop="colCycle">
  43. <template slot-scope="scope">
  44. <span>{{ getColCycleName(scope.row.colCycle) }}</span>
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="上次抄表日期" align="center" prop="lastTime" />
  48. <el-table-column label="上次抄表示数" align="center" prop="lastReading" />
  49. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  50. <template slot-scope="scope">
  51. <el-button size="mini" type="text" :disabled="!canFill(scope.row.lastTime)" icon="el-icon-info" @click="handleRecord(scope.row)">
  52. 填报</el-button>
  53. <el-button size="mini" type="text" icon="el-icon-document" @click="handleViewRec(scope.row)">
  54. 查看</el-button>
  55. </template>
  56. </el-table-column>
  57. </el-table>
  58. <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
  59. @pagination="getList" />
  60. <el-dialog :title="fillTitle" :visible.sync="fillFormOpen" width="500px" append-to-body>
  61. <el-form ref="fillForm" :model="fillForm" label-width="150px">
  62. <el-form-item label="设备编码">
  63. <el-input disabled :value="fillForm.deviceCode" />
  64. </el-form-item>
  65. <el-form-item label="上次抄表日期">
  66. <el-input disabled :value="fillForm.lastTime" />
  67. </el-form-item>
  68. <el-form-item label="上次抄表示数">
  69. <el-input disabled :value="fillForm.lastReading" />
  70. </el-form-item>
  71. <hr>
  72. <el-form-item label="本次抄表月份">
  73. <el-input disabled :value="currentMonth" />
  74. </el-form-item>
  75. <el-form-item required :rules="[{required:true,message:'请输入本次抄表示数'}]" label="本次抄表示数" prop="meterReading">
  76. <el-input v-model="fillForm.meterReading" oninput="value=value.replace(/[^\d]/g,'')" placeholder="请输入本次抄表示数" />
  77. </el-form-item>
  78. <el-form-item label="综合倍率" prop="magnification">
  79. <el-input disabled :value="fillForm.magnification" />
  80. </el-form-item>
  81. <el-form-item :label="`参考增量(${activeTab==='first'?'度':'吨'})`">
  82. <el-input disabled :value="increase" />
  83. </el-form-item>
  84. </el-form>
  85. <div slot="footer" class="dialog-footer">
  86. <el-button type="primary" @click="submitFillForm">确 定</el-button>
  87. <el-button @click="fillCancel">取 消</el-button>
  88. </div>
  89. </el-dialog>
  90. <!-- 历史抄表记录 -->
  91. <el-dialog :title="title" :visible.sync="recListOpen" width="1200px" append-to-body>
  92. <el-form ref="recListForm" :model="recListForm" label-width="80px">
  93. <el-form-item label="年份" prop="year">
  94. <el-date-picker v-model="recListForm.year" :clearable="false" @change="getHistoryList" value-format="yyyy" type="year"
  95. placeholder="选择年份">
  96. </el-date-picker>
  97. </el-form-item>
  98. <el-form-item label="计量设备" prop="year">
  99. <el-input disabled :value="recListForm.deviceCode" />
  100. </el-form-item>
  101. <el-form-item label="抄表历史" prop="recList">
  102. <el-table v-loading="loading" :data="recListForm.recList" max-height="280px">
  103. <el-table-column label="年份" align="center" prop="year" />
  104. <el-table-column label="月份" align="center" prop="meterMonth" >
  105. <template slot-scope="scope">
  106. <!-- 使用 JavaScript 字符串方法截取月份部分 -->
  107. {{ scope.row.meterMonth.slice(-2) }}
  108. </template>
  109. </el-table-column>
  110. <el-table-column label="抄表示数" align="center" prop="meterReading" />
  111. <el-table-column label="用量" align="center" prop="increase" />
  112. <el-table-column label="抄表日期" align="center" prop="meterTime" />
  113. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  114. <template slot-scope="scope">
  115. <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="!canEdit(scope.row.meterMonth)"
  116. @click="updateRecord(scope.row)">修改</el-button>
  117. </template>
  118. </el-table-column>
  119. </el-table>
  120. </el-form-item>
  121. </el-form>
  122. <div slot="footer" class="dialog-footer">
  123. <el-button @click="closeRecList">关 闭</el-button>
  124. </div>
  125. </el-dialog>
  126. </el-col>
  127. </el-row>
  128. </div>
  129. </template>
  130. <script>
  131. import { listDevice } from '@/api/device/meterDevice'
  132. import { listMeterReadingByParam, getLastRecord, addMeterReading, updateMeterReading, delMeterReading } from '@/api/device/meterRead'
  133. import { areaTreeSelect, areaTreeSelectByTag } from '@/api/basecfg/area'
  134. import Treeselect from '@riophae/vue-treeselect'
  135. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  136. import { dateFormat } from '@/utils/index.js'
  137. export default {
  138. name: 'Device',
  139. components: { Treeselect },
  140. data() {
  141. const nowDay = new Date()
  142. return {
  143. currentMonth: dateFormat(nowDay, 'yyyyMM'),
  144. activeTab: 'first',
  145. // 遮罩层
  146. loading: true,
  147. // 总条数
  148. total: 0,
  149. // 计量设备表格数据
  150. deviceList: [],
  151. // 弹出层标题
  152. title: '',
  153. // 记录表单开启
  154. recListOpen: false,
  155. // 填报表单开启
  156. fillFormOpen: false,
  157. // 区域名称
  158. areaName: undefined,
  159. areaOptions: [],
  160. defaultProps: {
  161. children: 'children',
  162. label: 'label'
  163. },
  164. // 能源分类树
  165. emsClsOptions: [
  166. { code: 45, name: '电表' },
  167. { code: 70, name: '水表' }
  168. ],
  169. // 查询参数
  170. queryParams: {
  171. pageNum: 1,
  172. pageSize: 10,
  173. areaCode: null,
  174. deviceCode: null,
  175. meterCls: 45
  176. },
  177. // 电表表单参数
  178. recListForm: {
  179. year: '',
  180. deviceCode: '',
  181. recList: []
  182. },
  183. fillTitle: '',
  184. fillForm: {
  185. id: '',
  186. deviceCode: '',
  187. areaCode: '',
  188. lastTime: '',
  189. lastReading: '',
  190. meterTime: '',
  191. meterReading: '',
  192. increase: '',
  193. magnification: 1
  194. },
  195. curRow: {},
  196. ifAdd: true // 判断 新增还是修改
  197. }
  198. },
  199. computed: {
  200. increase() {
  201. const { meterReading, magnification, lastReading } = this.fillForm
  202. if (meterReading && magnification) {
  203. return (meterReading - (lastReading || 0)) * magnification
  204. }
  205. return ''
  206. }
  207. },
  208. created() {
  209. this.getAreaTreeByTag('Area', 'Area_01')
  210. this.getList()
  211. },
  212. methods: {
  213. /** 查询计量设备列表 */
  214. getList() {
  215. this.loading = true
  216. listDevice(this.queryParams).then(response => {
  217. this.deviceList = response.rows.map(item=>({
  218. ...item,
  219. meterMonth:'',
  220. lastTime:'',
  221. lastReading:'',
  222. }))
  223. this.total = response.total
  224. this.loading = false
  225. this.deviceList.forEach(async item => {
  226. await getLastRecord(item.areaCode, item.deviceCode).then(({ data }) => {
  227. if (data) {
  228. item.lastTime = data.meterTime
  229. item.meterMonth = data.meterMonth
  230. item.lastReading = data.meterReading
  231. }
  232. })
  233. })
  234. })
  235. },
  236. /** 搜索按钮操作 */
  237. handleQuery() {
  238. this.queryParams.pageNum = 1
  239. this.getList()
  240. },
  241. /** 重置按钮操作 */
  242. resetQuery() {
  243. this.resetForm('queryForm')
  244. this.handleQuery()
  245. },
  246. handleTabChange() {
  247. // 根据newTabName给someParam赋值
  248. if (this.activeTab === 'first') {
  249. // 电表抄表
  250. this.queryParams.meterCls = '45'
  251. } else if (this.activeTab === 'second') {
  252. // 水表抄表
  253. this.queryParams.meterCls = '70'
  254. }
  255. this.handleQuery()
  256. },
  257. getObjTypeName(objType) {
  258. const typeMap = {
  259. 1: '区块',
  260. 2: '设备'
  261. }
  262. return typeMap[objType] || '未知'
  263. },
  264. getColCycleName(colCycle) {
  265. const cycleMap = {
  266. 0: '实时',
  267. 1: '分钟',
  268. 2: '小时',
  269. 3: '天',
  270. 4: '月'
  271. }
  272. return cycleMap[colCycle] || ''
  273. },
  274. getObjTagName(objTag) {
  275. const tagMap = {
  276. 0: '公摊表',
  277. 1: '个户表'
  278. }
  279. return tagMap[objTag] || '未知'
  280. },
  281. async getAreaTreeByTag(tier, tagCode) {
  282. await areaTreeSelectByTag(tier, tagCode).then(response => {
  283. this.areaOptions = response.data
  284. })
  285. },
  286. // 筛选节点
  287. filterNode(value, data) {
  288. if (!value) return true
  289. return data.label.indexOf(value) !== -1
  290. },
  291. // 节点单击事件
  292. handleNodeClick(data) {
  293. this.queryParams.areaCode = data.id
  294. this.handleQuery()
  295. },
  296. handleViewRec(row) {
  297. this.recListForm = this.$options.data().recListForm
  298. this.resetForm('recListForm')
  299. this.title = '(' + this.getObjTypeName(row.objType) + ')' + row.objName
  300. this.curRow = row
  301. this.recListForm.year = dateFormat(new Date(), 'yyyy')
  302. this.recListForm.deviceCode = row.deviceCode
  303. this.getHistoryList()
  304. this.recListOpen = true
  305. },
  306. getHistoryList() {
  307. const { areaCode, deviceCode } = this.curRow
  308. listMeterReadingByParam({
  309. areaCode,
  310. deviceCode,
  311. year: this.recListForm.year,
  312. orderFlag: 'desc'
  313. }).then(response => {
  314. this.recListForm.recList = response.data || []
  315. })
  316. },
  317. async handleRecord(row) {
  318. this.fillForm = this.$options.data().fillForm
  319. this.resetForm('fillForm')
  320. this.fillTitle = '(' + this.getObjTypeName(row.objType) + ')' + row.objName
  321. this.fillForm.deviceCode = row.deviceCode
  322. this.fillForm.areaCode = row.areaCode
  323. this.fillForm.magnification = row.magnification
  324. this.fillForm.lastTime = row.lastTime
  325. this.fillForm.lastReading = row.lastReading
  326. this.ifAdd = true
  327. // let existFlag = false
  328. // // 获取上次填报记录
  329. // await getLastRecord(row.areaCode, row.deviceCode).then(({ data }) => {
  330. // if (data) {
  331. // if (data.meterMonth === this.currentMonth) {
  332. // existFlag = true
  333. // } else {
  334. // this.fillForm.lastTime = data.meterTime
  335. // this.fillForm.lastReading = data.meterReading
  336. // }
  337. // }
  338. // })
  339. // if (row.meterMonth===this.currentMonth) {
  340. // this.$modal.msgError('当前月份已填报')
  341. // } else {
  342. this.fillFormOpen = true
  343. // }
  344. },
  345. canEdit(meterMonth) {
  346. return meterMonth === this.currentMonth
  347. },
  348. canFill (lastTime) {
  349. return dateFormat(new Date(lastTime),'yyyyMM')!==this.currentMonth
  350. },
  351. updateRecord(row) {
  352. this.ifAdd = false
  353. this.fillFormOpen = true
  354. this.fillForm = this.$options.data().fillForm
  355. this.resetForm('fillForm')
  356. this.fillTitle = this.curRow.objName
  357. this.fillForm.deviceCode = this.curRow.deviceCode
  358. this.fillForm.areaCode = this.curRow.areaCode
  359. this.fillForm.magnification = this.curRow.magnification
  360. this.fillForm.id = row.id
  361. this.fillForm.lastTime = row.lastTime
  362. this.fillForm.lastReading = row.lastReading
  363. this.fillForm.meterReading = row.meterReading
  364. },
  365. submitFillForm() {
  366. this.$refs['fillForm'].validate(valid => {
  367. if (valid) {
  368. this.fillForm.increase = this.increase
  369. if (this.ifAdd) {
  370. addMeterReading(this.fillForm).then(({ code, msg }) => {
  371. if (code === 200) {
  372. this.$modal.msgSuccess('填报成功')
  373. this.fillFormOpen = false
  374. } else {
  375. this.$modal.msgError(msg)
  376. }
  377. })
  378. } else {
  379. updateMeterReading(this.fillForm).then(({ code, msg }) => {
  380. if (code === 200) {
  381. this.$modal.msgSuccess('修改成功')
  382. this.getHistoryList()
  383. this.fillFormOpen = false
  384. } else {
  385. this.$modal.msgError(msg)
  386. }
  387. })
  388. }
  389. }
  390. })
  391. },
  392. fillCancel() {
  393. this.fillFormOpen = false
  394. },
  395. closeRecList() {
  396. this.recListOpen = false
  397. }
  398. }
  399. }
  400. </script>