login.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. <template>
  2. <view class="wrap">
  3. <ujp-navbar :isBack="false" title="">
  4. <view slot="right"
  5. v-if="!personInfo"
  6. @click="touristBl=true" style=" margin-right: 10px;color:#00B962"> 游客模式</view>
  7. </ujp-navbar>
  8. <view class="login">
  9. <view class="login-title">
  10. <h3>手机号登录/注册</h3>
  11. <p>欢迎来到{{projectName}}</p>
  12. <p v-if="activityInfo"><span style="color: red;">*</span>正在参加活动<span style="color: #3fbd70;" ><邀请有礼></span></p>
  13. </view>
  14. <view class="login-form">
  15. <view class="login-form-item">
  16. <view class="title">手机号</view>
  17. <view class="input">
  18. <u-input :customStyle="customStyle" :placeholderStyle="placeholderStyle" v-model="form.telephone" type="number" placeholder="请输入手机号" placeholder-style="font-size:16px;color:#ccc;"/>
  19. </view>
  20. <view class="tips">未注册的手机号验证后将自动注册</view>
  21. </view>
  22. <view class="login-form-item">
  23. <view class="title">验证码</view>
  24. <view class="input">
  25. <u-input :customStyle="customStyle" :placeholderStyle="placeholderStyle" v-model="form.verifyCode" type="number" placeholder="请输入验证码" placeholder-style="font-size:16px;color:#ccc;"/>
  26. <view class="code" :style="isCodeTipsColor ? 'color: #999999;' : ''" @click="getCode">{{codeTips}}</view>
  27. </view>
  28. <view style="width: 350px;">
  29. <u-checkbox-group>
  30. <u-checkbox class="tips" active-color="green" v-model="value" shape="circle" @change="checkboxChange()"></u-checkbox>
  31. </u-checkbox-group>
  32. <span>我已阅读并同意</span>
  33. <span @click="gotoUrl('pages/article/details?code=YHXY')" style="color: #3fbd70;">《会员协议》</span>和
  34. <span @click="gotoUrl('pages/article/details?code=YSZC')" style="color: #3fbd70;">《隐私协议》</span>
  35. </view>
  36. </view>
  37. </view>
  38. <u-button :style="[inputStyle]" class="login-btn" type="success" shape="circle" @click="login">登录</u-button>
  39. <u-verification-code :seconds="sendMsgSecond" ref="uCode" @change="codeChange" @end="end" @start="start" change-text="已发送(Xs)">
  40. </u-verification-code>
  41. </view>
  42. <view class="foot" v-if="!show2">
  43. <span style="color: red;">*</span>我们将使用您的微信昵称及头像,为您补全本平台帐号相关基础信息,请点击下方“<span style="color: #3fbd70;">使用完整服务</span>”。
  44. </view>
  45. <u-modal v-model="show1" @confirm="gotoGz"
  46. cancel-text="暂不关注"
  47. confirm-text="前往关注"
  48. confirm-color="#53b56b"
  49. :show-cancel-button="true"
  50. ref="uModal2" :asyncClose="true"
  51. >
  52. <view style="padding: 15px;"
  53. >请先关注<span style=" color: #53b56b;">{{projectName}}</span>公众号,然后进行会员注册</view>
  54. </u-modal>
  55. <u-modal v-model="touristBl"
  56. :show-cancel-button="true"
  57. @confirm="touristConfirm"
  58. cancel-text="取消" confirm-text="游客登录" title="提示">
  59. <view style="
  60. text-align: center;
  61. ">
  62. </view>
  63. <view style="text-align: center; padding: 10px;">游客身份充电将无法享受平台服务费8.5折及各类优惠券活动哦~</view>
  64. </u-modal>
  65. </view>
  66. </template>
  67. <script>
  68. import * as loginApi from '@/apis/login.js'
  69. import * as API from '@/apis/index.js'
  70. import * as API_weixin from '@/apis/weixin.js'
  71. import {
  72. checkPhone
  73. } from '@/utils'
  74. export default {
  75. data() {
  76. return {
  77. elderMode:false,
  78. customStyle:{
  79. 'font-size':'28rpx'
  80. },
  81. placeholderStyle:"font-size:28rpx",
  82. form: {
  83. telephone: '',
  84. verifyCode: '',
  85. },
  86. activityInfo:null,
  87. isSendMsgIng: false,
  88. isCodeTipsColor: false,
  89. sendMsgSecond: 60,
  90. codeTips: '',
  91. value: false,
  92. code: '',
  93. codeId: '',
  94. projectName:'',
  95. show1:false,
  96. show2:false,
  97. touristBl:false,
  98. personInfo:null,
  99. }
  100. },
  101. computed: {
  102. inputStyle() {
  103. let style = {};
  104. if(this.form.telephone) {
  105. style.color = "#fff";
  106. style.backgroundColor = this.$u.color['success'];
  107. }
  108. return style;
  109. }
  110. },
  111. onLoad(op) {
  112. this.projectName=process.car.ProjectName;
  113. if(op.jpcode) {
  114. var str1 = op.jpcode.slice(0,19);
  115. var str2 = op.jpcode.slice(20,21);
  116. var str3 = op.jpcode.slice(22);
  117. if(str1 == 'jp_team51_charge_id') {
  118. if(str2 == 'A') {
  119. this.code = str2;
  120. this.codeId = str3;
  121. uni.showToast({
  122. title:"注册后享受充电服务"
  123. })
  124. }
  125. }
  126. }
  127. var obj=this.carhelp.get("friends_invitation")
  128. if(obj){
  129. if(obj.date+1000*60*60*24 > new Date().getTime() ){
  130. this.form.inviteId=obj.op.uid
  131. this.form.code=obj.op.icode
  132. this.activityInfo="true";
  133. }
  134. }
  135. this.personInfo=this.carhelp.getPersonInfo()
  136. if(this.personInfo){
  137. if(this.personInfo.userType=="1"){
  138. }else{
  139. uni.redirectTo({
  140. url: '/pages/index/index'
  141. })
  142. }
  143. }
  144. },
  145. onReady() {
  146. this.elderMode = this.carhelp.get('getElderModeClass') == '长辈模式';
  147. if(this.elderMode)
  148. this.theme('elder')
  149. else
  150. this.theme('standard')
  151. },
  152. onShow() {
  153. this.checkSubscribe()
  154. },
  155. methods: {
  156. touristConfirm(){
  157. uni.showLoading({
  158. title: "加载中",
  159. mask: true,
  160. })
  161. this.form.nickName=this.carhelp.getUserInfo().nickname;
  162. this.form.headImg=this.carhelp.getUserInfo().headimgurl;
  163. this.form.openId= this.carhelp.getOpenId();
  164. this.form.source=2//创建渠道1电单车2电车
  165. loginApi.registerGuest(this.form).then((response) => {
  166. this.loginresponse(response);
  167. }).catch(error => {
  168. uni.showToast({
  169. title: error,
  170. icon: "none"
  171. })
  172. })
  173. },
  174. gotoGz(){
  175. this.carhelp.setGzDate()
  176. var url="https://mp.weixin.qq.com/s/mCHz1nNvg0xAICiBeIyKRQ";
  177. window.location.href=url
  178. },
  179. checkSubscribe(){
  180. API_weixin.checkSubscribe({
  181. openId: this.carhelp.getOpenId()
  182. }).then((res) => {
  183. if(res.data=="0"){
  184. this.show1=true
  185. }else{
  186. //this.init();
  187. this.show2=true;
  188. //this.carhelp.setGzDate()
  189. }
  190. //setGzDate
  191. }).catch(error => {
  192. uni.showToast({
  193. title: error
  194. })
  195. })
  196. },
  197. theme(type) {
  198. if(type == 'elder')
  199. {
  200. document.getElementsByTagName('body')[0].setAttribute('data-theme',type);
  201. let data = {
  202. "font-size":'32rpx',
  203. };
  204. this.customStyle = data;
  205. this.placeholderStyle = "font-size:32rpx";//data;
  206. }
  207. else
  208. {
  209. document.getElementsByTagName('body')[0].setAttribute('data-theme',type);
  210. let data ={
  211. "font-size":'28rpx',
  212. };
  213. this.customStyle = data;
  214. this.placeholderStyle = "font-size:28rpx";//data;
  215. }
  216. },
  217. codeChange(text) {
  218. this.codeTips = text;
  219. },
  220. start() {
  221. if (!this.isSendMsgIng) {
  222. uni.showLoading({
  223. title: "加载中",
  224. mask: true,
  225. })
  226. loginApi.getVerifyCode(this.form.telephone).then((response) => {
  227. uni.hideLoading();
  228. this.carhelp.set("getvcodetime", new Date().getTime());
  229. if (!"") {
  230. //倒计时
  231. uni.showToast({
  232. title: "发送成功"
  233. })
  234. } else {
  235. uni.showToast({
  236. title: "您的验证码已经发送[5分钟有效],请勿重复点击"
  237. })
  238. }
  239. }).catch(error => {
  240. uni.showToast({
  241. title: error,
  242. icon: "none"
  243. })
  244. })
  245. }
  246. },
  247. //倒计时
  248. end() {
  249. this.sendMsgSecond = 60;
  250. this.isSendMsgIng = false;
  251. this.isCodeTipsColor = false;
  252. },
  253. // 获取验证码
  254. getCode() {
  255. if (this.$refs.uCode.canGetCode) {} else {
  256. uni.showToast({
  257. title: '倒计时结束后再发送',
  258. icon: "none"
  259. })
  260. return
  261. }
  262. var checkPhoneResult = checkPhone(this.form.telephone);
  263. if (checkPhoneResult !== true) {
  264. uni.showToast({
  265. title: checkPhoneResult,
  266. })
  267. return;
  268. }
  269. this.$refs.uCode.start();
  270. this.isCodeTipsColor = true;
  271. },
  272. checkboxChange() {
  273. this.value = !this.value;
  274. },
  275. loginresponse(response){
  276. uni.hideLoading();
  277. var token = response ? response.data.token : '';
  278. this.carhelp.setToken(token);
  279. this.carhelp.setPersonInfo(response.data.regUser);
  280. if(!response.data.regUser.carId){
  281. var url="/pages/login/completeInfo?login=1"
  282. if(this.code == 'A') {
  283. url+="&jpcode=jp_team51_charge_id:A_" + this.codeId
  284. }
  285. uni.redirectTo({
  286. url:url
  287. })
  288. }else if(this.code == 'A') {
  289. var k=API.codeOperation("jp_team51_charge_id:A_"+this.codeId);
  290. if(k){
  291. uni.redirectTo({
  292. url:k
  293. })
  294. }
  295. } else {
  296. uni.redirectTo({
  297. url: '/pages/index/index'
  298. })
  299. }
  300. },
  301. login() {
  302. // if(!this.show2){
  303. // this.show1=true;
  304. // return
  305. // }
  306. var checkPhoneResult = checkPhone(this.form.telephone);
  307. if(!this.form.telephone || checkPhoneResult != true) {
  308. uni.showToast({
  309. title: checkPhoneResult,
  310. icon: "none"
  311. })
  312. return;
  313. }
  314. if(!this.form.verifyCode) {
  315. uni.showToast({
  316. title: "请输入验证码",
  317. icon: "none"
  318. })
  319. return
  320. }
  321. if(!this.value) {
  322. uni.showToast({
  323. title: "请勾选协议",
  324. icon: "none"
  325. })
  326. return
  327. }
  328. uni.showLoading({
  329. title: "加载中",
  330. mask: true,
  331. })
  332. //this.form.nickName= this.form.telephone;
  333. this.form.nickName=this.carhelp.getUserInfo().nickname;
  334. this.form.headImg=this.carhelp.getUserInfo().headimgurl;
  335. this.form.openId= this.carhelp.getOpenId();
  336. this.form.source=2//创建渠道1电单车2电车
  337. if(this.personInfo&&this.personInfo.userType=="1"){
  338. loginApi.validateGuestCode(this.form).then((response) => {
  339. this.loginresponse(response)
  340. }).catch(error => {
  341. uni.showToast({
  342. title: error,
  343. icon: "none"
  344. })
  345. })
  346. }else{
  347. loginApi.validateCode(this.form).then((response) => {
  348. this.loginresponse(response)
  349. }).catch(error => {
  350. uni.showToast({
  351. title: error,
  352. icon: "none"
  353. })
  354. })
  355. }
  356. }
  357. }
  358. }
  359. </script>
  360. <style>
  361. page{
  362. background-color: #fff;
  363. }
  364. </style>
  365. <style lang="scss" scoped>
  366. .foot{
  367. position:fixed;
  368. left: 0;
  369. right: 0;
  370. bottom: 0;
  371. background-color: #fff;
  372. padding: 0 10px;
  373. }
  374. @import "@/_theme.scss";
  375. .all{
  376. @include themeify{
  377. font-size: themed('font-size2');
  378. }
  379. }
  380. /deep/.placeholderStyle {
  381. font-size: themed('font-size2');
  382. }
  383. .wrap {
  384. @include themeify{
  385. font-size: themed('font-size2');
  386. }
  387. /* font-size: 28rpx;*/
  388. .login {
  389. width: 600rpx;
  390. padding-top: 80rpx;
  391. margin: 0 auto;
  392. .login-title {
  393. text-align: left;
  394. h3{
  395. @include themeify{
  396. font-size: themed('font-size7');
  397. }
  398. /* font-size: 48rpx;*/
  399. font-weight: normal;
  400. }
  401. p{
  402. margin-top: 4px;
  403. color:#777
  404. }
  405. }
  406. .login-form-item{
  407. margin-top: 40px;
  408. .title{
  409. margin-bottom: 8px;
  410. @include themeify{
  411. font-size: themed('font-size2');
  412. font-weight: themed('fontWeight');
  413. letter-spacing: themed('letterSpacing');
  414. }
  415. }
  416. .input {
  417. border-bottom: 1px solid #f7f7f7;
  418. position: relative;
  419. }
  420. .code{
  421. position: absolute;
  422. right: 0;
  423. top:7px;
  424. color:#1677FF;
  425. }
  426. .tips {
  427. color: $u-type-info;
  428. margin-top: 12px;
  429. @include themeify{
  430. font-size: themed('font-size1');
  431. }
  432. /* font-size: 12px;*/
  433. span{
  434. color:#3fbd70;
  435. }
  436. }
  437. }
  438. .login-btn {
  439. margin-top: 40px;
  440. background-color: #a7dbc2;
  441. @include themeify{
  442. font-size: themed('font-size3');
  443. }
  444. }
  445. .alternative {
  446. color: $u-tips-color;
  447. display: flex;
  448. justify-content: space-between;
  449. margin-top: 30rpx;
  450. }
  451. }
  452. }
  453. </style>