register.vue 8.9 KB

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