index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <view>
  3. <view class="login-logo">
  4. <u-image width="120rpx" height="120rpx" src="../../assets/img/logo.png" border-radius="20"></u-image>
  5. <h3>51充电联盟</h3>
  6. <p>运管中心</p>
  7. </view>
  8. <view class="login-form">
  9. <u-form :model="form" ref="uForm">
  10. <view class="login-form-row">
  11. <u-icon name="user-2-fill" custom-prefix="custom-icon" color="#b0b8c8" size="40"></u-icon>
  12. <u-line color="#d9e0ec" length="20" direction="col" margin="10px"/>
  13. <u-form-item label="" prop="phone" :border-bottom="false">
  14. <u-input v-model="form.phone" placeholder="请输入手机号" />
  15. </u-form-item>
  16. </view>
  17. <view class="login-form-row">
  18. <u-icon name="message-3-fill" custom-prefix="custom-icon" color="#b0b8c8" size="40"></u-icon>
  19. <u-line color="#d9e0ec" length="20" direction="col" margin="10px"/>
  20. <u-form-item label="" prop="code" :border-bottom="false">
  21. <u-input v-model="form.code" placeholder="请输入验证码" />
  22. </u-form-item>
  23. </view>
  24. <view class="login-code" >
  25. <span @click="getCode" >{{codeTips}}</span>
  26. </view>
  27. </u-form>
  28. <u-verification-code :seconds="sendMsgSecond" ref="uCode" @change="codeChange" @end="end" @start="start">
  29. </u-verification-code>
  30. <u-button style=" margin-top: 30px;"
  31. :class="{
  32. 'login-btn':!(form.phone&&form.code)
  33. }" type="primary"
  34. @click="finish">登录</u-button>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import * as API from '@/apis/finance.js'
  40. import {
  41. checkPhone
  42. } from '@/utils'
  43. export default {
  44. data() {
  45. return {
  46. form: {
  47. name: '',
  48. intro: '',
  49. phone: '',
  50. code: '',
  51. },
  52. backUrl: "",
  53. message: "",
  54. codeTips: '',
  55. isSendMsgIng: false,
  56. sendMsgSecond: 60 * 2,
  57. customStyle: {
  58. background: '#1677ff'
  59. }
  60. }
  61. },
  62. onLoad(op) {
  63. this.message = op.message;
  64. this.backUrl = op.back;
  65. if (op.phone) {
  66. this.form.phone = op.phone;
  67. }
  68. },
  69. methods: {
  70. codeChange(text) {
  71. this.codeTips = text;
  72. },
  73. //倒计时
  74. end() {
  75. this.sendMsgSecond = 2 * 60;
  76. this.isSendMsgIng = false;
  77. },
  78. finish() {
  79. if (!this.carhelp.getOpenId()) {
  80. // uni.showToast({
  81. // title: "请使用“微信”访问本系统登录"
  82. // })
  83. // return
  84. }
  85. if (!this.form.phone) {
  86. uni.showToast({
  87. title: "请输入手机号"
  88. })
  89. return
  90. }
  91. if (!this.form.code) {
  92. uni.showToast({
  93. title: "请输入验证码"
  94. })
  95. return
  96. }
  97. uni.showLoading({
  98. title: "加载中",
  99. mask: true,
  100. })
  101. var headImg = "";
  102. var userInfo = this.carhelp.get("xpgj_wx_user_info")
  103. if (userInfo) {
  104. headImg = userInfo.headimgurl;
  105. }
  106. API.validateCode({
  107. verifyCode: this.form.code,
  108. telephone: this.form.phone,
  109. openId: this.carhelp.getOpenId(),
  110. headImg: headImg
  111. }).then((response) => {
  112. this.loginset(response)
  113. }).catch(error => {
  114. uni.showToast({
  115. title: error,
  116. icon: "none"
  117. })
  118. })
  119. },
  120. start() {
  121. if (!this.isSendMsgIng) {
  122. uni.showLoading({
  123. title: "加载中",
  124. mask: true,
  125. })
  126. API.getVerifyCode(this.form.phone).then((response) => {
  127. uni.hideLoading();
  128. this.carhelp.set("getvcodetime", new Date().getTime());
  129. if (!"") {
  130. //倒计时
  131. uni.showToast({
  132. title: "发送成功"
  133. })
  134. } else {
  135. uni.showToast({
  136. title: "您的验证码已经发送[5分钟有效],请勿重复点击"
  137. })
  138. }
  139. }).catch(error => {
  140. uni.showToast({
  141. title: error,
  142. icon: "none"
  143. })
  144. })
  145. }
  146. },
  147. // 获取验证码
  148. getCode() {
  149. if (this.$refs.uCode.canGetCode) {
  150. } else {
  151. uni.showToast({
  152. title: '倒计时结束后再发送',
  153. icon: "none"
  154. })
  155. return
  156. }
  157. var checkPhoneResult = checkPhone(this.form.phone);
  158. if (checkPhoneResult !== true) {
  159. uni.showToast({
  160. title: checkPhoneResult,
  161. })
  162. return;
  163. }
  164. this.$refs.uCode.start();
  165. },
  166. loginset(response){
  167. var token = response ? response.data.token : '';
  168. this.carhelp.setToken(token);
  169. this.carhelp.setPersonInfo(response.data.user);
  170. this.carhelp.setPersonInfoPlus(response.data)
  171. //this.gotoUrl("pages/user/index")
  172. if(response.data.user.accountType=="8"){
  173. //企业车辆管理
  174. uni.redirectTo({
  175. url: '/pagesFinance/accountType8/chagingrecord/index'
  176. })
  177. }else{
  178. uni.redirectTo({
  179. url: '/pagesFinance/statistics/index'
  180. })
  181. }
  182. },
  183. query(){
  184. uni.showLoading({
  185. title: "加载中",
  186. mask: true,
  187. })
  188. API.findByOpenId({
  189. openId: this.carhelp.getOpenId(),
  190. }).then((response) => {
  191. this.loginset(response)
  192. }).catch(error => {
  193. uni.hideLoading();
  194. // if (!this.carhelp.getOpenId()) {
  195. // uni.showToast({
  196. // title: "请使用“微信”访问本系统登录"
  197. // })
  198. // return
  199. // }
  200. var time = this.carhelp.get("getvcodetime");
  201. if (time) {
  202. //this.$refs.uCode.start();
  203. var nowtime = new Date().getTime()
  204. var differ = (nowtime - time) / 1000
  205. if (differ < 2 * 60) {
  206. this.sendMsgSecond = 2 * 60 - parseInt(differ)
  207. this.isSendMsgIng = true;
  208. this.$refs.uCode.start();
  209. }
  210. }
  211. })
  212. }
  213. },
  214. onReady() {
  215. this.query()
  216. }
  217. }
  218. </script>
  219. <style>
  220. page{
  221. background: url(../../assets/img/bgbg.png) no-repeat;
  222. background-size: 100%;
  223. }
  224. </style>
  225. <style lang="scss" scoped>
  226. .login-logo{
  227. display: flex;
  228. flex-direction: column;
  229. align-items: center;
  230. padding-top: 20%;
  231. h3{
  232. margin:15px 0;
  233. }
  234. }
  235. /deep/.u-form-item{
  236. padding: 0;
  237. flex: 1;
  238. }
  239. .login-form{
  240. width: 80%;
  241. margin:50px auto 0;
  242. }
  243. .login-form-row{
  244. height: 40px;
  245. border: 1px solid #c7d1e2;
  246. background-color: #fff;
  247. border-radius: 10px;
  248. display: flex;
  249. align-items: center;
  250. padding: 2px 10px;
  251. margin-bottom: 15px;
  252. }
  253. .login-code{
  254. text-align: right;
  255. span{
  256. color:#005AD9;
  257. }
  258. }
  259. .login-btn{
  260. background-color: #cdd7e8;
  261. border-color:#cdd7e8 ;
  262. color:#fff;
  263. margin-top: 30px;
  264. }
  265. </style>