|
@@ -49,7 +49,9 @@
|
|
|
</view>
|
|
|
</view>
|
|
|
<view class="container-button">
|
|
|
- <view class="button" @click="handeleReceiveCoupon(coupon)">领取优惠券</view>
|
|
|
+ <view v-if="coupon.moneyCouponFlag === 1" class="button" @click="createCouponRecord(coupon)">
|
|
|
+ ¥{{ coupon.moneyCouponPrice }}购买</view>
|
|
|
+ <view v-else class="button" @click="handeleReceiveCoupon(coupon)">领取优惠券</view>
|
|
|
</view>
|
|
|
</template>
|
|
|
</view>
|
|
@@ -59,9 +61,11 @@
|
|
|
<script>
|
|
|
import { mapState, mapMutations } from 'vuex'
|
|
|
import wxLogin from '@/common/config/wxLogin.js'
|
|
|
- import { COUPON_TEXT_MAP } from '@/utils/coupon.share.js'
|
|
|
import authorize from '@/common/config/authorize.js'
|
|
|
+ import { COUPON_TEXT_MAP } from '@/utils/coupon.share.js'
|
|
|
+ import payMixins from '@/mixins/payMixins.js'
|
|
|
export default {
|
|
|
+ mixins: [payMixins],
|
|
|
data() {
|
|
|
return {
|
|
|
StaticUrl: this.$Static,
|
|
@@ -130,6 +134,45 @@
|
|
|
console.log('初始化优惠券信息异常~')
|
|
|
}
|
|
|
},
|
|
|
+ //购买优惠券
|
|
|
+ createCouponRecord(coupon) {
|
|
|
+ // 生成购买优惠券记录Id
|
|
|
+ if (!this.hasLogin) {
|
|
|
+ const pages = getCurrentPages()
|
|
|
+ const page = pages[pages.length - 1]
|
|
|
+ uni.setStorageSync('LOGIN_REDIRECT_URL', page.$page.fullPath)
|
|
|
+ this.$api.redirectTo('/pages/login/login')
|
|
|
+
|
|
|
+ } else {
|
|
|
+ this.WeChatCouponRecord(coupon)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 调用查询购买
|
|
|
+ async WeChatCouponRecord(coupon) {
|
|
|
+ try {
|
|
|
+ const userInfo = await this.$api.getStorage()
|
|
|
+ const data = await this.PayService.WeChatCouponRecord({ userId: userInfo.userId,
|
|
|
+ couponId: coupon.couponId })
|
|
|
+ this.MiniWxPayFor(data.data.couponRecordId)
|
|
|
+ } catch (error) {
|
|
|
+ this.$util.msg(error.msg, 2000)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 购买优惠券支付
|
|
|
+ async MiniWxPayFor(couponRecordId) {
|
|
|
+ const wechatcode = await authorize.getCode('weixin')
|
|
|
+ const userInfo = await this.$api.getStorage()
|
|
|
+ const params = {
|
|
|
+ userId: userInfo.userId,
|
|
|
+ couponId: this.param.couponId,
|
|
|
+ couponRecordId: couponRecordId,
|
|
|
+ payType: 'XCX',
|
|
|
+ code: wechatcode,
|
|
|
+ source: 1 //支付来源 1 小程序 2 WWW
|
|
|
+ }
|
|
|
+ this.weChatMiniCouponWxPay(params, 'Um_Event_shareCouponPay', '分享优惠券', '线上支付优惠券', this.couponId,
|
|
|
+ this.userId)
|
|
|
+ },
|
|
|
async handeleReceiveCoupon(coupon) {
|
|
|
// 点击优惠券领取按钮,
|
|
|
if (this.hasLogin) {
|
|
@@ -165,7 +208,7 @@
|
|
|
onShareAppMessage(res) {
|
|
|
//分享优惠券
|
|
|
if (res.from === 'button') {
|
|
|
- // 来自页面内转发按钮
|
|
|
+ // 来自页面内转发按钮
|
|
|
}
|
|
|
const randomIndex = Math.floor(Math.random() * COUPON_TEXT_MAP.length);
|
|
|
return {
|