svip.vue 8.0 KB

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