login.vue 5.8 KB

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