index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <template>
  2. <!-- 消息中心 -->
  3. <view class="main">
  4. <view class="top-tabs" :style="colorStyle">
  5. <view class="tabs" :class="{btborder:type === index}" v-for="(item,index) in tabsList" :key="index"
  6. @tap="changeTabs(index)">
  7. {{item.name}}
  8. </view>
  9. </view>
  10. <view v-if="list.length && type ===1" class="list">
  11. <view v-for="(item, index) in list" :key="index" class="item" @click="goChat(item.to_uid)">
  12. <view class="image-wrap">
  13. <image class="image" :src="item.avatar"></image>
  14. </view>
  15. <view class="text-wrap">
  16. <view class="name-wrap">
  17. <view class="name">{{ item.nickname }}</view>
  18. <view>{{ item._update_time }}</view>
  19. </view>
  20. <view class="info-wrap">
  21. <view v-if="item.message_type === 1" class="info" v-html="item.message"></view>
  22. <view v-if="item.message_type === 2" class="info" v-html="item.message"></view>
  23. <view v-if="item.message_type === 3" class="info">[图片]</view>
  24. <view v-if="item.message_type === 4" class="info">[语音]</view>
  25. <view v-if="item.message_type === 5" class="info">[商品]</view>
  26. <view v-if="item.message_type === 6" class="info">[订单]</view>
  27. <view class="num" v-if="item.mssage_num">{{ item.mssage_num }}</view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. <view class="list" v-if="list.length && type === 0">
  33. <view v-for="(item, index) in list" :key="index" class="item" @click="goDetail(item.id)">
  34. <view class="image-wrap">
  35. <image v-if="item.type === 1" class="image" src="../static/admin-msg.png"></image>
  36. <image v-else class="image" src="../static/user-msg.png"></image>
  37. <view class="no-look" v-if="!item.look"></view>
  38. </view>
  39. <view class="text-wrap">
  40. <view class="name-wrap">
  41. <view class="name">{{ item.title || '--' }}</view>
  42. <view>{{ item.add_time }}</view>
  43. </view>
  44. <view class="info-wrap">
  45. <view class="info" v-html="item.content"></view>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. <view v-else-if="finished && !list.length" class="empty-wrap">
  51. <view class="image-wrap">
  52. <image class="image" :src="imgHost + '/statics/images/noMessage.png'"></image>
  53. </view>
  54. <view>亲、暂无消息记录哟!</view>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. import {
  60. serviceRecord,
  61. messageSystem
  62. } from '@/api/user.js';
  63. import colors from '@/mixins/color.js';
  64. import {HTTP_REQUEST_URL} from '@/config/app';
  65. export default {
  66. mixins:[colors],
  67. data() {
  68. return {
  69. list: [],
  70. page: 1,
  71. type: 0,
  72. limit: 20,
  73. loading: false,
  74. finished: false,
  75. tabsList: [{
  76. key: 0,
  77. name: '站内消息'
  78. }, {
  79. key: 1,
  80. name: '客服消息'
  81. }],
  82. imgHost:HTTP_REQUEST_URL
  83. };
  84. },
  85. onShow() {
  86. uni.removeStorageSync('form_type_cart');
  87. this.page = 1
  88. this.list = []
  89. this.changeTabs(this.type)
  90. },
  91. onReachBottom() {
  92. if (this.type === 1) {
  93. this.getList()
  94. } else {
  95. this.messageSystem()
  96. }
  97. },
  98. onPullDownRefresh() {
  99. console.log('refresh');
  100. this.page = 1
  101. this.finished = false
  102. this.list = []
  103. if (this.type === 1) {
  104. this.getList()
  105. } else {
  106. this.messageSystem()
  107. }
  108. },
  109. methods: {
  110. changeTabs(index) {
  111. this.type = index
  112. this.page = 1
  113. this.limit = 20
  114. this.list = []
  115. this.finished = false
  116. if (index === 1) {
  117. this.getList()
  118. } else {
  119. this.messageSystem()
  120. }
  121. },
  122. // 站内信
  123. messageSystem() {
  124. if (this.loading || this.finished) {
  125. return;
  126. }
  127. this.loading = true;
  128. uni.showLoading({
  129. title: '加载中'
  130. });
  131. messageSystem({
  132. page: this.page,
  133. limit: this.limit
  134. })
  135. .then(res => {
  136. let data = res.data.list;
  137. uni.hideLoading();
  138. this.loading = false;
  139. this.list = this.list.concat(data);
  140. this.finished = data.length < this.limit;
  141. this.page += 1;
  142. uni.stopPullDownRefresh();
  143. })
  144. .catch(err => {
  145. uni.showToast({
  146. title: err.msg,
  147. icon: 'none'
  148. })
  149. })
  150. },
  151. // 客服list
  152. getList() {
  153. if (this.loading || this.finished) {
  154. return;
  155. }
  156. this.loading = true;
  157. uni.showLoading({
  158. title: '加载中'
  159. });
  160. serviceRecord({
  161. page: this.page,
  162. limit: this.limit
  163. })
  164. .then(res => {
  165. uni.stopPullDownRefresh();
  166. let data = res.data;
  167. uni.hideLoading();
  168. this.loading = false;
  169. data.forEach(item => {
  170. if (item.message_type === 1) {
  171. item.message = this.replace_em(item.message);
  172. }
  173. if (item.message_type === 2) {
  174. item.message = this.replace_em(item.message);
  175. }
  176. });
  177. this.list = this.list.concat(data);
  178. this.finished = data.length < this.limit;
  179. this.page += 1;
  180. })
  181. .catch(err => {
  182. uni.showToast({
  183. title: err.msg,
  184. icon: 'none'
  185. })
  186. })
  187. },
  188. replace_em(str) {
  189. str = str.replace(/\[em-([a-z_]*)\]/g, "<span class='em em-$1'/></span>");
  190. return str;
  191. },
  192. goChat(id) {
  193. // this.$router.push({ path: '/pages/customer_list/chat'})
  194. uni.navigateTo({
  195. url: '/pages/extension/customer_list/chat?to_uid=' + id + '&type=1'
  196. })
  197. },
  198. goDetail(id) {
  199. uni.navigateTo({
  200. url: '/pages/users/message_center/messageDetail?id=' + id,
  201. })
  202. },
  203. },
  204. }
  205. </script>
  206. <style lang="scss" scoped>
  207. .list {
  208. // background-color: #fff;
  209. overflow: hidden;
  210. padding-top: 100rpx;
  211. .item {
  212. background-color: #fff;
  213. display: flex;
  214. align-items: center;
  215. // height: 130rpx;
  216. padding: 30rpx 30rpx;
  217. margin: 10rpx 20rpx;
  218. border-radius: 12rpx;
  219. box-shadow: 0px 0px 1px 0px rgba(235, 214, 214, 0.75);
  220. -webkit-box-shadow: 0px 0px 1px 0px rgba(235, 214, 214, 0.75);
  221. -moz-box-shadow: 0px 0px 1px 0px rgba(235, 214, 214, 0.75);
  222. ~.item {
  223. border-top: 1rpx solid #f5f5f5;
  224. }
  225. .image{
  226. border-radius: 50%;
  227. }
  228. }
  229. .image-wrap {
  230. width: 88rpx;
  231. height: 88rpx;
  232. border-radius: 50%;
  233. position: relative;
  234. .no-look {
  235. position: absolute;
  236. width: 18rpx;
  237. height: 18rpx;
  238. border-radius: 50%;
  239. background-color: #1ABB1D;
  240. top: 0rpx;
  241. right: 0rpx;
  242. z-index: 999;
  243. }
  244. }
  245. .image {
  246. display: block;
  247. width: 100%;
  248. height: 100%;
  249. }
  250. .text-wrap {
  251. flex: 1;
  252. min-width: 0;
  253. margin-left: 20rpx;
  254. }
  255. .name-wrap {
  256. display: flex;
  257. align-items: center;
  258. font-size: 20rpx;
  259. color: #ccc;
  260. }
  261. .name {
  262. flex: 1;
  263. min-width: 0;
  264. margin-right: 20rpx;
  265. overflow: hidden;
  266. white-space: nowrap;
  267. text-overflow: ellipsis;
  268. font-size: 28rpx;
  269. color: #333;
  270. }
  271. .info-wrap {
  272. display: flex;
  273. align-items: center;
  274. margin-top: 18rpx;
  275. }
  276. .info {
  277. flex: 1;
  278. min-width: 0;
  279. overflow: hidden;
  280. white-space: nowrap;
  281. text-overflow: ellipsis;
  282. font-size: 24rpx;
  283. color: #999;
  284. }
  285. .num {
  286. min-width: 32rpx;
  287. height: 32rpx;
  288. border-radius: 16rpx;
  289. margin-left: 20rpx;
  290. background-color: #e93323;
  291. font-size: 20rpx;
  292. line-height: 32rpx;
  293. text-align: center;
  294. color: #fff;
  295. }
  296. }
  297. .empty-wrap {
  298. font-size: 26rpx;
  299. text-align: center;
  300. color: #999;
  301. .image-wrap {
  302. width: 414rpx;
  303. height: 436rpx;
  304. padding-top: 100rpx;
  305. margin: 0rpx auto 0;
  306. }
  307. .image {
  308. display: block;
  309. width: 100%;
  310. height: 100%;
  311. }
  312. }
  313. .main {
  314. position: relative;
  315. }
  316. .top-tabs {
  317. position: fixed;
  318. width: 100%;
  319. display: flex;
  320. align-items: center;
  321. background-color: #fff;
  322. font-size: 28rpx;
  323. border-radius: 8rpx;
  324. padding: 20rpx 0;
  325. margin-bottom: 10rpx;
  326. z-index: 1000;
  327. }
  328. .tabs {
  329. display: flex;
  330. align-items: center;
  331. padding: 4rpx 15rpx;
  332. margin: 0 20rpx;
  333. }
  334. .btborder {
  335. color: #fff;
  336. background-color: var(--view-theme);
  337. border-radius: 30rpx;
  338. }
  339. </style>