liyaozhi
2025-10-29 52b7c373601edbc5010471082eb88dadf70e382d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
<template>
    <view :class="[Visible ? 'usable-popup open' : 'usable-popup close', theme() || '']" :data-theme='theme()'>
        <view class="popup-bg" @click="closePopup(null)"></view>
        <view class="main pt30" v-on:click.stop>
            <view class="popup-title pb30 pr">
                <view class="title tc f32 fb">活动报名</view>
                <view class="iconfont icon-guanbi" @click="closePopup(null)"></view>
            </view>
            <scroll-view scroll-y="true" class="scroll-Y" :style="'height:' + scrollviewHigh + 'px;'">
                <view class="pb30">
                    <!-- 如果不是连盟汇会员,需要填写个人信息,报名后会自动加入活动发起的分会 -->
                    <view class="reg-section join-box p30 radius24 bg-white" v-if="!activityData.is_member">
                        <view class="tips f28 p20 radius12"><text class="iconfont icon-gantanhao mr10"></text> 您还不是{{activityData.store_name}}的会员,请完善以下信息,提交报名后即可成为会员。</view>
                        <view class="item d-s-c">
                            <view class="item-name">真实姓名</view>
                            <input type="text" maxlength="30" class="flex-1" placeholder="请输入真实姓名" v-model="formData.real_name" placeholder-class=
                            "placeholder" />
                        </view>
                        <view class="item d-s-c">
                            <view class="item-name">手机号码</view>
                            <input type="text" maxlength="30" class="flex-1" placeholder="请输入常用的手机号码" v-model="formData.mobile" placeholder-class=
                            "placeholder" />
                        </view>
                        <view class="item d-s-c">
                            <view class="item-name">单位/公司名称</view>
                            <input type="text" maxlength="30" class="flex-1" placeholder="请输入单位/公司名称" v-model="formData.company" placeholder-class=
                            "placeholder" />
                        </view>
                    </view>
                    <view class="reg-section pay-box p30 radius24 bg-white" v-if="activityData.fee > 0">
                        <view class="pay-item d-b-c">
                            <view class="title">报名费用</view>
                            <view class="theme-price"><text>¥</text>{{activityData.fee}}</view>
                        </view>
                        <view class="pay-item d-b-c pt40">
                            <view class="title">{{points_name()}}(共{{activityData.points}}个)</view>
                            <view class="">
                                <text class="gray9" v-if="activityData.points == 0">
                                    无可用
                                </text>
                                <text class="theme-price" v-else-if="formData.points_num > 0" @click="onPoints">
                                    -<text class="f24">¥</text>{{formData.points_money}} <text class='iconfont icon-jiantou'></text>
                                </text>
                                <text class="gray6 f28" v-else @click="onPoints">
                                    去选择 <text class='iconfont icon-jiantou'></text>
                                </text>
                            </view>
                        </view>
                        <view class="pay-item d-b-c pt40">
                            <view class="title">余额(共¥{{activityData.balance}}可用)</view>
                            <view class="">
                                <text class="gray9" v-if="activityData.balance == 0">
                                    无可用
                                </text>
                                <view class="price" v-else>
                                    <text class="f24 gray9" v-if="parseFloat(activityData.balance) < parseFloat(activityData.fee) && formData.is_combined_pay==1">需组合支付</text>
                                    <switch style="transform: scale(0.7); margin-right: -20rpx;" :checked="is_checked_balance" @change="onUseBalance" />
                                </view>
                                
                            </view>
                        </view>
                    </view>
                    <view class="reg-section pay-type p30 radius24 bg-white" v-if="onlinePrice > 0">
                        <view class="item d-b-c">
                            <view class="f30">需支付的金额</view>
                            <view class="theme-price f30 fb"><text class="f24">¥</text>{{onlinePrice}}</view>
                        </view>
                        <view class="item d-b-c" :class="{'active':formData.pay_type == 20}" @tap="payTypeFunc(20)">
                            <view class="d-s-c">
                                <view class="icon-left d-c-c mr10">
                                    <i class="icon iconfont icon-weixin"></i>
                                </view>
                                <view>
                                    <view class="key">微信支付</view>
                                    <view class="gray9">使用微信快捷支付</view>
                                </view>
                            </view>
                            <view class="icon-right">
                                <i class="icon iconfont icon-xuanze"></i>
                            </view>
                        </view>
                        <view v-if="showAlipay" class="item d-b-c" :class="{'active':formData.pay_type == 30}" @click="payTypeFunc(30)">
                            <view class="d-s-c">
                                <view class="icon-left d-c-c mr10">
                                    <i class="icon iconfont icon-zhifubao"></i>
                                </view>
                                <view>
                                    <view class="key">支付宝支付</view>
                                    <view class="gray9">使用支付宝支付</view>
                                </view>
                            </view>
                            <view class="icon-right">
                                <i class="icon iconfont icon-xuanze"></i>
                            </view>
                        </view>
                    </view>
                </view>
            </scroll-view>
            <view class="footer-btn bg-white p-0-30 pt20 pb20">
                <button type="default" @click="onSubmit" class="btn-submit">提交报名</button>
            </view>
        </view>
        <!-- 积分弹窗 -->
        <PointsForm :isOpenPoints="isOpenPoints" :activityData="activityData" :max_price="onlinePrice+formData.points_money" @close="closePointsFunc"></PointsForm>
    </view>
</template>
 
<script>
    import { pay } from '@/common/pay.js';
    import PointsForm from './points'; // 积分选择弹窗
    export default {
        components: {
            PointsForm
        },
        data() {
            return {
                /*手机高度*/
                phoneHeight: 0,
                /*可滚动视图区域高度*/
                scrollviewHigh: 0,
                /*是否可见*/
                Visible: false,
                /*表单*/
                formData: {
                    activity_id: '',
                    real_name: '',
                    mobile: '',
                    company: '',
                    shop_supplier_id: 0,
                    points_num: 0, // 抵扣的积分数量
                    points_money: 0, // 积分抵扣的金额
                    balance: 0, // 使用的余额
                    is_use_balance: 0, // 是否使用余额支付
                    is_combined_pay: 0, // 是否需要组合支付
                    pay_type: 20, // 支付方式,默认微信支付
                },
                /*尺寸比例*/
                ratio: 1,
                showAlipay: true, /*是否显示支付宝支付,只有在h5,非微信内打开才显示*/
                use_balance: 0, // 使用的余额
                is_checked_balance: false, // 是否
                activityData: {},
                isOpenPoints: false, // 是否打开积分弹窗
                validate: false,
                payData: [], // 半屏小程序相关
                isFirst: false,
            };
        },
        props: ['isOpenReg', 'in_radius'],
 
        onLoad() {},
        onShow() {
            let self = this;
            console.log('pay-res')
            let options = wx.getEnterOptionsSync();
            // 从半屏小程序返回时执行
            if (options.scene == '1038' && self.isFirst == true) {
                self.isFirst = false;
                self.onPayResult(options.referrerInfo.extraData);
            }
        },
        mounted() {
            this.init();
        },
        watch: {
            isOpenReg: function(n, o) {
                if (n != o) {
                    this.Visible = n;
                    this.getHeight();
                }
            }
        },
        computed: {
            // 最多可使用的余额
            maxBalance() {
                if (this.formData.is_use_balance == 1) {
                    return Math.min(this.activityData.balance, this.activityData.fee - this.formData.points_money);
                }
                return 0;
            },
            onlinePrice() {
                const online_price = Math.max(this.activityData.fee - this.formData.points_money - this.maxBalance, 0);
                return parseFloat(online_price.toFixed(2));
            },
        },
        methods: {
            /*初始化*/
            init() {
                let self = this;
                uni.getSystemInfo({
                    success(res) {
                        self.phoneHeight = res.windowHeight;
                        self.ratio = res.windowWidth / 750;
                        self.getHeight();
                    }
                });
            },
 
            /*获取高度*/
            getHeight() {
                // 连盟汇成员和非成员设置不用的高度
                if (this.activityData.is_member) {
                    this.scrollviewHigh = 680 * this.ratio;
                } else {
                    if (this.activityData.fee > 0) {
                        this.scrollviewHigh = this.phoneHeight * 0.8;
                    } else {
                        this.scrollviewHigh = 600 * this.ratio;
                    }
                }
            },
            
            // 半屏小程序返回
            onPayResult(e) {
                console.log(e)
                let self = this;
                self.loading = false;
                uni.hideLoading();
                self.isFirst = false;
                if (e.pay_result == 'success') {
                    self.paySuccess(self.payData);
                } else {
                    if(self.order_id > 0){
                        //兼容重新付款
                    }else{
                        self.payError(self.payData);
                    }    
                }
            },
            
            paySuccess(result) {
                let self = this;
                self.showSuccess("支付成功", function() {
                    self.$emit('close', 1);
                })
        
            },
            payError(result) {
                let self = this;
                self.showSuccess("支付成功", function() {
                    self.$emit('close', 2);
                })
            },
            
            // 是否使用余额支付
            onUseBalance(e) {
                if (e.target.value == true) {
                    this.is_checked_balance = true;
                    this.formData.is_use_balance = 1;
                    if (this.onlinePrice > 0) {
                        this.formData.is_combined_pay = 1;
                    }
                } else {
                    this.is_checked_balance = false;
                    this.formData.is_use_balance = 0;
                    this.formData.is_combined_pay = 0;
                }
            },
            
            /*选择支付方式*/
            payTypeFunc(e){
                this.formData.pay_type = e;
            },
            
            /*提交报名*/
            onSubmit() {
                let self = this;
                let reg_success = 1; // 1报名成功 2报名失败
                if (self.validateForm() && self.validate) {
                    uni.showLoading({
                        title: '正在提交',
                        mask: true
                    })
                    self.validate = false;
                    let params = self.formData;
                    self._post('branch.activity/submit', {
                        params: JSON.stringify(
                            Object.assign({}, params, {
                                balance: self.maxBalance,
                                activity_id: self.activityData.activity_id,
                                is_member: self.activityData.is_member,
                                pay_source: self.getPlatform(),
                                in_radius: self.in_radius ? 1 : 0 // 如果为1,报名成功后直接签到
                            })
                        )
                    }, function(res) {
                        uni.hideLoading();
                        if (res.data.online_money) {
                            // 半屏小程序支付 by lyzflash
                            if (res.data.payment.is_embed) {
                                // console.log(res.data.payment);
                                self.isFirst = true;
                                uni.openEmbeddedMiniProgram({
                                    appId: res.data.payment.embed_app_id,
                                    path: res.data.payment.embed_path,
                                    extraData: res.data.payment.extraData,
                                    envVersion: 'release', // develop开发版 trial体验版 release正式版 
                                    success:function() {
                                        console.log('打开半屏小程序成功');
                                    },
                                    fail:function() {
                                        console.log('打开半屏小程序失败');
                                    }
                                });
                                return;
                            }
                            pay(res, self, self.paySuccess, self.payError); 
                        } else if (res.code != 1) {
                            reg_success = 2; // 失败
                        }
                        self.$emit('close', reg_success);
                    });
                }
            },
            
            // 验证数据
            validateForm() {
                let self = this;
                if (!self.activityData.is_member) {
                    if (!self.formData.real_name) {
                        return self.showTips('请输入您的真实姓名');
                    }
                    if (!self.formData.mobile) {
                        return self.showTips('请输入您的手机号码');
                    }
                    if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(self.formData.mobile)) {
                        return self.showTips('请输入正确的手机号码');
                    }
                    if (!self.formData.company) {
                        return self.showTips('请输入单位/公司名称');
                    }
                }
                self.validate = true;
                return true;
            },
            
            // 提示框
            showTips(title, duration = 1000, icon = 'none') {
                uni.showToast({
                    title: title,
                    duration: duration,
                    icon: icon
                });
            },
 
            /*关闭弹窗*/
            closePopup(e) {
                this.$emit('close', e);
            },
            
            /*打开积分弹窗*/
            onPoints() {
                this.isOpenPoints = true;
            },
            
            /*关闭积分弹窗*/
            closePointsFunc(e) {
                if (e !== null) {
                    this.formData.points_num = e;
                    this.formData.points_money = parseFloat((e * this.activityData.points_ratio).toFixed(2));
                }
                this.isOpenPoints = false;
            },
        }
    };
</script>
 
<style lang="scss" scoped>
    .usable-popup .popup-bg {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        background: rgba(0, 0, 0, 0.6);
        z-index: 99;
    }
 
    .usable-popup .main {
        position: fixed;
        width: 100%;
        bottom: 0;
        min-height: 200rpx;
        background-color: #f5f5f5;
        transform: translate3d(0, 1380rpx, 0);
        transition: transform 0.2s cubic-bezier(0, 0, 0.25, 1);
        bottom: env(safe-area-inset-bottom);
        z-index: 99;
        border-radius: 30rpx 30rpx 0 0;
    }
 
    .usable-popup.open .main {
        transform: translate3d(0, 0, 0);
    }
 
    .usable-popup.close .popup-bg {
        display: none;
    }
 
    .footer-btn .btn-submit {
        height: 88rpx;
        line-height: 88rpx;
        font-size: 30rpx;
        @include background_color('background_color');
        color: #ffffff;
        border-radius: 88rpx;
    }
    
    .popup-title {
        .iconfont {
            position: absolute;
            right: 30rpx;
            top: 10rpx;
            color: #999999;
        }
    }
    
    .reg-section {
        + .reg-section {
            margin-top: 30rpx;
        }
    }
    
    .join-box {
        .item {
            padding-top: 60rpx;
            .item-name {
                font-size: 28rpx;
                width: 200rpx;
            }
        }
        .tips {
            background-color: #f7f7f7;
            color: #333;
        }
    }
    .pay-box {
        .pay-item {
            font-size: 30rpx;
            .title {
                
            }
            .theme-price {
                text {
                    font-size: 24rpx;
                }
            }
            .icon-jiantou {
                font-size: 24rpx;
            }
        }
    }
    .pay-type {
        .item {
            .icon-left {
                .icon-weixin {
                    font-size: 60rpx;
                    color: #04BE01;
                }
                .icon-zhifubao {
                    font-size: 50rpx;
                    color: #1281ff;
                }
            }
            .key {
                font-size: 28rpx;
            }
            .icon-right {
                .iconfont {
                    font-size: 48rpx;
                }
            }
            + .item {
                margin-top: 45rpx;
            }
            &.active {
                .icon-right {
                    .iconfont {
                        @include font_color('price_color');
                    }
                }
            }
        }
    }
</style>