register.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <view class="page">
  3. <!-- 公共组件-每个页面必须引入 -->
  4. <public-module></public-module>
  5. <view class="mx-3 mt-3">
  6. <!-- 账号密码登录 false代表账号密码登录 -->
  7. <view class="phone d-flex">
  8. <view class="title">电话号码</view>
  9. <input placeholder="请输入手机号" v-model="phone" maxlength="11"/>
  10. </view>
  11. <view class="phone d-flex">
  12. <view class="title">真实姓名</view>
  13. <input placeholder="请输入姓名" v-model="name" />
  14. </view>
  15. <view class="password d-flex">
  16. <view class="title">密码</view>
  17. <input placeholder="请输入密码" v-model="password" :password='isHidePassword' maxlength="15" style="padding-right: 200rpx;" />
  18. <view class="d-flex a-center j-center yanzhengma"><view style="font-size: 40rpx;" class="icon iconfont" :class="isHidePassword?'icon-buxianshimima':'icon-xianshimima'" @tap="isHidePassword = !isHidePassword"></view> </view>
  19. </view>
  20. <view class="code d-flex">
  21. <view class="title">验证码</view>
  22. <input placeholder="请输入验证码" v-model="code" maxlength="5" style="padding-right: 200rpx;"/>
  23. <view class="d-flex a-center j-center login-font-color yanzhengma" @tap="getCheckNum">
  24. <view class="d-flex a-center j-center" :class="!codetime?'yanzhengma1 main-text-color':'yanzhengma2'">{{!codetime?'获取验证码':codetime+' s'}}</view>
  25. </view>
  26. </view>
  27. <!-- 推荐信息 -->
  28. <template v-if="showRecommend">
  29. <view class="recommendInfo" >
  30. <view class="d-flex">
  31. <view><image src="/static/bigLogo.png"></image> </view>
  32. <view>
  33. <view><span class="text-muted mr-2">推荐人姓名</span> {{recommendername}}</view>
  34. <view><span class="text-muted mr-2">推荐人会员号</span> {{recommenderid}}</view>
  35. </view>
  36. </view>
  37. <view class="px-3 py-1 d-flex a-center j-center">请确认推荐人信息,注册后,推荐人将不可修改</view>
  38. </view>
  39. </template>
  40. <button class="my-3 mt-4 d-flex a-center j-center font-weight main-bg-color" :loading="loading" :class="{'main-bf-hover-color':disabled}" type="primary" @tap="submit" :disabled="disabled" style="letter-spacing: 20rpx;">注册</button>
  41. <view class="d-flex a-center j-center my-3" >
  42. 已有帐号?<view class="main-text-color" @tap="navigate({url:'/pages/login/login'},'reLaunch')">去登录</view>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import { pathToBase64,base64ToPath } from '@/common/image-tools-base64.js';
  49. import {mapMutations} from "vuex"
  50. export default {
  51. data() {
  52. return {
  53. name:"",
  54. phone:"",
  55. password:"",
  56. code:"",
  57. isHidePassword:true,
  58. disabled:true,
  59. loading:false,
  60. codetime:0,
  61. showRecommend:false,
  62. recommendername:"",
  63. recommenderid:""
  64. }
  65. },
  66. async onLoad(params) {
  67. // // #ifdef H5
  68. // document.getElementsByTagName('uni-page-head')[0].style.display = 'none'
  69. // // #endif
  70. if(!!params.id){
  71. this.recommenderid = params.id;
  72. // 查询推荐人信息
  73. let res = await this.$http.get('/user/findById?id='+params.id);
  74. if((res.code == '200') && (res.data!= null)){
  75. this.recommendername = res.data.name;
  76. this.showRecommend = true;
  77. }else{
  78. if(this.$base.baseUrl.indexOf("test")>-1){
  79. this.recommenderid="99140109M01D01001";
  80. this.recommendername = "耿陈杰";
  81. this.showRecommend = false;
  82. }else{
  83. this.recommenderid="99140109M03D01001";
  84. this.recommendername = "掌柜老王";
  85. this.showRecommend = false;
  86. }
  87. }
  88. }else{
  89. if(this.$base.baseUrl.indexOf("test")>-1){
  90. this.recommenderid="99140109M01D01001";
  91. this.recommendername = "耿陈杰";
  92. this.showRecommend = false;
  93. }else{
  94. this.recommenderid="99140109M03D01001";
  95. this.recommendername = "掌柜老王";
  96. this.showRecommend = false;
  97. }
  98. }
  99. },
  100. watch:{
  101. name(){
  102. this.OnBtnChange();
  103. },
  104. phone(val){
  105. this.OnBtnChange();
  106. },
  107. password(val){
  108. this.OnBtnChange();
  109. },
  110. code(val){
  111. this.OnBtnChange();
  112. }
  113. },
  114. methods: {
  115. ...mapMutations(['setUserModules']),
  116. // 改变按钮状态
  117. OnBtnChange(){
  118. if( this.phone && this.password && this.code && this.name){
  119. this.disabled=false; return;
  120. }
  121. this.disabled=true;
  122. },
  123. isPwdRules(){
  124. let mPattern = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/;
  125. return mPattern.test(this.password);
  126. },
  127. // 获取验证码
  128. async getCheckNum(){
  129. uni.hideKeyboard();
  130. if(this.codetime > 0) return;
  131. // 验证手机号合法性
  132. if (!this.phone) {
  133. return uni.showToast({title: '请输入手机号',icon: 'none'});
  134. }
  135. if (!this.$base.phoneRegular.test(this.phone)) {
  136. return uni.showToast({title: '请输入正确的手机号码',icon: 'none'});
  137. }
  138. // 请求服务器,发送验证码
  139. let res = await this.$http.get('/sendMsg',{phone:this.phone,type:"1"});
  140. // 请求失败处理
  141. if (res.code != 200){
  142. return uni.showToast({ title: res.data.msg, icon:"none" });
  143. }else{
  144. uni.showToast({ title: "发送成功", icon:"none" });
  145. }
  146. // 发送成功,开启倒计时
  147. this.codetime=60;
  148. let timer=setInterval(()=>{
  149. this.codetime--;
  150. if(this.codetime < 1){
  151. clearInterval(timer);
  152. this.codetime=0;
  153. }
  154. },1000);
  155. },
  156. // 提交注册
  157. async submit(){
  158. if (!this.name) {
  159. return uni.showToast({title: '请输入姓名',icon: 'none'});
  160. }
  161. // 验证手机号合法性
  162. if (!this.$base.phoneRegular.test(this.phone)) {
  163. return uni.showToast({title: '请输入正确的手机号码',icon: 'none'});
  164. }
  165. // 验证密码合法性
  166. if (!this.$base.passwordRegular.test(this.password)) {
  167. return uni.showToast({title: '密码须6-15位数字与字母组合',icon: 'none'});
  168. }
  169. // 请求服务器,发送验证码
  170. let res = await this.$http.post('/user/agentRegist',{
  171. "name":this.name,
  172. "identity":this.identity,
  173. "addressnow":this.addressnow,
  174. "password": this.password,
  175. "mobile": this.phone,
  176. "mobileMsg": this.code,
  177. "referrerId": this.recommenderid,
  178. "referrerName": this.recommendername
  179. });
  180. // 请求失败处理
  181. // var newPhone= "";
  182. // newPhone = this.phone;
  183. // this.password="";
  184. // this.phone="";
  185. // this.code="";
  186. // this.name="";
  187. if((res.code==200) && (!!res.data)){
  188. // #ifndef H5
  189. this.setUserModules({title:"userLoginId",data:res.data})
  190. uni.showToast({ title: '注册成功', icon:"success",duration:2000 });
  191. setTimeout(() => {
  192. return uni.reLaunch({url:"/pages/login/login"})
  193. }, 2000);
  194. // #endif
  195. // #ifdef H5
  196. setTimeout(() => {
  197. return uni.reLaunch({
  198. url:"/pages/register/registerSuccess?id="+res.data+'&phone='+ this.phone
  199. })
  200. }, 2000);
  201. // #endif
  202. }
  203. else if(res.code==500){
  204. uni.showToast({ title:res.msg , icon:"success",duration:2000 });
  205. }
  206. else{
  207. uni.showToast({ title: '已注册,重复注册', icon:"success",duration:2000 });
  208. }
  209. }
  210. }
  211. }
  212. </script>
  213. <style lang="scss" scoped>
  214. @import '@/style/mixin.scss';
  215. .idCardBefore{
  216. background: rgba($themeColor,0.1) url('/static/image/user/identy2.png') center center no-repeat;
  217. background-size: auto 70%;
  218. padding: 10upx;
  219. }
  220. .page{
  221. background: #F5F5F5;
  222. height: 100vh;
  223. width: 100%;
  224. position: absolute;
  225. }
  226. .phone,.password,.code{
  227. position: relative;
  228. height: 90upx;
  229. display: flex;
  230. align-items: center;
  231. background-color: #FFFFFF;
  232. padding: 0 30upx;
  233. margin-bottom: 26upx;
  234. }
  235. .phone .title,.password .title,.code .title{
  236. width: 160upx;
  237. flex-shrink: 0;
  238. color: #666;
  239. }
  240. .phone input,.password input,.code input{
  241. width: 350upx;
  242. font-size: 28upx;
  243. }
  244. .yanzhengma{
  245. width: 150upx;
  246. position: absolute;
  247. right: 30upx;
  248. }
  249. .yanzhengma1{
  250. font-size: 26upx;
  251. background: #FFFFFF;
  252. border-radius: 10rpx;
  253. width: 150rpx;
  254. padding: 5rpx 0;
  255. }
  256. .yanzhengma2{
  257. background: #FFFFFF;
  258. font-size: 26upx;
  259. color: #B2B2B2;
  260. border-radius: 10rpx;
  261. width: 150rpx;
  262. padding: 5rpx 0;
  263. }
  264. .recommendInfo{
  265. background: #FFFFFF;
  266. }
  267. .recommendInfo>view:nth-of-type(1){
  268. border-bottom: 1px solid #ddd;
  269. }
  270. .recommendInfo>view:nth-of-type(1)>view:nth-of-type(1){
  271. width: 150upx;
  272. height: 150upx;
  273. border-radius: 50%;
  274. }
  275. .recommendInfo>view:nth-of-type(1)>view:nth-of-type(1)>image{
  276. width: 100%;
  277. height: 100%;
  278. }
  279. .recommendInfo>view:nth-of-type(1)>view:nth-of-type(2){
  280. padding: 20upx;
  281. }
  282. .recommendInfo>view:nth-of-type(1)>view:nth-of-type(2)>view{
  283. height: 55upx;
  284. }
  285. .recommendInfo>view:nth-of-type(2){
  286. line-height: 50upx;
  287. }
  288. </style>