becomeVIP.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. <template>
  2. <view class="content hb column justify-center align-center bgf">
  3. <image :src="imgPath+'/app/image/becomevip.png'" mode="widthFix"></image>
  4. <view class="justify-start align-center fs24 base-color-9" v-if="userInfo.userId">
  5. <view>{{nameuser}}#</view>
  6. <view>{{userInfo.userId}}</view>
  7. </view>
  8. <view class="bolds">成为会员,享受更多权益</view>
  9. <!--#ifdef H5-->
  10. <view class="sure" @click="registerCourse">{{isVip==1?'您已成为会员':viptext}}</view>
  11. <!--#endif-->
  12. <!--#ifdef MP-WEIXIN-->
  13. <view class="base-bg-orange colorf ptb20 plr40 radius60"
  14. v-if="(userinfos==null||userinfos=='')&&imgname=='乐氏本源'" @click="nato()">授权用户信息</view>
  15. <view class="btns" v-else>
  16. <button class="author-btn" @click="handleAgree()">{{viptext}}</button>
  17. </view>
  18. <!--#endif-->
  19. <!--#ifdef MP-WEIXIN-->
  20. <u-popup :show="userlogo" mode="bottom" round='12'>
  21. <view class="userlogo column">
  22. <view class="mtb30 justify-start align-center ml20">
  23. <u-avatar :src="imgPath+'/app/image/logo.png'" size="50"></u-avatar>
  24. <view class="bold mlr20">{{imgname}}</view>
  25. <view>申请</view>
  26. </view>
  27. <view class="bold fs36 ml20">授权你的昵称头像信息</view>
  28. <view class="mtb20 justify-between align-center plr20">
  29. <view class="justify-start align-center">
  30. <view class="boxweixin" :class="userinfos.nickname==''?'boxnosel':'boxsel'">
  31. <view v-if="userinfos.nickname">√</view>
  32. </view>
  33. <view class="ml20">
  34. <view class="base-color-3 bold">第一步</view>
  35. <view class="fs24 base-color-9">请点击授权微信昵称</view>
  36. </view>
  37. </view>
  38. <view class="button-container">
  39. <input
  40. type="nickname"
  41. class="hidden-input"
  42. @blur="onNickNameInput"
  43. @input="onNickNameInput"
  44. />
  45. <button class="custom-button" :class="nameuser==''?'subname':'subavt'">{{nameuser?"已授权":'允许授权'}}</button>
  46. </view>
  47. </view>
  48. <view class="mtb20 justify-between align-center plr20 mt40">
  49. <view class="justify-start align-center">
  50. <view class="boxweixin" :class="userinfos.nickname==''?'boxnosel':'boxsel'">
  51. <view v-if="userinfos.avatar">√</view>
  52. </view>
  53. <view class="ml20">
  54. <view class="base-color-3 bold">第二步</view>
  55. <view class="fs24 base-color-9">请点击授权微信头像</view>
  56. </view>
  57. </view>
  58. <view class="button-container">
  59. <button open-type="chooseAvatar" @chooseavatar="onChooseAvatar" class="hidden-input"
  60. v-if="nameuser">
  61. 允许授权
  62. </button>
  63. <button class="custom-button sub" @click="shouquan" v-if="nameuser==''">允许授权</button>
  64. <button class="custom-button " :class="avataruser==''?'subname':'subavt'"
  65. v-else>{{avataruser?"已授权":'允许授权'}}</button>
  66. </view>
  67. </view>
  68. <view class="submitname" @click="confimrname" :class="nameuser&&avataruser?'subact':'sub'">确定</view>
  69. </view>
  70. </u-popup>
  71. <!--#endif-->
  72. <!-- <view class="footer-tips">重庆云联融智提供技术支持</view> -->
  73. </view>
  74. </template>
  75. <script>
  76. import { loginByMp,loginByMiniApp,checkUserInfo,editUser} from '@/api/user'
  77. import {handleFsUserWx,registerCourses} from '@/api/courseLook.js'
  78. export default {
  79. data() {
  80. return {
  81. isVip: 0,
  82. isWechat: false,
  83. isLogin: false,
  84. companyid:'',
  85. companyUserId:'',
  86. userInfo:{},
  87. tagIds:[],
  88. isbecomevip:0,
  89. viptext:'申请成为会员',
  90. userlogo:false,
  91. userinfos:{
  92. nickname:'',
  93. avatar:""
  94. },
  95. headImg:'',
  96. authType:0,//0微信登录 1手机号登录
  97. userdisabled:false,
  98. projectId:'',
  99. H5course:{}
  100. }
  101. },
  102. computed: {
  103. imgPath() {
  104. return this.$store.state.imgpath
  105. },
  106. imgname() {
  107. return this.$store.state.logoname
  108. },
  109. appid() {
  110. return this.$store.state.appid
  111. },
  112. nameuser() {
  113. return this.userinfos.nickname
  114. },
  115. avataruser() {
  116. return this.userinfos.avatar
  117. },
  118. },
  119. async onLoad(option) {
  120. uni.$on('usercode',(data)=>{
  121. console.log('huoqu ',data)
  122. this.goLogin(data)
  123. })
  124. uni.$on('vipMsg',(data)=>{
  125. console.log('vipMsg ',data)
  126. this.viptext=data
  127. })
  128. // let path = 'https://userapp.fbylive.com'//福本源
  129. // let path = 'https://userapp.zkhj6.com'//中康
  130. // let path = 'https://company.h5.test.ylrztop.com/api'//云融融智
  131. // let path = 'https://userapp.ashyisheng.com'//蜂巢快药
  132. let path = 'https://userapp.whhm.ylrzcloud.com/prod-api'//惠名大药房
  133. // let path = 'https://userapp.xdtongshuntang.top'//同顺堂
  134. // let path = 'https://userapp.liangmiaoedu.com'//良苗
  135. // let path = 'https://usercourse.beliyostore.com'//倍力优
  136. // let path = 'https://userapp.bainian1000y.cn/prod-api'//百年康城
  137. // let path = 'https://userapp.drkzyy.cn/prod-api'//青岛市德瑞康
  138. // let path = 'https://userappkyt.ylrzcloud.com'//宽益堂
  139. // let path = 'https://userapp.bjyjbao.com'//医建宝
  140. uni.setStorageSync('requestPath',path)
  141. if(uni.getStorageSync('userInfo')&&uni.getStorageSync('userInfo')!='{}') {
  142. this.userInfo = uni.getStorageSync('userInfo')
  143. } else {
  144. this.userInfo = {}
  145. }
  146. // this.userInfo=JSON.parse(uni.getStorageSync('userInfo')) || {};
  147. //#ifdef MP-WEIXIN
  148. let obj=uni.getStorageSync('TOKEN_WEXIN');
  149. //#endif
  150. // #ifdef H5
  151. let obj=uni.getStorageSync('TOKEN_KEY');
  152. // #endif
  153. // let obj=uni.getStorageSync('AppToken');
  154. this.isLogin = !!obj;
  155. let becomeVip=''
  156. if(!option.becomeVip){
  157. const keys = decodeURIComponent(Object.keys(option)[0]);
  158. becomeVip=JSON.parse(keys.split('becomeVip=')[1])
  159. console.log(becomeVip)
  160. }else{
  161. becomeVip = option.becomeVip ? JSON.parse(option.becomeVip) : {}
  162. }
  163. console.log(becomeVip)
  164. this.isLogin = !!obj;
  165. this.companyid = becomeVip.companyId || ''
  166. this.companyUserId=becomeVip.companyUserId || 0
  167. this.projectId=becomeVip.projectId
  168. this.H5course.companyId=becomeVip.companyId
  169. this.H5course.companyUserId=becomeVip.companyUserId
  170. this.H5course.projectId=becomeVip.projectId
  171. uni.setStorageSync('H5course',this.H5course)
  172. console.log(this.H5course)
  173. //#ifdef MP-WEIXIN
  174. // if(this.$store.state.logoname!=='乐氏本源'&&!uni.getStorageSync('userInfos')){
  175. // this.userlogo=true
  176. // }
  177. if(!uni.getStorageSync('userInfos')&&this.$store.state.logoname=='乐氏本源'){
  178. uni.navigateTo({
  179. url:'/pages_course/webview'
  180. })
  181. return
  182. }
  183. //#endif
  184. if(becomeVip.tagids==null||becomeVip.tagids==''){
  185. this.tagIds=[]
  186. }else{
  187. this.tagIds=becomeVip.tagids
  188. const arr =this.tagIds.split(",")
  189. .map(item => parseInt(item.trim(), 10))
  190. .filter(num => !isNaN(num)); // 过滤无效转换
  191. this.tagIds =arr
  192. // console.log(this.tagIds);
  193. }
  194. // this.isWechat = String(navigator.userAgent.toLowerCase().match(/MicroMessenger/i)) === "micromessenger"
  195. this.code = option.code
  196. // #ifdef H5
  197. if(this.code&&!this.isLogin) {
  198. this.loginByMp()
  199. }
  200. // #endif
  201. },
  202. onShow() {
  203. if(uni.getStorageSync('userInfo')&&uni.getStorageSync('userInfo')!='{}') {
  204. this.userInfo = uni.getStorageSync('userInfo')
  205. } else {
  206. this.userInfo = {}
  207. }
  208. this.userinfos=uni.getStorageSync('userinfos')
  209. let obj=uni.getStorageSync('TOKEN_WEXIN');
  210. console.log(uni.getStorageSync('userinfos'))
  211. this.isLogin = !!obj;
  212. if(this.isLogin&&this.isVip!=1) {
  213. this.registerCourse()
  214. }
  215. if(!this.userInfo.userId){
  216. this.goLogin()
  217. }
  218. },
  219. methods: {
  220. async goLogin(data) {
  221. console.log('huoqu111',data)
  222. if(data){
  223. console.log('huoqu1222',data)
  224. uni.showLoading({
  225. title: '加载中'
  226. })
  227. uni.login({
  228. provider: "weixin",
  229. success: async loginRes => {
  230. console.log(loginRes)
  231. let code = loginRes.code // 获取开发code
  232. handleFsUserWx({
  233. code: code,
  234. appId:this.appid,
  235. userId:data.userId
  236. })
  237. .then( res => {
  238. if(res.code==200){
  239. console.log(res)
  240. uni.hideLoading();
  241. uni.showToast({
  242. icon:'none',
  243. title: "登录成功",
  244. });
  245. this.userinfos=uni.getStorageSync('userinfos')
  246. uni.getStorageSync('TOKEN_WEXIN');
  247. this.userInfo=uni.getStorageSync('userInfo');
  248. this.isLogin = true
  249. setTimeout(()=>{
  250. this.registerCourse()
  251. },200)
  252. }else if(res.code==406){
  253. uni.hideLoading();
  254. uni.showToast({
  255. icon:'none',
  256. title: '该用户已成为其他销售会员',
  257. });
  258. }else{
  259. uni.hideLoading();
  260. uni.showToast({
  261. icon:'none',
  262. title: res.msg,
  263. });
  264. }
  265. })
  266. },
  267. })
  268. }else{
  269. await this.$store.dispatch('getWebviewUrl');
  270. uni.navigateTo({
  271. url:'/pages_course/webview?H5course='+uni.getStorageSync('H5course')
  272. })
  273. }
  274. },
  275. shouquan(){
  276. if(this.userinfos.nickname==''){
  277. uni.showToast({
  278. icon:'none',
  279. title: "请先授权微信昵称",
  280. });
  281. }
  282. },
  283. confimrname(){
  284. if(this.userinfos.nickname==''){
  285. uni.showToast({
  286. icon:'none',
  287. title: "请授权微信昵称",
  288. });
  289. return
  290. }
  291. if(this.userinfos.avatar==''){
  292. uni.showToast({
  293. icon:'none',
  294. title: "请授权微信头像",
  295. });
  296. return
  297. }
  298. uni.setStorageSync('userinfos',this.userinfos)
  299. this.editUserA()
  300. this.userlogo=false
  301. },
  302. onChooseAvatar(e){
  303. this.userinfos.avatar=e.detail.avatarUrl
  304. console.log(e.detail.avatarUrl)
  305. uni.uploadFile({
  306. url: uni.getStorageSync('requestPath')+'/app/common/uploadOSS', //仅为示例,非真实的接口地址
  307. filePath: e.detail.avatarUrl,
  308. name: 'file',
  309. formData: {
  310. 'user': 'test' // 上传附带参数
  311. },
  312. success: (uploadFileRes) => {
  313. console.log(uploadFileRes)
  314. // 根据接口具体返回格式 赋值具体对应url
  315. var data=JSON.parse(uploadFileRes.data)
  316. this.headImg=uni.getStorageSync('requestPath')+data.fileName
  317. this.userinfos.avatar=data.url
  318. }
  319. });
  320. },
  321. onNickNameInput(e){
  322. console.log(e)
  323. this.userinfos.nickname=e.detail.value
  324. },
  325. async nato(){
  326. await this.$store.dispatch('getWebviewUrl');
  327. uni.navigateTo({
  328. url:'/pages_course/webview'
  329. })
  330. },
  331. handleAgree(){
  332. console.log(144443)
  333. if(this.isVip==1){
  334. uni.showToast({
  335. title: '您已成为会员!',
  336. icon: 'none',
  337. duration: 2000,
  338. })
  339. }else{
  340. this.goLogin()
  341. uni.showToast({
  342. title: this.viptext,
  343. icon: 'none',
  344. duration: 2000,
  345. })
  346. }
  347. },
  348. getWechatCode() {
  349. if (this.isWechat) {
  350. // let appid = "wx961fadab9bcb792b"; //微信APPid(福本源)
  351. // let appid = "wx93ce67750e3cfba3"; //微信APPid(云联融智)
  352. // let appid = "wxea1da2b708ab3c2f"; //微信APPid(蜂巢快药)
  353. // let appid = "wx3de90a39feb8107a"; //微信APPid(中康看课)
  354. // let appid = "wxec49f9d783abf233"; //微信APPid(惠名大药房)
  355. // let appid = "wx5a0f7e1932e2689e"; //微信APPid(同顺堂)
  356. // let appid = "wxe0b82a0018449a62"; //微信APPid(良苗)
  357. // let appid = "wx568ea6b70350c585"; //微信APPid(倍力优)
  358. let appid = "wx0d021524695f1943"; //微信APPid(百年康城)
  359. // let appid = "wx090c5f399d65456e"; //微信APPid(青岛市德瑞康)
  360. // let appid = "wx52298c1781d5cc99"; //微信APPid(金慷建)
  361. let code = this.getUrlCode().code; //是否存在code
  362. let local = window.location.href;
  363. if (code == null || code === "") {
  364. let urlPaths = local.split("/registerCourse");
  365. uni.setStorageSync('beforLoginPage', urlPaths[1]);
  366. //不存在就打开上面的地址进行授权
  367. window.location.href =
  368. "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
  369. appid +
  370. "&redirect_uri=" +
  371. encodeURIComponent(local) +
  372. "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
  373. } else {
  374. this.code = code;
  375. this.loginByMp()
  376. }
  377. }else{
  378. uni.showToast({
  379. title: '请在微信浏览器中打开',
  380. icon:'error'
  381. })
  382. }
  383. },
  384. getUrlCode() {
  385. // 截取url中的code方法
  386. var url = location.search;
  387. var theRequest = new Object();
  388. if (url.indexOf("?") != -1) {
  389. var str = url.substr(1);
  390. var strs = str.split("&");
  391. for (var i = 0; i < strs.length; i++) {
  392. theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
  393. }
  394. }
  395. return theRequest;
  396. },
  397. loginByMp() {
  398. if (this.code == null) {
  399. return;
  400. }
  401. uni.showLoading({
  402. title: "处理中..."
  403. });
  404. loginByMp({code:this.code}).then(res => {
  405. uni.hideLoading();
  406. if (res.code == 200) {
  407. uni.setStorageSync('TOKEN_KEY', res.token);
  408. uni.setStorageSync('userInfo', JSON.stringify(res.user));
  409. this.userInfo= res.user
  410. let beforLoginUrl = uni.getStorageSync('beforLoginPage');
  411. this.isLogin = true
  412. this.registerCourse()
  413. } else {
  414. uni.showToast({
  415. title: res.msg,
  416. icon: 'none'
  417. });
  418. }
  419. },
  420. err => {}
  421. );
  422. },
  423. // 成为会员
  424. registerCourse() {
  425. console.log(123333)
  426. this.isVip = 0
  427. // 确保从本地存储重新获取最新数据
  428. // if(uni.getStorageSync('userInfo')){
  429. // this.userInfo=JSON.parse(uni.getStorageSync('userInfo'));
  430. // }
  431. // if (!this.userInfo.userId) {
  432. // // 空值检查
  433. // uni.showToast({ title: '用户未登录或信息不完整', icon: 'none' });
  434. // return;
  435. // }
  436. if(this.tagIds==null){
  437. this.tagIds=""
  438. }
  439. // console.log(this.tagIds)
  440. const data={
  441. userId:this.userInfo.userId,
  442. companyUserId:this.companyUserId,
  443. companyId:this.companyid,
  444. tagIds:this.tagIds,
  445. projectId:this.projectId
  446. }
  447. if(this.isLogin) {
  448. registerCourses(data).then(res=>{
  449. if(res.code == 200) {
  450. this.isVip = 1
  451. this.isbecomevip=1
  452. this.viptext='您已成为会员'
  453. uni.showToast({
  454. title: '注册成功',
  455. icon:'none'
  456. })
  457. } else {
  458. this.isbecomevip=1
  459. // console.log(this.isbecomevip)
  460. this.viptext=res.msg
  461. uni.showToast({
  462. icon:'none',
  463. title: res.msg
  464. })
  465. }
  466. })
  467. } else {
  468. // #ifdef H5
  469. this.getWechatCode()
  470. // #endif
  471. }
  472. }
  473. }
  474. }
  475. </script>
  476. <style lang="scss" scoped>
  477. page{
  478. background-color: #fff;
  479. }
  480. .subname{
  481. background-color: #00aa00;
  482. color: #fff;
  483. }
  484. .subavt{
  485. background-color: #fff;
  486. border: 2rpx #0a0 solid;
  487. color: #00aa00;
  488. }
  489. .boxweixin{
  490. width: 44rpx;
  491. height: 44rpx;
  492. border-radius: 50%;
  493. text-align: center;
  494. line-height: 34rpx;
  495. color: #0a0;
  496. }
  497. .boxnosel{
  498. border: #757575 4rpx solid;
  499. }
  500. .boxsel{
  501. border: #0a0 4rpx solid;
  502. }
  503. .button-container {
  504. position: relative;
  505. width: 240rpx;
  506. }
  507. .hidden-input {
  508. position: absolute;
  509. top: 0;
  510. left: 0;
  511. width: 100%;
  512. height: 100%;
  513. opacity: 0;
  514. z-index: 2;
  515. }
  516. .custom-button {
  517. position: relative;
  518. z-index: 1;
  519. /* 其他样式 */
  520. width:100%;
  521. margin: 0 auto;
  522. height: 80rpx;
  523. line-height: 60rpx;
  524. font-size: 28rpx;
  525. padding: 10rpx 20rpx;
  526. }
  527. .submitname{
  528. width: 90%;
  529. margin: 0 auto;
  530. text-align: center;
  531. padding: 30rpx;
  532. margin-top: 40rpx;
  533. }
  534. .sub{
  535. background-color: #f0f0f0;
  536. color: #0a0;
  537. }
  538. .subact{
  539. background-color: #0a0;
  540. color: #fff;
  541. }
  542. .userlogo{
  543. height: 760rpx;
  544. }
  545. .getlogo{
  546. width:240rpx;
  547. background-color: #fff;
  548. // padding: 10rpx 20rpx;
  549. }
  550. ::v-deep .u-popup {
  551. flex: 0 !important;
  552. }
  553. // .submitname{
  554. // width: 60%;
  555. // background-color: #05a8ee;
  556. // color: #fff;
  557. // margin: 0 auto;
  558. // border-radius: 80rpx;
  559. // text-align: center;
  560. // padding: 20rpx;
  561. // margin-top: 40rpx;
  562. // }
  563. .userlogo{
  564. height: 760rpx;
  565. }
  566. .getlogo{
  567. width:calc(60% - 40rpx);
  568. margin: 0 auto;
  569. background-color: #fff;
  570. padding: 10rpx 20rpx;
  571. image{
  572. width: 80rpx !important;
  573. height: 80rpx !important;
  574. }
  575. }
  576. .footer-tips {
  577. // margin-top: 14rpx;
  578. position: fixed;
  579. width: 100%;
  580. bottom: 44rpx;
  581. text-align: center;
  582. font-family: PingFang SC,PingFang SC;
  583. font-weight: 500;
  584. font-size: 12px;
  585. color: #bbb;
  586. transform: scale(0.8);
  587. }
  588. .content {
  589. image {
  590. width: 300rpx;
  591. height: 300rpx;
  592. }
  593. }
  594. .bolds {
  595. color: #999;
  596. font-size: 16px;
  597. height: auto;
  598. line-height: inherit;
  599. margin-bottom: 0;
  600. width: 304px;
  601. word-break: break-all;
  602. text-align: center;
  603. margin: 50rpx 0 100rpx 0;
  604. }
  605. .sure {
  606. width: 500rpx;
  607. background-color: #1777ff;
  608. line-height: 88rpx;
  609. text-align: center;
  610. border-radius: 8rpx;
  611. color: #fff;
  612. }
  613. .btns{
  614. position: relative;
  615. width: 630rpx;
  616. height: 80rpx;
  617. .author-btn{
  618. z-index:100;
  619. position: absolute;
  620. width: 630rpx;
  621. height: 80rpx;
  622. line-height: 80rpx;
  623. text-align: center;
  624. background: #1777ff;
  625. border-radius: 40rpx;
  626. font-size: 30rpx;
  627. font-family: PingFang SC;
  628. font-weight: 500;
  629. color: rgba(255, 255, 255, 1);
  630. }
  631. }
  632. </style>