msg.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. <template>
  2. <view class="msg">
  3. <statusBar :item="navBarData"></statusBar>
  4. <view class="allRead" @click="updateisread">
  5. 一键已读
  6. </view>
  7. <view class="top">
  8. <view class="left" @click="puMsg" :class="current == 0 ? info1 : info2">
  9. <view class="" style="position: relative;">
  10. <view class="msgq" v-if="msgn>0">
  11. {{msgn}}
  12. </view>
  13. <text>消息通知</text>
  14. </view>
  15. <view v-if="current == 0" class="yun">
  16. <image src="https://teacherapi.cocorobo.cn/teaching-file/static//yym/Ellipse 10.png"
  17. mode="aspectFill"></image>
  18. </view>
  19. </view>
  20. <view class="right" @click="sysMsg" :class="current == 1 ? info1 : info2">
  21. <view class="" style="position: relative;">
  22. <view class="msgq" v-if="msgn2>0">
  23. {{msgn2}}
  24. </view>
  25. <text>系统通知</text>
  26. </view>
  27. <view v-if="current == 1" class="yun">
  28. <image src="https://teacherapi.cocorobo.cn/teaching-file/static//yym/Ellipse 10.png"
  29. mode="aspectFill"></image>
  30. </view>
  31. </view>
  32. </view>
  33. <swiper class="scroll-view-height" @change="swipeIndex" :current="current" :duration="300">
  34. <swiper-item>
  35. <scroll-view scroll-y="true" @scrolltolower="informlower" style="height: 100%;">
  36. <view class="">
  37. <view class="" v-for="(item,index) in Msglist" :key="index">
  38. <view class="msgBlock" @click="readOneMsg" :data-id="item">
  39. <view class="dian" v-if="!item.isread">•</view>
  40. <view class="tit">
  41. <view>活动报名成功</view>
  42. <view class="msgtime">
  43. {{item.create_at}}
  44. </view>
  45. </view>
  46. <view class="contxt">恭喜!您已成功完成<text
  47. style="color: rgba(0, 86, 168, 1);">“{{item.acName}}”</text>活动报名。您的参与信息已经成功提交,您现在是我们活动的一部分,我们非常期待与您共度美好时光。
  48. </view>
  49. <view class="contxt">
  50. 以下是一些额外信息,以确保您充分了解您的参与:
  51. </view>
  52. <view class="contxt1" style="display: flex;">
  53. <view class="" style="width: 2em;text-align: center;">•</view>
  54. <view class=""> 活动名称: [{{item.acName}}]</view>
  55. </view>
  56. <view class="contxt1" style="display: flex;">
  57. <view class="" style="width: 2em;text-align: center;">•</view>
  58. <view class=""> 日期: [×××]</view>
  59. </view>
  60. <view class="contxt1" style="display: flex;">
  61. <view class="" style="width: 2em;text-align: center;">•</view>
  62. <!-- <view class=""> 时间: [{{item.begin_at}}]</view> -->
  63. <view class=""> 时间: [×××]</view>
  64. </view>
  65. <view class="contxt1" style="display: flex;">
  66. <view class="" style="width: 2em;text-align: center;">•</view>
  67. <view class=""> 地点: [{{item.address}}]</view>
  68. </view>
  69. </view>
  70. <view class="msgBlock" v-if="item.type==1" @click="readOneMsg" :data-id="item">
  71. <view class="dian" v-if="!item.isread">•</view>
  72. <view class="tit">
  73. <view>活动开始提醒</view>
  74. <text class="msgtime">{{item.create_at}}</text>
  75. </view>
  76. <view class="contxt">
  77. <text style="color: rgba(0, 86, 168, 1);">“丽湖职教双创教育国际虚拟教研室 • 常规教研活动
  78. 第9期”</text>活动现在已经在我们的平台上正式上线,欢迎您点击浏览和积极参加。不要错过这个令人兴奋的机会,我们期待着与您一同度过难忘的时光。点击活动名称进入活动详情哦!
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. <view class="loading">
  84. <view v-if="clLoading==1">数据加载中...</view>
  85. <view v-if="clLoading==2">没有更多了~~</view>
  86. </view>
  87. </scroll-view>
  88. </swiper-item>
  89. <swiper-item>
  90. <scroll-view scroll-y="true" @scrolltolower="syslower" style="height: 100%;">
  91. <view class="">
  92. <view class="" v-for="(item,index) in syslist" :key="index">
  93. <view class="msgBlock" @click="readOneMsg" :data-id="item">
  94. <view class="dian" v-if="!item.isread">•</view>
  95. <view class="tit">
  96. <view>恭喜您,成功加入会员</view>
  97. <text class="msgtime">{{item.create_at}}</text>
  98. </view>
  99. <view class="contxt1">
  100. 尊敬的<text style="color: rgba(0, 86, 168, 1);">{{item.username}}</text>,
  101. </view>
  102. <view class="contxt">
  103. 我们很高兴通知您,您已成功加入<text
  104. style="color: rgba(0, 86, 168, 1);">[XXX小程序会员]</text>!欢迎加入我们的团队,我们期待与您一同合作并参与。
  105. </view>
  106. </view>
  107. </view>
  108. </view>
  109. <view class="loading">
  110. <view v-if="sysLoading==1">数据加载中...</view>
  111. <view v-if="sysLoading==2">没有更多了~~</view>
  112. </view>
  113. </scroll-view>
  114. </swiper-item>
  115. </swiper>
  116. <!-- 弹窗 -->
  117. <view style="width: 750rpx;height: 100vh;background-color: rgba(0, 0, 0, .5);padding: 0;position: absolute;"
  118. v-show="showPopup">
  119. <!-- <view class="mask" v-show="showPopup" @click="closePopup"></view> -->
  120. <view class="popup-container">
  121. <view class="popup">
  122. <view class="header">
  123. <text>确认一键已读?</text>
  124. </view>
  125. <view class="footer">
  126. <view class="cancel-btn" @click="showPopup=false">取消</view>
  127. <view class="confirm-btn" @click="conf">确认</view>
  128. </view>
  129. </view>
  130. </view>
  131. </view>
  132. </view>
  133. </template>
  134. <script>
  135. export default {
  136. data() {
  137. return {
  138. navBarData: {
  139. title: '活动消息',
  140. btn: 1
  141. },
  142. Msglist: [],
  143. syslist: [],
  144. showPopup: false,
  145. current: 0, //消息页面切换
  146. info1: "info1", //类名
  147. info2: "info2",
  148. msgn: 0,
  149. msgn2: 0,
  150. clLoading: 0,
  151. sysLoading: 0,
  152. clcurrentPage: 1, //页数
  153. syscurrentPage: 1, //页数
  154. };
  155. },
  156. methods: {
  157. // 获取消息通知数据
  158. getdata() {
  159. let data = {
  160. oid: this.$store.state.user.openid, //用户id
  161. ty: 0,
  162. page: this.clcurrentPage,
  163. lim: 15
  164. }
  165. this.$request('/selectMessage', "POST", data).then(res => {
  166. console.log('获取消息通知数据', res);
  167. if (!res[0].length) {
  168. this.clLoading = 2
  169. } else {
  170. this.clLoading = 0
  171. }
  172. this.Msglist = [...this.Msglist, ...res[0]]
  173. })
  174. },
  175. // 获取系统通知数据
  176. getdata2() {
  177. let data = {
  178. oid: this.$store.state.user.openid, //用户id
  179. ty: 1,
  180. page: this.syscurrentPage,
  181. lim: 15
  182. }
  183. this.$request('/selectMessage', "POST", data).then(res => {
  184. console.log('获取系统通知数据', res);
  185. if (!res[0].length) {
  186. this.sysLoading = 2
  187. } else {
  188. this.sysLoading = 0
  189. }
  190. this.syslist = [...this.syslist, ...res[0]]
  191. })
  192. },
  193. // 点击单个已读
  194. readOneMsg(e) {
  195. const data = e.currentTarget.dataset.id
  196. console.log(data);
  197. let a = {
  198. openid: this.$store.state.user.openid, //用户id
  199. id: data.id
  200. }
  201. if (data.isread == 0) {
  202. this.$request('/updateOneIsRead', "POST", a).then(res => {
  203. console.log(res);
  204. this.getMag()
  205. // 去除信息列表右上未读红点,current判断所在哪个消息列表
  206. if (this.current == 0) {
  207. this.Msglist.forEach(e => {
  208. if (data.id == e.id) {
  209. e.isread = 1
  210. }
  211. })
  212. } else {
  213. this.syslist.forEach(e => {
  214. if (data.id == e.id) {
  215. e.isread = 1
  216. }
  217. })
  218. }
  219. })
  220. }
  221. },
  222. // 消息通知触底
  223. informlower() {
  224. console.log('没触底?');
  225. if (this.clLoading == 2) return
  226. this.clLoading = 1
  227. this.clcurrentPage++
  228. setTimeout(this.getdata, 1000)
  229. },
  230. // 系统通知触底
  231. syslower() {
  232. console.log('没触底?');
  233. if (this.sysLoading == 2) return
  234. this.sysLoading = 1
  235. this.syscurrentPage++
  236. setTimeout(this.getdata2, 1000)
  237. },
  238. // 更新已读
  239. updateisread() {
  240. this.showPopup = true
  241. },
  242. // 弹窗确认已读
  243. conf() {
  244. let data = {
  245. oid: this.$store.state.user.openid, //用户id
  246. type: this.current,
  247. }
  248. this.$request('/updateIsRead', "POST", data).then(res => {
  249. // console.log('获取', res);
  250. // 未读提示红点重置为0,在后面赋值
  251. // this.msgn = 0
  252. // this.msgn2 = 0
  253. // 调用方法赋值未读红点
  254. this.getMag()
  255. // 去除信息列表右上未读红点,current判断所在哪个消息列表
  256. if (this.current == 0) {
  257. this.Msglist.forEach(e => {
  258. e.isread = 1
  259. })
  260. } else {
  261. this.syslist.forEach(e => {
  262. e.isread = 1
  263. })
  264. }
  265. this.showPopup = false
  266. })
  267. },
  268. // 获取未读信息
  269. getMag() {
  270. this.$request('/selectUnreadMsg', "POST", {
  271. oid: this.$store.state.user.openid
  272. }).then(res => {
  273. console.log('获取未读信息', res);
  274. // 未读提示红点重置为0,在后面赋值
  275. this.msgn = 0
  276. this.msgn2 = 0
  277. let arr = res[0]
  278. if (arr.length != 0) {
  279. arr.forEach(e => {
  280. if (e.type == 0) {
  281. this.msgn = res[0][0].msg
  282. } else if (e.type == 1 && arr.length == 2) {
  283. this.msgn2 = res[0][1].msg
  284. } else if (e.type == 1 && arr.length == 1) {
  285. this.msgn2 = res[0][0].msg
  286. }
  287. })
  288. }
  289. })
  290. },
  291. puMsg() {
  292. this.current = 0;
  293. },
  294. sysMsg() {
  295. this.current = 1;
  296. },
  297. swipeIndex(index) {
  298. this.current = index.detail.current;
  299. },
  300. },
  301. onShow() {
  302. this.Msglist= []
  303. this.syslist= []
  304. this.getdata()
  305. this.getdata2()
  306. this.getMag()
  307. }
  308. }
  309. </script>
  310. <style lang="scss">
  311. .msg {
  312. display: flex;
  313. flex-direction: column;
  314. flex: 1;
  315. justify-content: space-between;
  316. width: 750rpx;
  317. height: 100vh;
  318. .allRead {
  319. position: fixed;
  320. font-size: 20rpx;
  321. width: 90rpx;
  322. height: 90rpx;
  323. border-radius: 50%;
  324. text-align: center;
  325. line-height: 90rpx;
  326. background-color: rgba(0, 86, 168, 1);
  327. color: #fff;
  328. right: 70rpx;
  329. z-index: 10;
  330. bottom: 100rpx;
  331. }
  332. .loading {
  333. height: 30rpx;
  334. text-align: center;
  335. padding-top: 20rpx;
  336. padding-bottom: 100rpx;
  337. font-size: 26rpx;
  338. color: #888;
  339. line-height: 2em;
  340. }
  341. .top {
  342. display: flex;
  343. justify-content: space-between;
  344. margin: auto;
  345. width: 100%;
  346. background-color: #ffffff;
  347. padding: 10px 20%;
  348. // position: relative;
  349. .msgq {
  350. width: 32rpx;
  351. height: 32rpx;
  352. background-color: rgba(213, 73, 65, 1);
  353. border-radius: 50rpx;
  354. color: #fff;
  355. font-size: 20rpx;
  356. display: flex;
  357. justify-content: center;
  358. align-items: center;
  359. position: absolute;
  360. top: -10rpx;
  361. right: -20rpx;
  362. font-weight: normal !important;
  363. }
  364. .info1 {
  365. font-weight: bold !important;
  366. position: relative;
  367. color: rgba(0, 0, 0, 0.8);
  368. font-size: 34rpx;
  369. line-height: 48rpx;
  370. width: 136rpx;
  371. height: 48rpx;
  372. text-align: center;
  373. .yun {
  374. width: 134rpx;
  375. height: 32rpx;
  376. position: absolute;
  377. left: 0;
  378. bottom: -10rpx;
  379. image {
  380. width: 100%;
  381. height: 100%;
  382. }
  383. }
  384. }
  385. .info2 {
  386. color: rgba(0, 0, 0, 0.6);
  387. font-size: 34rpx;
  388. font-weight: 400;
  389. line-height: 48rpx;
  390. width: 136rpx;
  391. height: 48rpx;
  392. text-align: center;
  393. font-family: 微软雅黑;
  394. }
  395. }
  396. .scroll-view-height {
  397. padding: 20rpx 0;
  398. flex: 1;
  399. .msgBlock {
  400. width: 720rpx;
  401. margin: auto;
  402. background-color: #ffffff;
  403. border-radius: 12px;
  404. padding: 28rpx 24rpx 32rpx 24rpx;
  405. margin-bottom: 20rpx;
  406. position: relative;
  407. .dian {
  408. position: absolute;
  409. right: 10rpx;
  410. top: -20rpx;
  411. font-size: 60rpx;
  412. color: rgba(213, 73, 65, 1);
  413. }
  414. .tit {
  415. font-size: 34rpx;
  416. font-weight: 400;
  417. height: 48rpx;
  418. line-height: 48rpx;
  419. margin-bottom: 20rpx;
  420. color: rgba(0, 0, 0, 0.8);
  421. display: flex;
  422. justify-content: space-between;
  423. .msgtime {
  424. line-height: 58rpx;
  425. font-size: 28rpx;
  426. color: rgba(0, 0, 0, 0.4);
  427. }
  428. }
  429. .contxt {
  430. text-indent: 2em;
  431. color: rgba(0, 0, 0, 0.6);
  432. font-size: 28rpx;
  433. line-height: 40rpx;
  434. }
  435. .contxt1 {
  436. color: rgba(0, 0, 0, 0.6);
  437. font-size: 28rpx;
  438. line-height: 40rpx;
  439. }
  440. }
  441. }
  442. }
  443. </style>