|
@@ -0,0 +1,274 @@
|
|
|
+<template>
|
|
|
+ <view class="message-page">
|
|
|
+ <van-sticky>
|
|
|
+ <view class="flex headar">
|
|
|
+ <view class="flex tab">
|
|
|
+ <view
|
|
|
+ :class="['tab-item',{act: default_tab === tab.type}]"
|
|
|
+ v-for="tab in tabs"
|
|
|
+ :key="tab.type"
|
|
|
+ @click="switchTabHandle(tab.type)"
|
|
|
+ >
|
|
|
+ {{ tab.label }}
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ <text class="right-txt" v-if="messageList.length" @click="allReadHandle">一键已读</text>
|
|
|
+ </view>
|
|
|
+ </van-sticky>
|
|
|
+ <view class="messlist-cont" v-if="messageList.length">
|
|
|
+ <view
|
|
|
+ class="message-item"
|
|
|
+ @touchstart="drawStart(item,$event)"
|
|
|
+ @touchmove="drawMove"
|
|
|
+ @touchend="drawEnd"
|
|
|
+ v-for="(item,index) in messageList"
|
|
|
+ :key="item.msg_id"
|
|
|
+ :data-index="index"
|
|
|
+ :style="'right:'+item.right+'rpx'"
|
|
|
+ >
|
|
|
+ <view class="info">
|
|
|
+ <view class="left flex">
|
|
|
+ <image :src="item.img" mode="" class="avatar"/>
|
|
|
+ <view class="content">
|
|
|
+ <view class="text_oneLine">{{item.content_first}}</view>
|
|
|
+ <view class="msg text_oneLine">{{item.content_second}}</view>
|
|
|
+ <view class="time">{{item.content_second}}</view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ <text class="read-ico" v-if="!item.is_read"/>
|
|
|
+ </view>
|
|
|
+ <view class="action" @click.stop="delMessageHandle(item)">删除</view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ <view class="nodata" v-else>
|
|
|
+ <image src="@/static/nodata.png" mode="" class="nodata-img"/>
|
|
|
+ <view>暂时没有新的消息哦</view>
|
|
|
+ <view>快去留言试试吧~</view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import * as $message from '@/api/message'
|
|
|
+ export default {
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ default_tab: 0,
|
|
|
+ tabs: [
|
|
|
+ {
|
|
|
+ label: '全部消息',
|
|
|
+ type: 0
|
|
|
+ },{
|
|
|
+ label: '回复',
|
|
|
+ type: 1
|
|
|
+ },{
|
|
|
+ label: '精选',
|
|
|
+ type: 2
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ page_no: 1,
|
|
|
+ messageList: [],
|
|
|
+ isHaveMore: true,
|
|
|
+ delBtnWidth: 176,
|
|
|
+ startX: 0
|
|
|
+ };
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ /* 切换tab */
|
|
|
+ switchTabHandle(type) {
|
|
|
+ this.default_tab = type;
|
|
|
+ this.page_no = 1;
|
|
|
+ this.getMessageList();
|
|
|
+ },
|
|
|
+
|
|
|
+ /* 获取列表 */
|
|
|
+ async getMessageList() {
|
|
|
+ const { code,data } = $message.apiMessageList({
|
|
|
+ type: this.default_tab,
|
|
|
+ current_index: this.page_no,
|
|
|
+ page_size: 20
|
|
|
+ })
|
|
|
+ if( code!==200 ) return
|
|
|
+
|
|
|
+ const { list,paging } = data;
|
|
|
+
|
|
|
+ this.isHaveMore = this.page_no >= paging.pages ? false : true;
|
|
|
+ this.messageList = this.page_no === 1 ? (list || []) : [...this.messageList,...list]
|
|
|
+ },
|
|
|
+
|
|
|
+ /* 一键已读 */
|
|
|
+ async allReadHandle() {
|
|
|
+ const { code } = $message.apiReadAll({ type: this.default_tab })
|
|
|
+ if( code!==200 ) return
|
|
|
+
|
|
|
+ this.page_no = 1;
|
|
|
+ this.getMessageList();
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /* 删除消息 */
|
|
|
+ delMessageHandle() {
|
|
|
+ uni.showModal({
|
|
|
+ title: "",
|
|
|
+ content: "确定要删除该留言吗?",
|
|
|
+ confirmColor: "#6784A7",
|
|
|
+ success: function() {
|
|
|
+
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ onPullDownRefresh() {
|
|
|
+ this.page_no = 1;
|
|
|
+ setTimeout(() => {
|
|
|
+ uni.stopPullDownRefresh()
|
|
|
+ }, 1500)
|
|
|
+ },
|
|
|
+
|
|
|
+ onReachBottom() {
|
|
|
+ if (!this.isHaveMore) return
|
|
|
+ this.page_no++
|
|
|
+ this.getMessageList()
|
|
|
+ },
|
|
|
+
|
|
|
+ async drawStart(item,e) {
|
|
|
+ let touch = e.touches[0];
|
|
|
+ this.startX = touch.clientX;
|
|
|
+
|
|
|
+ const { msg_id } = item;
|
|
|
+ const { code } = await apiReadOneMessage({ msg_id })
|
|
|
+ if( code!==200 ) return
|
|
|
+ item.is_read = 1;
|
|
|
+ },
|
|
|
+ //触摸滑动
|
|
|
+ drawMove(e) {
|
|
|
+ // console.log("滑动");
|
|
|
+ for (let index in this.messageList) {
|
|
|
+ this.$set(this.messageList[index],'right',0);
|
|
|
+ }
|
|
|
+ let touch = e.touches[0];
|
|
|
+ let item = this.messageList[e.currentTarget.dataset.index];
|
|
|
+ let disX = this.startX - touch.clientX;
|
|
|
+ if (disX >= 20) {
|
|
|
+ if (disX > this.delBtnWidth) {
|
|
|
+ disX = this.delBtnWidth;
|
|
|
+ }
|
|
|
+ this.$set(this.messageList[e.currentTarget.dataset.index],'right',disX);
|
|
|
+ } else {
|
|
|
+ this.$set(this.messageList[e.currentTarget.dataset.index],'right',0);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //触摸滑动结束
|
|
|
+ drawEnd(e) {
|
|
|
+ let item = this.messageList[e.currentTarget.dataset.index];
|
|
|
+ if (item.right >= this.delBtnWidth / 2) {
|
|
|
+ this.$set(this.messageList[e.currentTarget.dataset.index],'right',this.delBtnWidth);
|
|
|
+ } else {
|
|
|
+ this.$set(this.messageList[e.currentTarget.dataset.index],'right',0);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ onShow() {
|
|
|
+ this.getMessageList()
|
|
|
+ }
|
|
|
+ }
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss" scoped>
|
|
|
+.message-page {
|
|
|
+ padding: 40rpx 0;
|
|
|
+ .headar {
|
|
|
+ padding: 0 34rpx 20rpx;
|
|
|
+ justify-content: space-between;
|
|
|
+ font-size: 32rpx;
|
|
|
+ color: #E3B377;
|
|
|
+ background-color: #fff;
|
|
|
+
|
|
|
+ .right-txt {
|
|
|
+ font-size: 26rpx;
|
|
|
+ }
|
|
|
+ .tab-item {
|
|
|
+ color: #333;
|
|
|
+ margin-right: 50rpx;
|
|
|
+ &.act {
|
|
|
+ color: #E3B377;
|
|
|
+ position: relative;
|
|
|
+ &::after {
|
|
|
+ content: '';
|
|
|
+ position: absolute;
|
|
|
+ bottom: -20rpx;
|
|
|
+ left: 20%;
|
|
|
+ width: 50%;
|
|
|
+ height: 4rpx;
|
|
|
+ background-color: #E3B377;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .messlist-cont {
|
|
|
+ .message-item {
|
|
|
+ position: relative;
|
|
|
+ margin: 30rpx 0;
|
|
|
+ padding: 0 30rpx;
|
|
|
+ .info {
|
|
|
+ position: relative;
|
|
|
+ }
|
|
|
+ .left {
|
|
|
+ .avatar {
|
|
|
+ width: 65rpx;
|
|
|
+ height: 65rpx;
|
|
|
+ margin-right: 20rpx;
|
|
|
+ }
|
|
|
+ .content {
|
|
|
+ color: #666;
|
|
|
+ font-size: 28rpx;
|
|
|
+ width: 80%;
|
|
|
+ .msg {
|
|
|
+ color: #333;
|
|
|
+ font-size: 30rpx;
|
|
|
+ margin: 10rpx 0;
|
|
|
+ }
|
|
|
+ .time {
|
|
|
+ color: #999;
|
|
|
+ font-size: 24rpx;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .read-ico {
|
|
|
+ width: 30rpx;
|
|
|
+ height: 30rpx;
|
|
|
+ border-radius: 50%;
|
|
|
+ position: absolute;
|
|
|
+ right: 0;
|
|
|
+ top: 50%;
|
|
|
+ transform: translateY(-50%);
|
|
|
+ background-color: #D62020;
|
|
|
+ }
|
|
|
+
|
|
|
+ .action {
|
|
|
+ width: 176rpx;
|
|
|
+ height: 100%;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ background-color: #E86F6F;
|
|
|
+ color: #fff;
|
|
|
+ position: absolute;
|
|
|
+ right: -176rpx;
|
|
|
+ top: 0;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .nodata {
|
|
|
+ color: #999;
|
|
|
+ font-size: 34rpx;
|
|
|
+ text-align: center;
|
|
|
+ .nodata-img {
|
|
|
+ margin: 100rpx auto 60rpx;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|