becomeVip.vue 5.4 KB

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