temp.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <div class="stock">
  3. <template v-if="!addOrUpdateVisible && !detailVisible && !historyVisible">
  4. <el-form :inline="true" :model="dataForm" @keyup.enter.native="search()">
  5. <el-form-item label="所属部门">
  6. <org-component v-model="dataForm.orgId"/>
  7. </el-form-item>
  8. <el-form-item label="设备维护人">
  9. <user-component v-model="dataForm.maintainerId"/>
  10. </el-form-item>
  11. <el-form-item label="设备型号">
  12. <el-select
  13. v-model="dataForm.model"
  14. remote
  15. placeholder="请选择">
  16. <el-option
  17. v-for="item in optionsModel"
  18. :key="item.code"
  19. :label="item.value"
  20. :value="item.code">
  21. </el-option>
  22. </el-select>
  23. </el-form-item>
  24. <el-form-item label="设备编号">
  25. <el-input v-model="dataForm.code" placeholder="设备编号" clearable/>
  26. </el-form-item>
  27. <el-form-item label="最后上报时间">
  28. <el-date-picker
  29. v-model="dataForm.date"
  30. value-format="yyyy-MM-dd HH:mm:ss"
  31. type="datetimerange"
  32. range-separator="至"
  33. start-placeholder="开始时间"
  34. end-placeholder="结束时间">
  35. </el-date-picker>
  36. </el-form-item>
  37. <el-form-item>
  38. <el-button @click="search()">查询</el-button>
  39. <el-button v-if="isAuth('device:temp:save')" type="primary" @click="addOrUpdateHandle(0)">新增</el-button>
  40. </el-form-item>
  41. </el-form>
  42. <el-table
  43. :data="dataList"
  44. border
  45. v-loading="dataListLoading"
  46. style="width: 100%;">
  47. <el-table-column
  48. label="序号"
  49. type="index"
  50. width="50"
  51. align="center">
  52. </el-table-column>
  53. <el-table-column
  54. prop="code"
  55. header-align="center"
  56. align="center"
  57. min-width="120"
  58. label="设备编号">
  59. </el-table-column>
  60. <el-table-column
  61. prop="model"
  62. header-align="center"
  63. align="center"
  64. min-width="100"
  65. :formatter="formatOptionsModel"
  66. :show-overflow-tooltip="true"
  67. label="设备型号">
  68. </el-table-column>
  69. <el-table-column
  70. prop="orgStr"
  71. header-align="center"
  72. align="center"
  73. min-width="160"
  74. :show-overflow-tooltip="true"
  75. label="所属部门">
  76. </el-table-column>
  77. <el-table-column
  78. prop="maintainerStr"
  79. header-align="center"
  80. align="center"
  81. min-width="100"
  82. :show-overflow-tooltip="true"
  83. label="设备维护人">
  84. </el-table-column>
  85. <el-table-column
  86. prop="lastReportTime"
  87. header-align="center"
  88. align="center"
  89. min-width="160"
  90. :show-overflow-tooltip="true"
  91. label="最后一次上报时间">
  92. </el-table-column>
  93. <el-table-column
  94. prop="temperature"
  95. header-align="center"
  96. align="center"
  97. min-width="100"
  98. label="温度(℃)">
  99. </el-table-column>
  100. <el-table-column
  101. prop="humidity"
  102. header-align="center"
  103. align="center"
  104. min-width="100"
  105. label="湿度(%)">
  106. </el-table-column>
  107. <el-table-column
  108. prop="lastAlarmTime"
  109. header-align="center"
  110. align="center"
  111. min-width="160"
  112. :show-overflow-tooltip="true"
  113. label="最后一次报警时间">
  114. </el-table-column>
  115. <el-table-column
  116. prop="notes"
  117. header-align="center"
  118. align="center"
  119. min-width="180"
  120. :show-overflow-tooltip="true"
  121. label="备注">
  122. </el-table-column>
  123. <el-table-column
  124. fixed="right"
  125. header-align="center"
  126. align="center"
  127. width="200"
  128. label="操作">
  129. <template slot-scope="scope">
  130. <el-button v-if="isAuth('device:temp:info')" type="text" size="small" @click="detailHandle(scope.row.id)">查看</el-button>
  131. <el-button v-if="isAuth('device:temp:edit')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">编辑</el-button>
  132. <el-button v-if="isAuth('device:temp:list')" type="text" size="small" @click="historyHandle(scope.row)">历史数据</el-button>
  133. <el-button v-if="isAuth('device:temp:history')" style="color: red" type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
  134. </template>
  135. </el-table-column>
  136. </el-table>
  137. <el-pagination
  138. @size-change="sizeChangeHandle"
  139. @current-change="currentChangeHandle"
  140. :current-page="pageIndex"
  141. :page-sizes="[10, 20, 50, 100]"
  142. :page-size="pageSize"
  143. :total="totalPage"
  144. layout="total, sizes, prev, pager, next, jumper">
  145. </el-pagination>
  146. </template>
  147. <!-- 弹窗, 新增 / 修改 -->
  148. <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList" @onChose="onChose"></add-or-update>
  149. <detail v-if="detailVisible" ref="detail" @onChose="onChose"/>
  150. <history v-if="historyVisible" ref="history" @onChose="onChose"/>
  151. </div>
  152. </template>
  153. <script>
  154. import { getDictList } from '@/api/dict'
  155. import AddOrUpdate from './temp-add-or-update'
  156. import Detail from './temp-detail'
  157. import History from './temp-history'
  158. import OrgComponent from '../common/org-component'
  159. import UserComponent from '../common/user-component'
  160. export default {
  161. name: 'temp',
  162. components: {
  163. Detail,
  164. History,
  165. AddOrUpdate,
  166. UserComponent,
  167. OrgComponent
  168. },
  169. data () {
  170. return {
  171. addOrUpdateVisible: false,
  172. detailVisible: false,
  173. historyVisible: false,
  174. dataForm: {},
  175. dataList: [],
  176. pageIndex: 1,
  177. pageSize: 10,
  178. totalPage: 0,
  179. dataListLoading: false,
  180. dataListSelections: [],
  181. optionsModel: []
  182. }
  183. },
  184. created () {
  185. this.getModelList()
  186. this.getDataList()
  187. },
  188. methods: {
  189. onChose () {
  190. this.addOrUpdateVisible = false
  191. this.detailVisible = false
  192. this.historyVisible = false
  193. },
  194. // 获取温湿度计设备型号列表
  195. getModelList () {
  196. getDictList({type: 'temp_model'}).then(({data}) => {
  197. if (data) {
  198. this.optionsModel = data
  199. }
  200. })
  201. },
  202. // 查询
  203. search () {
  204. this.pageIndex = 1
  205. this.getDataList()
  206. },
  207. // 获取数据列表
  208. getDataList () {
  209. this.dataListLoading = true
  210. this.addOrUpdateVisible = false
  211. this.$http({
  212. url: this.$http.adornUrl('/iot-platform/temp/list'),
  213. method: 'get',
  214. params: this.$http.adornParams({
  215. 'current': this.pageIndex,
  216. 'size': this.pageSize,
  217. 'code': this.dataForm.code ? this.dataForm.code : null,
  218. 'model': this.dataForm.model ? this.dataForm.model : null,
  219. 'orgId': this.dataForm.orgId ? this.dataForm.orgId : null,
  220. 'maintainerId': this.dataForm.maintainerId ? this.dataForm.maintainerId : null,
  221. 'lastReportTimeStart': this.dataForm.date ? this.dataForm.date[0] : null,
  222. 'lastReportTimeEnd': this.dataForm.date ? this.dataForm.date[1] : null
  223. })
  224. }).then(({data}) => {
  225. if (data && data.code === '200') {
  226. this.dataList = data.data.records
  227. this.totalPage = Number(data.data.total)
  228. } else {
  229. this.dataList = []
  230. this.totalPage = 0
  231. }
  232. this.dataListLoading = false
  233. })
  234. },
  235. // 每页数
  236. sizeChangeHandle (val) {
  237. this.pageSize = val
  238. this.pageIndex = 1
  239. this.getDataList()
  240. },
  241. // 当前页
  242. currentChangeHandle (val) {
  243. this.pageIndex = val
  244. this.getDataList()
  245. },
  246. // 多选
  247. selectionChangeHandle (val) {
  248. this.dataListSelections = val
  249. },
  250. // 新增 / 修改
  251. addOrUpdateHandle (id, disable) {
  252. this.addOrUpdateVisible = true
  253. this.$nextTick(() => {
  254. this.$refs.addOrUpdate.init(id, disable)
  255. })
  256. },
  257. detailHandle (id) {
  258. this.detailVisible = true
  259. this.$nextTick(() => {
  260. this.$refs.detail.init(id)
  261. })
  262. },
  263. historyHandle (row) {
  264. this.historyVisible = true
  265. this.$nextTick(() => {
  266. this.$refs.history.init(row.code)
  267. })
  268. },
  269. // 转换属性“设备型号”
  270. formatOptionsModel (row) {
  271. for (let i = 0; i < this.optionsModel.length; i++) {
  272. if (this.optionsModel[i].code === row.model) {
  273. return this.optionsModel[i].value
  274. }
  275. }
  276. },
  277. // 删除
  278. deleteHandle (id) {
  279. if (!id) return
  280. let ids = []
  281. ids.push(id)
  282. this.$confirm(`确定删除?`, '提示', {
  283. confirmButtonText: '确定',
  284. cancelButtonText: '取消',
  285. type: 'warning'
  286. }).then(() => {
  287. this.$http({
  288. url: this.$http.adornUrl(`/iot-platform/temp/delete`),
  289. method: 'DELETE',
  290. data: ids
  291. }).then(({data}) => {
  292. if (data && data.code === '200') {
  293. this.$message({
  294. message: '操作成功',
  295. type: 'success',
  296. duration: 1500,
  297. onClose: () => {
  298. this.getDataList()
  299. }
  300. })
  301. } else {
  302. this.$message.error(data.msg)
  303. }
  304. })
  305. }).catch(() => {})
  306. }
  307. }
  308. }
  309. </script>
  310. <style scoped>
  311. </style>