register.vue 9.1 KB

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