register.vue 10 KB

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