becomeVIP.vue 17 KB

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