Pārlūkot izejas kodu

优惠券列表处理

kk.shi 3 gadi atpakaļ
vecāks
revīzija
f6a0d88d09

+ 8 - 1
api/integralinfo.js

@@ -60,12 +60,19 @@ class Integralinfo extends request {
     })
 }
   /**
-   * 删除门店职员
+   * 获取轮播图
    */
   static getBannerList(params) {
     return this.postRequest(`${this.INT_URL}app/banner/list`, params);
   }
 
+  /**
+   * 获取优惠券列表
+   */
+  static getList(params) {
+    return this.postRequest(`${this.INT_URL}app/coupon/list`, params);
+  }
+
        /**
    * 创建订单
    */

+ 47 - 3
pages/integral/integral.js

@@ -10,6 +10,7 @@ Page({
     noResult: false,
     noMore: false,
     bannerList: [],
+    couponList: [],
     channelid: '',
     shopid: '',
     storeid: ''
@@ -34,6 +35,7 @@ Page({
    */
   onShow: function () {
     this.getBannerList()
+    this.getCouponList()
   },
 
   /**
@@ -73,9 +75,9 @@ Page({
 
   getBannerList: function() {
     Integralinfo.getBannerList({
-      channelid: this.channelid,
-      shopid: this.shopid,
-      storeid: this.storeid
+      channelid: this.data.channelid,
+      shopid: this.data.shopid,
+      storeid: this.data.storeid
     }).then(res => {
         console.log(res.data)
         this.setData({
@@ -85,5 +87,47 @@ Page({
         console.log(err)
     })
 },
+
+getCouponList: function() {
+    Integralinfo.getList({
+        channelid: this.data.channelid,
+		shopid: this.data.shopid,
+		storeid: this.data.storeid
+    }).then(res => {
+        this.couponListView(res.data)
+        this.data.lock = false
+    }).catch(_ => {
+        console.log(_)
+        this.data.lock = false
+    })
+},
+
+couponListView: function(data) {
+    if (!Array.isArray(data) || data.length == 0) {
+        console.log("优惠券列表数据为空");
+    }
+    data.forEach((v) => {
+        v.quantity = 0
+        v.integral = v.price * v.ratio
+    })
+    if (this.mobile != '********') {
+        let num = this.integralNum > 20000 ? 19999 : this.integralNum
+        const arr = []
+        for (let i = 0; i < data.length; i++) {
+            data[i].quantity = parseInt(num / data[i].integral)
+            if (data[i].quantity > 0) {
+                num -= (data[i].quantity * data[i].price) * data[i].ratio
+                this.total += (data[i].quantity * data[i].price) * data[i].ratio
+                arr.push(data[i])
+                data.splice(i, 1)
+                i--
+            }
+        }
+        this.setData({
+            couponList: [...arr, ...data]
+        })
+    console.log(this.data.couponList)
+    }
+}
        
 })

+ 29 - 5
pages/integral/integral.wxml

@@ -1,10 +1,34 @@
 <!--pages/integral/integral.wxml-->
 <view class="integral-top">
   <swiper class="integral-banner" autoplay="true" indicator-dots="true">
-  <block wx:for="{{bannerList}}" wx:key="key" data-id="{{item.id}}">
-    <swiper-item>
-      <image class="head-follow" src="{{item.image}}"></image>
-    </swiper-item>
-  </block>
+    <block wx:for="{{bannerList}}" wx:key="key" data-id="{{item.id}}">
+      <swiper-item>
+        <image class="head-follow" src="{{item.image}}"></image>
+      </swiper-item>
+    </block>
   </swiper>
+</view>
+<view class="exchange-style">
+  <view class="exchange-text">免费兑换</view>
+</view>
+<view class="integral-list">
+  <view class="list-item flex-row" wx:for="{{couponList}}" wx:key="key" data-id="{{item.id}}">
+    <image class="item-img" src="{{item.image}}"></image>
+    <view class="content">
+      <view class="content-title over-ellipsis-two">
+        <text>{{item.name}}</text>
+      </view>
+      <view class="content-details">
+        <!-- <text>商品详情 ></text> -->
+      </view>
+      <view class="content-details">
+        <text>商品详情 ></text>
+      </view>
+    </view>
+    <view class="receive-style">
+      <view class="receive-button">
+        <view class="button-text">立即领取</view>
+      </view>
+    </view>
+  </view>
 </view>

+ 70 - 5
pages/integral/integral.wxss

@@ -1,11 +1,6 @@
 /* pages/integral/integral.wxss */
 page{
   background: #f5f5f5;
-  display:flex;
-  flex-flow: column nowrap;
-  justify-content: left;
-  align-items: center;
-  box-sizing: border-box;
 }
 /* 垂直方向布局,水平居中 **/
 .flex-column{
@@ -32,4 +27,74 @@ page{
 .head-follow{
   width: 100%;
   height: 100%;
+}
+
+.exchange-style{
+  height: 41px;
+  line-height: 41px;
+}
+
+.exchange-text{
+  font-size: 16px;
+  font-weight: bold;
+  padding-left: 12px;
+}
+
+.integral-list{
+  width: 750rpx;
+  border-radius: 16rpx;
+}
+
+.list-item{
+  width: 750rpx;
+  height: 208rpx;
+  padding: 24rpx 12rpx;
+  background: white;
+  margin-bottom: 8rpx;
+  box-sizing: border-box;
+}
+
+.item-img{
+  width: 166rpx;
+  height: 166rpx;
+  border: 2rpx solid #F2F6FC;
+}
+
+.content{
+  width: 380rpx;
+  margin-left: 20rpx;
+}
+
+.content-title{
+  height: 90rpx;
+  color: #333333;
+  font-size: 32rpx;
+  font-weight: 600;
+}
+
+.content-details{
+  height: 40rpx;
+  color: #b1b1b1;
+  font-size: 24rpx;
+  font-weight: 600;
+}
+
+.receive-style{
+  width: 170rpx;
+}
+
+.receive-button{
+  border-radius: 30rpx;
+  border: none;
+  height: 56rpx;
+  line-height: 56rpx;
+  background: rgba(255, 0, 0, 0.8);
+  box-shadow: rgb(221 221 221) -1px -1px 0px, rgb(51 51 51) 1px 1px 0px; 
+  text-align: center;
+}
+
+.button-text{
+  color: white;
+  font-size: 28rpx;
+  font-weight: bold;
 }