register.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <view class="container">
  3. <view class="wrapper">
  4. <view class="input-content">
  5. <!-- <view class="cu-form-group"
  6. style="border: 2upx solid whitesmoke;margin-bottom: 20px;border-radius: 30px">
  7. <view class="title text-black">用户名</view>
  8. <input :value="userName" placeholder="请输入用户名" data-key="userName" @input="inputChange" />
  9. </view> -->
  10. <view class="cu-form-group"
  11. style="border: 2upx solid whitesmoke;margin-bottom: 20px;border-radius: 30px">
  12. <view class="title text-black">手机号</view>
  13. <input type="number" :value="phone" placeholder="请输入手机号" maxlength="11" data-key="phone"
  14. @input="inputChange" />
  15. </view>
  16. <view class="cu-form-group padding-right-xs"
  17. style="border: 2upx solid whitesmoke;margin-bottom: 20px;border-radius: 30px">
  18. <text class="title text-black">验证码</text>
  19. <input type="number" :value="code" placeholder="请输入验证码" maxlength="6" data-key="code"
  20. @input="inputChange" @confirm="toLogin" />
  21. <button class="send-msg" @click="sendMsg" :disabled="sending">{{ sendTime }}</button>
  22. </view>
  23. <view class="cu-form-group"
  24. style="border: 2upx solid whitesmoke;margin-bottom: 20px;border-radius: 30px">
  25. <text class="title text-black">设置密码</text>
  26. <input type="password" :value="password" placeholder="请设置密码" placeholder-class="input-empty"
  27. maxlength="20" minlength="6" data-key="password" @input="inputChange" @confirm="toLogin" />
  28. </view>
  29. <view class="cu-form-group"
  30. style="border: 2upx solid whitesmoke;margin-bottom: 20px;border-radius: 30px">
  31. <text class="title text-black">邀请码</text>
  32. <input type="" maxlength="6" :value="invitation" placeholder="请填写邀请码(选填)"
  33. data-key="invitation" @input="inputChange" @confirm="toLogin" />
  34. </view>
  35. </view>
  36. <button class="confirm-btn" @click="toLogin">立即注册</button>
  37. <view class="footer">
  38. <text @tap="isShowAgree" class="cuIcon"
  39. :class="showAgree ? 'cuIcon-radiobox' : 'cuIcon-round'">同意</text>
  40. <!-- 协议地址 -->
  41. <navigator url="/my/setting/mimi" open-type="navigate">《隐私政策》</navigator>
  42. 和
  43. <navigator url="/my/setting/xieyi" open-type="navigate">《用户协议》</navigator>
  44. </view>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. export default {
  50. data() {
  51. return {
  52. userName: '',
  53. showAgree: false,
  54. code: '',
  55. phone: '',
  56. password: '',
  57. required: '否',
  58. sending: false,
  59. sendTime: '获取验证码',
  60. count: 60,
  61. relation: "",
  62. state: '',
  63. invitation: '',
  64. platform: ''
  65. };
  66. },
  67. onLoad() {
  68. this.invitation = this.$queue.getData('inviterCode') ? this.$queue.getData('inviterCode') : '';
  69. // #ifdef APP-PLUS
  70. this.platform = 'app'
  71. //#endif
  72. //#ifdef H5
  73. this.platform = 'H5'
  74. // #endif
  75. },
  76. methods: {
  77. showMa() {
  78. //查询官方邀请码
  79. this.$Request.getT('/app/common/type/4').then(res => {
  80. if (res.code == 0) {
  81. this.invitationCode = res.data.value;
  82. }
  83. });
  84. },
  85. // 注册邀请码必填
  86. invitationMa() {
  87. this.$Request.getT('/app/common/type/3').then(res => {
  88. if (res.code == 0) {
  89. this.required = res.data.value;
  90. }
  91. });
  92. },
  93. // 获取新用户优惠券数量
  94. newMa() {
  95. this.$Request.getT('/app/common/type/119').then(res => {
  96. if (res.code == 0) {
  97. this.amount = res.data.value;
  98. }
  99. });
  100. },
  101. isShowAgree() {
  102. //是否选择协议
  103. this.showAgree = !this.showAgree;
  104. },
  105. sendMsg() {
  106. const {
  107. phone
  108. } = this;
  109. if (!phone) {
  110. this.$queue.showToast('请输入手机号');
  111. } else if (phone.length !== 11) {
  112. this.$queue.showToast('请输入正确的手机号');
  113. } else {
  114. this.$queue.showLoading('正在发送验证码...');
  115. this.$Request.getT('/app/Login/sendMsg/' + phone + '/gzg' ).then(res => {
  116. if (res.code === 0) {
  117. this.sending = true;
  118. this.$queue.showToast('验证码发送成功请注意查收');
  119. this.countDown();
  120. uni.hideLoading();
  121. } else {
  122. uni.hideLoading();
  123. uni.showModal({
  124. showCancel: false,
  125. title: '短信发送失败',
  126. content: res.msg ? res.msg : '请一分钟后再获取验证码'
  127. });
  128. }
  129. });
  130. }
  131. },
  132. countDown() {
  133. const {
  134. count
  135. } = this;
  136. if (count === 1) {
  137. this.count = 60;
  138. this.sending = false;
  139. this.sendTime = '获取验证码';
  140. } else {
  141. this.count = count - 1;
  142. this.sending = true;
  143. this.sendTime = count - 1 + '秒后重新获取';
  144. setTimeout(this.countDown.bind(this), 1000);
  145. }
  146. },
  147. inputChange(e) {
  148. const key = e.currentTarget.dataset.key;
  149. this[key] = e.detail.value;
  150. },
  151. navBack() {
  152. uni.navigateBack();
  153. },
  154. navTo(url) {
  155. uni.navigateTo({
  156. url
  157. });
  158. },
  159. toLogin() {
  160. const {
  161. userName,
  162. phone,
  163. password,
  164. code,
  165. showAgree,
  166. invitation,
  167. } = this;
  168. // if (!userName) {
  169. // this.$queue.showToast('请输入用户名');
  170. // } else
  171. if (!phone) {
  172. this.$queue.showToast('请输入手机号');
  173. } else if (!code) {
  174. this.$queue.showToast('请输入验证码');
  175. } else if (!password) {
  176. this.$queue.showToast('请设置密码');
  177. } else if (password.length < 6) {
  178. this.$queue.showToast('密码位数必须大于六位');
  179. } else if (!showAgree) {
  180. this.$queue.showToast('请同意《用户协议》和《隐私政策》');
  181. } else {
  182. this.logining = true;
  183. this.$queue.showLoading('注册中...');
  184. this.$Request.post(`/app/Login/registerCode`, {
  185. userName: userName,
  186. password: password,
  187. phone: phone,
  188. openId: this.$queue.getData('openid') ? this.$queue.getData('openid') : '',
  189. inviterCode: this.invitation,
  190. platform: this.platform,
  191. msg: code
  192. }).then(res => {
  193. if (res.code === 0) {
  194. this.$queue.showToast('注册成功');
  195. this.$queue.setData("token", res.token);
  196. this.$queue.setData('userId', res.user.userId);
  197. this.$queue.setData('userName', res.user.userName);
  198. this.$queue.setData('phone', res.user.phone);
  199. this.$queue.setData('avatar', res.user.avatar?res.user.avatar: '../../static/logo.png');
  200. this.getUserInfo()
  201. setTimeout(function() {
  202. uni.switchTab({
  203. url:'/pages/index/index'
  204. })
  205. },1000)
  206. } else {
  207. uni.hideLoading();
  208. uni.showModal({
  209. showCancel: false,
  210. title: '注册失败',
  211. content: res.msg
  212. });
  213. }
  214. });
  215. }
  216. },
  217. //获取用户信息
  218. getUserInfo() {
  219. this.$Request.get("/app/user/selectUserById").then(res => {
  220. if (res.code == 0) {
  221. uni.hideLoading()
  222. this.$queue.setData('avatar', res.data.avatar?res.data.avatar:'../../static/logo.png');
  223. this.$queue.setData('userId', res.data.userId);
  224. this.$queue.setData('userName', res.data.userName);
  225. this.$queue.setData('phone', res.data.phone);
  226. this.$queue.setData("invitationCode", res.user.invitationCode);
  227. this.$queue.setData("inviterCode", res.user.inviterCode);
  228. this.userName = res.data.userName
  229. this.invitationCode = res.data.invitationCode
  230. uni.setStorageSync('invitationCode', res.data.invitationCode)
  231. setTimeout(function() {
  232. uni.switchTab({
  233. url:'/pages/index/index'
  234. })
  235. },1000)
  236. } else {
  237. uni.showModal({
  238. showCancel: false,
  239. title: '登录失败',
  240. content: res.msg
  241. });
  242. this.$queue.logout();
  243. }
  244. });
  245. }
  246. }
  247. };
  248. </script>
  249. <style lang="scss">
  250. .cu-form-group{
  251. background: #F6F6F6;
  252. }
  253. page {
  254. height: 100%;
  255. background: #FFFFFF !important;
  256. }
  257. .footer {
  258. padding-left: 140upx;
  259. margin-top: 32upx;
  260. text-align: center;
  261. display: flex;
  262. // color: #FFFFFF;
  263. }
  264. .send-msg {
  265. border-radius: 30px;
  266. color: #222;
  267. height: 30px;
  268. font-size: 10px;
  269. line-height: 30px;
  270. background: linear-gradient( 143deg, #FFE6EE 0%, #FF9AB2 100%);
  271. }
  272. .container {
  273. padding-top: 32upx;
  274. position: relative;
  275. width: 100%;
  276. height: 100%;
  277. overflow: hidden;
  278. background: #ffffff!important;
  279. }
  280. .wrapper {
  281. position: relative;
  282. z-index: 90;
  283. background: #ffffff;
  284. padding-bottom: 20px;
  285. }
  286. .input-content {
  287. padding: 32upx 80upx;
  288. }
  289. .confirm-btn {
  290. width: 582rpx;
  291. height: 100rpx;
  292. line-height: 100rpx;
  293. text-aligh:center;
  294. background: linear-gradient( 143deg, #FFE6EE 0%, #FF9AB2 100%);
  295. border-radius: 86rpx 86rpx 86rpx 86rpx;
  296. font-weight: bold;
  297. font-size: 32rpx;
  298. color: #222222;
  299. }
  300. </style>