index.vue 11 KB

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