Эх сурвалжийг харах

添加报名详情接口以及优惠券二维码添加更新功能

wkw 3 долоо хоног өмнө
parent
commit
57311c8a45

+ 7 - 0
api/other.js

@@ -88,6 +88,13 @@ export function finishCertificate(data) {
     data
   });
 }
+// 报名详情
+export function enrollDetail() {
+  return request({
+    url: `/api/enroll/detail`,
+    method: 'GET'
+  });
+}
 
 
 

+ 3 - 0
pages/couponDetail/couponDetail.js

@@ -45,5 +45,8 @@ Page({
     this.setData({
       codeType: this.data.codeType === 'qr' ? 'bar' : 'qr'
     });
+  },
+  onChange(){
+    this.getcouponDetail();
   }
 })

+ 2 - 2
pages/couponDetail/couponDetail.wxml

@@ -8,13 +8,13 @@
     <view class="code-box" wx:if="{{status == 0}}">
       <!-- 显示二维码 -->
       <block wx:if="{{codeType === 'qr'}}">
-        <image class="code-img" src="{{'data:image/png;base64,' + couponInfo.qr_code}}" mode="aspectFit" />
+        <image bindtap="onChange" class="code-img" src="{{'data:image/png;base64,' + couponInfo.qr_code}}" mode="aspectFit" />
         <view class="code-text">使用时向服务员出示此码</view>
         <view class="barcode" bindtap="toggleCode">切换至条形码</view>
       </block>
       <!-- 显示条形码 -->
       <block wx:elif="{{codeType === 'bar'}}">
-        <image class="code-img" src="{{'data:image/png;base64,' + couponInfo.bar_code}}" mode="aspectFit" />
+        <image bindtap="onChange" class="code-img" src="{{'data:image/png;base64,' + couponInfo.bar_code}}" mode="aspectFit" />
         <view class="code-text">使用时向服务员出示此码</view>
         <view class="barcode" bindtap="toggleCode">切换至二维码</view>
       </block>

+ 1 - 1
pages/mine/mine.js

@@ -48,7 +48,7 @@ Page({
     };
     if (pageMap[index]) {
       wx.navigateTo({ url: pageMap[index] });
-    } else if (index === 6) {
+    } else if (index === 5) {
       const tabbar = this.getTabBar && this.getTabBar();
       if (tabbar && tabbar.openShowAgreementModal) {
         tabbar.openShowAgreementModal()

+ 37 - 10
pages/register/register.js

@@ -1,4 +1,4 @@
-import { enroll,smsSend } from '../../api/other';
+import { enroll,smsSend,enrollDetail } from '../../api/other';
 import { FETCH_AND_FORMAT_USER_INFO } from '../../utils/util.js'
 import { uploadImage } from '../../utils/upload.js';
 import {BASE_URL} from '../../utils/request';
@@ -32,7 +32,24 @@ Page({
     couponInfo:{},
     filePath: '',  // 上传成功的文件路径
     fileType: '',   // image / pdf
-    baseUrl:BASE_URL
+    baseUrl:BASE_URL,
+    isEdit: false,// 是否已有报名信息
+  },
+  async onLoad(){
+    const res = await enrollDetail();
+    if (res.code == 200 && res.data) {
+      let { phone, nickname, gender, race_number, competition_image } = res.data;
+      this.setData({
+        formData: {
+          phone,
+          nickname,
+          race_number,
+          competition_image,
+          gender: gender == 0 ? '女' : '男'
+        },
+        isEdit: true
+      });
+    }
   },
 
   onShowPicker() {
@@ -153,8 +170,14 @@ Page({
 
   // 校验表单是否可提交
   checkFormValid() {
-    const { phone, captcha, nickname, gender, race_number,competition_image } = this.data.formData;
-    const valid = phone && captcha && nickname && gender && race_number && this.data.checked && !this.data.raceNumberError && !this.data.phoneError && competition_image;
+    const { phone, captcha, nickname, gender, race_number, competition_image } = this.data.formData;
+    const { isEdit, checked, raceNumberError, phoneError } = this.data;
+    let valid = false;
+    if (isEdit) {
+      valid = phone && nickname && gender && race_number && competition_image && checked && !raceNumberError && !phoneError;
+    } else {
+      valid = phone && captcha && nickname && gender && race_number && competition_image && checked && !raceNumberError && !phoneError;
+    }
     this.setData({ canSubmit: valid });
   },
   // 获取验证码
@@ -197,16 +220,20 @@ Page({
     };
     const res = await enroll(payload);
     if (res.code === 200) {
-      // 优惠券信息
-      this.setData({
-        couponInfo:res.data[0]
-      })
       await FETCH_AND_FORMAT_USER_INFO();
-      this.setData({ showRegistrationSuccess: true });
+      if (!this.data.isEdit) {
+        this.setData({
+          couponInfo: res.data[0],
+          showRegistrationSuccess: true
+        });
+      } else {
+        wx.showToast({ title: '修改成功', icon: 'none' });
+        wx.navigateBack({ delta: 1 });
+      }
     } else {
       wx.showToast({ title: res.message || '报名失败', icon: 'none', duration: 2000 });
     }
-  },
+  },  
   // 点击协议文字显示弹窗
   showAgreement(e) {
     const type = e.currentTarget.dataset.type;

+ 19 - 16
pages/register/register.wxml

@@ -15,26 +15,29 @@
             type="number"
             placeholder="请输入手机号"
             border="{{ false }}"
+            disabled="{{isEdit}}"
           />
           <view class="error-text">{{phoneError}}</view>
         </view>
 
-        <!-- 验证码 -->
-        <view class="from-li">
-          <image class="from-li-img" src="/static/image/register/yzm.png" mode="aspectFit" />
-          <van-field
-            model:value="{{formData.captcha}}"
-            bind:input="onInput"
-            data-field="captcha"
-            placeholder="请输入验证码"
-            border="{{ false }}"
-          >
-            <view slot="button" 
-              class="from-code {{codeDisabled ? 'disabled' : ''}}" 
-              bindtap="getCode">{{codeText}}
-            </view>
-          </van-field>
-        </view>
+        <!-- 验证码:仅未报名时显示 -->
+        <block wx:if="{{!isEdit}}">
+          <view class="from-li">
+            <image class="from-li-img" src="/static/image/register/yzm.png" mode="aspectFit" />
+            <van-field
+              model:value="{{formData.captcha}}"
+              bind:input="onInput"
+              data-field="captcha"
+              placeholder="请输入验证码"
+              border="{{ false }}"
+            >
+              <view slot="button" 
+                class="from-code {{codeDisabled ? 'disabled' : ''}}" 
+                bindtap="getCode">{{codeText}}
+              </view>
+            </van-field>
+          </view>
+        </block>
 
         <!-- 姓名 -->
         <view class="from-li">