index.vue 5.8 KB

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