messageList.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <view class="message-page">
  3. <van-sticky>
  4. <view class="flex headar">
  5. <view class="flex tab">
  6. <view
  7. :class="['tab-item',{act: default_tab === tab.type}]"
  8. v-for="tab in tabs"
  9. :key="tab.type"
  10. @click="switchTabHandle(tab.type)"
  11. >
  12. {{ tab.label }}
  13. </view>
  14. </view>
  15. <text class="right-txt" v-if="messageList.length" @click="allReadHandle">一键已读</text>
  16. </view>
  17. </van-sticky>
  18. <view class="messlist-cont" v-if="messageList.length">
  19. <view
  20. class="message-item"
  21. @touchstart="drawStart(item,$event)"
  22. @touchmove="drawMove"
  23. @touchend="drawEnd"
  24. v-for="(item,index) in messageList"
  25. :key="item.msg_id"
  26. :data-index="index"
  27. :style="'right:'+item.right+'rpx'"
  28. >
  29. <view class="info">
  30. <view class="left flex">
  31. <image :src="item.img" mode="" class="avatar"/>
  32. <view class="content">
  33. <view class="text_oneLine" style="width: 500rpx">{{item.content_first}}</view>
  34. <view class="msg text_oneLine">{{item.content_second}}</view>
  35. <view class="time">
  36. {{item.create_time | formatTime}}
  37. </view>
  38. </view>
  39. </view>
  40. <text class="read-ico" v-if="!item.is_read"/>
  41. <view class="detail-ico" @click="toReportDetail(item)">
  42. 查看详情<van-icon name="arrow"/>
  43. </view>
  44. </view>
  45. <view class="action" @click.stop="delMessageHandle(item,index)">删除</view>
  46. </view>
  47. </view>
  48. <view class="nodata" v-else>
  49. <image src="@/static/nodata.png" mode="" class="nodata-img"/>
  50. <view>暂时没有新的消息哦</view>
  51. <view>快去留言试试吧~</view>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import * as $message from '@/api/message.js'
  57. const dayjs = require('../utils/dayjs.min.js');
  58. dayjs.locale('zh-cn')
  59. export default {
  60. filters: {
  61. formatTime(val) {
  62. const time = new Date(val);
  63. const now = new Date();
  64. const infer_time = parseInt((now.getTime() - time.getTime())/1000/60/60/24);//时间差
  65. const infer_year = parseInt(now.getFullYear() - time.getFullYear());// 年限差
  66. //当天
  67. if(infer_time === 0) {
  68. return dayjs(time).format('HH:mm:ss')
  69. } else if(infer_time === 1) {
  70. return `昨天 ${dayjs(time).format('HH:mm:ss')}`
  71. } else if(infer_time === 2) {
  72. return `前天 ${dayjs(time).format('HH:mm:ss')}`
  73. } else if( infer_time >=3 && infer_time <=7 ) { //周内
  74. return dayjs(time).format('ddd HH:mm:ss')
  75. } else if(infer_year === 0) {
  76. return dayjs(time).format('MM-DD HH:mm:ss')
  77. } else {
  78. return dayjs(time).format('YYYY-MM-DD HH:mm:ss')
  79. }
  80. }
  81. },
  82. data() {
  83. return {
  84. default_tab: 0,
  85. tabs: [
  86. {
  87. label: '全部消息',
  88. type: 0
  89. },{
  90. label: '回复',
  91. type: 1
  92. },{
  93. label: '精选',
  94. type: 2
  95. },
  96. ],
  97. page_no: 1,
  98. messageList: [],
  99. isHaveMore: true,
  100. delBtnWidth: 176,
  101. startX: 0
  102. };
  103. },
  104. methods: {
  105. /* 切换tab */
  106. switchTabHandle(type) {
  107. this.default_tab = type;
  108. this.page_no = 1;
  109. this.getMessageList();
  110. },
  111. /* 获取列表 */
  112. async getMessageList() {
  113. const { code,data } = await $message.apiMessageList({
  114. type: this.default_tab,
  115. current_index: this.page_no,
  116. page_size: 20
  117. })
  118. if( code!==200 ) return
  119. const { list,paging } = data;
  120. this.isHaveMore = this.page_no >= paging.pages ? false : true;
  121. this.messageList = this.page_no === 1 ? (list || []) : [...this.messageList,...list];
  122. },
  123. /* 一键已读 */
  124. async allReadHandle() {
  125. const { code } = await $message.apiReadAll({ type: this.default_tab })
  126. if( code!==200 ) return
  127. this.page_no = 1;
  128. this.getMessageList();
  129. },
  130. /* 删除消息 */
  131. delMessageHandle({msg_id},index) {
  132. const _this = this;
  133. uni.showModal({
  134. title: "",
  135. content: "确定要删除该留言吗?",
  136. confirmColor: "#6784A7",
  137. success: async function(res) {
  138. if(res.confirm) {
  139. const { code } = await $message.apiDelMessage({ msg_id })
  140. if( code!==200 ) return
  141. uni.showToast({
  142. title: '删除成功',
  143. icon: 'none'
  144. })
  145. _this.messageList.splice(index,1)
  146. }
  147. }
  148. })
  149. },
  150. onPullDownRefresh() {
  151. this.page_no = 1;
  152. this.getMessageList()
  153. setTimeout(() => {
  154. uni.stopPullDownRefresh()
  155. }, 1500)
  156. },
  157. onReachBottom() {
  158. if (!this.isHaveMore) return
  159. this.page_no++
  160. this.getMessageList()
  161. },
  162. /* 到报告详情 */
  163. async toReportDetail( item ) {
  164. const { report_chapter_id,report_id,is_read,msg_id } = item;
  165. if(!is_read) {
  166. const { code } = await $message.apiReadOneMessage({ msg_id })
  167. item.is_read = 1;
  168. }
  169. report_chapter_id
  170. ? uni.navigateTo({url: `/pages-report/chapterDetail?chapterId=${report_chapter_id}&fromPage=message`})
  171. : uni.navigateTo({url:`/pages-report/reportDetail?reportId=${report_id}&fromPage=message`})
  172. },
  173. async drawStart(item,e) {
  174. let touch = e.touches[0];
  175. this.startX = touch.clientX;
  176. },
  177. //触摸滑动
  178. drawMove(e) {
  179. // console.log("滑动");
  180. for (let index in this.messageList) {
  181. this.$set(this.messageList[index],'right',0);
  182. }
  183. let touch = e.touches[0];
  184. let item = this.messageList[e.currentTarget.dataset.index];
  185. let disX = this.startX - touch.clientX;
  186. if (disX >= 20) {
  187. if (disX > this.delBtnWidth) {
  188. disX = this.delBtnWidth;
  189. }
  190. this.$set(this.messageList[e.currentTarget.dataset.index],'right',disX);
  191. } else {
  192. this.$set(this.messageList[e.currentTarget.dataset.index],'right',0);
  193. }
  194. },
  195. //触摸滑动结束
  196. drawEnd(e) {
  197. let item = this.messageList[e.currentTarget.dataset.index];
  198. if (item.right >= this.delBtnWidth / 2) {
  199. this.$set(this.messageList[e.currentTarget.dataset.index],'right',this.delBtnWidth);
  200. } else {
  201. this.$set(this.messageList[e.currentTarget.dataset.index],'right',0);
  202. }
  203. },
  204. },
  205. onShow() {
  206. this.getMessageList()
  207. }
  208. }
  209. </script>
  210. <style lang="scss" scoped>
  211. .message-page {
  212. padding: 40rpx 0;
  213. width: 750rpx;
  214. overflow-x: hidden;
  215. .headar {
  216. padding: 0 34rpx 20rpx;
  217. justify-content: space-between;
  218. font-size: 32rpx;
  219. color: #E3B377;
  220. background-color: #fff;
  221. .right-txt {
  222. font-size: 26rpx;
  223. }
  224. .tab-item {
  225. color: #333;
  226. margin-right: 50rpx;
  227. &.act {
  228. color: #E3B377;
  229. position: relative;
  230. &::after {
  231. content: '';
  232. position: absolute;
  233. bottom: -20rpx;
  234. left: 20%;
  235. width: 50%;
  236. height: 4rpx;
  237. background-color: #E3B377;
  238. }
  239. }
  240. }
  241. }
  242. .messlist-cont {
  243. .message-item {
  244. position: relative;
  245. margin: 30rpx 0;
  246. padding: 0 30rpx;
  247. .info {
  248. position: relative;
  249. }
  250. .left {
  251. .avatar {
  252. width: 65rpx;
  253. height: 65rpx;
  254. margin-right: 20rpx;
  255. }
  256. .content {
  257. color: #666;
  258. font-size: 28rpx;
  259. flex: 1;
  260. .msg {
  261. width: 500rpx;
  262. color: #333;
  263. font-size: 30rpx;
  264. margin: 10rpx 0;
  265. }
  266. .time {
  267. color: #999;
  268. font-size: 24rpx;
  269. }
  270. }
  271. }
  272. .read-ico {
  273. width: 26rpx;
  274. height: 26rpx;
  275. border-radius: 50%;
  276. position: absolute;
  277. right: 0;
  278. top: 50%;
  279. transform: translateY(-50%);
  280. background-color: #D62020;
  281. }
  282. .detail-ico {
  283. position: absolute;
  284. right: 0;
  285. bottom: 0;
  286. color: #666;
  287. }
  288. .action {
  289. width: 176rpx;
  290. height: 100%;
  291. display: flex;
  292. align-items: center;
  293. justify-content: center;
  294. background-color: #E86F6F;
  295. color: #fff;
  296. position: absolute;
  297. right: -176rpx;
  298. top: 0;
  299. }
  300. }
  301. }
  302. .nodata {
  303. color: #999;
  304. font-size: 34rpx;
  305. text-align: center;
  306. .nodata-img {
  307. margin: 100rpx auto 60rpx;
  308. }
  309. }
  310. }
  311. </style>