becomeVIP.vue 17 KB

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