多租户商城-商户小程序端
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.

377 lines
9.3 KiB

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