becomeVip.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <view class="centerV hb base-bg-f">
  3. <view class="w100 centerV" v-if="isH5vip!=true">
  4. <image src="@/static/image/becomevip.png" class="h193 w193 mb40"></image>
  5. <view class="bold">是否申请成为会员</view>
  6. <view class="justify-center w100 mt40 mb40">
  7. <view class="quxiao">取消</view>
  8. <view class="sure" @click="becomeVipfun">确定</view>
  9. </view>
  10. </view>
  11. <u-popup :show="showvip" @close="close" @open="open"
  12. mode='center' round='20' style="flex: 0;" >
  13. <view class="VIPvie w600 h600 column justify-center align-center">
  14. <image src="../../../static/manergevip/becomeTrue.png" class="h400 w400"></image>
  15. <view class="bold fs50 center mt80">{{tips}}!</view>
  16. </view>
  17. </u-popup>
  18. </view>
  19. </template>
  20. <script>
  21. import {
  22. becomeVip
  23. } from "@/api/courseManage.js"
  24. import {
  25. loginByMp
  26. } from '@/api/user'
  27. const isWechat = () => {
  28. return String(navigator.userAgent.toLowerCase().match(/MicroMessenger/i)) === "micromessenger";
  29. }
  30. export default {
  31. data() {
  32. return {
  33. userId: '',
  34. companyId: '',
  35. companyUserId: '',
  36. code: '',
  37. showvip: false,
  38. user:'',
  39. tips:'',
  40. isH5vip:false,
  41. becomeuser:{}
  42. }
  43. },
  44. onLoad(option) {
  45. if (option && option.user) {
  46. // console.log('分享链接进入',option)
  47. this.becomeuser = JSON.parse(option.user)
  48. this.companyId = this.becomeuser.companyId
  49. this.companyUserId = this.becomeuser.companyUserId
  50. // console.log('分享链接进入',this.becomeuser)
  51. // if(uni.getStorageSync("isH5vip")==true){
  52. // this.becomeVipfun()
  53. // }else{
  54. // setTimeout(() => {
  55. // this.getWechatCode()
  56. // this.userId=this.user.userId
  57. // console.log(this.userId)
  58. // }, 200)
  59. // }
  60. } else {
  61. this.companyId = option.companyId
  62. this.userId = option.userId
  63. this.companyUserId = option.companyUserId
  64. this.code = option.code
  65. }
  66. },
  67. onShow() {
  68. this.isH5vip = uni.getStorageSync("isH5vip")
  69. console.log(this.isH5vip)
  70. if (this.becomeuser&&JSON.stringify(this.becomeuser)!='{}'){
  71. if(uni.getStorageSync("isH5vip")==true){
  72. this.becomeVipfun()
  73. }else{
  74. setTimeout(() => {
  75. this.getWechatCode()
  76. this.userId=this.user.userId
  77. console.log(this.userId)
  78. }, 200)
  79. }
  80. }
  81. },
  82. methods: {
  83. close() {},
  84. open() {},
  85. becomeVipfun() {
  86. uni.showLoading({
  87. title: '正在加载中...'
  88. })
  89. if (this.becomeuser!=''){
  90. this.user = uni.getStorageSync("userInfo") ? JSON.parse(uni.getStorageSync("userInfo")) : {}
  91. this.userId=this.user.userId
  92. }
  93. const param = {
  94. companyId: this.companyId,
  95. userId: this.userId,
  96. companyUserId: this.companyUserId,
  97. }
  98. console.log(param)
  99. becomeVip(param).then(res => {
  100. if (res.code == 200) {
  101. console.log(res)
  102. // if(this.becomeuser==''){
  103. // setTimeout(()=>{
  104. this.showvip = true
  105. this.tips=res.msg
  106. // },1000)
  107. // }
  108. } else {
  109. uni.showToast({
  110. title: res.msg,
  111. icon: 'none'
  112. });
  113. }
  114. })
  115. },
  116. // 获取code
  117. getWechatCode() {
  118. if (isWechat) {
  119. let appid = "wx93ce67750e3cfba3"; //微信APPid
  120. let code = this.getUrlCode().code; //是否存在code
  121. let local = window.location.href;
  122. if (code == null || code === "") {
  123. let urlPaths = local.split("/courseh5");
  124. uni.setStorageSync('beforLoginPage', urlPaths[1]);
  125. window.location.href =
  126. "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
  127. appid +
  128. "&redirect_uri=" +
  129. encodeURIComponent(local) +
  130. "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
  131. } else {
  132. this.code = code;
  133. this.loginByMp()
  134. }
  135. }
  136. },
  137. getUrlCode() {
  138. // 截取url中的code方法
  139. var url = location.search;
  140. var theRequest = new Object();
  141. if (url.indexOf("?") != -1) {
  142. var str = url.substr(1);
  143. var strs = str.split("&");
  144. for (var i = 0; i < strs.length; i++) {
  145. theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
  146. }
  147. }
  148. return theRequest;
  149. },
  150. loginByMp() {
  151. if (this.code == null) {
  152. return;
  153. }
  154. uni.showLoading({
  155. title: "处理中..."
  156. });
  157. // let that = this;
  158. var data = {
  159. code: this.code,
  160. companyUserId:this.companyUserId
  161. }
  162. loginByMp(data).then(res => {
  163. uni.hideLoading();
  164. if (res.code == 200) {
  165. // 登录后存token和用户信息
  166. uni.setStorageSync('UserAppToken', res.token);
  167. this.isH5vip = uni.setStorageSync("isH5vip",res.isH5Vip);
  168. uni.setStorageSync('userInfo', JSON.stringify(res.user));
  169. let beforLoginUrl = uni.getStorageSync('beforLoginPage');
  170. // console.log("beforLoginUrl:"+beforLoginUrl);
  171. console.log(`登录成功后跳转${beforLoginUrl}`);
  172. uni.reLaunch({
  173. url: beforLoginUrl
  174. });
  175. } else {
  176. uni.showToast({
  177. title: res.msg,
  178. icon: 'none'
  179. });
  180. }
  181. },
  182. err => {}
  183. );
  184. },
  185. }
  186. }
  187. </script>
  188. <style lang="scss" scoped>
  189. .VIPvie {
  190. width: 580rpx;
  191. background: linear-gradient(to bottom, #c3dbfe 2%, #f6fbfe 50%);
  192. border-radius: 20rpx;
  193. height: 600rpx;
  194. position: relative;
  195. image {
  196. position: absolute;
  197. top: -120rpx;
  198. left: 16%;
  199. }
  200. }
  201. .quxiao {
  202. width: 30%;
  203. height: 72rpx;
  204. line-height: 72rpx;
  205. text-align: center;
  206. border: 2rpx solid #ccc;
  207. border-radius: 8rpx;
  208. color: #666;
  209. margin-right: 10rpx;
  210. }
  211. .sure {
  212. width: 30%;
  213. background-color: #1777ff;
  214. height: 72rpx;
  215. line-height: 72rpx;
  216. text-align: center;
  217. border-radius: 8rpx;
  218. color: #fff;
  219. margin-left: 10rpx;
  220. }
  221. </style>