privilege.nvue 14 KB

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