privilege.nvue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. <template>
  2. <view class="page" @click.stop="handleClick" catchtouchmove="true" :style="{'height':privilegeBoxHei+'px'}" >
  3. <view class="privilegeBox es es-ver es-br-38 es-pt-10 es-pb-30 ">
  4. <view class="es es-fx es-pc es-h-56 es-ml-40 es-mr-20 es-mt-10">
  5. <image class="es-w-74 es-h-40" style="position: absolute;left:55px;top:20rpx" src="/static/image/course/xiangyun.png"></image>
  6. <text class="es-fs-32 es-h-56 es-fw-500 prititle">开通VIP专享以下特权</text>
  7. <image class="es-w-74 es-h-40" style="position: absolute;right:55px;top:20rpx" src="/static/image/course/xiangyun2.png"></image>
  8. <image class="es-w-40 es-h-40" style="position: absolute;right:0;top:0" @tap="closePopup" src="/static/images/close40.png"></image>
  9. </view>
  10. <view class="sec1 es-mt-20 es-ml-48 es-mr-48 ">
  11. <view class="es x-bc es-pl-28 es-pt-12 fl-row" >
  12. <view class="l1">
  13. <view class="x-f fl-row">
  14. <image class="es-w-44 es-h-44" src="/static/image/course/privilege/fozhu.png"></image>
  15. <text class="es-ml-8 es-c-white es-fs-32 es-fw-600">名家讲堂</text>
  16. </view>
  17. <text class="es-fs-30 es-mt-10 es-c-99">畅享10000+VIP视频</text>
  18. </view>
  19. <view class="es">
  20. <image src="/static/image/course/zyx.png" class="es-w-183 es-h-98 es-br-15"></image>
  21. </view>
  22. </view>
  23. </view>
  24. <view class="sec2 es es-fx es-pc es-h-40 es-mt-40 es-ml-48 es-mr-48 fl-row">
  25. <text class="es-fs-30 es-h-56 es-fw-bold" style="color: #FFDAA3;">超多权益待你开启</text>
  26. </view>
  27. <!-- AI舌诊 -->
  28. <view class="primenu-box es es-fx es-pc es-mb-20 es-ml-48 es-mr-48 fl-row" >
  29. <view class="content-inner fl-row">
  30. <view class="item">
  31. <image class="img" src="/static/image/course/privilege/she.png" mode="heightFix"></image>
  32. <text class="label">AI舌诊</text>
  33. </view>
  34. <view class="item">
  35. <image class="img" src="/static/image/course/privilege/tizhi.png" mode="heightFix"></image>
  36. <text class="label">体质检测</text>
  37. </view>
  38. <view class="item" >
  39. <image class="img" src="/static/image/course/privilege/baike.png" mode="heightFix"></image>
  40. <text class="label">养生百科</text>
  41. </view>
  42. <view class="item">
  43. <image class="img" src="/static/image/course/privilege/yishu.png" mode="heightFix"></image>
  44. <text class="label">经典医书</text>
  45. </view>
  46. <view class="item">
  47. <image class="img" src="/static/image/course/privilege/more.png" mode="heightFix"></image>
  48. <text class="label">多设备登陆</text>
  49. </view>
  50. <view class="item">
  51. <image class="img" src="/static/image/course/privilege/ad.png" mode="heightFix"></image>
  52. <text class="label">去除广告</text>
  53. </view>
  54. </view>
  55. </view>
  56. <!-- 开通会员 -->
  57. <view class="vipMethodBox es-ml-48 es-mr-48 es-mt-10 es-pt-10 es-pb-10 es-br-5">
  58. <view v-for="(item, index) in vipMethods" :key="index" @tap="changeVipMethod(index)" class="vipMethodItem es x-bc fl-row">
  59. <view class="x-bc es-ml-14 ">
  60. <text class="es-fs-32 es-fw-500 es-ml-14 color1" :class="index==1?'es-fw-bold color2':''">{{item}}</text>
  61. </view>
  62. <view class="es-w-40 es-h-40 es-mr-14 es-mr-26 circular" v-if="index==1&&vipMethodIdx!=index"></view>
  63. <image class="es-w-40 es-h-40 es-br-ban es-mr-14 es-mr-26" v-else :src="vipMethodIdx==index?'/static/image/course/vipBuy/check.png':'/static/image/course/vipBuy/check_mr.png'"></image>
  64. </view>
  65. </view>
  66. <!-- 支付方式 -->
  67. <view v-if="isShowPayType" class="payTypeBox es-ml-48 es-mr-28 es-mt-40 x-bc fl-row" >
  68. <view v-for="(item, index) in payTypes" :key="index" @tap="changePayType(index)" class="payTypeItem es x-bc " :class="payType==index+1?'pt_ac':''">
  69. <view class="x-bc es-ml-14">
  70. <image class="es-w-59 es-h-52" :src="index==0?'/static/image/course/vipBuy/wx.png':'/static/image/course/vipBuy/zfb.png'"></image>
  71. <text class="es-fs-33 es-c-white es-fw-500 es-ml-14">{{item}}</text>
  72. </view>
  73. <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>
  74. <text v-else class="es-w-40 es-h-40 es-br-ban es-mr-14 circle"></text>
  75. </view>
  76. </view>
  77. <view class="es es-mt-30 es-ml-48 es-mr-48 x-c fl-row">
  78. <view @tap="doBuy()" class="es-h-94 x-c vipCourseBtn vipAc es-br-46" style="width: 310rpx;">
  79. <text class="es-fw-700 es-fs-34" style="color: #1B1F22;">立即购买</text>
  80. </view>
  81. </view>
  82. </view>
  83. </view>
  84. </template>
  85. <script>
  86. import { createCourseOrder,createIntegralOrder,createVipOrder,aliPayment,wxPayment } from '@/api/course'
  87. import { showLoginPage } from '@/utils/login'
  88. export default {
  89. data() {
  90. return {
  91. vipSelIndex:0,
  92. vipMethods:["开通会员","芳华币兑换","0.01元购买"],
  93. vipMethodIdx:1,
  94. isShowPayType:false,
  95. payTypes:["微信支付","支付宝支付"],
  96. payType:1,//微信支付1 支付宝支付2
  97. createType:2,//1直接购买,2芳华币兑换 3开通会员
  98. courseId:null,
  99. videoId:null,
  100. orderId:null,
  101. order:null,
  102. subNVue:null,
  103. sellPrice:0,
  104. privilegeBoxHei:0,
  105. catalogIndex:-1,
  106. integral: 0, // 芳华币
  107. }
  108. },
  109. mounted() {
  110. let that=this;
  111. this.subNVue= uni.getSubNVueById('privilege');
  112. uni.$on('privilege', (data) => {
  113. that.videoId=data.videoId;
  114. that.courseId=data.courseId;
  115. that.sellPrice=data.sellPrice;
  116. that.catalogIndex=data.catalogIndex;
  117. that.vipMethods=["开通会员", data.integral + "芳华币兑换", data.sellPrice+"元购买"];
  118. });
  119. uni.$on('closePrivilege', () => {
  120. that.closePopup();
  121. });
  122. const res = uni.getSystemInfoSync();
  123. this.privilegeBoxHei=uni.upx2px(1150);
  124. //let tempHei=res.windowHeight*0.65;
  125. },
  126. methods: {
  127. changeVip(index){
  128. this.vipSelIndex=index;
  129. if(index==2){
  130. this.showPopPrivilege();
  131. }
  132. },
  133. changeVipMethod(index){
  134. this.vipMethodIdx=index;
  135. const vipMethod=this.vipMethods[index];
  136. this.isShowPayType=false;
  137. if(vipMethod.indexOf('元购买')!=-1){ //直接购买
  138. this.isShowPayType=true;
  139. this.createType=1;
  140. //this.changeFrame(true);
  141. }
  142. if(vipMethod.indexOf('芳华币兑换')!=-1){ //芳华币兑换
  143. this.createType=2;
  144. //this.changeFrame(false);
  145. }
  146. if(vipMethod.indexOf('开通会员')!=-1){ //开通会员
  147. this.createType=3;
  148. //this.changeFrame(false);
  149. }
  150. },
  151. changePayType(index){
  152. this.payType=index+1;
  153. },
  154. doBuy(){
  155. if(this.createType==1){ //直接购买
  156. this.createCourseOrder();
  157. }
  158. else if(this.createType==2){ //芳华币兑换
  159. this.createIntegralOrder();
  160. }
  161. else{ //开通会员
  162. //this.$navTo('./vipBuy');
  163. uni.navigateTo({url: './vipBuy' });
  164. setTimeout(e => {
  165. this.subNVue.hide();
  166. }, 500)
  167. }
  168. },
  169. createCourseOrder(){
  170. if(!this.isLogin()){
  171. uni.showToast({title:"请先登录",icon: 'none'});
  172. return;
  173. }
  174. uni.showLoading({title:""});
  175. let params={"courseId":this.courseId,"createType":this.createType,"videoId":this.videoId,"payType":this.payType};
  176. createCourseOrder(params).then(res => {
  177. uni.hideLoading();
  178. if(res.code==200){
  179. this.order=res.order;
  180. if(this.payType==1){ //微信支付
  181. this.doWxPay();
  182. }else{ //支付宝
  183. this.doAlipay();
  184. }
  185. }else{
  186. uni.showToast({title: res.msg,icon: 'error'});
  187. }
  188. },
  189. rej => {}
  190. );
  191. },
  192. createIntegralOrder(){
  193. if(!this.isLogin()){
  194. uni.showToast({title:"请先登录",icon: 'none'});
  195. return;
  196. }
  197. uni.showLoading({title:""});
  198. let params={"courseId":this.courseId,"videoId":this.videoId};
  199. createIntegralOrder(params).then(res => {
  200. uni.hideLoading();
  201. if(res.code==200){
  202. uni.showToast({title: "兑换成功",icon: 'success'});
  203. uni.$emit("refreshCatalog",this.catalogIndex);
  204. this.closePopup();
  205. }else{
  206. uni.showToast({title: res.msg,icon: 'error'});
  207. }
  208. },
  209. rej => {}
  210. );
  211. },
  212. doAlipay(){
  213. let that=this;
  214. var data = {orderId:this.order.orderId};
  215. // #ifdef APP-PLUS
  216. const tzCashier=uni.requireNativePlugin("TZBank-Cashier");
  217. uni.showLoading();
  218. aliPayment(data).then(res => {
  219. uni.hideLoading();
  220. if(res.code==200){
  221. if(res.type=="tz"){
  222. //console.log("qxj res:"+JSON.stringify(res));
  223. //console.log("qxj orderFlowNo:"+res.data.body.orderFlowNo+" businessCstNo:"+res.data.body.orderNo+" platMerCstNo:"+res.data.body.platMerCstNo);
  224. that.closePopup();
  225. const match = res.data.body.url.match(/[\?&]businessCstNo=([^&]+)/);
  226. const businessCstNo = match ? match[1] : null;
  227. console.log("qxj tzCashier:"+tzCashier+" businessCstNo:"+businessCstNo);
  228. tzCashier.pay({
  229. env:0,
  230. wxMiniProgramType:0,
  231. wxAppId:'wx703c4bd07bbd1695',
  232. wxUniversalLink:"https://yjf.runtzh.com/",
  233. orderFlowNo:res.data.body.orderFlowNo,
  234. businessCstNo:businessCstNo,
  235. platMerCstNo:res.data.body.platMerCstNo
  236. },(res)=>{
  237. uni.$emit('showPayTips', {"courseOrderId":that.order.orderId});
  238. });
  239. }
  240. else if(res.type=='hf'){
  241. //this.$refs.popTip.open()
  242. if(res.data.qr_code==null){
  243. uni.showToast({title:res.data.bank_message,icon:'none'});
  244. return;
  245. }
  246. this.closePopup();
  247. if (uni.getSystemInfoSync().platform == 'android') {
  248. var alipayScheme ='alipays://platformapi/startApp?&saId=10000007&qrcode=' + res.data.qr_code;
  249. }else{
  250. var alipayScheme ='alipay://platformapi/startApp?&saId=10000007&qrcode=' + res.data.qr_code;
  251. }
  252. // 在uni-app中使用plus.runtime.openURL打开URL
  253. plus.runtime.openURL(alipayScheme, function(error) {
  254. console.log("qxj alipayScheme error:"+error);
  255. if (error) {
  256. uni.showToast({title:error.message,icon:'error' });
  257. }
  258. });
  259. uni.$emit('showPayTips', {"courseOrderId":this.order.orderId});
  260. }
  261. }
  262. else{
  263. uni.showToast({title:res.msg,icon:'none'})
  264. }
  265. },
  266. rej => {}
  267. );
  268. // #endif
  269. },
  270. doWxPay(){
  271. var that=this;
  272. setTimeout(()=>{
  273. this.closePopup();
  274. },5000);
  275. plus.share.getServices(function(res){
  276. var sweixin = null;
  277. for(var i=0;i<res.length;i++){
  278. var t = res[i];
  279. if(t.id == 'weixin'){
  280. sweixin = t;
  281. }
  282. }
  283. if(sweixin){
  284. console.log('调起小程序');
  285. uni.$emit('showPayTips', { "courseOrderId":that.order.orderId });
  286. //唤起微信跳转小程序
  287. sweixin.launchMiniProgram({
  288. id:"gh_7a6a32e5ef61",
  289. path:'/pages_order/courseOrderPayment?orderId='+that.order.orderId+"&payMethod=app",
  290. type:0 // 微信小程序版本类型,可取值: 0-正式版; 1-测试版; 2-体验版。 默认值为0。
  291. },function(){
  292. console.log("微信唤起成功");
  293. return true;
  294. },function(e){
  295. console.log("微信唤起失败",e);
  296. uni.showToast({
  297. title:'微信唤起失败,请检查是否有微信应用',
  298. icon:'none'
  299. });
  300. return false;
  301. });
  302. }else{
  303. uni.showToast({
  304. title:'微信唤起失败,请检查是否安装微信应用',
  305. icon:'none',
  306. duration:3000
  307. })
  308. return false;
  309. }
  310. },function(res){
  311. console.log(JSON.stringify(res));
  312. });
  313. },
  314. handleClick() {
  315. // 阻止事件冒泡
  316. },
  317. changeFrame(isCheck){
  318. console.log("qxj changeFrame");
  319. let pHeight=isCheck?1320:1020;
  320. const subNVue = uni.getSubNVueById('privilege');
  321. subNVue.setStyle({
  322. "bottom": "0",
  323. "left": "0",
  324. "width": "100%",
  325. "height" : pHeight+'upx' ,
  326. });
  327. },
  328. closePopup() {
  329. const subNVue = uni.getSubNVueById('privilege');
  330. subNVue.hide('slide-out-bottom');
  331. },
  332. isLogin() {
  333. let obj=uni.getStorageSync("AppToken");
  334. return !!obj;
  335. },
  336. },
  337. destroyed() {
  338. console.log("qxj privilege destroyed----")
  339. // 注销全局配置监听
  340. uni.$off("privilege");
  341. uni.$off("closePrivilege");
  342. }
  343. }
  344. </script>
  345. <style>
  346. .fl-row{
  347. display: flex;
  348. flex-direction: row;
  349. }
  350. .page{
  351. background-color:#171a1d;
  352. border-radius: 20rpx;
  353. }
  354. .privilegeBox{
  355. /* background-color:#171a1d; */
  356. box-sizing: border-box;
  357. }
  358. .prititle{
  359. color: #ffdaa3 !important;
  360. text-align: center;
  361. margin-top: 20rpx;
  362. }
  363. .primenu-box {
  364. display: flex;
  365. flex: 1;
  366. justify-content: center;
  367. align-items: center;
  368. }
  369. .content-inner {
  370. display: flex;
  371. flex: 1;
  372. flex-wrap: wrap;
  373. justify-content: space-between;
  374. }
  375. .content-inner .item{
  376. width: 100px;
  377. height: 75px;
  378. display: flex;
  379. flex-direction: column;
  380. align-items: center;
  381. justify-content: center;
  382. margin-top: 26rpx;
  383. }
  384. .content-inner .item .img{
  385. width: 84rpx;
  386. height: 84rpx;
  387. margin-bottom: 8rpx;
  388. }
  389. .content-inner .item .label{
  390. font-size: 32rpx;
  391. color: #83878A;
  392. }
  393. .vipMethodBox{
  394. background:#2a2f32;
  395. display: flex;
  396. flex: 1;
  397. }
  398. .vipMethodItem{
  399. border-radius: 10rpx;
  400. height: 70rpx;
  401. color: #FDD8A1;
  402. }
  403. .payTypeBox{
  404. display: flex;
  405. flex: 1;
  406. }
  407. .payTypeItem{
  408. border:1px solid #fff;
  409. border-radius: 10rpx;
  410. display: flex;
  411. flex: 1;
  412. height: 94rpx;
  413. margin-right: 20rpx;
  414. }
  415. .circle{
  416. border:1px solid #FDD8A1;
  417. }
  418. .pt_ac{
  419. border:1px solid #FDD8A1;
  420. }
  421. .color1{
  422. color: #FFDAA3;
  423. }
  424. .color2 {
  425. color: #fff;
  426. }
  427. .circular {
  428. border-radius: 50%;
  429. border: 1px solid #fff;
  430. }
  431. .slider-box{
  432. flex:1
  433. }
  434. .vipCourseBtn{
  435. background: #1B1F22;
  436. border-radius: 46rpx;
  437. border: 1px solid #FFDAA3;
  438. color: #FFDAA3;
  439. width: calc(33.33333% - 46.6666rpx);
  440. }
  441. .vipAc{
  442. background: linear-gradient(90deg, #FFE0B2, #F8BA8B);
  443. border-radius: 46rpx;
  444. border: 1px solid #FFDAA3;
  445. color: #1B1F22;
  446. }
  447. </style>