健康同学微信公众号h5项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

442 lines
12KB

  1. <template>
  2. <div class="news">
  3. <!-- <van-nav-bar title="消息通知" left-arrow @click-left="onNavBack" left-text="返回" /> -->
  4. <NavBar title="消息通知" @on-click-left="onNavBack"> </NavBar>
  5. <div class="list-con">
  6. <van-list v-model="loading" :finished="finished" :immediate-check="false" @load="onLoad">
  7. <div class="item">
  8. <div :class="[formatClass(item.typeName), 'list']" v-for="(item, index) in listData" :key="index">
  9. <div class="title">
  10. <span>{{ new Date($own.formatTime(item.time)).Format('MM月dd日 hh:mm') }}</span>
  11. </div>
  12. <div class="con" @click="listClick(item.typeName, item)">
  13. <div class="left">
  14. <i></i>
  15. </div>
  16. <div class="left">
  17. <p class="tit">{{ formatClass(item.typeName, true) }}</p>
  18. <p class="time">{{ new Date($own.formatTime(item.time)).Format('yyyy-MM-dd hh:mm:ss') }}</p>
  19. <p>{{ item.message }}</p>
  20. </div>
  21. <div class="right" v-show="formatClass(item.typeName) == 'sos' || item.typeName == 'DrownReport'">
  22. 详情
  23. </div>
  24. </div>
  25. </div>
  26. </div>
  27. </van-list>
  28. <div class="newsNotData" v-if="!isHasData">暂无消息~</div>
  29. </div>
  30. </div>
  31. </template>
  32. <script>
  33. /* import DialogService from '@/services/dialog-service'; */
  34. import ToastService from '@/services/toast-service';
  35. import APIUser from '@/api/user';
  36. import NavBar from '@/components/NavBar';
  37. export default {
  38. components: {
  39. NavBar
  40. },
  41. data() {
  42. return {
  43. personName: '',
  44. listData: [],
  45. loading: false,
  46. finished: false,
  47. pageNumber: 5, //每次显示多少条
  48. begNumber: 1, //页数
  49. isHasData: false //是否存在数据
  50. };
  51. },
  52. methods: {
  53. // 返回
  54. onNavBack() {
  55. // this.$router.go(-1);
  56. // todo 此处不能修改为 go(-1);因为情景有:微信推送时进入该页面,此时点击返回就该路由至首页。
  57. this.$router.push({ name: this.$route.query.toRouter || 'location' });
  58. },
  59. getData(begNumber, pageNumber, firstLoad) {
  60. /* let url = "/api/Alarm/AlarmList";
  61. let jsonData = {
  62. deviceId: this.$store.getters.deviceId,
  63. userId: this.$store.getters.userId,
  64. pageNumber,
  65. begNumber,
  66. timeOffset: -new Date().getTimezoneOffset() / 60
  67. };
  68. this.$axios
  69. .post(url, jsonData) */
  70. if (firstLoad) {
  71. ToastService.loading({
  72. message: '加载中'
  73. });
  74. }
  75. APIUser.alarmList({
  76. deviceId: this.$store.getters.deviceId,
  77. userId: this.$store.getters.userId,
  78. pageNumber,
  79. begNumber,
  80. timeOffset: -new Date().getTimezoneOffset() / 60
  81. })
  82. .then(res => {
  83. let item = res.data;
  84. this.isHasData = item.alarmList.length > 0;
  85. item.alarmList.forEach(val => {
  86. this.listData.push(val);
  87. });
  88. this.loading = false;
  89. if (item.alarmList == null || item.alarmList.length == 0) {
  90. this.finished = true;
  91. }
  92. })
  93. .catch(err => {
  94. console.log(err);
  95. })
  96. .finally(() => {
  97. ToastService.clear();
  98. });
  99. },
  100. listClick(name, item) {
  101. if (name == 'SOS') {
  102. this.$router.push({ name: 'details', query: item });
  103. } else if (name == 'DrownReport') {
  104. // 重新组装接口数据
  105. let queryData = item.urlDetail.split('?');
  106. let params = queryData[1].split('&');
  107. let queryBody = {
  108. imei: this.formatUrl(params, 'imei'),
  109. poiId: this.formatUrl(params, 'poiId'),
  110. title: this.formatUrl(params, 'title'),
  111. lng: this.formatUrl(params, 'lng'),
  112. lat: this.formatUrl(params, 'lat'),
  113. address: this.formatUrl(params, 'address'),
  114. time: this.formatUrl(params, 'time'),
  115. status: this.formatUrl(params, 'status'),
  116. showBack: '1'
  117. };
  118. this.$router.push({ name: 'dangerAreaDetails', query: queryBody });
  119. }
  120. },
  121. formatUrl(params, name) {
  122. let valueList = params
  123. .filter(item => {
  124. return item.split('=')[0] === name;
  125. })[0]
  126. .split('=');
  127. return valueList[1];
  128. },
  129. formatClass(val, text) {
  130. let value = '';
  131. /* Area = 6,//区域警告
  132. Temperature = 10,//体温推送
  133. CallLog = 11, //话单推送
  134. Healthy = 12, //心率、血氧、血压推送
  135. DrownReport = 13, //水域告警推送
  136. NoWear = 14, //水域告警推送 */
  137. switch (val) {
  138. case 'SOS':
  139. value = text ? '报警通知' : 'sos';
  140. break;
  141. case 'LowBattery':
  142. value = text ? '电量通知' : 'warning';
  143. break;
  144. case 'Entry':
  145. case 'Exit':
  146. value = text ? '围栏通知' : 'outOfRange';
  147. break;
  148. case 'PowerOff':
  149. value = text ? '关机报警' : 'off';
  150. break;
  151. case 'Area':
  152. value = text ? '区域报警' : 'area';
  153. break;
  154. /* case "Temperature":
  155. value = text ? '体温报警' : 'default'
  156. break; */
  157. case 'CallLog':
  158. value = text ? '话单推送' : 'callLog';
  159. break;
  160. case 'Healthy':
  161. value = text ? '健康通知' : 'healthy';
  162. break;
  163. case 'DrownReport':
  164. value = text ? '水域通知' : 'drownReport';
  165. break;
  166. case 'NoWear':
  167. value = text ? '携带监测' : 'noWear';
  168. break;
  169. }
  170. return value;
  171. },
  172. onLoad() {
  173. this.begNumber++;
  174. this.getData(this.begNumber, this.pageNumber);
  175. }
  176. },
  177. mounted() {
  178. this.getData(this.begNumber, this.pageNumber, true);
  179. /* let url = window.location.search;
  180. let id = url.split('user_id=')[1]; */
  181. let alarmUrl = window.location.href.split('msgId=')[1];
  182. if (alarmUrl) {
  183. this.$router.push({ name: 'alarmDetails', query: { msgId: alarmUrl } });
  184. }
  185. /* if (id) {
  186. if (id != this.$store.getters.userId) {
  187. DialogService.confirm({
  188. title: '登录失效,请重新登录~'
  189. }).then(() => {
  190. this.$router.push({ name: 'login' });
  191. });
  192. }
  193. } */
  194. console.log(this.$store.getters.userId);
  195. }
  196. };
  197. </script>
  198. <style lang="scss" scoped>
  199. .news {
  200. height: 100vh;
  201. overflow: hidden;
  202. background-color: $background;
  203. .list-con {
  204. position: relative;
  205. height: calc(100vh - 160px);
  206. overflow: scroll;
  207. .newsNotData {
  208. @include center();
  209. font-size: 32px;
  210. padding: 20px;
  211. }
  212. .item {
  213. padding: 0 35px;
  214. display: flex;
  215. flex-flow: column;
  216. justify-content: flex-start;
  217. align-items: center;
  218. .list {
  219. width: 100%;
  220. .title {
  221. @include center;
  222. margin: 20px 0;
  223. span {
  224. padding: 8px 12px;
  225. @include colorAndFont(#fff, 24);
  226. border-radius: 25px;
  227. background: #d1d1d1;
  228. }
  229. }
  230. .con {
  231. padding: 18px 20px 35px;
  232. position: relative;
  233. width: 100%;
  234. background: #fff;
  235. border-radius: 10px;
  236. box-sizing: border-box;
  237. display: flex;
  238. align-items: center;
  239. .left {
  240. display: flex;
  241. align-items: flex-start;
  242. flex-flow: column;
  243. i {
  244. width: 80px;
  245. height: 80px;
  246. border-radius: 50%;
  247. margin-right: 15px;
  248. @include center();
  249. &:after {
  250. content: '';
  251. position: absolute;
  252. }
  253. }
  254. p {
  255. @include colorAndFont(#787878, 28);
  256. &.tit {
  257. @include colorAndFont(#313131, 32);
  258. font-weight: 600;
  259. margin-bottom: 2px;
  260. }
  261. &.time {
  262. @include colorAndFont(#b4b7be, 24);
  263. margin-bottom: 12px;
  264. }
  265. }
  266. }
  267. .right {
  268. padding: 5px 20px;
  269. position: absolute;
  270. top: 30px;
  271. right: 30px;
  272. background: $blue;
  273. border-radius: 4px;
  274. @include colorAndFont(#fff, 28);
  275. }
  276. }
  277. &.warning {
  278. .con {
  279. .left {
  280. i {
  281. background: #ff4c39;
  282. &:after {
  283. width: 24px;
  284. height: 40px;
  285. @include icon;
  286. @include icon_position(24, 40, 368, 6);
  287. }
  288. }
  289. }
  290. }
  291. }
  292. &.sos {
  293. .con {
  294. .left {
  295. i {
  296. background: #ffa92f;
  297. &:after {
  298. width: 56px;
  299. height: 19px;
  300. @include icon;
  301. @include icon_position(56, 19, 306, 20);
  302. }
  303. }
  304. }
  305. }
  306. }
  307. &.outOfRange {
  308. .con {
  309. .left {
  310. i {
  311. background: $blue;
  312. &:after {
  313. width: 52px;
  314. height: 52px;
  315. @include icon;
  316. @include icon_position(52, 52, 251, 0);
  317. }
  318. }
  319. }
  320. }
  321. }
  322. &.off {
  323. .con {
  324. .left {
  325. i {
  326. background: #fd6666;
  327. &:after {
  328. width: 50px;
  329. height: 50px;
  330. @include icon;
  331. @include icon_position(50, 50, 300, 150);
  332. }
  333. }
  334. }
  335. }
  336. }
  337. &.default {
  338. .con {
  339. .left {
  340. i {
  341. background: $background;
  342. &:after {
  343. width: 60px;
  344. height: 60px;
  345. @include icon;
  346. @include icon_position(50, 50, 250, 200);
  347. }
  348. }
  349. }
  350. }
  351. }
  352. &.drownReport {
  353. .con {
  354. .left {
  355. i {
  356. background: $next;
  357. @include center();
  358. &:after {
  359. width: 50px;
  360. height: 50px;
  361. background: url('~@/assets/myself/drownReport.png') no-repeat;
  362. background-size: 50px;
  363. }
  364. }
  365. }
  366. }
  367. }
  368. &.callLog {
  369. .con {
  370. .left {
  371. i {
  372. background: $background;
  373. @include center();
  374. &:after {
  375. width: 50px;
  376. height: 50px;
  377. background: url('~@/assets/myself/callLog.png') no-repeat;
  378. background-size: 50px;
  379. }
  380. }
  381. }
  382. }
  383. }
  384. &.healthy {
  385. .con {
  386. .left {
  387. i {
  388. background: $background;
  389. @include center();
  390. &:after {
  391. width: 50px;
  392. height: 50px;
  393. background: url('~@/assets/myself/healthy.png') no-repeat;
  394. background-size: 50px;
  395. }
  396. }
  397. }
  398. }
  399. }
  400. &.noWear {
  401. .con {
  402. .left {
  403. i {
  404. background: $background;
  405. @include center();
  406. &:after {
  407. width: 50px;
  408. height: 50px;
  409. background: url('~@/assets/myself/noWear.png') no-repeat;
  410. background-size: 50px;
  411. }
  412. }
  413. }
  414. }
  415. }
  416. }
  417. }
  418. }
  419. }
  420. </style>