index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <!-- 消息中心 -->
  3. <view class="main">
  4. <view class="px-20">
  5. <view class="w-full bg--w111-fff rd-24rpx mt-24 p-32 flex-between-center"
  6. v-if="system.id" @tap="goDetail">
  7. <view class="left-pic w-88 h-88 rd-50-p111- flex-center">
  8. <text class="iconfont icon-ic_message1 fs-48 text--w111-fff"></text>
  9. </view>
  10. <view class="flex-1 pl-24">
  11. <view class="flex-between-center">
  12. <view class="fs-32 lh-44rpx w-200 line1">{{system.title}}</view>
  13. <text class="fs-22 text--w111-999 lh-30rpx">{{ system.add_time }}</text>
  14. </view>
  15. <view class="flex-between-center mt-8">
  16. <view class="fs-24 text--w111-999 lh-34rpx w-430 line1">{{system.content}}</view>
  17. <view class="dot" v-if="system.message_num > 0"></view>
  18. </view>
  19. </view>
  20. </view>
  21. <view class="w-full bg--w111-fff rd-24rpx mt-24 p-32 flex-between-center"
  22. v-for="(item, index) in list" :key="index" @tap="goChat(item.to_uid)">
  23. <image :src="item.avatar" class="w-88 h-88 rd-50-p111-"></image>
  24. <view class="flex-1 pl-24">
  25. <view class="flex-between-center">
  26. <view class="fs-32 lh-44rpx w-200 line1">{{ item.nickname }}</view>
  27. <view class="fs-22 text--w111-999 lh-30rpx">{{ item._update_time }}</view>
  28. </view>
  29. <view class="flex-between-center mt-8">
  30. <view class="fs-24 text--w111-999 lh-34rpx w-430 line1"
  31. v-if="[1,2].includes(item.message_type)"
  32. v-html="item.message"></view>
  33. <view v-else>{{messageType | filterType}}</view>
  34. <text class="badge" v-if="item.mssage_num > 0">{{ item.mssage_num > 99 ? '99+' : item.mssage_num}}</text>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import {serviceRecord} from '@/api/user.js';
  43. import colors from '@/mixins/color.js';
  44. import {HTTP_REQUEST_URL} from '@/config/app';
  45. export default {
  46. data() {
  47. return {
  48. list: [], //客服消息
  49. system:{}, //站内信
  50. page: 1,
  51. type: 0,
  52. limit: 20,
  53. loading: false,
  54. finished: false,
  55. imgHost:HTTP_REQUEST_URL
  56. };
  57. },
  58. filters:{
  59. messageType(val){
  60. let obj = {
  61. 3: '[图片]',
  62. 4: '[语音]',
  63. 5: '[商品]',
  64. 6: '[订单]',
  65. };
  66. return obj[val]
  67. }
  68. },
  69. onShow() {
  70. this.page = 1
  71. this.list = [];
  72. this.finished = false;
  73. this.getList();
  74. },
  75. onReachBottom() {
  76. this.getList()
  77. },
  78. onPullDownRefresh() {
  79. this.page = 1
  80. this.list = [];
  81. this.finished = false;
  82. this.getList();
  83. },
  84. methods: {
  85. // 站内信
  86. getList() {
  87. if (this.loading || this.finished) {
  88. return;
  89. }
  90. this.loading = true;
  91. uni.showLoading({
  92. title: '加载中'
  93. });
  94. serviceRecord({
  95. page: this.page,
  96. limit: this.limit
  97. }).then(res => {
  98. uni.hideLoading();
  99. uni.stopPullDownRefresh();
  100. let data = res.data.service;
  101. this.system = res.data.system;
  102. this.loading = false;
  103. data.forEach(item => {
  104. if ([1,2].includes(item.message_type)) {
  105. item.message = this.replace_em(item.message);
  106. }
  107. });
  108. this.list = this.list.concat(data);
  109. this.finished = data.length < this.limit;
  110. this.page += 1;
  111. })
  112. .catch(err => {
  113. uni.showToast({
  114. title: err.msg,
  115. icon: 'none'
  116. })
  117. })
  118. },
  119. replace_em(str) {
  120. str = str.replace(/\[em-([a-z_]*)\]/g, "<span class='em em-$1'/></span>");
  121. return str;
  122. },
  123. goChat(id) {
  124. uni.navigateTo({
  125. url: '/pages/extension/customer_list/chat?to_uid=' + id + '&type=1'
  126. })
  127. },
  128. goDetail() {
  129. uni.navigateTo({
  130. url: '/pages/users/message_center/messageDetail'
  131. })
  132. },
  133. },
  134. }
  135. </script>
  136. <style lang="scss" scoped>
  137. .left-pic{
  138. background: linear-gradient(180deg, #FFC657 0%, #FE653B 100%);
  139. }
  140. .dot{
  141. width: 20rpx;
  142. height: 20rpx;
  143. border-radius: 50%;
  144. background-color: #e93323;
  145. }
  146. .badge{
  147. min-width: 32rpx;
  148. max-width: 56rpx;
  149. height: 32rpx;
  150. font-size: 22rpx;
  151. line-height: 32rpx;
  152. text-align: center;
  153. padding: 0 8rpx;
  154. border-radius: 20rpx;
  155. color: #fff;
  156. background-color: #e93323;
  157. }
  158. </style>