绿满眶商城微信小程序-uniapp
zhanghua
5 天以前 1113721c0e068c57adbc15149cce15563960a7f2
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<template>
  <div class="box">
    <u-navbar class="navbar">
      <view class="slot-wrap">
        <u-search placeholder="搜索直播间" @custom="searchLive" @clear="clear" @search="searchLive" v-model="keyword"></u-search>
      </view>
    </u-navbar>
    <!-- 轮播图 -->
    <u-swiper @click="clickSwiper" class="swiper" :effect3d="true" :list="swiperImg">
 
    </u-swiper>
    <u-tabs :is-scroll="false" @change="changeTabs" :current="current" :active-color="activeColor" inactive-color="#606266" ref="tabs" :list="tabs"></u-tabs>
 
    <div class="wrapper">
      <!-- 直播中 全部 直播回放 -->
      <div class="live-item" :class="{'invalid':item.status == 'END'}" v-for="(item,index) in liveList" :key="index" @click="handleLivePlayer(item)">
        <div class="live-cover-img">
          <div class="tips">
            <div class="live-box">
              <image class="live-gif" src="./static/live.gif"></image>
            </div>
            <span>{{item.status == 'END' ? '已结束' : item.status =='NEW' ? '未开始' : '直播中'}}</span>
          </div>
          <div class="bg"></div>
          <u-image width="326" height="354" :src="item.shareImg" />
        </div>
        <div class="live-goods">
          <div class="live-goods-name">
            {{item.name}}
          </div>
          <div class="live-store">
            <span class="wes">lilishop</span>
          </div>
          <div class="live-goods-list">
            <div class="live-goods-item">
              <u-image border-radius="20" :src="item.roomGoodsList ? item.roomGoodsList[0] : ''" height="140"></u-image>
            </div>
            <div class="live-goods-item">
              <u-image border-radius="20" :src="item.roomGoodsList ? item.roomGoodsList[1] : ''" height="140"></u-image>
            </div>
          </div>
        </div>
      </div>
      <u-loadmore v-if="liveList.length > 10" bg-color="#f8f8f8" :status="status" />
    </div>
  </div>
</template>
 
<script>
import '@/components/uview-components/uview-ui'
import { getLiveList } from "@/api/promotions.js";
export default {
  data() {
    return {
      status: "loadmore",
      activeColor: this.$lightColor,
      current: 0, // 当前tabs索引
      keyword: "", //搜索直播间
      // 标签栏
      tabs: [
        {
          name: "直播中",
        },
        {
          name: "全部",
        },
      ],
      // 导航栏的配置
      background: {
        background: "#ff9f28",
      },
      // 直播间params
      params: [
        {
          pageNumber: 1,
          pageSize: 10,
          status: "START",
        },
        {
          pageNumber: 1,
          pageSize: 4,
        },
      ],
      // 推荐直播间Params
      recommendParams: {
        pageNumber: 1,
        pageSize: 3,
        recommend: 0,
      },
      // 直播间列表
      liveList: [],
      // 推荐直播间列表
      recommendLiveList: [],
 
      //轮播图滚动的图片
      swiperImg: [
        {
          image:
            "https://lilishop-oss.oss-cn-beijing.aliyuncs.com/48d789cb9c864b7b87c1c0f70996c3e8.jpeg",
        },
      ],
    };
  },
  onShow() {
    this.params[this.current].pageNumber = 1;
    this.liveList = [];
    this.getLives();
    this.getRecommendLives();
  },
  onReachBottom() {
    this.params[this.current].pageNumber++;
    this.getLives();
  },
  methods: {
    /**
     * 点击标签栏切换
     */
    changeTabs(index) {
      this.current = index;
      this.init();
    },
 
    /**
     * 初始化直播间
     */
    init() {
      this.liveList = [];
      this.status = "loadmore";
      this.getLives();
    },
 
    /**
     * 清除搜索内容
     */
    clear() {
      delete this.params[this.current].name;
      this.init();
    },
    /**
     * 点击顶部推荐直播间
     */
    clickSwiper(val) {
      console.log(this.swiperImg[val]);
      this.handleLivePlayer(this.swiperImg[val]);
    },
 
    /**
     * 搜索直播间
     */
    searchLive(val) {
      this.params[this.current].pageNumber = 1;
      this.params[this.current].name = val;
      this.init();
    },
    /**
     * 获取推荐直播间
     */
    async getRecommendLives() {
      this.status = "loading";
      let recommendLives = await getLiveList(this.recommendParams);
      if (recommendLives.data.success) {
        // 推荐直播间
        if (recommendLives.data.result.records.length ) {
          this.status = "loadmore";
          this.recommendLives = recommendLives.data.result.records;
        } else {
          this.status = "noMore";
        }
 
        /**
         * 如果推荐直播间没有的情况下
         * 1.获取直播间第一个图片
         * 2.如果没有直播间设置一个默认图片
         */
 
        if (!this.recommendLives.length) {
          if (this.liveList[0].shareImg) {
            this.$set(this, "swiperImg", [
              {
                image: this.liveList[0].shareImg,
                roomId: this.liveList[0].roomId,
              },
            ]);
          }
        } else {
          this.recommendLives.forEach((item) => {
            this.$set(this, "swiperImg", [
              { image: item.shareImg, roomId: item.roomId },
            ]);
          });
        }
      }
    },
 
    /**
     * 获取直播间
     */
    async getLives() {
      this.status = "loading";
      let res = await getLiveList(this.params[this.current]);
      // 直播间
      if (res.data.success) {
        if (res.data.result.records.length ) {
          this.status = "loadmore";
          this.liveList.push(...res.data.result.records);
        } else {
          this.status = "noMore";
        }
        res.data.result.total >
        this.params[this.current].pageNumber *
          this.params[this.current].pageSize
          ? (this.status = "loadmore")
          : (this.status = "noMore");
 
      
        this.liveList.forEach((item) => {
          if (item.roomGoodsList) {
            item.roomGoodsList = JSON.parse(item.roomGoodsList);
          }
        });
      }
    },
 
    /**
     * 进入直播间
     */
    handleLivePlayer(val) {
      // #ifdef MP-WEIXIN
      let roomId = val.roomId; // 填写具体的房间号,可通过下面【获取直播房间列表】 API 获取
      let customParams = encodeURIComponent(
        JSON.stringify({ path: "pages/index/index", pid: 1 })
      ); // 开发者在直播间页面路径上携带自定义参数,后续可以在分享卡片链接和跳转至商详页时获取,详见【获取自定义参数】、【直播间到商详页面携带参数】章节(上限600个字符,超过部分会被截断)
      uni.navigateTo({
        url:
          "plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=" +
          roomId +
          "&custom_params=" +
          customParams,
      });
      // #endif
 
      // #ifndef MP-WEIXIN
      uni.showToast({
        title: "请从微信小程序中预览直播功能",
        duration: 2000,
        icon: "none",
      });
      // #endif
    },
  },
};
</script>
 
<style lang="scss" scoped>
.slot-wrap {
  display: flex;
  align-items: center;
  /* 如果您想让slot内容占满整个导航栏的宽度 */
  flex: 1;
  /* 如果您想让slot内容与导航栏左右有空隙 */
  /* padding: 0 30rpx; */
}
.invalid {
  filter: grayscale(1);
}
.wrapper {
  padding: 0 24rpx;
}
.live-item {
  display: flex;
  overflow: hidden;
  border-radius: 20rpx;
  flex-wrap: wrap;
  background: #fff;
 
  margin: 20rpx 0;
}
.live-cover-img {
  position: relative;
}
.swiper {
  margin: 20rpx 0;
}
 
.live-goods {
  position: relative;
  flex: 1;
  padding: 16rpx 24rpx 24rpx;
}
.live-goods-name {
  height: 84rpx;
  font-weight: bold;
  font-size: 30rpx;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}
.live-store {
  display: flex;
  align-items: center;
  margin: 20rpx 0;
  overflow: hidden;
  width: calc(100% - 50rpx);
}
.live-gif {
  width: 20rpx;
  height: 20rpx;
}
.live-box {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  width: 40rpx;
  margin-right: 10rpx;
  height: 40rpx;
  background: linear-gradient(90deg, #ff6b35, #ff9f28, #ffcc03);
}
.live-goods-list {
  display: flex;
  align-items: center;
  justify-content: space-between;
  > .live-goods-item {
    flex: 1;
  }
  > .live-goods-item:nth-of-type(1) {
    padding-right: 38rpx;
  }
}
 
.live-icon,
.zan {
  position: absolute;
  width: 80rpx;
  height: 80rpx;
  z-index: 9;
}
.tips {
  display: flex;
  position: absolute;
  z-index: 9;
 
  align-items: center;
  top: 20rpx;
  right: 0;
  padding: 4rpx 12rpx 4rpx 0;
  font-size: 24rpx;
  border-radius: 100px;
  color: #fff;
  background: rgba(0, 0, 0, 0.46);
}
.live-icon {
  right: 0;
  top: 104rpx;
}
 
.zan {
  bottom: 0;
  right: 0;
  width: 100rpx;
  height: 100rpx;
}
.bg {
  position: absolute;
  bottom: 4rpx;
  width: 100%;
  height: 100rpx;
  z-index: 8;
  background-image: -webkit-gradient(
    linear,
    left bottom,
    left top,
    from(rgba(0, 0, 0, 0.25)),
    color-stop(82%, transparent)
  );
  background-image: linear-gradient(0deg, rgba(0, 0, 0, 0.25), transparent 82%);
  border-bottom-left-radius: 20rpx;
}
</style>