register.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <template>
  2. <view class="register">
  3. <navbar ref="navbar" :config="config" backColor="#666"></navbar>
  4. <form @submit="formSubmit">
  5. <view class="item">
  6. <view class="top">
  7. 手机号注册
  8. </view>
  9. <!-- <view class="phone">
  10. <view class="name">
  11. 手机号
  12. </view>
  13. <input type="number" name="phone" @input="onPhone" placeholder="请输入手机号" maxlength="11"
  14. placeholder-style="color:#cccccc; font-size:28rpx;" />
  15. </view> -->
  16. <view class="verification">
  17. <view class="name">
  18. 手机号
  19. </view>
  20. <input type="number" @input="onPhone" v-model="phone" name="phone" placeholder="请填写手机号" maxlength="11"
  21. placeholder-style="color:#cccccc; font-size:28rpx;" />
  22. <!-- <button :loading="loading" class="obtain active" open-type="getPhoneNumber" @getphonenumber="getPhone">获取手机号</button> -->
  23. </view>
  24. <view class="verification">
  25. <view class="name">
  26. 验证码
  27. </view>
  28. <input type="number" class="adjustment" v-model="code" name="code" maxlength="6" placeholder="请输入验证码"
  29. placeholder-style="color:#cccccc; font-size:28rpx;" />
  30. <button class="obtain" :disabled="disabled" :class="isPhone?'active':''" @click="judgeRegister">
  31. {{verification}}
  32. </button>
  33. </view>
  34. <view class="invitation">
  35. <view class="name">
  36. 邀请码
  37. </view>
  38. <input type="text" value="" name="invitation" maxlength="8" placeholder="请输入邀请码"
  39. @input="invitationCode" placeholder-style="color:#cccccc; font-size:28rpx;" />
  40. </view>
  41. <view class="password">
  42. <view class="name">
  43. 登录密码
  44. </view>
  45. <input type="text" password="true" name="password" value="" @input="onPass" placeholder="请输入登录密码"
  46. maxlength="11" placeholder-style="color:#cccccc; font-size:28rpx;" />
  47. </view>
  48. </view>
  49. <!-- 协议问题 -->
  50. <view class="choice">
  51. <view class="whole">
  52. <view class="top" v-if="flag" @click="onFlag">
  53. <icon type="success" color="#069D4D" size="17"></icon>
  54. </view>
  55. <view v-else style="width: 34rpx;height: 34rpx;border-radius: 50%;border: #ccc solid 1rpx;"
  56. @click="onFlag"></view>
  57. </view>
  58. <view class="agree">
  59. 我已阅读并同意<text @click="goToAgreement">《会员注册协议》</text>
  60. </view>
  61. </view>
  62. <!-- 按钮 -->
  63. <view class="button">
  64. <button class="agree-register" @click="formSubmit()">
  65. 同意协议并注册
  66. </button>
  67. <button class="go-to-login" @click="goToLogin">
  68. 去登录
  69. </button>
  70. <!-- <view class="go-to-login" @click="goToLogin">
  71. 去登录
  72. </view> -->
  73. </view>
  74. </form>
  75. </view>
  76. </template>
  77. <script>
  78. import {
  79. appRegister,
  80. getVerfityCode
  81. } from "../../../api/login.js"
  82. export default {
  83. data() {
  84. return {
  85. // 头部导航
  86. config: {
  87. back: true, //false是tolbar页面 是则不写
  88. title: '用户注册',
  89. color: '#1A1A1A',
  90. //背景颜色;参数一:透明度(0-1);参数二:背景颜色(array则为线性渐变,string为单色背景)
  91. backgroundColor: [1, "#fff"],
  92. statusBarFontColor: '#1A1A1A',
  93. },
  94. phone: "", //手机号
  95. disabled: false, //按钮
  96. isPhone: false, //手机号正则
  97. password: "",
  98. code:"",
  99. invitation: "",
  100. time: 60, //倒计时
  101. verification: "获取验证码",
  102. List: [{
  103. id: '1',
  104. price: 100.00,
  105. name: "商品"
  106. }],
  107. active: null,
  108. flag: false,
  109. isGetPhone: false
  110. }
  111. },
  112. methods: {
  113. getPhone(e) {
  114. const that = this;
  115. wx.checkSession({
  116. success () {
  117. if(e.detail.errMsg=="getPhoneNumber:ok"){
  118. that.$http.post('/account/app/register', {mobile: that.phone}).then((res) => {
  119. if(res.code == 200) {
  120. that.phone = res.data.mobile
  121. }
  122. })
  123. }
  124. },
  125. fail () {
  126. // session_key 已经失效,需要重新执行登录流程
  127. that.$mUtil.toast('微信登录已过期', 2000);
  128. setTimeout(() => {
  129. uni.navigateBack({
  130. delta: 1
  131. });
  132. },2500)
  133. }
  134. })
  135. },
  136. //跳转协议
  137. goToAgreement() {
  138. uni.navigateTo({
  139. url: "./agreement"
  140. })
  141. },
  142. //跳转到登录页
  143. goToLogin() {
  144. uni.redirectTo({
  145. url: "./login"
  146. })
  147. // let getOenId = uni.getStorageSync('openId')
  148. // console.log(getOenId)
  149. },
  150. //倒计时
  151. countDown() {
  152. var that = this
  153. if (that.time <= 0) {
  154. that.disabled = false;
  155. that.verification = "重新获取";
  156. that.isPhone = true;
  157. that.time = 60
  158. clearInterval(that.clear);
  159. } else {
  160. that.disabled = true;
  161. --that.time;
  162. that.verification = this.time + "s";
  163. }
  164. },
  165. //获取验证码
  166. judgeRegister() {
  167. if (this.isPhone){
  168. this.$http.get("/account/verify-mobile/" + this.phone, ).then(res => {
  169. if (res && res.code == 200) {
  170. if (res.data == true) {
  171. this.$mUtil.toast("该手机号已被注册")
  172. } else if (res.data == false) {
  173. let res = this.$http.post(getVerfityCode, this.phone).then(res => {
  174. if (res && res.code == 200) {
  175. this.disabled = false;
  176. this.isPhone = false;
  177. this.verification = this.time + 's';
  178. this.clear = setInterval(this.countDown, 1000);
  179. this.$mUtil.toast("发送成功")
  180. } else {
  181. this.$mUtil.toast(res.msg)
  182. }
  183. })
  184. }
  185. }
  186. })
  187. }
  188. },
  189. obtainCode() {
  190. if (this.isPhone) {
  191. this.disabled = false;
  192. this.isPhone = false;
  193. this.verification = this.time + 's';
  194. this.clear = setInterval(this.countDown, 1000);
  195. }
  196. },
  197. beforeDestroy() {
  198. clearInterval(this.clear)
  199. },
  200. //邀请码
  201. invitationCode(e) {
  202. let invitationCode = e.detail.value
  203. this.invitation = invitationCode
  204. },
  205. // 手机号
  206. onPhone(e) {
  207. let onPhone = e.detail.value
  208. this.phone = onPhone
  209. if (onPhone.match(this.$mConfig.telRegex)) {
  210. if(this.verification=='获取验证码'||this.verification=='重新获取'){
  211. this.isPhone = true
  212. }
  213. } else {
  214. this.isPhone = false
  215. }
  216. },
  217. onPass(e) {
  218. let onPass = e.detail.value
  219. this.password = onPass
  220. },
  221. //同意并注册
  222. formSubmit(e) {
  223. if (!this.phone) {
  224. this.$mUtil.toast('请输入手机号')
  225. return false
  226. }
  227. if (!(this.phone.match(this.$mConfig.telRegex))) {
  228. this.$mUtil.toast('请输入正确手机号')
  229. return false
  230. }
  231. if (!this.code) {
  232. this.$mUtil.toast("请输入验证码")
  233. return false
  234. }
  235. if (!this.password) {
  236. this.$mUtil.toast("请输入登录密码")
  237. return false
  238. }
  239. if (!this.flag) {
  240. this.$mUtil.toast('请先同意协议')
  241. return false
  242. }
  243. let param = {
  244. mobile: this.phone,
  245. captcha: this.code,
  246. invitation_code: this.invitation,
  247. password: this.password
  248. }
  249. this.$http.post(appRegister, param)
  250. .then(res => {
  251. if (res.code == 200) {
  252. this.$mUtil.toast("注册成功")
  253. setTimeout(() => {
  254. uni.redirectTo({
  255. url: "./login"
  256. })
  257. }, 1000)
  258. }
  259. })
  260. },
  261. // 协议
  262. onFlag() {
  263. this.flag = !this.flag
  264. },
  265. radioChange(index) {
  266. if (this.active == index) {
  267. this.active == null;
  268. } else {
  269. this.active = index
  270. }
  271. }
  272. }
  273. }
  274. </script>
  275. <style lang="scss" scoped>
  276. .button {
  277. margin: 70rpx 50rpx;
  278. .agree-register {
  279. color: #FFFFFF;
  280. font-weight: 400;
  281. font-size: 32rpx;
  282. // padding: 22rpx 0rpx;
  283. width: 550rpx;
  284. text-align: center;
  285. background-color: #FA6138;
  286. border-radius: 20rpx;
  287. margin-left: 50rpx;
  288. }
  289. .go-to-login {
  290. font-weight: 400;
  291. color: #FA6138;
  292. font-size: 32rpx;
  293. // padding: 22rpx 0;
  294. width: 550rpx;
  295. text-align: center;
  296. margin-top: 24rpx;
  297. border: 1rpx solid #3775F6;
  298. border-radius: 20rpx;
  299. margin-left: 50rpx;
  300. box-sizing: border-box;
  301. }
  302. }
  303. .agree {
  304. font-size: 28rpx;
  305. color: #999999;
  306. font-weight: Regular;
  307. margin-left: 10rpx;
  308. text {
  309. font-weight: 400;
  310. color: #FA6138;
  311. }
  312. }
  313. .choice {
  314. margin: 0 50rpx;
  315. display: flex;
  316. .whole {
  317. display: flex;
  318. .top {
  319. display: flex;
  320. }
  321. }
  322. }
  323. .password {
  324. display: flex;
  325. align-items: center;
  326. padding: 40rpx 0 40rpx 0;
  327. border-bottom: 1rpx solid #E6E6E6;
  328. .name {
  329. font-size: 28rpx;
  330. font-weight: 500;
  331. color: #333333;
  332. margin-right: 40rpx;
  333. }
  334. }
  335. .invitation {
  336. display: flex;
  337. align-items: center;
  338. padding: 40rpx 0 40rpx 0;
  339. border-bottom: 1rpx solid #E6E6E6;
  340. .name {
  341. font-size: 28rpx;
  342. font-weight: Medium;
  343. color: #333333;
  344. margin-right: 40rpx;
  345. }
  346. }
  347. .verification {
  348. display: flex;
  349. flex-wrap: nowrap;
  350. padding: 40rpx 0 34rpx 0;
  351. align-items: center;
  352. border-bottom: 1rpx solid #E6E6E6;
  353. .name {
  354. font-size: 28rpx;
  355. color: #333333;
  356. line-height: 28rpx;
  357. font-weight: 500;
  358. margin-right: 40rpx;
  359. }
  360. .adjustment {
  361. flex: 1;
  362. }
  363. .obtain {
  364. // padding: 14rpx 30rpx;
  365. padding: 0 30rpx;
  366. color: #999;
  367. background-color: #FFFFFF;
  368. font-size: 28rpx;
  369. font-weight: Regular;
  370. border: 1rpx solid #B3B3B3;
  371. border-radius: 36rpx;
  372. }
  373. .active {
  374. background-color: #FA6138;
  375. color: #FFFFFF;
  376. border: none;
  377. }
  378. }
  379. .register {
  380. .item {
  381. margin: 80rpx 50rpx 40rpx 50rpx;
  382. .top {
  383. font-size: 38rpx;
  384. font-weight: Bold;
  385. color: #333333;
  386. line-height: 28rpx;
  387. }
  388. .phone {
  389. display: flex;
  390. align-items: center;
  391. padding: 40rpx 0 34rpx 0;
  392. border-bottom: 1rpx solid #E6E6E6;
  393. .name {
  394. margin-right: 40rpx;
  395. }
  396. }
  397. }
  398. }
  399. </style>