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