Jelajahi Sumber

修改逻辑

lex-xin 4 hari lalu
induk
melakukan
32e14df7f4

+ 14 - 81
miniprogram/app.ts

@@ -1,62 +1,39 @@
 // app.ts
-import { api_login, api_queryUserInfo } from "./api/login";
 import { api_getOpenId } from "./api/new";
 const config = require("./config");
 
 App<IAppOption>({
   globalData: {
-    // 在客服页面使用
-    top: 0, // 初始的上偏移
+    top: 0,
     baseUrl: config?.baseUrl,
     appId: "",
-    deviceNum: "", // 设备信息
-    isLogin: false, // 是否登录
-    userInfo: {} as any
+    deviceNum: "",
+    isLogin: false,
+    userInfo: {} as any,
   },
   onLaunch() {
-    // 展示本地存储能力
-    // const logs = wx.getStorageSync('logs') || []
-    // logs.unshift(Date.now())
-    // wx.setStorageSync('logs', logs)
-
     this.setAppId();
+    wx.setStorageSync("traceId", this.getRandomKey());
 
-    // 登录
-    wx.login({
-      success: async (res) => {
-        this.onLogin(res.code);
-      },
-    });
-
-    wx.setStorageSync("traceId", this.getRandomKey())
-
-    // 获取openId
     wx.login({
       success: async (res) => {
         await api_getOpenId({
           code: res.code,
-          appId: this.globalData.appId
-        }).then((res: any) => {
-          // 存储openId
-          wx.setStorageSync("openId", res.data.data);
-        })
-      }
-    })
+          appId: this.globalData.appId,
+        }).then((result: any) => {
+          wx.setStorageSync("openId", result.data.data);
+        });
+      },
+    });
   },
   getRandomKey() {
-    let key = "" + new Date().getTime() + Math.floor(Math.random() * 1000000);
-    return key;
+    return "" + new Date().getTime() + Math.floor(Math.random() * 1000000);
   },
   setAppId() {
-    //获取当前小程序appId
     const accountInfo = wx.getAccountInfoSync();
     this.globalData.appId = accountInfo.miniProgram.appId;
-    // wxRequest.config.appid = accountInfo.miniProgram.appId;
-    //先设置appid再引入接口文件,防止appid未更新问题
-    // require("./utils/request/api.js");
-    // 获取设备信息
+
     const deviceInfo = wx.getDeviceInfo();
-    // 品牌 设备型号 操作系统及版本 客户端平台
     const deviceNum =
       deviceInfo.brand +
       "-" +
@@ -66,52 +43,8 @@ App<IAppOption>({
       "-" +
       deviceInfo.system;
     this.globalData.deviceNum = deviceNum;
-    // 设置客服初始位置
+
     const systemInfo = wx.getWindowInfo();
     this.globalData.top = systemInfo.windowHeight - 180;
   },
-  // userInfoReadyCallback(result) {
-  //   console.log(result, 'result')
-  // }
-  /** 微信登录 */
-  async onLogin(code: string) {
-    wx.showLoading({
-      mask: true,
-      title: "加载中...",
-    });
-    try {
-      // 开始登录
-      const { data } = await api_login({
-        autoRegister: false,
-        client_id: "cooleshow-student-wxlite",
-        client_secret: "cooleshow-student-wxlite",
-        deviceNum: this.globalData.deviceNum,
-        extra: "",
-        grant_type: "password",
-        loginType: "WECHAT_MA",
-        multiUser: false,
-        username: this.globalData.appId,
-        password: code,
-      });
-
-      if (data.code === 200) {
-        const userToken = data.data.token_type + " " + data.data.access_token;
-        wx.setStorageSync("token", userToken);
-        this.globalData.isLogin = true;
-        const users = await api_queryUserInfo({
-          wxAppId: this.globalData.appId,
-        });
-        if (users.data.code === 200) {
-          this.globalData.userInfo = users.data.data;
-        } else {
-          wx.removeStorageSync("token");
-          this.globalData.isLogin = false;
-        }
-        console.log(users);
-      } else {
-        this.globalData.isLogin = false;
-      }
-    } catch {}
-    wx.hideLoading();
-  },
 });

+ 3 - 2
miniprogram/pages/index/index.less

@@ -550,9 +550,9 @@ page {
 .gift-section {
   display: inline-flex;
   align-items: center;
-  min-width: 310rpx;
+  max-width: 100%;
   height: 68rpx;
-  padding: 0 28rpx;
+  padding: 0 20rpx;
   margin-bottom: 48rpx;
   box-sizing: border-box;
   background: #fff1d6;
@@ -563,6 +563,7 @@ page {
     color: #15171c;
     font-weight: 500;
     line-height: 40rpx;
+    white-space: nowrap;
   }
 }
 

+ 41 - 17
miniprogram/pages/index/index.ts

@@ -59,12 +59,39 @@ function formatGiftText(item: any) {
 }
 
 function buildPeriodList(list: any[]) {
-  return list.map((item: any) => ({
+  return list.map((item: any, index: number) => ({
     label: item.typeName || item.title || item.name || formatPeriodText(item.num, item.period),
     value: String(item.id),
     disabled: Number(item.stockNum ?? 1) <= 0,
+    viewId: `period-${index}`,
   }));
 }
+
+function getPeriodScrollIntoView(periodList: any[], selectedPeriod: string) {
+  return periodList.find((item: any) => String(item.value) === String(selectedPeriod))?.viewId || "";
+}
+
+function selectDefaultTeacherVip(list: any[]) {
+  const saleableList = list.filter((item: any) => Number(item.stockNum ?? 1) > 0);
+  const candidates = saleableList.length ? saleableList : list;
+  const getSearchText = (item: any) => [
+    item.name,
+    item.title,
+    item.label,
+    item.typeName,
+  ].filter(Boolean).join("");
+  const isOneYear = (item: any) => {
+    const text = getSearchText(item);
+    return (Number(item.num) === 1 && item.period === "YEAR") || /(?:1|一)年/.test(text);
+  };
+  const isTrial = (item: any) => /体验卡/.test(getSearchText(item));
+
+  return candidates.find((item: any) => isOneYear(item) && isTrial(item))
+    || candidates.find(isOneYear)
+    || candidates.find((item: any) => item.isHot)
+    || candidates[0]
+    || {};
+}
 // pages/orders/orders.ts
 Page({
   /**
@@ -144,6 +171,7 @@ Page({
     userTypes: PURCHASE_TYPE.STUDENT, // 用户类型:WECHAT_MINI | TEACHER_VIP
     periodList: [] as any,
     selectedPeriod: '', // 选中的期限
+    periodScrollIntoView: '',
     showBonusGift: false, // 是否显示额外赠送
   },
 
@@ -352,10 +380,15 @@ Page({
   },
   // 格式化类型
   applyPurchaseData(purchaseData: any) {
+    const periodScrollIntoView = getPeriodScrollIntoView(
+      purchaseData.periodList,
+      purchaseData.selectedPeriod
+    );
     this.setData({
       list: purchaseData.list,
       periodList: purchaseData.periodList,
       selectedPeriod: purchaseData.selectedPeriod,
+      periodScrollIntoView,
       instrumentList: purchaseData.instrumentList,
       isOverSaled: purchaseData.isOverSaled,
       selected: purchaseData.selected,
@@ -406,13 +439,11 @@ Page({
           goodsType: item.goodsType || PURCHASE_TYPE.TEACHER,
         };
       });
-      const selected = list.find((item: any) => item.isHot && item.stockNum > 0)
-        || list.find((item: any) => item.stockNum > 0)
-        || list[0]
-        || {};
+      const selected = selectDefaultTeacherVip(list);
+      const periodList = buildPeriodList(list);
       const purchaseData = {
         list,
-        periodList: buildPeriodList(list),
+        periodList,
         selectedPeriod: selected?.id ? String(selected.id) : '',
         instrumentList: [],
         isOverSaled: !list.some((item: any) => item.stockNum > 0),
@@ -581,19 +612,11 @@ Page({
   },
   /** 我的订单 */
   onOrder() {
-    // 判断是否登录
-    if (!this.isLogin()) {
-      return;
-    }
     wx.navigateTo({
       url: "../orders/orders",
     });
   },
   onBuyShop() {
-    // 判断是否登录
-    if (!this.isLogin()) {
-      return;
-    }
     this.setData({
       popupShow: true,
       // showSelectedProduct: true,
@@ -629,6 +652,7 @@ Page({
     this.setData({
       selectedPeriod: String(value),
       selected: selectedItem,
+      periodScrollIntoView: getPeriodScrollIntoView(this.data.periodList, String(value)),
       showBonusGift: Boolean(formatGiftText(selectedItem))
     }, () => {
       // 根据选中的期限更新商品
@@ -676,9 +700,9 @@ Page({
     // 判断是否登录
     const that = this;
     debounce(function () {
-      if (!that.isLogin()) {
-        return;
-      }
+      // if (!that.isLogin()) {
+      //   return;
+      // }
       const params = [] as any
       const selected = that.data.selected
       if (selected.id) {

+ 2 - 2
miniprogram/pages/index/index.wxml

@@ -120,9 +120,9 @@
         <!-- 选择期限 -->
         <view class="period-select-section">
           <view class="section-label">选择期限</view>
-          <scroll-view class="period-options-scroll" scroll-x="{{true}}" enhanced="{{true}}" show-scrollbar="{{false}}">
+          <scroll-view class="period-options-scroll" scroll-x="{{true}}" enhanced="{{true}}" show-scrollbar="{{false}}" scroll-into-view="{{ periodScrollIntoView }}" scroll-with-animation="{{true}}">
             <view class="period-options">
-              <view wx:for="{{ periodList }}" wx:key="value" class="period-btn {{ selectedPeriod === item.value ? 'active' : '' }}" bind:tap="onSelectPeriod" data-value="{{ item.value }}">
+              <view wx:for="{{ periodList }}" wx:key="value" id="{{ item.viewId }}" class="period-btn {{ selectedPeriod === item.value ? 'active' : '' }}" bind:tap="onSelectPeriod" data-value="{{ item.value }}">
                 {{ item.label }}
               </view>
             </view>

+ 15 - 7
miniprogram/pages/orders/order-detail.ts

@@ -75,9 +75,9 @@ Page({
     // this.getAreas()
     if (options.orderInfo) {
       const goods = JSON.parse(decodeURIComponent(options.orderInfo));
-      // console.log(goods, 'goods')
+      console.log(goods, 'goods')
 
-      // console.log(options, 'options')
+      console.log(options, 'options')
       const infos = {
         allSalePrice: 0,
         allOriginPrice: 0,
@@ -178,6 +178,9 @@ Page({
       const beneficiary: any = result.beneficiary
 
       const tempSchoolAddress = [beneficiary?.provinceName, beneficiary?.cityName, beneficiary?.regionName, beneficiary?.schoolAreaName, GRADE_ENUM[beneficiary?.currentGradeNum], beneficiary?.currentClass + '班']
+      console.log(result, "result")
+      console.log(result.userNote, "result.userNote")
+      let that = this
       this.setData({
         receiveAddress: addresses?.id,
         receiveAddressInfo: {
@@ -185,12 +188,13 @@ Page({
           name: addresses?.name,
           phoneNumber: addresses?.phoneNumber
         },
-        userBeneficiaryId: beneficiary.schoolAreaId, // 添加购买人信息
+        userBeneficiaryId: beneficiary?.schoolAreaId, // 添加购买人信息
         userBeneficiaryInfo: {
-          name: beneficiary.name,
-          phoneNumber: beneficiary.phone,
+          name: beneficiary?.name,
+          phoneNumber: beneficiary?.phone,
           schoolInfo: tempSchoolAddress.join('')
         },
+        userNote: result.userNote,
         'goodsInfo.createTime': result.createTime
       })
     } catch {
@@ -337,6 +341,8 @@ Page({
       return
     }
 
+    console.log(this.data, 'data - info')
+
     if (!this.data.userNote || !/^1[3456789]\d{9}$/.test(this.data.userNote)) {
       wx.showToast({
         title: '请输入正确的手机号',
@@ -383,6 +389,7 @@ Page({
           paymentType: orderType
         })
         if (data.code === 200) {
+          console.log(data.data)
           const { paymentConfig, paymentType, orderNo } = data.data.paymentConfig
           this.onExecutePay(paymentConfig, paymentType, orderNo)
         } else {
@@ -391,7 +398,7 @@ Page({
       } else {
         const { data } = await api_executeOrderV2({
           "orderType": orderType,
-          "paymentType": orderType,
+          "paymentType": this.data.paymentType,
           "paymentCashAmount": allSalePrice,
           "paymentCouponAmount": 0,
           "shopId": shopId,
@@ -427,6 +434,7 @@ Page({
         }
       }
     } catch(e) {
+      console.log(e, 'e - error')
       wx.hideLoading()
     }
   },
@@ -437,7 +445,7 @@ Page({
           merOrderNo: paymentConfig.merOrderNo,
           paymentChannel: this.data.paymentChannel || 'wx_lite',
           paymentType,
-          userId: app.globalData.userInfo?.id,
+          userId: paymentConfig.userId,
           code: wxres.code,
           wxMiniAppId: app.globalData.appId
         })

+ 1 - 1
miniprogram/pages/orders/orders.ts

@@ -303,7 +303,7 @@ Page({
           merOrderNo: paymentConfig.merOrderNo,
           paymentChannel: this.data.paymentChannel || 'wx_lite',
           paymentType,
-          userId: app.globalData.userInfo?.id,
+          userId: paymentConfig.userId,
           code: wxres.code,
           wxMiniAppId: app.globalData.appId
         })