login.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 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 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. </view>
  38. </template>
  39. <script>
  40. import * as loginApi from '@/apis/login.js'
  41. import * as API from '@/apis/index.js'
  42. import {
  43. checkPhone
  44. } from '@/utils'
  45. export default {
  46. data() {
  47. return {
  48. form: {
  49. telephone: '',
  50. verifyCode: '',
  51. },
  52. activityInfo:null,
  53. isSendMsgIng: false,
  54. sendMsgSecond: 60,
  55. codeTips: '',
  56. value: false,
  57. code: '',
  58. codeId: '',
  59. projectName:'',
  60. }
  61. },
  62. computed: {
  63. inputStyle() {
  64. let style = {};
  65. if(this.form.telephone) {
  66. style.color = "#fff";
  67. style.backgroundColor = this.$u.color['success'];
  68. }
  69. return style;
  70. }
  71. },
  72. onLoad(op) {
  73. this.projectName=process.car.ProjectName;
  74. if(op.jpcode) {
  75. var str1 = op.jpcode.slice(0,19);
  76. var str2 = op.jpcode.slice(20,21);
  77. var str3 = op.jpcode.slice(22);
  78. if(str1 == 'jp_team51_charge_id') {
  79. if(str2 == 'A') {
  80. this.code = str2;
  81. this.codeId = str3;
  82. uni.showToast({
  83. title:"注册后享受充电服务"
  84. })
  85. }
  86. }
  87. }
  88. var obj=this.carhelp.get("friends_invitation")
  89. if(obj){
  90. if(obj.date+1000*60*60*24 > new Date().getTime() ){
  91. this.form.inviteId=obj.op.uid
  92. this.form.code=obj.op.code
  93. this.activityInfo=obj.activityInfo;
  94. }
  95. }
  96. },
  97. methods: {
  98. codeChange(text) {
  99. this.codeTips = text;
  100. },
  101. start() {
  102. if (!this.isSendMsgIng) {
  103. uni.showLoading({
  104. title: "加载中",
  105. mask: true,
  106. })
  107. loginApi.getVerifyCode(this.form.telephone).then((response) => {
  108. uni.hideLoading();
  109. this.carhelp.set("getvcodetime", new Date().getTime());
  110. if (!"") {
  111. //倒计时
  112. uni.showToast({
  113. title: "发送成功"
  114. })
  115. } else {
  116. uni.showToast({
  117. title: "您的验证码已经发送[5分钟有效],请勿重复点击"
  118. })
  119. }
  120. }).catch(error => {
  121. uni.showToast({
  122. title: error,
  123. icon: "none"
  124. })
  125. })
  126. }
  127. },
  128. //倒计时
  129. end() {
  130. this.sendMsgSecond = 60;
  131. this.isSendMsgIng = false;
  132. },
  133. // 获取验证码
  134. getCode() {
  135. if (this.$refs.uCode.canGetCode) {} else {
  136. uni.showToast({
  137. title: '倒计时结束后再发送',
  138. icon: "none"
  139. })
  140. return
  141. }
  142. var checkPhoneResult = checkPhone(this.form.telephone);
  143. if (checkPhoneResult !== true) {
  144. uni.showToast({
  145. title: checkPhoneResult,
  146. })
  147. return;
  148. }
  149. this.$refs.uCode.start();
  150. },
  151. checkboxChange() {
  152. this.value = !this.value;
  153. },
  154. login() {
  155. var checkPhoneResult = checkPhone(this.form.telephone);
  156. if(!this.form.telephone || checkPhoneResult != true) {
  157. uni.showToast({
  158. title: checkPhoneResult,
  159. icon: "none"
  160. })
  161. return;
  162. }
  163. if(!this.form.verifyCode) {
  164. uni.showToast({
  165. title: "请输入验证码",
  166. icon: "none"
  167. })
  168. return
  169. }
  170. if(!this.value) {
  171. uni.showToast({
  172. title: "请勾选协议",
  173. icon: "none"
  174. })
  175. return
  176. }
  177. uni.showLoading({
  178. title: "加载中",
  179. mask: true,
  180. })
  181. this.form.nickName= this.carhelp.getUserInfo().nickname;
  182. this.form.headImg=this.carhelp.getUserInfo().headimgurl;
  183. this.form.openId= this.carhelp.getOpenId();
  184. loginApi.validateCode(this.form).then((response) => {
  185. uni.hideLoading();
  186. var token = response ? response.data.token : '';
  187. this.carhelp.setToken(token);
  188. this.carhelp.setPersonInfo(response.data.regUser);
  189. if(!response.data.regUser.carId){
  190. var url="/pages/login/completeInfo?login=1"
  191. if(this.code == 'A') {
  192. url+="&jpcode=jp_team51_charge_id:A_" + this.codeId
  193. }
  194. uni.redirectTo({
  195. url:url
  196. })
  197. }else if(this.code == 'A') {
  198. var k=API.codeOperation("jp_team51_charge_id:A_"+this.codeId);
  199. if(k){
  200. uni.redirectTo({
  201. url:k
  202. })
  203. }
  204. } else {
  205. uni.redirectTo({
  206. url: '/pages/index/index'
  207. })
  208. }
  209. }).catch(error => {
  210. uni.showToast({
  211. title: error,
  212. icon: "none"
  213. })
  214. })
  215. }
  216. }
  217. }
  218. </script>
  219. <style>
  220. page{
  221. background-color: #fff;
  222. }
  223. </style>
  224. <style lang="scss" scoped>
  225. .wrap {
  226. font-size: 28rpx;
  227. .login {
  228. width: 600rpx;
  229. padding-top: 80rpx;
  230. margin: 0 auto;
  231. .login-title {
  232. text-align: left;
  233. h3{
  234. font-size: 48rpx;
  235. font-weight: normal;
  236. }
  237. p{
  238. margin-top: 4px;
  239. color:#777
  240. }
  241. }
  242. .login-form-item{
  243. margin-top: 40px;
  244. .title{
  245. margin-bottom: 8px;
  246. }
  247. .input {
  248. border-bottom: 1px solid #f7f7f7;
  249. position: relative;
  250. }
  251. .code{
  252. position: absolute;
  253. right: 0;
  254. top:7px;
  255. color:#1677FF;
  256. }
  257. .tips {
  258. color: $u-type-info;
  259. margin-top: 12px;
  260. font-size: 12px;
  261. span{
  262. color:#3fbd70;
  263. }
  264. }
  265. }
  266. .login-btn {
  267. margin-top: 40px;
  268. background-color: #a7dbc2;
  269. }
  270. .alternative {
  271. color: $u-tips-color;
  272. display: flex;
  273. justify-content: space-between;
  274. margin-top: 30rpx;
  275. }
  276. }
  277. }
  278. </style>