messageCenter.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <template>
  2. <view class="messageCenter">
  3. <global-loading />
  4. <view>
  5. <view v-if="messageList.length" class="flex-items flex-sp-between fs26 topTitBox">
  6. <view>
  7. 未读消息{{ num }}条
  8. </view>
  9. <view v-if="num != 0" class="allRead" @click="allMessage">
  10. 全部已读
  11. </view>
  12. </view>
  13. <u-swipe-action
  14. v-for="(item, index) in messageList" :key="item.noticeId" class="u-swipe-action" :show="item.show"
  15. :index="index" :options="options" @click="productClick(item)"
  16. >
  17. <view class="messageItem" @click="goToMesDetail(item.noticeId, item.only, item.jump)">
  18. <view class="messageBox">
  19. <view class="messageType">
  20. <view v-if="item.noticeType == 1" class="messageTypeL">
  21. <view class="iconBox">
  22. <image src="../../static/images/origin/notice.png" alt=""></image>
  23. <view v-if="item.ifRead === 0" class="redBox"></view>
  24. </view>
  25. <span>订单消息</span>
  26. </view>
  27. <view v-else class="messageTypeL">
  28. <view class="iconBox">
  29. <image src="../../static/images/origin/notice.png" alt=""></image>
  30. </view>
  31. <span>系统公告</span>
  32. </view>
  33. <view class="messageTypeR">{{ item.createTime }}</view>
  34. </view>
  35. <view>
  36. <rich-text class="messageInfo" :nodes="item.htmlData"></rich-text>
  37. </view>
  38. </view>
  39. <!-- <view class="messageBtn"> -->
  40. <!-- <span class="viewDetail">查看详情</span> -->
  41. <!-- <span class="arrow"></span> -->
  42. <!-- </view> -->
  43. </view>
  44. </u-swipe-action>
  45. </view>
  46. <view v-if="ifEmpty" class="empty-box">
  47. <image class="question-empty" src="../../static/images/origin/bgnull.png"></image>
  48. <view class="tohome-box flex-items-plus">暂无消息</view>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import parse from 'mini-html-parser2'
  54. const NET = require('../../utils/request')
  55. const API = require('../../config/api')
  56. export default {
  57. data() {
  58. return {
  59. list: 3,
  60. messageList: [],
  61. page: 1,
  62. pageSize: 10,
  63. loadingType: 0,
  64. num: 0,
  65. options: [ {
  66. text: '删除',
  67. style: {
  68. backgroundColor: '#F15C48'
  69. }
  70. } ],
  71. ifEmpty: false
  72. }
  73. },
  74. onShow() {
  75. this.page = 1
  76. this.messageList = []
  77. this.getAllMessage()
  78. this.GetUser()
  79. },
  80. onLoad() {
  81. },
  82. onReachBottom() {
  83. if (this.loadingType == 1) {
  84. uni.stopPullDownRefresh()
  85. } else {
  86. this.page = this.page + 1
  87. this.getAllMessage()
  88. }
  89. },
  90. methods: {
  91. GetUser() {
  92. NET.request(API.GetUser, {}, 'GET').then((res) => {
  93. this.num = res.data.notRead
  94. })
  95. .catch((res) => {
  96. })
  97. },
  98. parseText(html) {
  99. parse(html, (err, htmlData) => htmlData)
  100. },
  101. formatRichText(html) {
  102. let newContent = html.replace(/<img[^>]*>/gi, function (match, capture) {
  103. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '')
  104. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '')
  105. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '')
  106. return match
  107. })
  108. newContent = newContent.replace(/style="[^"]+"/gi, function (match, capture) {
  109. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(
  110. /width:[^;]+;/gi,
  111. 'max-width:100%;'
  112. )
  113. return match
  114. })
  115. newContent = newContent.replace(/<br[^>]*\/>/gi, '')
  116. newContent = newContent.replace(
  117. /\<img/gi,
  118. '<img style="max-width:100%;height:auto;display:block;margin-top:0;margin-bottom:0;"'
  119. )
  120. return newContent
  121. },
  122. getAllMessage() {
  123. // uni.showLoading({
  124. // mask: true,
  125. // title: '加载中...'
  126. // })
  127. NET.request(API.getMessage, {
  128. 'page': this.page,
  129. 'pageSize': this.pageSize
  130. }, 'GET').then((res) => {
  131. uni.hideLoading()
  132. if (res.data.length == 0) {
  133. this.loadingType = 1
  134. this.page = this.page
  135. } else {
  136. const _messageList = this.messageList.concat(res.data.list)
  137. this.messageList = _messageList.map((item) => {
  138. let newContent = item.noticeContent.replace(/<img[^>]*>/gi, function (
  139. match,
  140. capture
  141. ) {
  142. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '')
  143. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '')
  144. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '')
  145. return match
  146. })
  147. newContent = newContent.replace(/style="[^"]+"/gi, function (match, capture) {
  148. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(
  149. /width:[^;]+;/gi,
  150. 'max-width:100%;'
  151. )
  152. return match
  153. })
  154. newContent = newContent.replace(/<br[^>]*\/>/gi, '')
  155. newContent = newContent.replace(
  156. /\<img/gi,
  157. '<img style="max-width:100%;height:auto;display:block;margin-top:0;margin-bottom:0;"'
  158. )
  159. // return newContent;
  160. parse(newContent, (err, htmlData) => {
  161. item.htmlData = htmlData
  162. })
  163. return item
  164. })
  165. if (this.messageList.length === 0) {
  166. this.ifEmpty = true
  167. }
  168. // let unReadList = []
  169. // unReadList = this.messageList.filter(el => el.ifRead == 0)
  170. // this.num = unReadList.length
  171. }
  172. })
  173. .catch((res) => {
  174. uni.hideLoading()
  175. uni.showToast({
  176. title: '失败',
  177. icon: 'none'
  178. })
  179. })
  180. },
  181. // 删除消息
  182. productClick(item) {
  183. // uni.showLoading({
  184. // mask: true,
  185. // title: '正在删除...'
  186. // })
  187. NET.request(API.delMessage, {
  188. noticeId: item.noticeId
  189. }, 'post').then((res) => {
  190. uni.hideLoading()
  191. if (res.code == 200) {
  192. this.page = 1
  193. this.messageList = []
  194. this.getAllMessage()
  195. this.GetUser()
  196. } else {
  197. uni.showToast({
  198. title: res.errMsg,
  199. icon: 'none'
  200. })
  201. }
  202. })
  203. },
  204. allMessage() {
  205. NET.request(API.allMessage, {}, 'post').then((res) => {
  206. if (res.code == 200) {
  207. uni.showToast({
  208. title: '全部已读',
  209. icon: 'none'
  210. })
  211. this.page = 1
  212. this.messageList = []
  213. this.getAllMessage()
  214. this.GetUser()
  215. } else {
  216. uni.showToast({
  217. title: res.errMsg,
  218. icon: 'none'
  219. })
  220. }
  221. })
  222. },
  223. goToMesDetail(noticeId, only, jump) {
  224. NET.request(API.readNotice, {
  225. noticeId
  226. }, 'post').then((res) => {
  227. if (res.code == 200) {
  228. if (jump == 2) {
  229. uni.navigateTo({
  230. url: '../../pages_category_page1/orderModule/orderDetails?orderId=' +
  231. only + '&noticeId=' +
  232. noticeId
  233. })
  234. } else {
  235. uni.navigateTo({
  236. url: 'messageDetail?noticeId=' + noticeId
  237. })
  238. }
  239. } else {
  240. uni.showToast({
  241. title: res.errMsg,
  242. icon: 'none'
  243. })
  244. }
  245. })
  246. }
  247. }
  248. }
  249. </script>
  250. <style lang="scss" scoped>
  251. page {
  252. background: #FFFFFF;
  253. }
  254. .messageCenter {
  255. height: 100%;
  256. width: 100%;
  257. .topTitBox {
  258. height: 100rpx;
  259. padding: 0 20rpx;
  260. background: #f7f7f7;
  261. .allRead {
  262. width: 144rpx;
  263. height: 56rpx;
  264. line-height: 56rpx;
  265. text-align: center;
  266. color: #333333;
  267. background: #FFFFFF;
  268. }
  269. }
  270. .empty-box {
  271. display: flex;
  272. justify-content: center;
  273. flex-direction: column;
  274. align-items: center;
  275. padding-top: 50%;
  276. .tohome-box {
  277. color: #999999;
  278. margin-top: 50rpx;
  279. }
  280. .question-empty {
  281. width: 113rpx;
  282. height: 98rpx;
  283. }
  284. }
  285. .u-swipe-action {
  286. margin-bottom: 20upx !important;
  287. }
  288. .messageItem {
  289. width: 100%;
  290. background: #FFFFFF;
  291. border-bottom: 2rpx solid #F8F8F8;
  292. .messageBox {
  293. .messageType {
  294. padding: 30upx;
  295. display: flex;
  296. align-items: center;
  297. justify-content: space-between;
  298. .iconBox {
  299. border-radius: 50%;
  300. background: #C5AA7B;
  301. width: 60rpx;
  302. height: 60rpx;
  303. display: flex;
  304. align-items: center;
  305. justify-content: center;
  306. margin-right: 20upx;
  307. position: relative;
  308. .redBox {
  309. width: 20upx;
  310. height: 20upx;
  311. background-color: red;
  312. border-radius: 50%;
  313. position: absolute;
  314. right: 0upx;
  315. top: 0upx;
  316. }
  317. }
  318. .messageTypeL {
  319. display: flex;
  320. align-items: center;
  321. image {
  322. width: 50upx;
  323. height: 50upx;
  324. border-radius: 50%;
  325. }
  326. span {
  327. font-size: 32upx;
  328. color: #333333;
  329. }
  330. }
  331. .messageTypeR {
  332. color: #CCCCCC;
  333. font-size: 24upx;
  334. }
  335. }
  336. .messageInfo {
  337. width: 670upx;
  338. display: block;
  339. overflow: hidden;
  340. text-overflow: ellipsis;
  341. white-space: nowrap;
  342. margin: 20upx 40upx 20upx;
  343. img {
  344. width: 100%;
  345. margin-bottom: 25upx;
  346. }
  347. p {
  348. padding: 0 40upx;
  349. color: #999999;
  350. font-size: 28upx;
  351. }
  352. }
  353. }
  354. .messageBtn {
  355. margin-top: 20upx;
  356. border-top: 1upx solid #EEEEEE;
  357. height: 88upx;
  358. display: flex;
  359. justify-content: space-between;
  360. align-items: center;
  361. padding: 0 40upx;
  362. .viewDetail {
  363. color: #333333;
  364. font-size: 28upx;
  365. }
  366. .arrow {
  367. display: block;
  368. width: 28upx;
  369. height: 28upx;
  370. background: url("../../static/images/origin/arrowRight.png") no-repeat center center;
  371. background-size: contain;
  372. }
  373. }
  374. }
  375. }
  376. </style>