svip.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <!-- svip页面 -->
  2. <template>
  3. <view class="ezy-svip-page">
  4. <view class="icon-title-navBar-box">
  5. <!-- 返回按钮 ↓ -->
  6. <view class="nav-bar-icon" @click="goBack"></view>
  7. <view class="nav-bar-title">开通svip</view>
  8. </view>
  9. <!-- :class="'svip-login'+Id" 改到下方 -->
  10. <icon :class="'svip-login'+cardId"></icon>
  11. <view class="svip-list-box">
  12. <view v-for="(item, index) in svipArr" :key="index" class="list-item-box">
  13. <icon class="list-icon" :style="{backgroundImage: 'url(' + item.iconPath + ')'}"></icon>
  14. <view>
  15. <view class="list-title">{{item.title}}</view>
  16. <view class="list-content" v-html="item.content"></view>
  17. </view>
  18. </view>
  19. </view>
  20. <view class="open-svip-box">
  21. <view class="svip-price-box">
  22. <view>原价:<text class="original-price">¥598</text></view>
  23. <view class="discount-price">活动价:¥198</view>
  24. </view>
  25. <radio-group @change="radioChange" class="pay-type-box">
  26. <view class="type-radio-title">支付方式</view>
  27. <view class="type-radio-content">
  28. <view class="type-radio-box">
  29. <icon class="wx-radio"></icon>
  30. <text>微信</text>
  31. <radio value="weixin" :checked="payType==='weixin'" activeBackgroundColor="transparent"
  32. :class="{'radio-checked': payType==='weixin'}" />
  33. </view>
  34. <view class="type-radio-box">
  35. <icon class="zfb-radio"></icon>
  36. <text>支付宝</text>
  37. <radio value="zhifubao" :checked="payType==='zhifubao'" activeBackgroundColor="transparent"
  38. :class="{'radio-checked': payType==='zhifubao'}" style="margin-right: 0;" />
  39. </view>
  40. </view>
  41. </radio-group>
  42. <view class="open-svip-btn" @click="creatOrder">立即开通</view>
  43. </view>
  44. <CustomTabBar></CustomTabBar>
  45. <!-- 蛋破壳 -->
  46. <pay-success ref="daoPokeRef"></pay-success>
  47. <pay-successAll ref="daoPokeAllRef"></pay-successAll>
  48. </view>
  49. </template>
  50. <script setup>
  51. import {
  52. ref
  53. } from "vue";
  54. import {
  55. orderAdd,
  56. orderPayAli,
  57. orderPayWx,
  58. } from "@/api/order.js"
  59. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  60. import cacheManager from "@/utils/cacheManager.js";
  61. import paySuccess from './paySuccess.vue';
  62. import paySuccessAll from './paySuccessAll.vue';
  63. import {
  64. onLoad,
  65. onReady
  66. } from '@dcloudio/uni-app';
  67. import {
  68. toast,
  69. getUserIdentity
  70. } from "@/utils/common";
  71. let payType = ref('zhifubao')
  72. let cardId = ref('')
  73. let formPage = ref('')
  74. const daoPokeRef = ref(null);
  75. const daoPokeAllRef = ref(null);
  76. const isVip = getUserIdentity();
  77. const svipArr = [{
  78. iconPath: 'static/images/pay/svip-list-icon1.png',
  79. title: '学习资源,随心畅学',
  80. content: `解锁L1~L6全等级数学思维优质学习资源,<br/>满足多样学习需求`
  81. },
  82. {
  83. iconPath: 'static/images/pay/svip-list-icon2.png',
  84. title: '名师打造,优质路径',
  85. content: '资深名师精心规划学习路径,引领高效提升方向'
  86. },
  87. {
  88. iconPath: 'static/images/pay/svip-list-icon3.png',
  89. title: '进度分析,个性贴心',
  90. content: '优先参与丰富真题测试,精准洞察学习状况'
  91. },
  92. {
  93. iconPath: 'static/images/pay/svip-list-icon4.png',
  94. title: '真题测试,优先体验',
  95. content: '成为会员,即刻畅享专属权益,开启无忧学习之旅'
  96. }
  97. ];
  98. onLoad((options) => {
  99. cardId.value = options.cardId
  100. formPage.value = options.formPage
  101. })
  102. function radioChange(data) {
  103. payType.value = data.detail.value;
  104. }
  105. function creatOrder(data) {
  106. if (payType.value == 'weixin') {
  107. let req = {
  108. cardId: cardId.value
  109. }
  110. orderAdd(req).then(res => {
  111. console.log('res', res);
  112. console.log(' res.data.id', res.data.id);
  113. orderPayWx({
  114. id: res.data.id
  115. }).then(res2 => {
  116. console.log('res2', res2);
  117. uni.requestPayment({
  118. "provider": "wxpay",
  119. "orderInfo": {
  120. "appid": res2.data.appid, // 应用ID(AppID)
  121. "partnerid": res2.data.partnerId, // 商户号(PartnerID)
  122. "prepayid": res2.data.prepayId, // 预支付交易会话ID
  123. "package": res2.data.packageVal, // 固定值
  124. "noncestr": res2.data.nonceStr, // 随机字符串
  125. "timestamp": res2.data.timestamp, // 时间戳(单位:秒)
  126. "sign": res2.data.sign // 签名,这里用的 MD5 签名
  127. }, //此处为服务器返回的订单信息字符串
  128. success: function(res) {
  129. var rawdata = JSON.parse(res.rawdata);
  130. console.log('支付成功');
  131. console.log('rawdata', rawdata);
  132. // toast("支付成功");
  133. cacheManager.updateVipStatus('auth', cardId.value)
  134. cacheManager.updateObject('auth', {
  135. growthType: 1
  136. })
  137. if (isVip != 'VIP') {
  138. daoPokeRef.value.handleShow();
  139. } else {
  140. daoPokeAllRef.value.handleShow();
  141. }
  142. setTimeout(() => {
  143. daoPokeRef.value.handleClose();
  144. daoPokeAllRef.value.handleClose();
  145. if (formPage.value == 'my') {
  146. uni.redirectTo({
  147. url: '/pages/my/index'
  148. })
  149. } else {
  150. uni.redirectTo({
  151. url: '/pages/study/index'
  152. })
  153. }
  154. }, 3000)
  155. },
  156. fail: function(err) {
  157. // toast('支付失败:' + JSON.stringify(err));
  158. console.log('支付失败:' + JSON.stringify(err));
  159. }
  160. });
  161. }).catch((error) => {
  162. console.log(error);
  163. })
  164. })
  165. } else {
  166. let req = {
  167. cardId: cardId.value
  168. }
  169. orderAdd(req).then(res => {
  170. console.log('res', res);
  171. orderPayAli({
  172. id: res.data.id
  173. }).then(res2 => {
  174. console.log('res2', res2);
  175. uni.requestPayment({
  176. "provider": "alipay",
  177. "orderInfo": res2.data.text, //此处为服务器返回的订单信息字符串
  178. success: function(res) {
  179. var rawdata = JSON.parse(res.rawdata);
  180. console.log('支付成功');
  181. console.log('rawdata', rawdata);
  182. // toast("支付成功");
  183. cacheManager.updateVipStatus('auth', cardId.value)
  184. cacheManager.updateObject('auth', {
  185. growthType: 1
  186. })
  187. if (isVip != 'VIP') {
  188. daoPokeRef.value.handleShow();
  189. } else {
  190. daoPokeAllRef.value.handleShow();
  191. }
  192. setTimeout(() => {
  193. daoPokeRef.value.handleClose();
  194. daoPokeAllRef.value.handleClose();
  195. if (formPage.value == 'my') {
  196. uni.redirectTo({
  197. url: '/pages/my/index'
  198. })
  199. } else {
  200. uni.redirectTo({
  201. url: '/pages/study/index'
  202. })
  203. }
  204. }, 3000)
  205. },
  206. fail: function(err) {
  207. // toast('支付失败:' + JSON.stringify(err));
  208. console.log('支付失败:' + JSON.stringify(err));
  209. }
  210. });
  211. })
  212. })
  213. }
  214. }
  215. function goBack(data) {
  216. if (formPage.value == 'my') {
  217. uni.redirectTo({
  218. url: '/pages/my/index'
  219. })
  220. } else {
  221. uni.redirectTo({
  222. url: '/pages/study/index'
  223. })
  224. }
  225. }
  226. </script>
  227. <style>
  228. </style>