Browse Source

feat: 优化

wkw 3 weeks ago
parent
commit
48c9a975d9

+ 8 - 0
api/other.js

@@ -31,4 +31,12 @@ export function storeList(params) {
     data: params
   });
 }
+export function storeDetail(store_id,params) {
+  return request({
+    url: `/api/store/${store_id}`,
+    method: 'GET',
+    data: params
+  });
+}
+
 

+ 1 - 0
api/user.js

@@ -22,6 +22,7 @@ export function getUserInfo() {
 // 更新用户信息
 export function userModify(data) {
   return request({
+    loading: false,
     url: '/api/user/modify',
     method: 'PUT',
     data

+ 5 - 0
app.json

@@ -35,5 +35,10 @@
         "text": "我的"
       }
     ]
+  },
+  "permission": {
+    "scope.userLocation": {
+      "desc": "你的位置信息将用于推荐附近的门店"
+    }
   }
 }

+ 7 - 0
pages/index/index.js

@@ -50,4 +50,11 @@ Page({
       console.log("没找到 tabbar 组件")
     }
   },
+  onShareAppMessage() {
+    return {
+      title: '这里是分享标题',
+      path: '/pages/index/index',
+      imageUrl: '/static/tabbar/weixin.png'
+    }
+  },
 })

+ 51 - 32
pages/mine/mine.js

@@ -1,3 +1,7 @@
+import {BASE_URL} from '../../utils/request';
+import { uploadImage } from '../../utils/upload.js';
+import { MAKE_PHONE_CALL } from '../../utils/util.js';
+import {userModify} from '../../api/user';
 const app = getApp();
 Page({
   data: {
@@ -9,47 +13,32 @@ Page({
       { icon: '/static/image/me-5.png', title: '设置' },
       { icon: '/static/image/me-6.png', title: '联系客服' }
     ],
-    userInfo: {}
+    userInfo: {},
+    programConfig:{},
+    url:BASE_URL,
+    showAgreementModal:false
   },
   goPage(e){
     const index = e.currentTarget.dataset.index;
-    if(index == 0){
-      wx.navigateTo({
-        url: `/pages/rules/rules?type=${index}`
-      })
-    }else if(index == 1){
-      wx.navigateTo({
-        url: `/pages/rules/rules?type=${index}`
-      })
-    }else if(index == 4){
-      wx.navigateTo({
-        url: `/pages/setting/setting`
-      })
-    }else if(index == 2){
-      wx.navigateTo({
-        url: `/pages/registrationRecords/registrationRecords`
-      })
-    }else if(index == 3){
-      wx.navigateTo({
-        url: `/pages/coupon/coupon`
-      })
+    const pageMap = {
+      0: `/pages/rules/rules?type=${index}`,
+      1: `/pages/rules/rules?type=${index}`,
+      2: `/pages/registrationRecords/registrationRecords`,
+      3: `/pages/coupon/coupon`,
+      4: `/pages/setting/setting`
+    };
+    if (pageMap[index]) {
+      wx.navigateTo({ url: pageMap[index] });
+    } else if (index === 5) {
+      this.setData({ showAgreementModal: true });
     }
   },
   onLoad(options) {
     this.setData({
-      userInfo: app.globalData.userInfo
+      userInfo: app.globalData.userInfo,
+      programConfig:app.globalData.programConfig
     });
   },
-  /**
-   * 生命周期函数--监听页面初次渲染完成
-   */
-  onReady() {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面显示
-   */
   onShow() {
     if (typeof this.getTabBar === 'function' && this.getTabBar()) {
       this.getTabBar().setData({ selected: 2 })
@@ -58,6 +47,36 @@ Page({
       userInfo: app.globalData.userInfo
     });
   },
+   // 头像
+   async onChooseAvatar(e) {
+    const { avatarUrl } = e.detail;
+    // 上传到服务器
+    const res = await uploadImage(avatarUrl);
+    this.setData({
+      "userInfo.avatar":avatarUrl
+    });
+    this.onSave(res.path);
+  },
+  async onSave(pathUrl){
+    const res = await userModify({avatar:pathUrl});
+    if(res.code == 200){
+      wx.showToast({
+        title: '更新成功',
+        icon: 'none',
+        duration: 2000
+      });
+      app.globalData.userInfo = res.data;
+    }else{
+      wx.showToast({
+        title: res.message || '更新失败',
+        icon: 'none',
+        duration: 2000
+      });
+    }
+  },
+  onPhone(){
+    MAKE_PHONE_CALL('15527606226');
+  },
 
   /**
    * 生命周期函数--监听页面隐藏

+ 2 - 1
pages/mine/mine.json

@@ -2,7 +2,8 @@
   "usingComponents": {
     "van-image": "@vant/weapp/image/index",
     "van-cell": "@vant/weapp/cell/index",
-    "van-cell-group": "@vant/weapp/cell-group/index"
+    "van-cell-group": "@vant/weapp/cell-group/index",
+    "van-dialog": "@vant/weapp/dialog/index"
   },
   "navigationStyle": "custom"
 }

+ 17 - 2
pages/mine/mine.wxml

@@ -1,8 +1,10 @@
 <view class="container">
-  <image class="index-img" src="/static/image/me-bg.png" mode="aspectFit"></image>
+  <image class="index-img" src="{{url + '/static/image/me-bg.png'}}" mode="aspectFit"></image>
   <view class="mine">
     <view class="user-box">
-      <van-image round width="144rpx" height="144rpx" fit="cover" src="{{userInfo.avatar}}" />
+      <button class="avatar-wrapper" open-type="chooseAvatar"   bind:chooseavatar="onChooseAvatar">
+        <van-image lazy-load round width="144rpx" height="144rpx" fit="cover" src="{{userInfo.avatar}}" />
+      </button>
       <view class="user-text mt28">{{userInfo.nickname}}</view>
       <view class="user-text user-number">参赛号:103910</view>
     </view>
@@ -24,4 +26,17 @@
       </view>
     </view>
   </view>
+  <!-- 客服弹窗 -->
+  <van-dialog
+    confirm-button-class="confirm-btn"
+    use-slot
+    title="联系客服"
+    show="{{showAgreementModal}}"
+    show-cancel-button="{{false}}"
+  >
+    <view class="dialog-box">
+      <image class="box-code" src="{{programConfig.customer_qrcode}}" mode="aspectFill"></image>
+      <view class="box-text" bindtap="onPhone">客服电话:15527606226</view>
+    </view>
+  </van-dialog>
 </view>

+ 40 - 0
pages/mine/mine.wxss

@@ -96,3 +96,43 @@ page {
 .logo-item{
   margin-bottom: 170rpx;
 }
+/* 客服弹框样式 */
+.van-dialog__header{
+  font-weight: bold !important;
+}
+.dialog-box{
+  padding: 32rpx;
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+}
+.box-code{
+  width: 264rpx;
+  height: 264rpx;
+  border-radius: 20rpx;
+}
+.box-text{
+  font-family: PingFangSC, PingFang SC;
+  font-weight: 400;
+  font-size: 24rpx;
+  color: #8D8D8D;
+  line-height: 34rpx;
+  margin-top: 32rpx;
+}
+.confirm-btn{
+  width: 100% !important;
+  color: #FDA233 !important;
+}
+.avatar-wrapper{
+  background: none;
+  border: none;
+  padding: 0;
+  margin: 0 !important;
+  line-height: normal;
+  border-radius: 50%;
+  overflow: hidden;
+  box-sizing: border-box;
+}
+button::after {
+  border: none;
+}

+ 5 - 3
pages/register/register.js

@@ -20,7 +20,8 @@ Page({
     showRegistrationSuccess: false,
     canSubmit: false, // 按钮是否可点击
     showAgreementModal:false,
-    agreementContent:''
+    agreementContent:'',
+    agreementTitle:''
   },
 
   onShowPicker() {
@@ -112,10 +113,11 @@ Page({
   // 点击协议文字显示弹窗
   showAgreement(e) {
     const type = e.currentTarget.dataset.type;
-    const dataInfo = app.globalData.programConfig.marathon_event;
+    const dataInfo = app.globalData.programConfig.marathon_event;   
     this.setData({
       showAgreementModal: true,
-      agreementContent: type == 'rules'?dataInfo.rules : type == 'liability'?dataInfo.disclaimer : dataInfo.privacy_policy 
+      agreementContent: type == 'rules'?dataInfo.rules : type == 'liability'?dataInfo.disclaimer : dataInfo.privacy_policy,
+      agreementTitle:type == 'rules'?'活动规则': type == 'liability'?'免责协议' : '隐私政策'
     });
   },
   closeAgreementModal() {

+ 5 - 3
pages/register/register.wxml

@@ -158,12 +158,14 @@
 
   <!-- 协议弹窗 -->
   <van-dialog
+    confirm-button-class="confirm-btn"
+    use-slot
+    title="{{agreementTitle}}"
     show="{{showAgreementModal}}"
     show-cancel-button="{{false}}"
-    bind:close="closeAgreementModal"
   >
-    <scroll-view style="max-height:70vh;">
+    <view class="dialog-box">
       <rich-text nodes="{{agreementContent}}" />
-    </scroll-view>
+    </view>
   </van-dialog>
 </view>

+ 13 - 0
pages/register/register.wxss

@@ -179,4 +179,17 @@
   color: #ee0a24;
   font-size: 24rpx;
   margin-top: 10rpx;
+}
+.van-dialog__header{
+  font-weight: bold !important;
+}
+.dialog-box{
+  height: 40vh;
+  overflow: auto;
+  padding: 0 32rpx;
+  margin: 32rpx 0;
+}
+.confirm-btn{
+  width: 100% !important;
+  color: #FDA233 !important;
 }

+ 2 - 1
pages/registrationRecords/registrationRecords.js

@@ -30,7 +30,8 @@ Page({
       let allList = isRefresh ? newList : [...this.data.cardList, ...newList];
       allList = allList.map(item => ({
         ...item,
-        img: statusImgMap[item.status]
+        img: statusImgMap[item.status],
+        genderText:item.gender == 0?'女':'男'
       }));
       this.setData({
         cardList: allList,

+ 3 - 3
pages/registrationRecords/registrationRecords.wxml

@@ -9,7 +9,7 @@
     refresher-triggered="{{refreshing}}"
     bindrefresherrefresh="onPullDownRefresh"
   >
-    <view class="card-box" wx:for="{{cardList}}" wx:key="index">
+    <view class="card-box {{ index === 0 ? 'first-card' : '' }}" wx:for="{{cardList}}" wx:key="index">
       <view class="card-top">
         <view class="card-title-box">
           <view class="card-title">{{item.marathon_event.doings_name}}</view>
@@ -20,11 +20,11 @@
       <view class="cell-box">
         <van-cell title="参赛姓名" value="{{item.nickname}}" border="{{ false }}" />
         <van-cell title="手机号" value="{{item.phone}}" border="{{ false }}" />
-        <van-cell title="性别" value="{{item.gender}}" border="{{ false }}" />
+        <van-cell title="性别" value="{{item.genderText}}" border="{{ false }}" />
         <van-cell title="身份证号" value="{{item.race_number}}" border="{{ false }}" />
         <van-cell custom-class="cell-list" title="参赛号码" value="{{item.competition_no}}" border="{{ false }}" />
       </view>
     </view>
-    <view wx:if="{{noMore}}" class="loading">没有更多数据了</view>
   </scroll-view>
+  <view wx:if="{{noMore}}" class="loading">没有更多数据了</view>
 </view>

+ 4 - 0
pages/registrationRecords/registrationRecords.wxss

@@ -11,6 +11,9 @@
   border-radius: 28rpx;
   margin: 40rpx 32rpx;
 }
+.first-card{
+  margin: 32rpx 32rpx 40rpx;
+}
 .card-top{
   display: flex;
   position: relative;
@@ -69,4 +72,5 @@
   color: #969799;
   font-size:24rpx;
   text-align: center;
+  padding-bottom: 32rpx;
 }

+ 1 - 0
pages/setting/setting.js

@@ -55,6 +55,7 @@ Page({
         duration: 2000
       });
       app.globalData.userInfo = res.data;
+      wx.navigateBack({ delta: 1 });
     }else{
       wx.showToast({
         title: res.message || '保存失败',

+ 3 - 0
pages/setting/setting.wxss

@@ -25,6 +25,9 @@
 .cell-box-phone{
   border-bottom: 0;
 }
+.van-cell:after{
+  border: none !important;
+}
 .van-icon{
   color: #000 !important;
 }

+ 28 - 3
pages/store/store.js

@@ -7,11 +7,31 @@ Page({
     pageSize: 10,      // 每页条数
     loadingMore: false,// 是否正在加载
     noMore: false,     // 是否已没有更多数据
-    refreshing: false  // 下拉刷新状态
+    refreshing: false,  // 下拉刷新状态
+    latitude:0,
+    longitude:0
   },
 
   onLoad() {
-    // this.loadData(true);
+    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)
+      }
+    })
   },
 
   // 请求数据
@@ -20,7 +40,12 @@ Page({
     this.setData({ loadingMore: true });
     const page = isRefresh ? 1 : this.data.page;
     try {
-      const res = await storeList({ page, pageSize: this.data.pageSize });
+      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({

+ 5 - 5
pages/store/store.wxml

@@ -11,16 +11,16 @@
     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.img}}" mode="aspectFill"/>
+      <image class="card-img" src="{{ item.img || '/static/image/store-bg.png'}}"  mode="aspectFill"/>
       <view class="card-ri">
-        <view class="card-ri-title m-ellipsis">{{item.title}}</view>
-        <view class="card-ri-time">{{item.time}}</view>
+        <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}}</view>
+          <view>{{item.distance}}km</view>
         </view>
       </view>
     </view>
-    <view wx:if="{{noMore}}" class="loading">没有更多数据了</view>
   </scroll-view>
+  <view wx:if="{{noMore}}" class="loading">没有更多数据了</view>
 </view>

+ 3 - 2
pages/store/store.wxss

@@ -1,6 +1,6 @@
 /* pages/store/store.wxss */
 .content{
-  margin: 34rpx 32rpx;
+  margin: 34rpx 0;
   flex: 1;
   overflow: auto;
 }
@@ -8,7 +8,7 @@
   display: flex;
   align-items: center;
   height: 160rpx;
-  margin-bottom: 48rpx;
+  margin: 0 32rpx 48rpx;
 }
 .no-margin{
   margin-bottom: 0;
@@ -54,4 +54,5 @@
   color: #969799;
   font-size:24rpx;
   text-align: center;
+  padding-bottom: 15rpx;
 }

+ 38 - 8
pages/storeDetail/storeDetail.js

@@ -1,20 +1,50 @@
-// pages/storeDetail/storeDetail.js
+import { storeDetail } from '../../api/other';
+import { MAKE_PHONE_CALL } from '../../utils/util.js';
 Page({
-
-  /**
-   * 页面的初始数据
-   */
   data: {
-
+    dataInfo:{},
+    latitude:0,
+    longitude:0
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad(options) {
-
+    wx.getLocation({
+      type: 'wgs84',
+      success: (res) => {
+        this.setData({
+          latitude: res.latitude,
+          longitude: res.longitude
+        })
+        this.loadData(options.id)
+      },
+      fail: (err) => {
+        wx.showModal({
+          title: '提示',
+          content: '获取定位失败,请检查是否开启定位权限',
+          showCancel: false,
+          confirmText: '我知道了'
+        })
+        this.loadData(options.id)
+      }
+    })
+    
+  },
+  async loadData(id){
+    const res = await storeDetail(id,{longitude:this.data.longitude,latitude:this.data.latitude});
+    if(res.code == 200){
+      this.setData({
+        dataInfo:res.data
+      })
+    }else{
+      wx.showToast({ title: res.message || '加载失败', icon: 'none' });
+    }
+  },
+  onPhone(){
+    MAKE_PHONE_CALL(this.data.dataInfo.phone);
   },
-
   /**
    * 生命周期函数--监听页面初次渲染完成
    */

+ 7 - 7
pages/storeDetail/storeDetail.wxml

@@ -2,20 +2,20 @@
   <header text="店铺详情"></header>
   <view class="content">
     <view class="shop-card">
-      <image class="card-img" src="/static/image/banners1.png" mode="aspectFill"/>
+      <image class="card-img" src="{{dataInfo.img || '/static/image/store-bg.png'}}" mode="aspectFill"/>
       <view class="card-ri">
-        <view class="card-ri-title">便宜坊烤鸭店</view>
-        <view class="card-ri-time">营业时间 12:00-13:00</view>
-        <view class="card-ri-distance">距您3.0km</view>
+        <view class="card-ri-title">{{dataInfo.name}}</view>
+        <view class="card-ri-time">营业时间 {{dataInfo.business_hours}}</view>
+        <view class="card-ri-distance">距您{{dataInfo.distance}}km</view>
       </view>
     </view>
     <view class="address">
-      <view>洪山街道文化大道332号城中村改造开发用地K11地块商业3栋1-2层(2)商-2层></view>
+      <view class="address-text">{{dataInfo.address}}</view>
       <view class="address-icon">
         <image class="ad-img" src="/static/image/address.png" mode="aspectFit"/>
-        <image class="ad-img" src="/static/image/phone.png" mode="aspectFit"/>
+        <image class="ad-img" src="/static/image/phone.png" mode="aspectFit" bindtap="onPhone"/>
       </view>
     </view>
-    <image class="detail" src="/static/image/banners1.png" mode="aspectFill"></image>
+    <rich-text style="width: 100%;" nodes="{{dataInfo.introduction}}" />
   </view>
 </view>

+ 4 - 0
pages/storeDetail/storeDetail.wxss

@@ -52,6 +52,10 @@
   line-height: 40rpx;
   display: flex;
   align-items: center;
+  margin-bottom: 36rpx;
+}
+.address-text{
+  flex: 1;
 }
 .address-icon{
   margin-left: 20rpx;

BIN
static/image/me-bg.png


BIN
static/image/store-bg.png


+ 1 - 1
utils/request.js

@@ -1,4 +1,4 @@
-const BASE_URL = 'https://a.bianyifang.com'; // 统一接口域名
+export const BASE_URL = 'https://a.bianyifang.com';
 
 function request({ loading = true, url, method = 'GET', data = {}, header = {} }) {
   return new Promise((resolve, reject) => {

+ 1 - 2
utils/upload.js

@@ -1,5 +1,4 @@
-const BASE_URL = 'https://a.bianyifang.com';
-
+import {BASE_URL} from './request';
 /**
  * 上传图片
  * @param {string} filePath 本地文件路径

+ 15 - 17
utils/util.js

@@ -1,19 +1,17 @@
-const formatTime = date => {
-  const year = date.getFullYear()
-  const month = date.getMonth() + 1
-  const day = date.getDate()
-  const hour = date.getHours()
-  const minute = date.getMinutes()
-  const second = date.getSeconds()
+const MAKE_PHONE_CALL = (phoneNumber) => {
+  if (!phoneNumber) {
+    phoneNumber = '15527606226';
+  }
 
-  return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
-}
+  wx.makePhoneCall({
+    phoneNumber: phoneNumber,
+    success() {
+      console.log('拨打电话成功');
+    },
+    fail(err) {
+      console.error('拨打电话失败', err);
+    }
+  });
+};
 
-const formatNumber = n => {
-  n = n.toString()
-  return n[1] ? n : `0${n}`
-}
-
-module.exports = {
-  formatTime
-}
+export { MAKE_PHONE_CALL };