svip.vue 7.8 KB

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