vipBuy.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <template>
  2. <!-- <page-meta :page-style="pageStyle"></page-meta> -->
  3. <view class="content">
  4. <es-nav-bg-black title="御君方会员" right="管理订阅"></es-nav-bg-black>
  5. <view class="es-fx es-pc es-h-168 es-ml-44 es-mr-44 es-mt-20">
  6. <image class="topBg" src="../../static/image/course/vipBuy/topbg.png"></image>
  7. <view class="topItem es es-fx x-f">
  8. <image class="es-w-104 es-h-56" style="position: absolute;left:-32rpx;top:0" src="../../static/image/course/xiangyun.png"></image>
  9. <view class="es-fs-40 es-h-156 es-fw-bold x-c" style="color: #FFDAA3;">
  10. <view class="es x-bc " style="margin-left: 90rpx;">
  11. <image class="es-w-120 es-h-120 es-br-ban" :src="!$isEmpty(user.avatar)?user.avatar:avatar" ></image>
  12. <view class="y-b es-ml-20">
  13. <view class="es-fw-bold es-fs-32 es es-ac" :class="user.isVip==1?'vipC':'es-c-white'" >
  14. {{ $isEmpty(user.nickName)?"暂无昵称":user.nickName }}
  15. <image v-if="user.isVip==1" @tap="loginNavTo('../course/vipBuy')" class="es-w-40 es-h-40 es-ml-10" src="../../static/image/mine/vip.png"></image>
  16. </view>
  17. <view v-if="user.isVip==1" class="es-fs-22 es-mt-10 es-c-white" style="color: #929A9D">有效期至:{{ $formatDate(user.vipEndDate) }}</view>
  18. <view v-else class="es-fs-26 es-c-white">开通VIP享<span class="es-fw-bold es-fs-44" style="color: #929A9D;">6</span>大特权</view>
  19. </view>
  20. </view>
  21. </view>
  22. <image class="es-w-104 es-h-56" style="position: absolute;right:-32rpx;bottom:30rpx" src="../../static/image/course/xiangyun2.png"></image>
  23. </view>
  24. </view>
  25. <!-- Vip选项 -->
  26. <scroll-view class="payBox es x-f es-ml-44 es-mt-40" scroll-x="true" >
  27. <view v-for="(item, index) in dataList" :key="index" @tap="changePackage(index)" class="payItem es-ac es-pc" :class="pickIndex==index?'ac':''">
  28. <image v-if="pickIndex==index" class="san" src="../../static/image/course/vipBuy/item_san.png"></image>
  29. <view class="es-fs-28 es-c-white es-fw-400 x-c" style="margin-top: 54rpx;">{{item.packageName}}</view>
  30. <view class="es-c-white es-fs-44 es-fw-500 es-mt-2 x-c-28 price x-c">¥{{item.sellPrice}}</view>
  31. <view class="es-fs-24 es-fw-400 oriPriceBox x-c">
  32. <view>原价</view>
  33. <view class="oriPrice">¥{{item.price}}
  34. <view class="zkline"></view>
  35. </view>
  36. </view>
  37. <view class="es es-h-44 es-bc-theme es-c-white es-br-9 es-fs-28 x-c es-fx es-ml-33 es-mr-33 es-mt-10" >限时优惠</view>
  38. </view>
  39. </scroll-view>
  40. <!-- 支付方式 -->
  41. <view class="es-mr-44 es-ml-44 es-mt-40">
  42. <view class="es-c-white es-fs-40 es-fw-700">支付方式</view>
  43. <view class="es-mt-30 x-bc">
  44. <view v-for="(item, index) in payTypes" :key="index" @tap="changePayType(index)" class="payTypeItem es x-bc " :class="payType==index+1?'pt_ac':''">
  45. <view class="x-bc es-ml-14">
  46. <image class="es-w-59 es-h-52" :src="index==0?'../../static/image/course/vipBuy/wx.png':'../../static/image/course/vipBuy/zfb.png'"></image>
  47. <view class="es-fs-33 es-c-white es-fw-500 es-ml-14">{{item}}</view>
  48. </view>
  49. <image v-if="payType==index+1" src="../../static/image/course/vipBuy/check.png" class="es-w-40 es-h-40 es-br-ban es-mr-14"></image>
  50. <view v-else class="es-w-40 es-h-40 es-br-ban es-mr-14 circle"></view>
  51. </view>
  52. </view>
  53. </view>
  54. <!-- 购买须知 -->
  55. <view class="es-mr-44 es-ml-44 es-mt-40">
  56. <view class="es-c-white es-fs-40 es-fw-700">购买须知</view>
  57. <view class="es-mt-24 es-c-white es-fs-28" style="line-height: 40rpx;">1.有效期内,会员内容都可使用 <br/> 2.御君方会员为虛拟服务,开通后不支持退款<br/> 3.支付成功会员权益自动生效<br/></view>
  58. <view class="x-c es-mt-50 es-c es-fs-28 es-fw-500">
  59. <view class="es-mr-40" @tap="openH5(0)">《会员服务协议》</view>
  60. <view>《自动续费协议》</view>
  61. </view>
  62. </view>
  63. <!-- 底部bottom -->
  64. <view class="es payBot x-bc">
  65. <view class="es-fs-56 es-fw-bold x-bc es-ml-44" style="color: #FDD8A1;">¥{{checkPrice}} <view class="tehui">(限时优惠)</view></view>
  66. <view class="es btnPay x-c" @tap="doBuy">立即开通</view>
  67. </view>
  68. <uni-popup ref="popTip" type="dialog">
  69. <uni-popup-dialog cancelText="支付失败" confirmText="支付成功" mode="base" content="是否已支付成功?" title="提示" :duration="2000" :before-close="true" @close="confirmTip" @confirm="confirmTip"></uni-popup-dialog>
  70. </uni-popup>
  71. </view>
  72. </template>
  73. <script>
  74. import {getUserInfo} from '@/api/user'
  75. import { getPackageList,createVipOrder,vipZfbPayment,getVipOrderById } from '@/api/course'
  76. export default {
  77. data() {
  78. return {
  79. dataList:[],
  80. pickIndex:0,
  81. packageItem:{sellPrice:0,price:0},
  82. checkPrice:0.0,
  83. payTypes:["微信支付","支付宝支付"],
  84. payType:1,//微信支付:1 支付宝支付:2
  85. user:{
  86. avatar:"/static/images/detault_head.png",
  87. userName:"",
  88. phone:"",
  89. nickName:"",
  90. },
  91. order:null,
  92. showPayTips:false,
  93. }
  94. },
  95. // onBackPress() {
  96. // // 手动调用返回方法
  97. // uni.navigateBack({ delta: 1});
  98. // // 阻止默认的返回行为
  99. // return true;
  100. // },
  101. onLoad(options) {
  102. this.initData();
  103. },
  104. onShow() {
  105. if(this.showPayTips){
  106. this.$refs.popTip.open();
  107. this.showPayTips=false;
  108. }
  109. },
  110. onUnload() {
  111. const subNVue = uni.getSubNVueById('privilege');
  112. if(subNVue){
  113. setTimeout(e => {
  114. subNVue.show();
  115. }, 200);
  116. }
  117. },
  118. methods: {
  119. initData(){
  120. this.getPackageList();
  121. this.getUserInfo();
  122. },
  123. getPackageList(){
  124. getPackageList().then(res => {
  125. if(res.code==200){
  126. this.dataList=res.data;
  127. this.packageItem=this.dataList[0];
  128. this.checkPrice=this.packageItem.sellPrice;
  129. }
  130. },
  131. rej => {}
  132. );
  133. },
  134. doBuy(){
  135. this.createVipOrder();
  136. },
  137. createVipOrder(){
  138. if(!this.$isLogin()){
  139. this.$showLoginPage();
  140. return;
  141. }
  142. uni.showLoading({title:""});
  143. let params={"packageId":this.packageItem.packageId,"payType":this.payType};
  144. createVipOrder(params).then(res => {
  145. console.log("qxj createVipOrder res:"+JSON.stringify(res));
  146. uni.hideLoading();
  147. if(res.code==200){
  148. this.order=res.order;
  149. if(this.payType==1){ //微信支付
  150. this.doWxPay();
  151. }else{ //支付宝
  152. this.doAlipay();
  153. }
  154. }else{
  155. uni.showToast({title: res.msg,icon: 'none'});
  156. }
  157. },
  158. rej => {}
  159. );
  160. },
  161. changePackage(index){
  162. this.pickIndex=index;
  163. this.packageItem=this.dataList[index];
  164. this.checkPrice=this.packageItem.sellPrice;
  165. },
  166. changePayType(index){
  167. this.payType=index+1;
  168. },
  169. getUserInfo(){
  170. let that=this;
  171. getUserInfo().then(res => {
  172. if(res.code==200){
  173. if(res.user!=null){
  174. uni.setStorageSync('userInfo',JSON.stringify(res.user));
  175. this.user=res.user;
  176. }
  177. else{
  178. uni.showToast({
  179. icon:'none',
  180. title: res.msg,
  181. });
  182. }
  183. }
  184. },
  185. rej => {}
  186. );
  187. },
  188. doAlipay(){
  189. var data = {orderId:this.order.orderId};
  190. let that=this;
  191. // #ifdef APP-PLUS
  192. const tzCashier=uni.requireNativePlugin("TZBank-Cashier");
  193. uni.showLoading();
  194. vipZfbPayment(data).then(res => {
  195. uni.hideLoading();
  196. if(res.code==200){
  197. if(res.type=="tz"){
  198. //console.log("qxj res:"+JSON.stringify(res));
  199. //console.log("qxj orderFlowNo:"+res.data.body.orderFlowNo+" businessCstNo:"+res.data.body.orderNo+" platMerCstNo:"+res.data.body.platMerCstNo);
  200. const match = res.data.body.url.match(/[\?&]businessCstNo=([^&]+)/);
  201. const businessCstNo = match ? match[1] : null;
  202. console.log("qxj tzCashier:"+tzCashier+" businessCstNo:"+businessCstNo);
  203. tzCashier.pay({
  204. env:0,
  205. wxMiniProgramType:0,
  206. wxAppId:'wx703c4bd07bbd1695',
  207. wxUniversalLink:"https://yjf.runtzh.com/",
  208. orderFlowNo:res.data.body.orderFlowNo,
  209. businessCstNo:businessCstNo,
  210. platMerCstNo:res.data.body.platMerCstNo
  211. },(res)=>{
  212. // uni.showToast({
  213. // title:'收银台回调:'+JSON.stringify(res),
  214. // icon:'none'
  215. // })
  216. uni.$emit('closePrivilege', {});
  217. that.showPayTips=true;
  218. });
  219. }
  220. else if(res.type=='hf'){
  221. if (uni.getSystemInfoSync().platform == 'android') {
  222. var alipayScheme ='alipays://platformapi/startApp?&saId=10000007&qrcode=' + res.data.qr_code;
  223. }else{
  224. var alipayScheme ='alipay://platformapi/startApp?&saId=10000007&qrcode=' + res.data.qr_code;
  225. }
  226. // 在uni-app中使用plus.runtime.openURL打开URL
  227. plus.runtime.openURL(alipayScheme, function(error) {
  228. });
  229. uni.$emit('closePrivilege', {});
  230. that.showPayTips=true;
  231. }
  232. }
  233. else{
  234. uni.showToast({title:res.msg,icon:'none'})
  235. }
  236. },
  237. rej => {}
  238. );
  239. // #endif
  240. },
  241. doWxPay(){
  242. var that=this;
  243. plus.share.getServices(function(res){
  244. var sweixin = null;
  245. for(var i=0;i<res.length;i++){
  246. var t = res[i];
  247. if(t.id == 'weixin'){
  248. sweixin = t;
  249. }
  250. }
  251. if(sweixin){
  252. let path='/pages_order/userVipOrderPayment?orderId='+that.order.orderId+"&payMethod=app";
  253. console.log('调起小程序 path:'+path);
  254. //唤起微信跳转小程序
  255. sweixin.launchMiniProgram({
  256. id:"gh_7a6a32e5ef61",
  257. path:'/pages_order/userVipOrderPayment?orderId='+that.order.orderId+"&payMethod=app",
  258. type:0 // 微信小程序版本类型,可取值: 0-正式版; 1-测试版; 2-体验版。 默认值为0。
  259. },function(){
  260. console.log("微信唤起成功");
  261. return true;
  262. },function(e){
  263. console.log("微信唤起失败",e);
  264. uni.showToast({
  265. title:'微信唤起失败,请检查是否有微信应用',
  266. icon:'none'
  267. });
  268. return false;
  269. });
  270. that.showPayTips=true;
  271. uni.$emit('closePrivilege', {});
  272. }else{
  273. uni.showToast({
  274. title:'微信唤起失败,请检查是否有微信应用',
  275. icon:'none',
  276. duration:3000
  277. });
  278. return false;
  279. }
  280. },function(res){
  281. console.log(JSON.stringify(res));
  282. });
  283. },
  284. getVipOrderById(){
  285. getVipOrderById(this.order.orderId).then(res => {
  286. this.$refs.popTip.close();
  287. if(res.code==200){
  288. if(res.data.status==1 || res.data.payTime!=null){
  289. // #ifdef APP-PLUS
  290. if(plus.runtime.channel=="baidu"){ //获取渠道标识
  291. let bdCmdType=uni.getStorageSync("bdCmdType");
  292. if(bdCmdType!=null && parseInt(bdCmdType)<=2){
  293. //this.$registerIdCode("orders",2,res.data.payMoney.toString()); //已下单
  294. }
  295. }
  296. // #endif
  297. this.getUserInfo();
  298. uni.showToast({title:"支付成功",icon:'success'});
  299. }else{
  300. uni.showToast({title:"支付失败",icon:'error'});
  301. }
  302. }
  303. setTimeout(()=>{
  304. this.$navBack();
  305. },2000);
  306. },
  307. rej => {}
  308. );
  309. },
  310. openH5(index){
  311. uni.setStorageSync('url',index==0?"https://userapp.his.cdwjyyh.com/web/userAgreement":"https://userapp.his.cdwjyyh.com/web/privacyPolicy");
  312. uni.navigateTo({
  313. url:"/pages/index/h5"
  314. })
  315. },
  316. closeTip(){
  317. this.$refs.popTip.close();
  318. this.getVipOrderById();
  319. },
  320. confirmTip() {
  321. uni.showLoading({title:"请稍侯...",mask:true});
  322. setTimeout(()=>{
  323. uni.hideLoading();
  324. this.getVipOrderById();
  325. uni.$emit('refreshUser', {});
  326. },2000);
  327. // setTimeout(()=>{
  328. // this.$navBack();
  329. // },2000);
  330. },
  331. }
  332. }
  333. </script>
  334. <style>
  335. page {
  336. background-color: #1B1F22;
  337. }
  338. .topBg{
  339. position: absolute;
  340. width:calc(100% - 88rpx) ;
  341. height:168rpx;
  342. z-index: 5;
  343. }
  344. .topItem{
  345. width: 100%;
  346. height: 100%;
  347. z-index: 10;
  348. }
  349. .payBox{
  350. display:flex;
  351. white-space:nowrap;
  352. overflow-x: scroll;
  353. }
  354. .payItem{
  355. position: relative;
  356. display: inline-block;
  357. width: 209rpx;
  358. height: 286rpx;
  359. background-image: url(../../static/image/course/vipBuy/item.png);
  360. background-repeat: no-repeat;
  361. background-size: cover;
  362. background-position: center;
  363. /* background-attachment: fixed; */
  364. margin-right: 12rpx;
  365. }
  366. .ac{
  367. background-image: url(../../static/image/course/vipBuy/item_ac.png);
  368. .price{
  369. color: #C4AA83;
  370. }
  371. }
  372. .san{
  373. position: absolute;
  374. left: calc(50% - 25rpx);
  375. top:-10rpx;
  376. width: 50rpx;
  377. height: 42rpx;
  378. }
  379. .price{
  380. color: #fff;
  381. }
  382. .oriPriceBox{
  383. color: #797A7D;
  384. .oriPrice{
  385. position: relative;
  386. }
  387. .zkline{
  388. position: absolute;
  389. left: 0;
  390. top:18rpx;
  391. height: 1px;
  392. width: 100%;
  393. background-color:#797A7D ;
  394. }
  395. }
  396. .payTypeItem{
  397. background-color:#1B1F22;
  398. border:1px solid #fff;
  399. border-radius: 10rpx;
  400. width: calc(50% - 15rpx);
  401. height: 94rpx;
  402. }
  403. .circle{
  404. border:1px solid #fff;
  405. }
  406. .pt_ac{
  407. border:1px solid #FDD8A1;
  408. }
  409. .payBot{
  410. position: fixed;
  411. bottom: 0;
  412. left: 0;
  413. right: 0;
  414. width: 100%;
  415. height: 170rpx;
  416. }
  417. .tehui{
  418. color: #8B8F92;
  419. font-size: 26rpx;
  420. font-weight: 400;
  421. }
  422. .btnPay{
  423. width: 246rpx;
  424. height: 84rpx;
  425. background: linear-gradient(90deg, #FFE0B2, #F8BA8B);
  426. border-radius: 41rpx;
  427. margin-right: 44rpx;
  428. font-weight: 700;
  429. font-size: 40rpx;
  430. color: #1B1F22;
  431. line-height: 61rpx;
  432. }
  433. .vipC{
  434. color: #FDD8A1;
  435. }
  436. </style>