register.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. uni.showToast({ title:res.msg , icon:"success",duration:2000 });
  79. this.showRecommend = false;
  80. // if(this.$base.baseUrl.indexOf("test")>-1){
  81. // this.recommenderid="99140109M01D01001";
  82. // this.recommendername = "耿陈杰";
  83. // this.showRecommend = false;
  84. // }else{
  85. // this.recommenderid="99140109M03D01001";
  86. // this.recommendername = "掌柜老王";
  87. // this.showRecommend = false;
  88. // }
  89. }
  90. }
  91. // else{
  92. // if(this.$base.baseUrl.indexOf("test")>-1){
  93. // this.recommenderid="99140109M01D01001";
  94. // this.recommendername = "耿陈杰";
  95. // this.showRecommend = false;
  96. // }else{
  97. // this.recommenderid="99140109M03D01001";
  98. // this.recommendername = "掌柜老王";
  99. // this.showRecommend = false;
  100. // }
  101. // }
  102. },
  103. watch:{
  104. name(){
  105. this.OnBtnChange();
  106. },
  107. phone(val){
  108. this.OnBtnChange();
  109. },
  110. password(val){
  111. this.OnBtnChange();
  112. },
  113. code(val){
  114. this.OnBtnChange();
  115. }
  116. },
  117. methods: {
  118. ...mapMutations(['setUserModules']),
  119. // 改变按钮状态
  120. OnBtnChange(){
  121. if( this.phone && this.password && this.code && this.name){
  122. this.disabled=false; return;
  123. }
  124. this.disabled=true;
  125. },
  126. isPwdRules(){
  127. let mPattern = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/;
  128. return mPattern.test(this.password);
  129. },
  130. // 获取验证码
  131. async getCheckNum(){
  132. uni.hideKeyboard();
  133. if(this.codetime > 0) return;
  134. // 验证手机号合法性
  135. if (!this.phone) {
  136. return uni.showToast({title: '请输入手机号',icon: 'none'});
  137. }
  138. if (!this.$base.phoneRegular.test(this.phone)) {
  139. return uni.showToast({title: '请输入正确的手机号码',icon: 'none'});
  140. }
  141. // 请求服务器,发送验证码
  142. let res = await this.$http.get('/sendMsg',{phone:this.phone,type:"1"});
  143. // 请求失败处理
  144. if (res.code != 200){
  145. return uni.showToast({ title: res.data.msg, icon:"none" });
  146. }else{
  147. uni.showToast({ title: "发送成功", icon:"none" });
  148. }
  149. // 发送成功,开启倒计时
  150. this.codetime=60;
  151. let timer=setInterval(()=>{
  152. this.codetime--;
  153. if(this.codetime < 1){
  154. clearInterval(timer);
  155. this.codetime=0;
  156. }
  157. },1000);
  158. },
  159. // 提交注册
  160. async submit(){
  161. if (!this.name) {
  162. return uni.showToast({title: '请输入姓名',icon: 'none'});
  163. }
  164. // 验证手机号合法性
  165. if (!this.$base.phoneRegular.test(this.phone)) {
  166. return uni.showToast({title: '请输入正确的手机号码',icon: 'none'});
  167. }
  168. // 验证密码合法性
  169. if (!this.$base.passwordRegular.test(this.password)) {
  170. return uni.showToast({title: '密码须6-15位数字与字母组合',icon: 'none'});
  171. }
  172. // 请求服务器,发送验证码
  173. let res = await this.$http.post('/user/agentRegist',{
  174. "name":this.name,
  175. "identity":this.identity,
  176. "addressnow":this.addressnow,
  177. "password": this.password,
  178. "mobile": this.phone,
  179. "mobileMsg": this.code,
  180. "referrerId": this.recommenderid,
  181. "referrerName": this.recommendername
  182. });
  183. // 请求失败处理
  184. // var newPhone= "";
  185. // newPhone = this.phone;
  186. // this.password="";
  187. // this.phone="";
  188. // this.code="";
  189. // this.name="";
  190. if((res.code==200) && (!!res.data)){
  191. // #ifndef H5
  192. this.setUserModules({title:"userLoginId",data:res.data})
  193. uni.showToast({ title: '注册成功', icon:"success",duration:2000 });
  194. setTimeout(() => {
  195. return uni.reLaunch({url:"/pages/login/login"})
  196. }, 2000);
  197. // #endif
  198. // #ifdef H5
  199. setTimeout(() => {
  200. return uni.reLaunch({
  201. url:"/pages/register/registerSuccess?id="+res.data+'&phone='+ this.phone
  202. })
  203. }, 2000);
  204. // #endif
  205. }
  206. else {
  207. uni.showToast({
  208. title:res.msg , icon:"success",duration:2000 });
  209. }
  210. // else{
  211. // uni.showToast({ title: '已注册,重复注册', icon:"success",duration:2000 });
  212. // }
  213. }
  214. }
  215. }
  216. </script>
  217. <style lang="scss" scoped>
  218. @import '@/style/mixin.scss';
  219. .idCardBefore{
  220. background: rgba($themeColor,0.1) url('/static/image/user/identy2.png') center center no-repeat;
  221. background-size: auto 70%;
  222. padding: 10upx;
  223. }
  224. .page{
  225. background: #F5F5F5;
  226. height: 100vh;
  227. width: 100%;
  228. position: absolute;
  229. }
  230. .phone,.password,.code{
  231. position: relative;
  232. height: 90upx;
  233. display: flex;
  234. align-items: center;
  235. background-color: #FFFFFF;
  236. padding: 0 30upx;
  237. margin-bottom: 26upx;
  238. }
  239. .phone .title,.password .title,.code .title{
  240. width: 160upx;
  241. flex-shrink: 0;
  242. color: #666;
  243. }
  244. .phone input,.password input,.code input{
  245. width: 350upx;
  246. font-size: 28upx;
  247. }
  248. .yanzhengma{
  249. width: 150upx;
  250. position: absolute;
  251. right: 30upx;
  252. }
  253. .yanzhengma1{
  254. font-size: 26upx;
  255. background: #FFFFFF;
  256. border-radius: 10rpx;
  257. width: 150rpx;
  258. padding: 5rpx 0;
  259. }
  260. .yanzhengma2{
  261. background: #FFFFFF;
  262. font-size: 26upx;
  263. color: #B2B2B2;
  264. border-radius: 10rpx;
  265. width: 150rpx;
  266. padding: 5rpx 0;
  267. }
  268. .recommendInfo{
  269. background: #FFFFFF;
  270. }
  271. .recommendInfo>view:nth-of-type(1){
  272. border-bottom: 1px solid #ddd;
  273. }
  274. .recommendInfo>view:nth-of-type(1)>view:nth-of-type(1){
  275. width: 150upx;
  276. height: 150upx;
  277. border-radius: 50%;
  278. }
  279. .recommendInfo>view:nth-of-type(1)>view:nth-of-type(1)>image{
  280. width: 100%;
  281. height: 100%;
  282. }
  283. .recommendInfo>view:nth-of-type(1)>view:nth-of-type(2){
  284. padding: 20upx;
  285. }
  286. .recommendInfo>view:nth-of-type(1)>view:nth-of-type(2)>view{
  287. height: 55upx;
  288. }
  289. .recommendInfo>view:nth-of-type(2){
  290. line-height: 50upx;
  291. }
  292. </style>