login.vue 9.3 KB

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