register.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <template>
  2. <view class="container edit_wrap">
  3. <view class="flex justify-between " style="padding: 40rpx 30rpx;;box-sizing: border-box;">
  4. <view class="" style="font-size: 38rpx;">
  5. <text class="text-bold text-black">注册认证</text>
  6. </view>
  7. <view class="text-red" style="padding-top: 12rpx;">
  8. <text style="font-size: 38rpx;">1</text>
  9. <text class="text-df">/3</text>
  10. </view>
  11. </view>
  12. <form>
  13. <view class="form_group">
  14. <text class="red">*</text>
  15. <text class="sex">姓名:</text>
  16. <input placeholder="请与物业登记处保持一致" placeholder-class="placeholder_style" type="text" class="placeholder_style" @input="nameInput">
  17. </input>
  18. </view>
  19. <view class="form_group">
  20. <text class="red">*</text>
  21. <text class="sex">手机:</text>
  22. <input placeholder="请与物业登记处保持一致" v-model="tel" placeholder-class="placeholder_style" type="number" maxlength="11" class="placeholder_style" >
  23. </input>
  24. </view>
  25. <view class="form_group">
  26. <text class="red">*</text>
  27. <text class="sex">验证码:</text>
  28. <input type="text" class="sendmsg_input" @input="verifyCodeInput"></input>
  29. <button class="right code_btn" @tap="sendMsgButton" :disabled="disabled" :style="'background-color:' + color">{{text}}</button>
  30. </view>
  31. <view style="display:flex;margin:20rpx 20rpx">
  32. <u-checkbox v-model="isCheck" active-color="blue">
  33. <navigator url="/pages/webview/webview"><text style="color:#5db5fe">请阅读并同意用户协议</text></navigator>
  34. </u-checkbox>
  35. </view>
  36. <view class="tips">
  37. <text style="padding-left: 40rpx;">认证后用户可享受更多权益,随时获取到您所在小区的动态</text>
  38. </view>
  39. <button open-type="getUserInfo" @getuserinfo="showDialogBtn" class=" footer-fixed" >
  40. <view class="cu-btn flex text-lg bg-red-btn" style="padding: 46rpx 0;">
  41. 确认
  42. </view>
  43. </button>
  44. </form>
  45. </view>
  46. </template>
  47. <script>
  48. //获取app实例
  49. var app = getApp();
  50. export default {
  51. data() {
  52. return {
  53. text: '获取验证码',
  54. //按钮文字
  55. currentTime: 61,
  56. //倒计时
  57. disabled: false,
  58. //按钮是否禁用
  59. name: null,
  60. //姓名
  61. tel: null,
  62. //获取到的手机栏中的值
  63. verify_code: null,
  64. //验证码
  65. isCheck: true,
  66. color: ""
  67. };
  68. },
  69. onLoad() {
  70. this.tel=this.$auth.getMineBase().user.mobile || ''
  71. },
  72. methods: {
  73. //获取姓名栏input中的值
  74. nameInput: function (e) {
  75. this.setData({
  76. name: e.detail.value
  77. });
  78. },
  79. //获取验证码栏input中的值
  80. verifyCodeInput: function (e) {
  81. this.setData({
  82. verify_code: e.detail.value
  83. });
  84. },
  85. //获取验证码按钮
  86. sendMsgButton: function () {
  87. let that = this;
  88. that.setData({
  89. disabled: true,
  90. //只要点击了按钮就让按钮禁用 (避免正常情况下多次触发定时器事件)
  91. color: '#ccc'
  92. });
  93. let name = that.name;
  94. let tel = that.tel; //把手机号跟倒计时值变例成js值
  95. let currentTime = that.currentTime; //warn为当手机号为空或格式不正确时提示用户的文字,默认为空
  96. let warn = null;
  97. if (name == null) {
  98. warn = "姓名不能为空";
  99. } else if (tel == null) {
  100. warn = "手机号码不能为空";
  101. } else if (tel.trim().length != 11 || !/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[189])\d{8}$/.test(tel)) {
  102. warn = "手机号格式不正确";
  103. } else {
  104. //发送短信
  105. that.sendMessage(); //设置一分钟的倒计时
  106. let interval = setInterval(function () {
  107. currentTime--; //每执行一次让倒计时秒数减一
  108. that.setData({
  109. text: currentTime + 's' //按钮文字变成倒计时对应秒数
  110. }); //如果当秒数小于等于0时 停止计时器 且按钮文字变成重新发送 且按钮变成可用状态 倒计时的秒数也要恢复成默认秒数 即让获取验证码的按钮恢复到初始化状态只改变按钮文字
  111. if (currentTime <= 0) {
  112. clearInterval(interval);
  113. that.setData({
  114. text: '重新发送',
  115. currentTime: 61,
  116. disabled: false,
  117. color: '#59a5f0'
  118. });
  119. }
  120. }, 1000);
  121. }; //判断 当提示错误信息文字不为空 即手机号输入有问题时提示用户错误信息 并且提示完之后一定要让按钮为可用状态 因为点击按钮时设置了只要点击了按钮就让按钮禁用的情况
  122. if (warn != null) {
  123. //自动关闭提示弹窗
  124. app.globalData.autoFailHint(warn);
  125. that.setData({
  126. disabled: false,
  127. color: '#59a5f0'
  128. });
  129. return;
  130. }
  131. ;
  132. },
  133. //确认
  134. showDialogBtn: function (e) {
  135. console.log(e);
  136. app.globalData.totalStep=3
  137. let that = this;
  138. let name = that.name;
  139. if (name == null) {
  140. //自动关闭提示弹窗
  141. app.globalData.autoFailHint("请填写姓名");
  142. return;
  143. }
  144. let tel = that.tel;
  145. if (tel == null) {
  146. //自动关闭提示弹窗
  147. app.globalData.autoFailHint("请输入手机号");
  148. return;
  149. }
  150. if (tel.trim().length != 11 || !/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/.test(tel)) {
  151. //自动关闭提示弹窗
  152. app.globalData.autoFailHint("请填写正确的手机号码");
  153. return;
  154. }
  155. let verify_code = that.verify_code;
  156. if (verify_code == null) {
  157. //自动关闭提示弹窗
  158. app.globalData.autoFailHint("请填写验证码");
  159. return;
  160. }
  161. if (!that.isCheck) {
  162. app.globalData.autoFailHint("请同意用户协议");
  163. return;
  164. } //注册
  165. //构建参数
  166. let params = {};
  167. params['name'] = name;
  168. params['tel'] = tel;
  169. params['verify_code'] = verify_code;
  170. params['create_type'] = 0;
  171. params['openid'] = uni.getStorageSync("openid");
  172. let operation = 'miniprogram/memberRegister';
  173. app.globalData.postRequest(params, operation, function (res) {
  174. //注册成功
  175. if (res.data.result_code == 1) {
  176. app.globalData.oneFailHint(res.data.result_msg, function () {
  177. //注册成功之后重新拉取一次会员信息
  178. let params = {};
  179. params['openid'] = uni.getStorageSync("openid");
  180. let operation = 'miniprogram/getMemberByOpenid';
  181. app.globalData.postRequest(params, operation, function (res) {
  182. console.info("getMemberByOpenid==" + res.data.result_msg); //获取成功
  183. if (res.data.result_code == 1) {
  184. let member = res.data.member;
  185. app.globalData.member = member; //未认证状态--提示去认证
  186. if (member.state == 0) {
  187. uni.redirectTo({
  188. url:"../auth/auth"
  189. })
  190. } else {
  191. uni.reLaunch({
  192. url: '/pages/index/index'
  193. });
  194. }
  195. } else {
  196. app.globalData.oneFailHint(res.data.result_msg);
  197. }
  198. });
  199. });
  200. } else {
  201. app.globalData.oneFailHint(res.data.result_msg);
  202. }
  203. });
  204. },
  205. //申请短信验证码
  206. sendMessage: function () {
  207. //构建参数
  208. let params = {};
  209. params['tel'] = this.tel;
  210. params['play_type'] = '2';
  211. let operation = 'member/getSmsCode';
  212. app.globalData.postRequest(params, operation, function (res) {
  213. //短信发送成功
  214. if (res.data.result_code == 1) {
  215. app.globalData.autoFailHint(res.data.result_msg);
  216. } else {
  217. app.globalData.oneFailHint(res.data.result_msg);
  218. }
  219. });
  220. }
  221. }
  222. };
  223. </script>
  224. <style lang="scss">
  225. page {
  226. background: #fff;
  227. }
  228. .edit_wrap {
  229. font-size: 30rpx;
  230. padding: 0rpx 20rpx 20rpx;
  231. color: #333;
  232. }
  233. .form_group {
  234. display: flex;
  235. flex-direction: row;
  236. justify-content: space-between;
  237. margin: 20rpx 20rpx;
  238. line-height: 100rpx;
  239. position: relative;
  240. font-size: 26rpx;
  241. border-bottom: 2rpx solid #ddd;
  242. }
  243. .form_group .item {
  244. text-align: right;
  245. line-height: 80rpx;
  246. }
  247. .form_group .red {
  248. color: red;
  249. position: absolute;
  250. left: 0;
  251. }
  252. .form_group text.sex {
  253. margin-left: 15px;
  254. text-align: right;
  255. }
  256. .form_group .radio-group {
  257. text-align: left;
  258. }
  259. .form_group input, .form_group picker {
  260. width: 500rpx;
  261. border-radius: 8rpx;
  262. height: 100rpx;
  263. line-height: 100rpx;
  264. padding: 0rpx 20rpx;
  265. color: #333;
  266. box-sizing: border-box;
  267. position: relative;
  268. z-index: 1;
  269. }
  270. .form_group button {
  271. font-size: 24rpx;
  272. background: $base-btn-color;
  273. margin:10rpx 0 0 10rpx;
  274. color: #fff;
  275. }
  276. .form_group .sendmsg_input {
  277. width: 340rpx;
  278. margin-left: 36rpx;
  279. }
  280. .tips {
  281. padding: 0 10rpx;
  282. text-align: center;
  283. font-size: 24rpx;
  284. color: #999;
  285. margin-top: 20rpx;
  286. }
  287. .placeholder_style {
  288. font-family: '微软雅黑';
  289. color: #adadad;
  290. font-size: 26rpx;
  291. }
  292. .save_btn {
  293. width: 600rpx;
  294. background: #d24a58;
  295. font-size: 32rpx;
  296. color: #fff;
  297. border-radius: 0rpx;
  298. margin: 40rpx 0rpx 10rpx;
  299. }
  300. .code_btn {
  301. width: 150rpx;
  302. background: $base-btn-color;
  303. height: 60rpx;
  304. line-height: 60rpx;
  305. text-align: center;
  306. border-radius: 10rpx;
  307. color: #fff;
  308. font-size: 33rpx;
  309. padding: 0 10rpx;
  310. }
  311. .password_contet image {
  312. width: 48rpx;
  313. height: 48rpx;
  314. position: absolute;
  315. left: 50%;
  316. top: 50%;
  317. transform: translate(-50%, -50%);
  318. }
  319. .password_contet {
  320. position: absolute;
  321. right: 0;
  322. top: 50%;
  323. transform: translate(0, -50%);
  324. width: 80rpx;
  325. height: 80rpx;
  326. z-index: 999;
  327. }
  328. checkbox .wx-checkbox-input {
  329. width: 34rpx;
  330. height: 34rpx;
  331. }
  332. checkbox .wx-checkbox-input.wx-checkbox-input-checked::before {
  333. color: $base-btn-color;
  334. }
  335. </style>