index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <template>
  2. <view class="content">
  3. <view class="msg-box">
  4. <view style="margin-bottom:10rpx;position:relative" v-for="item in msgList" :key="item.id">
  5. <view class="msg-item">
  6. <view class="msg-row">
  7. <image src="@/static/image/bj1.png" style="margin-right:20rpx;width: 40rpx;height:40rpx;"
  8. alt="">
  9. <view class="msg-content">
  10. 名称 :{{item.itemReadName}}
  11. </view>
  12. </view>
  13. <view class="msg-row">
  14. <image src="@/static/image/bj4.png" style="margin-right:20rpx;width: 40rpx;height:40rpx;"
  15. alt="">
  16. <view class="msg-content">
  17. 类型 :{{item.alarmType}}
  18. </view>
  19. </view>
  20. <view class="msg-row">
  21. <image src="@/static/image/bj3.png" style="margin-right:20rpx;width: 40rpx;height:40rpx;"
  22. alt="">
  23. <view class="msg-content">
  24. 时间 :{{item.alarmTime}}
  25. </view>
  26. </view>
  27. <view class="msg-row">
  28. <image src="@/static/image/bj2.png" style="margin-right:20rpx;width: 40rpx;height:40rpx;"
  29. alt="">
  30. <view class="msg-content">
  31. 报警描述 :<text style="font-weight: normal;">{{item.alarmText}}</text>
  32. </view>
  33. </view>
  34. <view class="msg-row" v-if="item.itemId!=0">
  35. <image src="@/static/image/bj5.png" style="margin-right:20rpx;width: 40rpx;height:40rpx;"
  36. alt="">
  37. <view class="msg-content">
  38. 报警值 :<text style="font-weight: normal;">{{item.alarmValue}}</text>
  39. </view>
  40. </view>
  41. <view class="msg-row">
  42. <u-button type="primary" size="small" class="cl" @click="handleMsg(item)">查看详情</u-button>
  43. </view>
  44. </view>
  45. <!-- <view class="msg-btn">
  46. <u-button type="primary" size="small" class="cl" @click="handleMsg(item.id)">查看详情</u-button>
  47. </view> -->
  48. <!-- <view class="emergent" v-if="item.readState!==0">
  49. <image src="@/static/image/jjbq.png" alt="" style="width:95rpx;height:80rpx">
  50. </view> -->
  51. </view>
  52. <view v-if="queryForm" class="query-screen">
  53. <view>
  54. 关键字
  55. </view>
  56. <div style="margin: 20px 0;">
  57. <input v-model="queryParams.queryKey" placeholder="请输入点位名称查询"/>
  58. </div>
  59. <view>
  60. 报警类型
  61. </view>
  62. <div style="margin: 20px 0;">
  63. <uni-data-select v-model="queryParams.alarmType" :localdata="alarmTypeList"></uni-data-select>
  64. </div>
  65. <view>
  66. 报警时间
  67. </view>
  68. <uni-datetime-picker v-model="range" type="datetimerange" start-placeholder="起始时间"
  69. end-placeholder="终止时间" @change="handelDate" return-type="timestamp" />
  70. <view class="month-btn">
  71. <u-button class="reset" style="width:200rpx" @click="reset">重置</u-button>
  72. <u-button type="primary" style="width:200rpx" @click="handelQuery">确认</u-button>
  73. </view>
  74. </view>
  75. </view>
  76. <u-empty v-if="!msgList.length" class="empty" icon="../../static/data.png" text="暂无数据">
  77. </u-empty>
  78. </view>
  79. </template>
  80. <script>
  81. import {
  82. getDayTime,
  83. timeToDate
  84. } from '@/utils/date.js'
  85. export default {
  86. data() {
  87. return {
  88. queryForm:false,
  89. // 日期选择
  90. range: [],
  91. //报警类型
  92. alarmTypeList:[
  93. {
  94. text:'数据源报警',
  95. value:'数据源',
  96. },
  97. {
  98. text:'点位报警',
  99. value:'点位'
  100. }
  101. ],
  102. // 查询参数
  103. queryParams: {
  104. queryKey:null,
  105. startDate:null,
  106. endDate:null,
  107. alarmType:null,
  108. page: 1,
  109. limit: 20
  110. },
  111. // 列表数据
  112. msgList: [],
  113. isload:false,
  114. pageCounts:0,
  115. };
  116. },
  117. onShow() {
  118. this.queryParams.limit = 20
  119. //this.loadAllAlarmData()
  120. this.getMsgList(true)
  121. uni.pageScrollTo({
  122. scrollTop: 0,
  123. duration: 0
  124. })
  125. },
  126. onPullDownRefresh() {
  127. //console.log('onPullDownRefresh')
  128. this.queryParams.page = 1
  129. this.getMsgList(true)
  130. },
  131. onReachBottom() {
  132. //console.log('onReachBottom')
  133. if(this.queryParams.page > this.pageCounts){
  134. this.isload = true
  135. }else{
  136. this.queryParams.page = this.queryParams.page + 1
  137. this.getMsgList(false)
  138. this.isload = false
  139. }
  140. },
  141. methods: {
  142. // 获取消息数据
  143. getMsgList(isCover) {
  144. if((this.queryParams.startDate==null) || (this.queryParams.endDate==null)){
  145. let dDate = getDayTime();
  146. this.queryParams.startDate = timeToDate(dDate[0])
  147. this.queryParams.endDate = timeToDate(dDate[1])
  148. }
  149. uni.$http.get('/mobileAlarm/queryUserAlarmData', this.queryParams).then(res => {
  150. const data = res.data
  151. if (data.code === 200) {
  152. this.pageCounts = data.data.count / this.queryForm.limit
  153. if(isCover){
  154. this.msgList = data.data.userAlarmLogList
  155. }else{
  156. this.msgList = this.msgList.concat(data.data.userAlarmLogList)
  157. }
  158. uni.stopPullDownRefresh()
  159. }
  160. })
  161. },
  162. //立即处理
  163. handleMsg(item) {
  164. uni.navigateTo({
  165. url: "/pages/message/msg-detail/index?data=" + JSON.stringify(item),
  166. })
  167. },
  168. onNavigationBarButtonTap(e){
  169. this.queryForm = !this.queryForm;
  170. if(this.queryForm){
  171. this.range = getDayTime()
  172. this.handelDate(this.range)
  173. }
  174. },
  175. resolvingDate(date) {
  176. if (!date) {
  177. return;
  178. }
  179. //date是传入的时间
  180. let d = new Date(date);
  181. let month = (d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1);
  182. let day = d.getDate() < 10 ? '0' + d.getDate() : d.getDate();
  183. let hours = d.getHours() < 10 ? '0' + d.getHours() : d.getHours();
  184. let min = d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes();
  185. let sec = d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds();
  186. let times;
  187. times = d.getFullYear() + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + sec;
  188. return times
  189. },
  190. //选择日期
  191. handelDate(date) {
  192. this.queryParams.startDate = this.resolvingDate(date[0])
  193. this.queryParams.endDate = this.resolvingDate(date[1])
  194. },
  195. //重置按钮
  196. reset() {
  197. this.queryParams = {
  198. queryKey:null,
  199. startDate:null,
  200. endDate:null,
  201. alarmType:null,
  202. page: 1,
  203. limit: 20
  204. }
  205. },
  206. //确认按钮查询
  207. handelQuery() {
  208. //如果没有选择时间,默认当天的起止时间
  209. this.queryParams.page = 1
  210. this.queryForm = false;
  211. this.getMsgList(true);
  212. },
  213. }
  214. }
  215. </script>
  216. <style lang="scss" scoped>
  217. .content {
  218. //padding: 20rpx 45rpx 20rpx 45rpx;
  219. background: #EEEDF2;
  220. }
  221. .empty {
  222. width: 400rpx;
  223. height: 400rpx;
  224. position: absolute;
  225. top: 50%;
  226. left: 50%;
  227. margin-top: -280rpx !important;
  228. margin-left: -200rpx;
  229. }
  230. .msg-box {
  231. .msg-item {
  232. background: #ffffff;
  233. padding: 25rpx;
  234. margin-bottom: 4rpx;
  235. .msg-row {
  236. display: flex;
  237. align-items: center;
  238. margin-bottom: 20rpx;
  239. .msg-content {
  240. width: 500rpx;
  241. white-space: nowrap;
  242. text-overflow: ellipsis;
  243. overflow: hidden;
  244. font-size: 14px;
  245. }
  246. }
  247. }
  248. .msg-btn {
  249. background: #ffffff;
  250. padding: 25rpx;
  251. .cl {
  252. width: 180rpx;
  253. margin-right: 0
  254. }
  255. }
  256. .emergent {
  257. position: absolute;
  258. right: 30rpx;
  259. top: 0;
  260. }
  261. .query-screen {
  262. width: 96vw;
  263. padding: 0 20rpx;
  264. background: #ffffff;
  265. position: absolute;
  266. top: 0;
  267. z-index: 999;
  268. .month {
  269. display: flex;
  270. justify-content: space-between;
  271. align-items: center;
  272. font-size: 28rpx;
  273. margin: 40rpx 0;
  274. .month-item {
  275. padding: 10rpx 20rpx;
  276. background: #ECECEC;
  277. color: #000000;
  278. border-radius: 12rpx;
  279. }
  280. .month-select {
  281. padding: 10rpx 20rpx;
  282. border-radius: 12rpx;
  283. background: #289BFF;
  284. color: #ffffff;
  285. }
  286. }
  287. .month-btn {
  288. display: flex;
  289. justify-content: space-around;
  290. margin-top: 40rpx;
  291. margin-bottom: 40rpx;
  292. .reset {
  293. background: #EAF4FF;
  294. color: #469DED;
  295. border: 1px solid #A3B8CB;
  296. }
  297. }
  298. }
  299. }
  300. </style>