wkw 3 주 전
부모
커밋
666b17240e

+ 1 - 0
api/other.js

@@ -3,6 +3,7 @@ import request from '../utils/request.js';
 // 微信小程序首页配置信息
 export function miniProgramConfig() {
   return request({
+    loading: false,
     url: '/api/wechat/mini-program/config',
     method: 'GET'
   });

+ 2 - 1
app.json

@@ -10,7 +10,8 @@
     "pages/registrationRecords/registrationRecords",
     "pages/coupon/coupon",
     "pages/couponDetail/couponDetail",
-    "pages/competitionRecords/competitionRecords"
+    "pages/competitionRecords/competitionRecords",
+    "pages/storeIcon/storeIcon"
   ],
   "window": {
     "navigationBarTextStyle": "black",

+ 2 - 2
pages/couponDetail/couponDetail.js

@@ -9,8 +9,8 @@ Page({
     couponInfo:{}
   },
   goPage(){
-    wx.switchTab({
-      url: '/pages/store/store'
+    wx.navigateTo({
+      url: '/pages/storeIcon/storeIcon'
     })
   },
   onLoad(options) {

+ 1 - 3
pages/index/index.js

@@ -36,9 +36,7 @@ Page({
     })
   },
   onShow() {
-    if(!wx.getStorageSync('programConfig')){
-      this.getminiProgramConfig();
-    }
+    this.getminiProgramConfig();
     if (typeof this.getTabBar === 'function' && this.getTabBar()) {
       this.getTabBar().setData({
         selected: 0

+ 1 - 1
pages/index/index.wxml

@@ -13,7 +13,7 @@
           <image 
             class="swiper-image" 
             src="{{item.img}}" 
-            mode="aspectFit"
+            mode="widthFix"
             lazy-load="true" 
           />
         </swiper-item>

+ 1 - 2
pages/index/index.wxss

@@ -16,7 +16,7 @@
 .bg-color{
   background-color: #F7F7F7;
   border-radius: 60rpx 60rpx 0 0;
-  margin-top: -90rpx;
+  margin-top: -110rpx;
   position: relative;
   z-index: 1;
 }
@@ -29,7 +29,6 @@
   background: #FFFFFF;
   border-radius: 28rpx;
   padding: 28rpx 40rpx 36rpx;
-  
 }
 .rules-bg{
   background: rgba(246, 190, 32, 0.13);

+ 88 - 0
pages/storeIcon/storeIcon.js

@@ -0,0 +1,88 @@
+import { storeList } from '../../api/other';
+
+Page({
+  data: {
+    list: [],          // 门店列表
+    page: 1,           // 当前页
+    pageSize: 10,      // 每页条数
+    loadingMore: false,// 是否正在加载
+    noMore: false,     // 是否已没有更多数据
+    refreshing: false,  // 下拉刷新状态
+    latitude:0,
+    longitude:0
+  },
+
+  onLoad(options) {
+    wx.getLocation({
+      type: 'wgs84',
+      success: (res) => {
+        this.setData({
+          latitude: res.latitude,
+          longitude: res.longitude
+        })
+        this.loadData(true)
+      },
+      fail: (err) => {
+        wx.showModal({
+          title: '提示',
+          content: '获取定位失败,请检查是否开启定位权限',
+          showCancel: false,
+          confirmText: '我知道了'
+        })
+        this.loadData(true)
+      }
+    })
+  },
+
+  // 请求数据
+  async loadData(isRefresh = false) {
+    if (this.data.loadingMore) return;
+    this.setData({ loadingMore: true });
+    const page = isRefresh ? 1 : this.data.page;
+    try {
+      const res = await storeList({ 
+        page, 
+        pageSize: this.data.pageSize,
+        longitude:this.data.longitude,
+        latitude:this.data.latitude
+      });
+      const newList = res.data.list || [];
+      const allList = isRefresh ? newList : [...this.data.list, ...newList];
+      this.setData({
+        list: allList,
+        loadingMore: false,
+        page: page + 1,
+        noMore: allList.length >= res.data.total,
+        refreshing: false
+      });
+    } catch (err) {
+      console.error(err);
+      this.setData({ loadingMore: false, refreshing: false });
+      wx.showToast({ title: '加载失败', icon: 'none' });
+    }
+  },
+  // 页面触底事件
+  onReachBottom() {
+    if (!this.data.noMore) {
+      this.loadData();
+    }
+  },
+  // 下拉刷新
+  onPullDownRefresh() {
+    this.loadData(true);
+  },
+
+  // 点击门店
+  goDetail(e) {
+    const id = e.currentTarget.dataset.id;
+    wx.navigateTo({
+      url: `/pages/storeDetail/storeDetail?id=${id}`
+    });
+  },
+
+  onShow() {
+    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
+      this.getTabBar().setData({ selected: 1 });
+    }
+  }
+});

+ 6 - 0
pages/storeIcon/storeIcon.json

@@ -0,0 +1,6 @@
+{
+  "usingComponents": {
+    "header": "/components/Header/Header"
+  },
+  "navigationStyle": "custom"
+}

+ 26 - 0
pages/storeIcon/storeIcon.wxml

@@ -0,0 +1,26 @@
+<view class="container">
+  <header text="门店" isLeftIcon="{{true}}"></header>
+
+  <scroll-view
+    class="content"
+    scroll-y="true"
+    bindscrolltolower="onReachBottom"
+    lower-threshold="50"
+    refresher-enabled="true"
+    refresher-triggered="{{refreshing}}"
+    bindrefresherrefresh="onPullDownRefresh"
+  >
+    <view wx:for="{{list}}" wx:key="index" class="list-card {{index === list.length - 1 ? 'no-margin' : ''}}" bindtap="goDetail" data-id="{{item.id}}">
+      <image class="card-img" src="{{ item.avatar}}"  mode="aspectFit"/>
+      <view class="card-ri">
+        <view class="card-ri-title m-ellipsis">{{item.name}}</view>
+        <view class="card-ri-time">营业时间 {{item.business_hours}}</view>
+        <view class="card-ri-address">
+          <view class="address-text m-ellipsis">{{item.address}}</view>
+          <view>{{item.distance}}km</view>
+        </view>
+      </view>
+    </view>
+  </scroll-view>
+  <view wx:if="{{noMore}}" class="loading">没有更多数据了</view>
+</view>

+ 60 - 0
pages/storeIcon/storeIcon.wxss

@@ -0,0 +1,60 @@
+/* pages/store/store.wxss */
+.container{
+  height: 100vh;
+}
+.content{
+  margin: 34rpx 0;
+  flex: 1;
+  overflow: auto;
+}
+.list-card{
+  display: flex;
+  align-items: center;
+  height: 160rpx;
+  margin: 0 32rpx 48rpx;
+}
+.no-margin{
+  margin-bottom: 0;
+}
+.card-img{
+  width: 160rpx;
+  height: 160rpx;
+  border-radius: 28rpx;
+  margin-right: 18rpx;
+}
+.card-ri{
+  flex: 1;
+  overflow: hidden;
+}
+.card-ri-title{
+  font-weight: 500;
+  font-size: 28rpx;
+  color: #000000;
+  line-height: 40rpx;
+}
+.card-ri-time{
+  font-weight: 400;
+  font-size: 24rpx;
+  color: #666666;
+  margin: 12rpx 0 28rpx;
+  box-sizing: border-box;
+  line-height: 40rpx;
+}
+.card-ri-address{
+  display: flex;
+  align-items: center;
+  justify-content: space-between;
+  font-weight: 400;
+  font-size: 24rpx;
+  color: #333333;
+  line-height: 40rpx;
+}
+.address-text{
+  margin-right: 10rpx;
+}
+.loading{
+  color: #969799;
+  font-size:24rpx;
+  text-align: center;
+  padding-bottom: 32rpx;
+}