index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  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" @click="allLook()">
  11. {{$t(`全部已读`)}}
  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. msgLookDel
  77. } from '@/api/user.js';
  78. import colors from '@/mixins/color.js';
  79. import home from '@/components/home';
  80. import tuiDrawer from '@/components/tuiDrawer/index.vue'
  81. import {
  82. HTTP_REQUEST_URL
  83. } from '@/config/app';
  84. export default {
  85. mixins: [colors],
  86. components: {
  87. home,
  88. tuiDrawer
  89. },
  90. data() {
  91. return {
  92. imgHost: HTTP_REQUEST_URL,
  93. list: [],
  94. page: 1,
  95. type: 0,
  96. limit: 20,
  97. loading: false,
  98. finished: false,
  99. tabsList: [{
  100. key: 0,
  101. name: '站内消息'
  102. }, {
  103. key: 1,
  104. name: '客服消息'
  105. }],
  106. startData: {
  107. clientX: 0,
  108. clientY: 0
  109. },
  110. actions: [{
  111. name: '删除',
  112. color: '#fff',
  113. fontsize: 28, //单位rpx
  114. width: 70, //单位px
  115. background: '#E6A23C'
  116. },
  117. {
  118. name: '已读',
  119. color: '#fff',
  120. fontsize: 28, //单位rpx
  121. width: 70, //单位px
  122. background: '#409EFF'
  123. },
  124. ],
  125. actionsIsLook: [{
  126. name: '删除',
  127. color: '#fff',
  128. fontsize: 28, //单位rpx
  129. width: 70, //单位px
  130. background: '#E6A23C'
  131. }, ]
  132. };
  133. },
  134. onShow() {
  135. this.page = 1
  136. this.list = []
  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. this.page = 1
  148. this.finished = false
  149. this.list = []
  150. if (this.type === 1) {
  151. this.getList()
  152. } else {
  153. this.messageSystem()
  154. }
  155. },
  156. methods: {
  157. start(e) {
  158. this.startData.clientX = e.changedTouches[0].clientX;
  159. this.startData.clientY = e.changedTouches[0].clientY;
  160. },
  161. end(e) {
  162. const subX = e.changedTouches[0].clientX - this.startData.clientX;
  163. const subY = e.changedTouches[0].clientY - this.startData.clientY;
  164. if (subY > 50 || subY < -50) {
  165. console.log('上下滑')
  166. } else {
  167. if (subX > 50) {
  168. console.log('右滑')
  169. if (this.type == 1) {
  170. this.type = 0
  171. this.changeTabs(this.type)
  172. }
  173. } else if (subX < -50) {
  174. if (this.type == 0) {
  175. this.type = 1
  176. this.changeTabs(this.type)
  177. }
  178. console.log('左滑')
  179. } else {
  180. console.log('无效')
  181. }
  182. }
  183. },
  184. // 滑动点击操作
  185. bindClick(e, item) {
  186. if (e.index == 0) {
  187. msgLookDel({
  188. id: item.id,
  189. key: 'is_del',
  190. value: 1
  191. }).then(res => {
  192. let i = this.list.findIndex(e=>{
  193. return e.id === item.id
  194. })
  195. this.list.splice(i,1)
  196. }).catch(err => {
  197. uni.showToast({
  198. title: err.msg,
  199. icon: 'none'
  200. })
  201. })
  202. } else {
  203. // 已读
  204. msgLookDel({
  205. id: item.id,
  206. key: 'look',
  207. value: 1
  208. }).then(res => {
  209. item.look = 1
  210. }).catch(err => {
  211. uni.showToast({
  212. title: err.msg,
  213. icon: 'none'
  214. })
  215. })
  216. }
  217. },
  218. allLook() {
  219. msgLookDel({
  220. id: 0,
  221. key: 'look',
  222. value: 1,
  223. all: 1
  224. }).then(res => {
  225. this.page = 1
  226. this.limit = 20
  227. this.list = []
  228. this.finished = false
  229. if (this.type === 1) {
  230. this.getList()
  231. } else {
  232. this.messageSystem()
  233. }
  234. }).catch(err => {
  235. uni.showToast({
  236. title: err.msg,
  237. icon: 'none'
  238. })
  239. })
  240. },
  241. changeTabs(index) {
  242. this.type = index
  243. this.page = 1
  244. this.limit = 20
  245. this.list = []
  246. this.finished = false
  247. if (index === 1) {
  248. this.getList()
  249. } else {
  250. this.messageSystem()
  251. }
  252. },
  253. // 站内信
  254. messageSystem() {
  255. if (this.loading || this.finished) {
  256. return;
  257. }
  258. this.loading = true;
  259. uni.showLoading({
  260. title: this.$t(`加载中`)
  261. });
  262. messageSystem({
  263. page: this.page,
  264. limit: this.limit
  265. })
  266. .then(res => {
  267. let data = res.data;
  268. uni.hideLoading();
  269. this.loading = false;
  270. this.list = this.list.concat(data.list);
  271. this.finished = data.list.length < this.limit;
  272. this.page += 1;
  273. uni.stopPullDownRefresh();
  274. })
  275. .catch(err => {
  276. uni.showToast({
  277. title: err.msg,
  278. icon: 'none'
  279. })
  280. })
  281. },
  282. // 客服list
  283. getList() {
  284. if (this.loading || this.finished) {
  285. return;
  286. }
  287. this.loading = true;
  288. uni.showLoading({
  289. title: '加载中'
  290. });
  291. serviceRecord({
  292. page: this.page,
  293. limit: this.limit
  294. })
  295. .then(res => {
  296. uni.stopPullDownRefresh();
  297. let data = res.data;
  298. uni.hideLoading();
  299. this.loading = false;
  300. data.forEach(item => {
  301. if (item.message_type === 1) {
  302. item.message = this.replace_em(item.message);
  303. }
  304. if (item.message_type === 2) {
  305. item.message = this.replace_em(item.message);
  306. }
  307. });
  308. this.list = this.list.concat(data);
  309. this.finished = data.length < this.limit;
  310. this.page += 1;
  311. })
  312. .catch(err => {
  313. uni.showToast({
  314. title: err.msg,
  315. icon: 'none'
  316. })
  317. })
  318. },
  319. replace_em(str) {
  320. str = str.replace(/\[em-([a-z_]*)\]/g, "<span class='em em-$1'/></span>");
  321. return str;
  322. },
  323. goChat(id) {
  324. uni.navigateTo({
  325. url: '/pages/extension/customer_list/chat?to_uid=' + id + '&type=1'
  326. })
  327. },
  328. goDetail(id) {
  329. uni.navigateTo({
  330. url: '/pages/users/message_center/messageDetail?id=' + id,
  331. })
  332. },
  333. },
  334. }
  335. </script>
  336. <style lang="scss" scoped>
  337. .list {
  338. // background-color: #fff;
  339. overflow: hidden;
  340. padding-top: 100rpx;
  341. .item {
  342. background-color: #fff;
  343. display: flex;
  344. align-items: center;
  345. // height: 130rpx;
  346. padding: 30rpx 30rpx;
  347. margin: 10rpx 20rpx;
  348. border-radius: 12rpx;
  349. box-shadow: 0px 0px 1px 0px rgba(235, 214, 214, 0.75);
  350. -webkit-box-shadow: 0px 0px 1px 0px rgba(235, 214, 214, 0.75);
  351. -moz-box-shadow: 0px 0px 1px 0px rgba(235, 214, 214, 0.75);
  352. ~.item {
  353. border-top: 1rpx solid #f5f5f5;
  354. }
  355. .image {
  356. border-radius: 50%;
  357. }
  358. }
  359. .image-wrap {
  360. width: 88rpx;
  361. height: 88rpx;
  362. border-radius: 50%;
  363. position: relative;
  364. .no-look {
  365. position: absolute;
  366. width: 18rpx;
  367. height: 18rpx;
  368. border-radius: 50%;
  369. background-color: #1ABB1D;
  370. top: 0rpx;
  371. right: 0rpx;
  372. z-index: 999;
  373. }
  374. }
  375. .image {
  376. display: block;
  377. width: 100%;
  378. height: 100%;
  379. }
  380. .text-wrap {
  381. flex: 1;
  382. min-width: 0;
  383. margin-left: 20rpx;
  384. }
  385. .name-wrap {
  386. display: flex;
  387. align-items: center;
  388. font-size: 20rpx;
  389. color: #ccc;
  390. }
  391. .name {
  392. flex: 1;
  393. min-width: 0;
  394. margin-right: 20rpx;
  395. overflow: hidden;
  396. white-space: nowrap;
  397. text-overflow: ellipsis;
  398. font-size: 28rpx;
  399. color: #333;
  400. }
  401. .info-wrap {
  402. display: flex;
  403. align-items: center;
  404. margin-top: 18rpx;
  405. }
  406. .info {
  407. flex: 1;
  408. min-width: 0;
  409. overflow: hidden;
  410. white-space: nowrap;
  411. text-overflow: ellipsis;
  412. font-size: 24rpx;
  413. color: #999;
  414. }
  415. .num {
  416. min-width: 32rpx;
  417. height: 32rpx;
  418. border-radius: 16rpx;
  419. margin-left: 20rpx;
  420. background-color: #e93323;
  421. font-size: 20rpx;
  422. line-height: 32rpx;
  423. text-align: center;
  424. color: #fff;
  425. }
  426. }
  427. .empty-wrap {
  428. font-size: 26rpx;
  429. text-align: center;
  430. color: #999;
  431. .image-wrap {
  432. width: 414rpx;
  433. height: 436rpx;
  434. padding-top: 100rpx;
  435. margin: 0rpx auto 0;
  436. }
  437. .image {
  438. display: block;
  439. width: 100%;
  440. height: 100%;
  441. }
  442. }
  443. .main {
  444. position: relative;
  445. min-height: 100vh;
  446. }
  447. .top-tabs {
  448. position: fixed;
  449. width: 100%;
  450. display: flex;
  451. align-items: center;
  452. background-color: #fff;
  453. font-size: 28rpx;
  454. border-radius: 8rpx;
  455. padding: 20rpx 0;
  456. margin-bottom: 10rpx;
  457. z-index: 1000;
  458. transition: all 0.3s;
  459. justify-content: space-between;
  460. .read-all {
  461. margin-right: 24rpx;
  462. font-size: 24rpx;
  463. }
  464. }
  465. .tabs {
  466. display: flex;
  467. }
  468. .item {
  469. display: flex;
  470. align-items: center;
  471. padding: 4rpx 15rpx;
  472. margin: 0 20rpx;
  473. animation: Gradient 0.3s;
  474. border-radius: 30rpx;
  475. transition: all 0.4s;
  476. }
  477. .btborder {
  478. color: #fff;
  479. background-color: var(--view-theme);
  480. border-radius: 30rpx;
  481. }
  482. @-webkit-keyframes Gradient {
  483. 0% {
  484. background-color: pink;
  485. }
  486. 50% {
  487. background-position: 100% 50%
  488. }
  489. 100% {
  490. background-position: 0% 50%
  491. }
  492. }
  493. @-moz-keyframes Gradient {
  494. 0% {
  495. background-position: 0% 50%
  496. }
  497. 50% {
  498. background-position: 100% 50%
  499. }
  500. 100% {
  501. background-position: 0% 50%
  502. }
  503. }
  504. @keyframes Gradient {
  505. 0% {
  506. background-position: 0% 50%
  507. }
  508. 50% {
  509. background-position: 100% 50%
  510. }
  511. 100% {
  512. background-position: 0% 50%
  513. }
  514. }
  515. </style>