becomeVIP.vue 17 KB

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