ealarm.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <template>
  2. <div class="mod-role">
  3. <el-container>
  4. <!-- form表单 -->
  5. <el-header>
  6. <div class="rect rect-form">
  7. <el-form :inline="true" :model="form" @keyup.enter.native="getDataList()" size="mini" ref="form">
  8. <!-- <el-form-item style="width: 140px">
  9. <el-select placeholder="牧场" v-model="form.farmId" :disabled="farmId > 0">
  10. <el-option
  11. v-for="item in farmList"
  12. :key="item.value"
  13. :label="item.label"
  14. :value="item.value">
  15. </el-option>
  16. </el-select>
  17. </el-form-item> -->
  18. <el-form-item style="width: 140px">
  19. <el-select placeholder="参数名称" v-model="form.thresholdType">
  20. <el-option
  21. v-for="item in thresholdTypes"
  22. :key="item.value"
  23. :label="item.label"
  24. :value="item.value">
  25. </el-option>
  26. </el-select>
  27. </el-form-item>
  28. <el-form-item>
  29. <el-button @click="getDataList()" icon="el-icon-search">查 询</el-button>
  30. </el-form-item>
  31. <el-form-item>
  32. <el-button
  33. icon="el-icon-circle-close"
  34. @click="clearAll">清 空</el-button>
  35. </el-form-item>
  36. </el-form>
  37. </div>
  38. </el-header>
  39. <!-- role表格 -->
  40. <el-main>
  41. <div class="rect rect-table">
  42. <!-- 新增 删除按钮 -->
  43. <el-form inline size="mini">
  44. <el-form-item>
  45. <el-button
  46. icon="el-icon-plus"
  47. @click="addOrUpdateHandle()">
  48. 新 增
  49. </el-button>
  50. </el-form-item>
  51. <el-form-item>
  52. <el-button
  53. icon="el-icon-delete"
  54. type="danger"
  55. @click="deleteHandle()"
  56. :disabled="dataListSelections.length <= 0">
  57. 删 除
  58. </el-button>
  59. </el-form-item>
  60. <el-form-item>
  61. <el-button
  62. icon="el-icon-download"
  63. type="danger"
  64. @click="exportExcel()">
  65. 导出Excel
  66. </el-button>
  67. </el-form-item>
  68. </el-form>
  69. <el-table
  70. :data="dataList"
  71. border
  72. stripe
  73. v-loading="dataListLoading"
  74. @selection-change="selectionChangeHandle"
  75. style="width: 100%;"
  76. size="mini"
  77. height="540"
  78. :header-cell-style="{background:'rgb(245,245,245)',color:'#000',height: '45px',fontSize: '13px',fontWeight: 'normal',borderBottom: '1px solid #ccc'}"
  79. :cell-style="{color: '#888',fontSize: '13px'}">
  80. <el-table-column
  81. type="selection"
  82. header-align="center"
  83. align="center"
  84. width="50">
  85. </el-table-column>
  86. <!-- <el-table-column
  87. prop="farmName"
  88. header-align="center"
  89. align="center"
  90. label="牧场名称">
  91. <template slot-scope="scope">
  92. <span>{{thresholdTypes[scope.row.thresholdType - 1].label}}</span>
  93. </template>
  94. </el-table-column> -->
  95. <el-table-column
  96. header-align="center"
  97. align="center"
  98. label="参数名称">
  99. <template slot-scope="scope">
  100. <span>{{thresholdTypes[scope.row.thresholdType - 1].label}}</span>
  101. </template>
  102. </el-table-column>
  103. <el-table-column
  104. prop="thresholdValue"
  105. header-align="center"
  106. align="center"
  107. label="阈值">
  108. </el-table-column>
  109. <el-table-column
  110. header-align="center"
  111. align="center"
  112. label="操作">
  113. <template slot-scope="scope">
  114. <el-button
  115. type="text"
  116. size="mini"
  117. style="color: rgb(24,144,255)"
  118. @click="addOrUpdateHandle(scope.row.id)">
  119. 编辑
  120. </el-button>
  121. <el-button
  122. type="text"
  123. size="mini"
  124. @click="deleteHandle(scope.row.id)"
  125. style="color: rgb(24,144,255)">
  126. 删除
  127. </el-button>
  128. </template>
  129. </el-table-column>
  130. </el-table>
  131. <el-pagination
  132. @size-change="sizeChangeHandle"
  133. @current-change="currentChangeHandle"
  134. :current-page="pageIndex"
  135. :page-sizes="[10, 20, 50, 100]"
  136. :page-size="pageSize"
  137. :total="totalPage"
  138. layout="total, sizes, prev, pager, next, jumper">
  139. </el-pagination>
  140. <!-- 弹窗, 新增 / 修改 -->
  141. <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList" :thresholdTypes="thresholdTypes"></add-or-update>
  142. </div>
  143. </el-main>
  144. </el-container>
  145. </div>
  146. </template>
  147. <script>
  148. import AddOrUpdate from './ealarm-add-or-update'
  149. export default {
  150. data () {
  151. return {
  152. form: {
  153. thresholdType: '',
  154. // farmId: ''
  155. },
  156. dataList: [],
  157. pageIndex: 1,
  158. pageSize: 10,
  159. totalPage: 0,
  160. dataListLoading: false,
  161. dataListSelections: [],
  162. addOrUpdateVisible: false,
  163. // farmId: undefined,
  164. // farmList: [], // 牧场List
  165. labelPosition: 'right',
  166. thresholdTypes: [
  167. {
  168. label: '室内高温',
  169. value: 1
  170. },
  171. {
  172. label: '室内低温',
  173. value: 2
  174. },
  175. {
  176. label: '室内空气污染',
  177. value: 3
  178. },
  179. {
  180. label: '饮用水污染',
  181. value: 4
  182. },
  183. {
  184. label: '室外高温',
  185. value: 5
  186. },
  187. {
  188. label: '室外低温',
  189. value: 6
  190. },
  191. {
  192. label: '室外空气污染',
  193. value: 7
  194. },
  195. {
  196. label: '体温高温',
  197. value: 8
  198. },
  199. {
  200. label: '体温低温',
  201. value: 9
  202. },
  203. {
  204. label: '耳标电量过低',
  205. value: 10
  206. }
  207. ]
  208. }
  209. },
  210. components: {
  211. AddOrUpdate
  212. },
  213. activated () {
  214. this.getDataList()
  215. },
  216. methods: {
  217. // 获取数据列表
  218. getDataList () {
  219. // this.farmId = this.$cookie.get('farmId') === 'null'? undefined: parseInt(this.$cookie.get('farmId'))
  220. this.dataListLoading = true
  221. this.$http({
  222. url: this.$http.adornUrl('/management/thresholdManagement/list'),
  223. method: 'get',
  224. params: this.$http.adornParams({
  225. 'page': this.pageIndex,
  226. 'limit': this.pageSize,
  227. 'thresholdType': this.form.thresholdType || undefined,
  228. 'farmId': parseInt(this.$cookie.get('formFarmId'))
  229. })
  230. }).then(async({data}) => {
  231. // 获取所有牧场
  232. // this.farmList = []
  233. // let farmList = []
  234. // let farmResult = await this.$http({
  235. // url: this.$http.adornUrl("/management/farm/findAll"),
  236. // method: "get",
  237. // params: this.$http.adornParams({})
  238. // })
  239. // farmResult.data.all && (farmList = farmResult.data.all)
  240. // farmList.forEach(farm => {
  241. // let item = {
  242. // label: farm.name,
  243. // value: farm.id
  244. // }
  245. // this.farmList.push(item)
  246. // })
  247. // 获取报警List
  248. if (data && data.code === 0) {
  249. this.dataList = data.page.list
  250. this.totalPage = data.page.totalCount
  251. } else {
  252. this.dataList = []
  253. this.totalPage = 0
  254. this.$message.error(data.msg)
  255. }
  256. // this.form.farmId = (this.form.farmId || this.farmId) || undefined
  257. this.dataListLoading = false
  258. })
  259. },
  260. // form表单清空,单元SelectedList 和 栏期SelectedList重置
  261. clearAll () {
  262. this.form.thresholdType = ''
  263. },
  264. // 每页数
  265. sizeChangeHandle (val) {
  266. this.pageSize = val
  267. this.pageIndex = 1
  268. this.getDataList()
  269. },
  270. // 当前页
  271. currentChangeHandle (val) {
  272. this.pageIndex = val
  273. this.getDataList()
  274. },
  275. // 多选
  276. selectionChangeHandle (val) {
  277. this.dataListSelections = val
  278. },
  279. // 新增 / 修改
  280. addOrUpdateHandle (id) {
  281. this.addOrUpdateVisible = true
  282. this.$nextTick(() => {
  283. this.$refs.addOrUpdate.init(id)
  284. })
  285. },
  286. // 导出Excel
  287. exportExcel () {
  288. // this.$http({
  289. // url: this.$http.adornUrl('/management/thresholdManagement/exportXls'),
  290. // method: 'get',
  291. // params: this.$http.adornParams({
  292. // 'thresholdType': this.form.thresholdType || undefined,
  293. // 'farmId': parseInt(this.$cookie.get('formFarmId'))
  294. // })
  295. // }).then()
  296. // window.open(`http://192.168.1.57:88/api/management/thresholdManagement/exportXls?thresholdType=${this.form.thresholdType}&farmId=${parseInt(this.$cookie.get('formFarmId'))}`);
  297. this.$http({
  298. url: this.$http.adornUrl('/management/thresholdManagement/exportXls'),
  299. method: 'get',
  300. params: this.$http.adornParams({
  301. 'thresholdType': this.form.thresholdType || undefined,
  302. 'farmId': parseInt(this.$cookie.get('formFarmId'))
  303. }),
  304. responseType: 'blob'
  305. }).then(({data}) => {
  306. if (!data) {
  307. this.$message.error('文件下载失败')
  308. return
  309. }
  310. let url = window.URL.createObjectURL(new Blob([data], {type: 'application/vnd.ms-excel'}))
  311. let link = document.createElement('a')
  312. link.style.display = 'none'
  313. link.href = url
  314. link.setAttribute('download', '阈值列表.xls')
  315. document.body.appendChild(link)
  316. link.click()
  317. document.body.removeChild(link)
  318. window.URL.revokeObjectURL(url)
  319. })
  320. },
  321. // 删除
  322. deleteHandle (id) {
  323. var ids = id ? [id] : this.dataListSelections.map(item => {
  324. return item.id
  325. })
  326. this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
  327. confirmButtonText: '确定',
  328. cancelButtonText: '取消',
  329. type: 'warning'
  330. }).then(() => {
  331. this.$http({
  332. url: this.$http.adornUrl('/management/thresholdManagement/delete'),
  333. method: 'post',
  334. data: this.$http.adornData(ids, false)
  335. }).then(({data}) => {
  336. if (data && data.code === 0) {
  337. this.getDataList()
  338. this.$message({
  339. message: '操作成功',
  340. type: 'success',
  341. duration: 1500
  342. })
  343. } else {
  344. this.$message.error(data.msg)
  345. }
  346. })
  347. }).catch(() => {})
  348. }
  349. }
  350. }
  351. </script>
  352. <style scoped>
  353. .rect {
  354. background-color: #fff;
  355. padding: 30px 15px;
  356. border-radius: 5px;
  357. border: 1px solid #e8e8e8;
  358. }
  359. .rect-form {
  360. padding-bottom: 10px;
  361. }
  362. .rect-table {
  363. margin-top: 20px;
  364. }
  365. .demo-table-expand {
  366. font-size: 0;
  367. margin-left: 40px;
  368. }
  369. .demo-table-expand label {
  370. width: 90px;
  371. color: #99a9bf;
  372. }
  373. .demo-table-expand .el-form-item {
  374. margin-right: 0;
  375. margin-bottom: 0;
  376. width: 80%;
  377. }
  378. .el-table .height {
  379. background: rgba(254, 254, 254, 0.5);
  380. }
  381. /deep/ .el-table--mini td, .el-table--mini th {
  382. padding: 3px 0 !important;
  383. height: 20px !important;
  384. }
  385. /deep/ .el-checkbox__input.is-checked+.el-checkbox__label {
  386. color: rgb(24,144,255);
  387. background-color: rgb(24,144,255);
  388. border-color: rgb(24,144,255);
  389. }
  390. /deep/.el-table .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner {
  391. background-color: rgb(24,144,255);
  392. border-color: rgb(24,144,255);
  393. }
  394. /deep/.el-table .el-checkbox__inner:hover {
  395. border-color: rgb(24,144,255);
  396. }
  397. /deep/.el-table .el-checkbox__input.is-focus .el-checkbox__inner {
  398. border-color: rgb(24,144,255);
  399. }
  400. /deep/.el-table #select .cell .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner {
  401. background-color: rgb(24,144,255);
  402. border-color: rgb(24,144,255);
  403. }
  404. </style>