register.vue 12 KB

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