login.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <view class="wrap">
  3. <view class="login">
  4. <view class="login-title">
  5. <h3>手机号登录/注册</h3>
  6. <p>欢迎来到荆易充</p>
  7. </view>
  8. <view class="login-form">
  9. <view class="login-form-item">
  10. <view class="title">手机号</view>
  11. <view class="input">
  12. <u-input v-model="form.telephone" type="number" placeholder="请输入手机号" placeholder-style="font-size:16px;color:#ccc;"/>
  13. </view>
  14. <view class="tips">未注册的手机号验证后将自动注册</view>
  15. </view>
  16. <view class="login-form-item">
  17. <view class="title">验证码</view>
  18. <view class="input">
  19. <u-input v-model="form.verifyCode" type="number" placeholder="请输入验证码" placeholder-style="font-size:16px;color:#ccc;"/>
  20. <view class="code" @click="getCode">{{codeTips}}</view>
  21. </view>
  22. <u-checkbox-group>
  23. <u-checkbox class="tips" v-model="value" shape="circle" @change="checkboxChange()">
  24. <view v-if="!form.telephone && !value">我已阅读并同意<span>《会员协议》</span>和<span>《隐私协议》</span></view>
  25. <view v-else>我已阅读并同意<span style="color: #000000;">《会员协议》</span>和<span style="color: #000000;">《隐私协议》</span></view>
  26. </u-checkbox>
  27. </u-checkbox-group>
  28. </view>
  29. </view>
  30. <u-button :style="[inputStyle]" class="login-btn" type="success" shape="circle" @click="login">登录</u-button>
  31. <u-verification-code :seconds="sendMsgSecond" ref="uCode" @change="codeChange" @end="end" @start="start" change-text="已发送(XS)">
  32. </u-verification-code>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. import * as loginApi from '@/apis/login.js'
  38. import {
  39. checkPhone
  40. } from '@/utils'
  41. export default {
  42. data() {
  43. return {
  44. form: {
  45. telephone: '',
  46. verifyCode: '',
  47. },
  48. isSendMsgIng: false,
  49. sendMsgSecond: 60,
  50. codeTips: '',
  51. value: false,
  52. code: '',
  53. codeId: '',
  54. }
  55. },
  56. computed: {
  57. inputStyle() {
  58. let style = {};
  59. if(this.form.telephone) {
  60. style.color = "#fff";
  61. style.backgroundColor = this.$u.color['success'];
  62. }
  63. return style;
  64. }
  65. },
  66. onLoad(op) {
  67. if(op.id) {
  68. var str1 = op.id.slice(0,19);
  69. var str2 = op.id.slice(20,21);
  70. var str3 = op.id.slice(22);
  71. if(str1 == 'jp_team51_charge_id') {
  72. if(str2 == 'A') {
  73. this.code = str2;
  74. this.codeId = str3;
  75. }
  76. }
  77. }
  78. },
  79. methods: {
  80. codeChange(text) {
  81. this.codeTips = text;
  82. },
  83. start() {
  84. if (!this.isSendMsgIng) {
  85. uni.showLoading({
  86. title: "加载中",
  87. mask: true,
  88. })
  89. loginApi.getVerifyCode(this.form.telephone).then((response) => {
  90. uni.hideLoading();
  91. this.carhelp.set("getvcodetime", new Date().getTime());
  92. if (!"") {
  93. //倒计时
  94. uni.showToast({
  95. title: "发送成功"
  96. })
  97. } else {
  98. uni.showToast({
  99. title: "您的验证码已经发送[5分钟有效],请勿重复点击"
  100. })
  101. }
  102. }).catch(error => {
  103. uni.showToast({
  104. title: error,
  105. icon: "none"
  106. })
  107. })
  108. }
  109. },
  110. //倒计时
  111. end() {
  112. this.sendMsgSecond = 60;
  113. this.isSendMsgIng = false;
  114. },
  115. // 获取验证码
  116. getCode() {
  117. if (this.$refs.uCode.canGetCode) {} else {
  118. uni.showToast({
  119. title: '倒计时结束后再发送',
  120. icon: "none"
  121. })
  122. return
  123. }
  124. var checkPhoneResult = checkPhone(this.form.telephone);
  125. if (checkPhoneResult !== true) {
  126. uni.showToast({
  127. title: checkPhoneResult,
  128. })
  129. return;
  130. }
  131. this.$refs.uCode.start();
  132. },
  133. checkboxChange() {
  134. this.value = !this.value;
  135. },
  136. login() {
  137. var checkPhoneResult = checkPhone(this.form.telephone);
  138. if(!this.form.telephone || checkPhoneResult != true) {
  139. uni.showToast({
  140. title: checkPhoneResult,
  141. icon: "none"
  142. })
  143. return;
  144. }
  145. if(!this.form.verifyCode) {
  146. uni.showToast({
  147. title: "请输入验证码",
  148. icon: "none"
  149. })
  150. return
  151. }
  152. if(!this.value) {
  153. uni.showToast({
  154. title: "请勾选协议",
  155. icon: "none"
  156. })
  157. return
  158. }
  159. uni.showLoading({
  160. title: "加载中",
  161. mask: true,
  162. })
  163. loginApi.validateCode({
  164. verifyCode: this.form.verifyCode,
  165. telephone: this.form.telephone,
  166. nickName: this.carhelp.getUserInfo().nickname,
  167. openId: this.carhelp.getOpenId(),
  168. }).then((response) => {
  169. uni.hideLoading();
  170. var token = response ? response.data.token : '';
  171. this.carhelp.setToken(token);
  172. this.carhelp.setPersonInfo(response.data.regUser);
  173. if(this.code == 'A') {
  174. uni.navigateBack({
  175. url: '/pages/searchPile/stationAndPile/chargingPileDetails?id=' + this.codeId
  176. })
  177. } else {
  178. uni.redirectTo({
  179. url: '/pages/index/index'
  180. })
  181. }
  182. }).catch(error => {
  183. uni.showToast({
  184. title: error,
  185. icon: "none"
  186. })
  187. })
  188. }
  189. }
  190. }
  191. </script>
  192. <style>
  193. page{
  194. background-color: #fff;
  195. }
  196. </style>
  197. <style lang="scss" scoped>
  198. .wrap {
  199. font-size: 28rpx;
  200. .login {
  201. width: 600rpx;
  202. padding-top: 80rpx;
  203. margin: 0 auto;
  204. .login-title {
  205. text-align: left;
  206. h3{
  207. font-size: 48rpx;
  208. font-weight: normal;
  209. }
  210. p{
  211. margin-top: 4px;
  212. color:#777
  213. }
  214. }
  215. .login-form-item{
  216. margin-top: 40px;
  217. .title{
  218. margin-bottom: 8px;
  219. }
  220. .input {
  221. border-bottom: 1px solid #f7f7f7;
  222. position: relative;
  223. }
  224. .code{
  225. position: absolute;
  226. right: 0;
  227. top:7px;
  228. color:#1677FF;
  229. }
  230. .tips {
  231. color: $u-type-info;
  232. margin-top: 12px;
  233. font-size: 12px;
  234. span{
  235. color:#3fbd70;
  236. }
  237. }
  238. }
  239. .login-btn {
  240. margin-top: 40px;
  241. background-color: #a7dbc2;
  242. }
  243. .alternative {
  244. color: $u-tips-color;
  245. display: flex;
  246. justify-content: space-between;
  247. margin-top: 30rpx;
  248. }
  249. }
  250. }
  251. </style>