msg.vue 13 KB

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