index.vue 9.1 KB

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