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