register.vue 9.0 KB

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