绿满眶商城微信小程序-uniapp
xiangpei
6 天以前 70738d032bd80f5b13075f8a13045ff4de57c2c3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<template>
  <view class="content">
    <u-navbar class="my-title" title-size="32" :title="'消息(' + talkList.length + ')'"></u-navbar>
    <scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData(tabIndex)">
      
      <!-- 消息列表 -->
      <div class="iconBox">
        <view class="icon-list">
          <view class="icon-item" @click="cleanUnread()">
            <div class="bag bag1">
              <u-icon name="trash" size="50" color="#fff"></u-icon>
            </div>
            <view>清除未读</view>
          </view>
          <view class="icon-item" @click="navigateTo('/pages/tabbar/home/title')">
            <div class="bag bag2">
              <u-icon name="bell" size="50" color="#fff"></u-icon>
            </div>
            <view>系统消息</view>
          </view>
        </view>
      </div>
      <u-search class="nav-search" v-model="userName" clearabled @change="userTalkList()" placeholder="搜索用户"
        :show-action="false"></u-search>
      <view class="talk-view" :key="index" v-for="(item, index) in talkList">
        <view>
          <view @click="onclickToTalkInfo(item)">
            <view class="talk-item-view">
              <view class="talk-img">
                <u-avatar :src="item.face" :text="item.face ? '' : item.name" bg-color="#DDDDDD"></u-avatar>
              </view>
              <view class="talk-info">
                <view class="talk-name u-line-2">{{ item.name }}
                  <u-tag class="talk-tag" size="mini" text="店铺" type="warning" v-if="item.storeFlag" />
                </view>
                <view class="talk-message">
                  <span v-if="item.lastMessageType == 'MESSAGE'">{{ item.lastTalkMessage }}</span>
                  <span v-if="item.lastMessageType == 'GOODS'">[商品链接]</span>
                  <span v-if="item.lastMessageType == 'ORDER'">[订单信息]</span>
                </view>
              </view>
              <view class="talk-time">
                <view>
                  {{ beautifyTime(item.lastTalkTime) }}
                </view>
                <view>
                  <u-badge type="error" absolute :offset="[45, 20]" :count="item.unread"></u-badge>
                </view>
              </view>
            </view>
          </view>
        </view>
      </view>
      <!-- 空白页 -->
      <u-empty text="暂无信息" mode="list" v-if="talkList.length === 0"></u-empty>
    </scroll-view>
  </view>
</template>
 
<script>
import '@/components/uview-components/uview-ui'
import { getTalkList, clearmeaager } from "@/api/im.js";
import storage from "@/utils/storage.js";
import { beautifyTime } from "@/utils/filters.js"
export default {
  data () {
    return {
      storage,
      count: {
        loadStatus: "more",
      },
      talkList: [], //聊天列表
      userName: '',
      pointData: {}, //累计获取 未输入 集合
    };
  },
 
  onShow () {
    this.userTalkList();
  },
  onPullDownRefresh () {
    this.userTalkList()
    console.log('下拉事件');
    setTimeout(function () {
      uni.stopPullDownRefresh();
    }, 1000);
  },
  /**
   * 触底加载
   */
  onReachBottom () {
    this.userTalkList();
  },
  methods: {
    beautifyTime,
    onclickToTalkInfo (val) {
      storage.setTalkToUser(val)
      uni.navigateTo({
        url:
          "/pages/mine/im/index?talkId=" + val.id,
      });
    },
    /**
     * 获取聊天列表
     */
    userTalkList () {
      let params = {
        userName: this.userName,
      }
      uni.showLoading({
        title: "加载中",
      });
      getTalkList(params).then((res) => {
         if (this.$store.state.isShowToast){ uni.hideLoading() };
        if (res.data.success) {
          this.talkList = res.data.result;
          console.log(this.talkList, 'this.talkListthis.talkList');
        }
      });
    },
    navigateTo (url) {
      uni.navigateTo({
        url,
      });
    },
    cleanUnread () {
      clearmeaager().then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          this.userTalkList();
          uni.showToast({
            icon: "none",
            title: res.data.message,
          });
        }
      })
    },
  },
};
</script>
  
<style lang="scss" scoped>
.talk-view {
  border-radius: 20rpx;
  background-color: #fff;
 
  .talk-item-view {
    display: flex;
    flex-wrap: wrap;
    flex-direction: row;
    padding: 10rpx 20rpx;
 
    .talk-img {
      width: 100rpx;
      height: 100rpx;
      margin-right: 10rpx;
      margin-bottom: 10rpx;
    }
 
    .talk-info {
      padding-left: 30rpx;
      flex: 1;
 
      .talk-name {
        font-size: 28rpx;
        margin-bottom: 10rpx;
        font-weight: bold;
        color: #333333;
      }
 
      .talk-message {
        font-size: 28rpx;
        margin-top: 10rpx;
        color: #888787;
 
      }
 
 
      .talk-tag {
        margin-left: 10rpx;
      }
    }
  }
}
 
.talk-time {
  position: relative;
}
 
.iconBox {
  width: 94%;
  margin: 0 3%;
  background: #fff;
  border-radius: 20rpx;
  box-shadow: 0 4rpx 24rpx 0 rgba($color: #f6f6f6, $alpha: 1);
  // transform: translateY(-30rpx);
}
 
.icon-list {
  height: 140rpx;
  text-align: center;
  font-size: $font-sm;
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 0 3%;
  color: #999;
 
  .icon-item {
    position: relative;
    line-height: 2em;
    width: 96rpx;
 
    :first-child {
      font-size: 48rpx;
      margin-bottom: 10rpx;
    }
  }
}
 
.bag {
  width: 56rpx;
  height: 56rpx;
  border-radius: 50%;
  margin: 0 auto;
}
 
.bag1 {
  background: #ff0015;
}
 
.bag2 {
  background: #73AF7C;
}
</style>
<style lang="scss" scoped>
@import "./index-app.scss";
</style>