index.vue 11 KB

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