sexAndAge.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <view class="sex-box">
  3. <en-nav @navHeight="setNavHeight" ></en-nav>
  4. <view class="login-box" :style="{'height':'calc(100vh - '+navHeight+'px)'}">
  5. <view class="login-top">
  6. <view class="login-title">
  7. <text class="title-item sys-color-black sys-weight-600">性别&年龄</text>
  8. </view>
  9. <view class="local-txt sys-color-gray-9">注册完成,您的性别将无法修改</view>
  10. <view class="sex-data" >
  11. <view class="sex-item" @click="setSex(1)">
  12. <view class="item-img">
  13. <view class="sex-img-box">
  14. <image class="sex-img" :src="'/static/img/perfect/boy-'+(sex===1?'ok':'no')+'.png'" mode="aspectFill"></image>
  15. </view>
  16. <view class="ok-img-box">
  17. <image class="ok-img" :src="'/static/img/common/'+(sex===1?'ok':'no')+'.png'" mode="aspectFill"></image>
  18. </view>
  19. </view>
  20. <view class="item-text sys-color-gray-9">我是男生</view>
  21. </view>
  22. <view class="sex-item" @click="setSex(2)">
  23. <view class="item-img">
  24. <view class="sex-img-box">
  25. <image class="sex-img" :src="'/static/img/perfect/girl-'+(sex===2?'ok':'no')+'.png'" mode="aspectFill"></image>
  26. </view>
  27. <view class="ok-img-box">
  28. <image class="ok-img" :src="'/static/img/common/'+(sex===2?'ok':'no')+'.png'" mode="aspectFill"></image>
  29. </view>
  30. </view>
  31. <view class="item-text sys-color-gray-9">我是女生</view>
  32. </view>
  33. </view>
  34. <view class="local-txt sys-color-gray-9">设置生日(年龄大于18岁)</view>
  35. <view class="age-data" :class="{'apply-shake':isShake}" >
  36. <view class="age-item">
  37. <view class="age-input">
  38. <input class="input-one" :focus="yearFocus" v-model="ageObj.year" type="number" :min="mixYear" :max="maxYear" placeholder="1999" @blur="verifyAge"></input>
  39. </view>
  40. <view class="age-text sys-color-black">年</view>
  41. </view>
  42. <view class="age-item">
  43. <view class="age-input">
  44. <input type="number" :focus="monthFocus" v-model="ageObj.month" min="1" max="12" placeholder="01" @blur="verifyAge"></input>
  45. </view>
  46. <view class="age-text sys-color-black">月</view>
  47. </view>
  48. <view class="age-item">
  49. <view class="age-input">
  50. <input type="number" :focus="dayFocus" v-model="ageObj.day" min="1943" max="2006" placeholder="01" @blur="verifyAge"></input>
  51. </view>
  52. <view class="age-text sys-color-black">日</view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <view class="login-bottom">
  58. <view class="login-but sys-color-white sys-background-black sys-selected-but" @click="setNextStep"
  59. :class="{'sys-unselected-but':!isOK,'apply-shake':isShakeBut}">下一步</view>
  60. </view>
  61. </view>
  62. </template>
  63. <script>
  64. import EnNav from "@/components/en-utils/en-nav/en-nav";
  65. import tools from "@/service/tools";
  66. import $ from 'jquery'
  67. export default {
  68. components: {EnNav},
  69. data() {
  70. return {
  71. navHeight:40,
  72. isOK:false,
  73. isShake:false,
  74. isShakeBut:false,
  75. age:'',
  76. sex:'',
  77. ageObj:{
  78. year:'',
  79. month:'',
  80. day:'',
  81. },
  82. yearFocus:false,
  83. monthFocus:false,
  84. dayFocus:false,
  85. mixYear:2003,
  86. maxYear:2003,
  87. placeholderYear:1990,
  88. maxDay:31,
  89. }
  90. },
  91. onLoad(query) {
  92. let year=tools.getYear()
  93. this.mixYear=year-80
  94. this.maxYear=year-18
  95. this.placeholderYear=year-24
  96. },
  97. watch:{
  98. 'age':function (){
  99. this.verifyIsOK()
  100. },
  101. 'sex':function (){
  102. this.verifyIsOK()
  103. },
  104. 'ageObj.year':function (){
  105. if(this.ageObj.year.length>=4){
  106. this.setFocus(2)
  107. }
  108. },
  109. 'ageObj.month':function (){
  110. if(this.ageObj.month.length>=2){
  111. this.setFocus(3)
  112. }
  113. },
  114. 'ageObj.day':function (){
  115. if(this.ageObj.day.length>=2){
  116. this.setFocus(0)
  117. }
  118. },
  119. },
  120. methods: {
  121. setFocus(type){
  122. this.yearFocus=false
  123. this.monthFocus=false
  124. this.dayFocus=false
  125. if(type===1){
  126. this.yearFocus=true
  127. }else if(type===2){
  128. this.monthFocus=true
  129. }else if(type===3){
  130. this.dayFocus=true
  131. }
  132. },
  133. setNextStep(){
  134. if(this.isOK){
  135. uni.navigateTo({
  136. 'url':'/pages/perfect/nickname'
  137. })
  138. }else {
  139. tools.error('请完善信息')
  140. this.isShakeBut=true
  141. setTimeout(()=>{
  142. this.isShakeBut=false
  143. },500)
  144. }
  145. },
  146. verifyAge(){
  147. if(this.ageObj.year!=='' ){
  148. if(this.ageObj.year > this.maxYear || this.ageObj.year < this.mixYear){
  149. this.setShake()
  150. this.ageObj.year=''
  151. this.setFocus(1)
  152. }else {
  153. if(this.ageObj.month!=='' ){
  154. if( this.ageObj.month > 12 || this.ageObj.month < 1){
  155. this.setShake()
  156. this.ageObj.month=''
  157. this.ageObj.day=''
  158. this.setFocus(2)
  159. }else {
  160. this.maxDay=tools.getCountDays(this.ageObj.year+'-'+this.ageObj.month)
  161. if(this.ageObj.day!==''){
  162. if(this.ageObj.day > this.maxDay || this.ageObj.day < 1){
  163. this.setShake()
  164. this.ageObj.day=''
  165. this.setFocus(3)
  166. }else {
  167. this.age=this.ageObj.year+'-'+this.ageObj.month+'-'+this.ageObj.day
  168. }
  169. }else {
  170. this.age=''
  171. }
  172. }
  173. }else {
  174. this.age=''
  175. }
  176. }
  177. }else {
  178. this.age=''
  179. }
  180. },
  181. setShake(){
  182. this.isShake=true
  183. setTimeout(()=>{
  184. this.isShake=false
  185. },500)
  186. },
  187. setSex(sex){
  188. this.sex=sex
  189. },
  190. verifyIsOK(){
  191. this.isOK = this.age!=='' && this.sex !== '';
  192. },
  193. setNavHeight(navHeight){
  194. this.navHeight=navHeight+41
  195. },
  196. }
  197. }
  198. </script>
  199. <style scoped lang="scss">
  200. @import "/static/css/shake.css";
  201. .sex-box{
  202. .login-top{
  203. padding:0 80rpx;
  204. margin-top: 80rpx;
  205. .login-title{
  206. .title-item{
  207. font-size: 48rpx;
  208. }
  209. }
  210. .sex-data{
  211. padding: 80rpx 64rpx;
  212. display: flex;
  213. justify-content: space-between;
  214. .sex-item{
  215. .item-img{
  216. width: 160rpx;
  217. height: 160rpx;
  218. position: relative;
  219. .sex-img-box{
  220. .sex-img{
  221. width: 160rpx;
  222. height: 160rpx;
  223. }
  224. }
  225. .ok-img-box{
  226. position: absolute;
  227. bottom: 0;
  228. right: 10rpx;
  229. .ok-img{
  230. width: 32rpx;
  231. height: 32rpx;
  232. }
  233. }
  234. }
  235. .item-text{
  236. width: 160rpx;
  237. height: 44rpx;
  238. line-height: 44rpx;
  239. text-align: center;
  240. font-size: 28rpx;
  241. }
  242. }
  243. }
  244. .age-data{
  245. margin-top: 32rpx;
  246. display: flex;
  247. justify-content: space-between;
  248. .age-item{
  249. display: flex;
  250. justify-content: flex-start;
  251. .age-input{
  252. height: 44rpx;
  253. margin-right: 24rpx;
  254. .input-one{
  255. width: 80rpx;
  256. }
  257. input{
  258. width: 40rpx;
  259. line-height: 44rpx;
  260. font-size: 32rpx;
  261. font-weight: 400;
  262. }
  263. input::placeholder{
  264. color: #BDBDBD;
  265. font-size: 32rpx;
  266. font-weight: 400;
  267. }
  268. }
  269. .age-text{
  270. font-size: 32rpx;
  271. font-weight: 400;
  272. line-height: 44rpx;
  273. height: 44rpx;
  274. }
  275. }
  276. }
  277. .local-txt{
  278. padding-top: 24rpx;
  279. font-size: 28rpx;
  280. text-align: left;
  281. }
  282. }
  283. .login-bottom{
  284. padding-bottom: calc(58rpx + env(safe-area-inset-bottom));
  285. position: absolute;
  286. bottom: 0;
  287. left: 68rpx;
  288. width:calc(100vw - 136rpx);
  289. .login-but{
  290. margin-top: 120rpx;
  291. }
  292. }
  293. }
  294. </style>