svip.vue 9.0 KB

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