Commit 7853cd3393e1818e949c7d97260acdb54e02e7d3
1 parent
a1d00f34
生日日期输入优化
Showing
2 changed files
with
72 additions
and
9 deletions
packageA/pages/profile/profile.js
| ... | ... | @@ -77,7 +77,7 @@ Page({ |
| 77 | 77 | lat: null, //维度 |
| 78 | 78 | lon: null, //经度 |
| 79 | 79 | loading: 0, |
| 80 | - | |
| 80 | + oldBirtthDayLength:0, //生日日期个数 | |
| 81 | 81 | }, |
| 82 | 82 | //通过路径跳转到其他页面 |
| 83 | 83 | goto: function (e) { |
| ... | ... | @@ -1126,20 +1126,81 @@ Page({ |
| 1126 | 1126 | let address = this.getInput(e); |
| 1127 | 1127 | this.data.address = address; |
| 1128 | 1128 | }, |
| 1129 | - | |
| 1129 | + //获取生日 | |
| 1130 | + getbind(e) { | |
| 1131 | + console.log("获取生日222222222"); | |
| 1132 | + console.log(e); | |
| 1133 | + let b = this.getInput(e); | |
| 1134 | + let length = b.length; | |
| 1135 | + let oldBirtthDayLength=this.data.oldBirtthDayLength | |
| 1136 | + if (length > oldBirtthDayLength) { | |
| 1137 | + if (b.length==4) { | |
| 1138 | + b+='-' | |
| 1139 | + } | |
| 1140 | + if (b.length==7) { | |
| 1141 | + b+='-' | |
| 1142 | + } | |
| 1143 | + // if (b.length==6 && b[5] >1) { | |
| 1144 | + // console.log(b[5]); | |
| 1145 | + | |
| 1146 | + // } | |
| 1147 | + } | |
| 1148 | + this.setData({ | |
| 1149 | + datet: b, | |
| 1150 | + oldBirtthDayLength:length, | |
| 1151 | + }); | |
| 1152 | + }, | |
| 1130 | 1153 | //获取生日 |
| 1131 | 1154 | bindChange: function (e) { |
| 1155 | + console.log("获取生日11111111"); | |
| 1156 | + console.log(e); | |
| 1132 | 1157 | let strBirthday = e.detail.value; |
| 1133 | 1158 | let age = this.verifyBirthday(strBirthday); |
| 1134 | 1159 | |
| 1135 | 1160 | if (age <= 10) { |
| 1136 | 1161 | app.my_warnning("会员年龄不能小于10岁(含10岁)", 0, this); |
| 1162 | + this.setData({ | |
| 1163 | + datet: '', | |
| 1164 | + }); | |
| 1137 | 1165 | } else if (age >= 70) { |
| 1138 | 1166 | app.my_warnning("会员年龄不能超过70岁(含70岁)", 0, this); |
| 1139 | - } else { | |
| 1140 | 1167 | this.setData({ |
| 1141 | - datet: e.detail.value, | |
| 1142 | - }); | |
| 1168 | + datet: '', | |
| 1169 | + }); | |
| 1170 | + } else { | |
| 1171 | + let value = e.detail.value | |
| 1172 | + | |
| 1173 | + if (value.length==8) { | |
| 1174 | + value+='01' | |
| 1175 | + } | |
| 1176 | + if (value.length==7) { | |
| 1177 | + value+='-01' | |
| 1178 | + } | |
| 1179 | + if (value.length==9) { | |
| 1180 | + let ov=value[value.length-1] | |
| 1181 | + let nv=value.slice(0,-1) | |
| 1182 | + if (ov==0) { | |
| 1183 | + nv+='01' | |
| 1184 | + }else{ | |
| 1185 | + nv+='0'+ov | |
| 1186 | + } | |
| 1187 | + value=nv | |
| 1188 | + } | |
| 1189 | + // let reg= /^(\d{4})-(\d{2})-(\d{2})$/; | |
| 1190 | + let reg= /^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/ | |
| 1191 | + console.log('日期验证'); | |
| 1192 | + console.log(value); | |
| 1193 | + console.log(reg.test(value)); | |
| 1194 | + if (reg.test(value)) { | |
| 1195 | + this.setData({ | |
| 1196 | + datet: value, | |
| 1197 | + }); | |
| 1198 | + }else{ | |
| 1199 | + app.my_warnning("出生日期格式不对", 0, this); | |
| 1200 | + this.setData({ | |
| 1201 | + datet: '', | |
| 1202 | + }); | |
| 1203 | + } | |
| 1143 | 1204 | } |
| 1144 | 1205 | |
| 1145 | 1206 | }, | ... | ... |
packageA/pages/profile/profile.wxml
| ... | ... | @@ -90,14 +90,16 @@ |
| 90 | 90 | <view class="shrink0">出生日期:</view> |
| 91 | 91 | <view class="flex fs28 Birth pdl20 jc_fe"> |
| 92 | 92 | <view class="user-txt-right pdl20 flex ai-center"> |
| 93 | - <checkbox-group bindchange="isLunar"> | |
| 93 | + <input bindinput="getbind" bindblur="bindChange" maxlength="10" type="number" value="{{datet}}" class="user-txt-right pdl20 f1 t-r" placeholder="请输入出生日期"></input> | |
| 94 | + <picker class="pdl20" bindchange='bindChange' mode="date" start="{{year-70}}-1-1" end="{{year}}-12-31"> | |
| 95 | + <!-- <view class="flex ai-center">{{datet?datet:"请选择时间"}}<view class="angle">∟</view></view> --> | |
| 96 | + <image src="{{iurl}}/miniapp/images/calendar.png" style="width: 40rpx;height: 40rpx;"></image> | |
| 97 | + </picker> | |
| 98 | + <checkbox-group bindchange="isLunar" class="pdl20"> | |
| 94 | 99 | <label class="flex ai-center"> |
| 95 | 100 | <checkbox value="{{isLunar}}" checked="{{isLunar}}"/>农历 |
| 96 | 101 | </label> |
| 97 | 102 | </checkbox-group> |
| 98 | - <picker class="pdl20" bindchange='bindChange' mode="date" start="{{year-70}}-1-1" end="{{year}}-12-31"> | |
| 99 | - <view class="flex ai-center">{{datet?datet:"请选择时间"}}<view class="angle">∟</view></view> | |
| 100 | - </picker> | |
| 101 | 103 | |
| 102 | 104 | |
| 103 | 105 | </view> | ... | ... |