register.vue 12 KB

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