index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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,"merchantUser");
  169. this.carhelp.setPersonInfo(response.data.user,"merchantUser");
  170. this.carhelp.setPersonInfoPlus(response.data, "merchantUser")
  171. //this.gotoUrl("pages/user/index")
  172. uni.redirectTo({
  173. url: '/pagesFinance/statistics/index'
  174. })
  175. },
  176. query(){
  177. uni.showLoading({
  178. title: "加载中",
  179. mask: true,
  180. })
  181. API.findByOpenId({
  182. openId: this.carhelp.getOpenId(),
  183. }).then((response) => {
  184. this.loginset(response)
  185. }).catch(error => {
  186. uni.hideLoading();
  187. // if (!this.carhelp.getOpenId()) {
  188. // uni.showToast({
  189. // title: "请使用“微信”访问本系统登录"
  190. // })
  191. // return
  192. // }
  193. var time = this.carhelp.get("getvcodetime");
  194. if (time) {
  195. //this.$refs.uCode.start();
  196. var nowtime = new Date().getTime()
  197. var differ = (nowtime - time) / 1000
  198. if (differ < 2 * 60) {
  199. this.sendMsgSecond = 2 * 60 - parseInt(differ)
  200. this.isSendMsgIng = true;
  201. this.$refs.uCode.start();
  202. }
  203. }
  204. })
  205. }
  206. },
  207. onReady() {
  208. this.query()
  209. }
  210. }
  211. </script>
  212. <style>
  213. page{
  214. background: url(../../assets/img/bgbg.png) no-repeat;
  215. background-size: 100%;
  216. }
  217. </style>
  218. <style lang="scss" scoped>
  219. .login-logo{
  220. display: flex;
  221. flex-direction: column;
  222. align-items: center;
  223. padding-top: 20%;
  224. h3{
  225. margin:15px 0;
  226. }
  227. }
  228. /deep/.u-form-item{
  229. padding: 0;
  230. flex: 1;
  231. }
  232. .login-form{
  233. width: 80%;
  234. margin:50px auto 0;
  235. }
  236. .login-form-row{
  237. height: 40px;
  238. border: 1px solid #c7d1e2;
  239. background-color: #fff;
  240. border-radius: 10px;
  241. display: flex;
  242. align-items: center;
  243. padding: 2px 10px;
  244. margin-bottom: 15px;
  245. }
  246. .login-code{
  247. text-align: right;
  248. span{
  249. color:#005AD9;
  250. }
  251. }
  252. .login-btn{
  253. background-color: #cdd7e8;
  254. border-color:#cdd7e8 ;
  255. color:#fff;
  256. margin-top: 30px;
  257. }
  258. </style>