| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- <template>
- <view class="container">
- <view class="login-wrap">
- <view class="login-form">
- <u--form
- labelPosition="left"
- :model="userInfo"
- :rules="rules"
- ref="form1"
- >
- <u-form-item
- label="手机号"
- prop="phonenumber"
- labelWidth="auto"
- labelAlign="right"
- >
- <u--input
- v-model="userInfo.phonenumber"
- placeholder="请输入手机号"
- border="bottom"
- type="number"
- maxlength="11"
- ></u--input>
- </u-form-item>
- <u-form-item
- labelWidth="auto"
- labelAlign="right"
- label="验证码"
- prop="smsCode"
- width="120"
- >
- <u--input
- v-model="userInfo.smsCode"
- disabledColor="#ffffff"
- placeholder="请输入验证码"
- border="bottom"
- maxlength="4"
- ></u--input>
- <template #right>
- <view class="identifying-code">
- <u-code
- ref="uCode2"
- @change="codeChange2"
- keep-running
- start-text="获取验证码"
- ></u-code>
- <text
- @tap="getCode2"
- :text="tips2"
- class="u-page__code-text"
- >{{tips2}}</text>
- </view>
- </template>
- </u-form-item>
- </u--form>
- </view>
- </view>
- <view v-if="errTipShow" class="h-err">
- <text>你输入的手机号码已存在,请换一个</text>
- </view>
- <view @click="setPhone()" class="op-btn-wrap">
- <view class="h-btn">
- <text>确定</text>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- errTipShow: false,
- errShow: false,
- userInfo: {
- auth: true,
- phonenumber: '',
- phone: '',
- smsCode: '',
- openId: '',
- password: "",
- transactionPassword: "",
- reference: "",
- type: '' // 实名认证创建新账号
- },
- tips2: '',
- rules: {
- phonenumber: [
- {
- required: true,
- min: 10,
- max: 12,
- message: '请输入11位电话号码',
- trigger: ['blur', 'change'],
- },
- {
- // 此为同步验证,可以直接返回true或者false,如果是异步验证,稍微不同,见下方说明
- validator: (rule, value, callback) => {
- // 调用uView自带的js验证规则,详见:https://www.uviewui.com/js/test.html
- return !this.$isDataEmpty(value);
- },
- message: "请认真填写电话号码",
- trigger: ['blur', 'change'],
- }
- ],
- smsCode: {
- required: true,
- min: 4,
- max: 6,
- message: '请输入4位验证码',
- trigger: ['blur', 'change'],
- },
- },
- }
- },
- onLoad(option) {
- },
- onReady() {
- this.$refs.form1.setRules(this.rules)
- },
- methods: {
- // 验证电话号码是否存在
- saveSetPhoneData(){
- let that = this;
- // 验证电话号码是否存在
- setPhone(null,{data:this.userInfo}).then((res)=>{
- uni.showToast({
- title: '绑定成功'
- })
- setTimeout(function() {
- // 选择完成后返回上一页
- uni.navigateBack({
- delta: 1,
- success: function(res) {
- console.log('返回成功');
- }
- });
- }, 2000); // 延迟2秒执行
- }).catch(() =>{
- uni.showToast({
- title: "操作失败"
- })
- });
- },
- // 去绑定账号密码页面
- setPhone(){
- let that = this;
- this.$refs.form1.validate().then(res => {
- that.saveSetPhoneData();
- }).catch(errors => {
- uni.$u.toast('校验失败,请认真填写')
- })
- },
- codeChange2(text) {
- this.tips2 = text;
- },
- getCode2() {
- let that = this;
- if (this.$refs.uCode2.canGetCode) {
- that.getSmsCode();
- } else {
- uni.$u.toast('倒计时结束后再发送');
- }
- },
- // 获取手机验证码
- getSmsCode(){
- let that = this;
- if(this.$isDataEmpty(this.userInfo.phonenumber)){
- uni.$u.toast('请认真填写手机号');
- return;
- }
- // 验证电话号码是否存在
- phoneIsExist(null,{data:this.userInfo}).then((res)=>{
- if(res.phoneIsExist){ // 存在
- that.errTipShow = true;
- setTimeout(() => {
- that.errTipShow = false;
- // 在这里编写延迟执行的代码
- that.userInfo.phonenumber = null;
- }, 3000);
- } else {
- that.getPhoneCode();
- }
- }).catch(() =>{
- uni.showToast({
- title: "操作失败",
- duration: 3000
- })
- });
- },
- // 获取验证码
- getPhoneCode(){
- let that = this;
- // 模拟向后端请求验证码
- uni.showLoading({
- title: '正在获取验证码'
- })
- getSmsCode({data:{phonenumber:this.userInfo.phonenumber,auth: true}}).then((res)=>{
- uni.hideLoading();
- // 这里此提示会被this.start()方法中的提示覆盖
- uni.$u.toast('验证码已发送');
- // 通知验证码组件内部开始倒计时
- that.$refs.uCode2.start();
- }).catch(() =>{
- uni.showToast({
- title: "操作失败"
- })
- });
- },
- }
- }
- </script>
- <style lang="scss">
- page,body{
- background: #fff;
- }
- .h-err{
- color: red;
- text-align: center;
- font-size: 14px;
- }
- .h-popo-content{
- height: 170px;
- padding: 12px;
- width: 300px;
- text-align: center;
- font-size: 14px;
- font-family: PingFangSC-Semibold, PingFang SC;
- .h-img{
- display: flex;
- justify-content: center;
- }
- .h-text{
- margin-top: 12px;
- font-weight: 400;
- color: #666666;
- }
- .text{
- margin-top: 6px;
- font-weight: 400;
- color: #666666;
- }
- .h-btn-wrap{
- display: flex;
- justify-content: space-between;
- color: #333333;
- text-align: center;
- margin-top: 14px;
- .h-left-btn{
- height: 32px;
- line-height: 30px;
- background: #EEEEEE;
- width: 100px;
- text-align: center;
- border-radius: 16px;
- margin: 0 auto;
- }
- .h-right-btn{
- height: 32px;
- line-height: 30px;
- background: #FFE05C;
- width: 100px;
- border-radius: 16px;
- margin: 0 auto;
- }
- }
- }
- .container{
- background: #fff;
- height: 300px;
- .login-wrap {
- display: flex;
- justify-content: center;
- .login-form{
- width: 90%;
- }
- .account{
- display: flex;
- }
- .identifying-code{
- }
- }
- .op-btn-wrap{
- margin-top: 30px;
- display: flex;
- justify-content: center;
- align-items: center;
- .h-btn{
- text-align: center;
- width: 343px;
- height: 42px;
- background: #FFE05C;
- border-radius: 27px;
- line-height: 42px;
- }
- }
- }
- </style>
|