sexAndAge.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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" 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" 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" 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" :class="{'sys-unselected-but':!isOK}">登录</view>
  59. </view>
  60. </view>
  61. </template>
  62. <script>
  63. import EnNav from "@/components/en-utils/en-nav/en-nav";
  64. import tools from "@/service/tools";
  65. export default {
  66. components: {EnNav},
  67. data() {
  68. return {
  69. navHeight:40,
  70. isOK:false,
  71. isShake:false,
  72. age:'',
  73. sex:'',
  74. ageObj:{
  75. year:'',
  76. month:'',
  77. day:'',
  78. },
  79. mixYear:2003,
  80. maxYear:2003,
  81. placeholderYear:1990,
  82. maxDay:31,
  83. }
  84. },
  85. onLoad(query) {
  86. let year=tools.getYear()
  87. this.mixYear=year-80
  88. this.maxYear=year-18
  89. this.placeholderYear=year-24
  90. },
  91. watch:{
  92. 'age':function (){
  93. this.verifyIsOK()
  94. },
  95. 'sex':function (){
  96. this.verifyIsOK()
  97. },
  98. },
  99. methods: {
  100. verifyAge(){
  101. if(this.ageObj.year!=='' ){
  102. if(this.ageObj.year > this.maxYear || this.ageObj.year < this.mixYear){
  103. this.setShake()
  104. this.ageObj.year=''
  105. }else {
  106. if(this.ageObj.month!=='' ){
  107. if(this.ageObj.month > 12 || this.ageObj.month < 1){
  108. this.setShake()
  109. this.ageObj.month=''
  110. this.ageObj.day=''
  111. }else {
  112. this.maxDay=tools.getCountDays(this.ageObj.year+'-'+this.ageObj.month)
  113. if(this.ageObj.day!==''){
  114. if(this.ageObj.day > this.maxDay || this.ageObj.day < 1){
  115. this.setShake()
  116. this.ageObj.day=''
  117. }else {
  118. this.age=this.ageObj.year+'-'+this.ageObj.month+'-'+this.ageObj.day
  119. }
  120. }
  121. }
  122. }
  123. }
  124. }
  125. },
  126. setShake(){
  127. this.isShake=true
  128. setTimeout(()=>{
  129. this.isShake=false
  130. },500)
  131. },
  132. setSex(sex){
  133. this.sex=sex
  134. },
  135. verifyIsOK(){
  136. this.isOK = this.age!=='' && this.sex !== '';
  137. },
  138. setNavHeight(navHeight){
  139. this.navHeight=navHeight+41
  140. },
  141. }
  142. }
  143. </script>
  144. <style scoped lang="scss">
  145. @import "/static/css/shake.css";
  146. .sex-box{
  147. padding: 82rpx 80rpx 0 80rpx;
  148. box-sizing: border-box;
  149. .login-top{
  150. .login-title{
  151. .title-item{
  152. font-size: 48rpx;
  153. }
  154. }
  155. .sex-data{
  156. padding: 80rpx 64rpx;
  157. display: flex;
  158. justify-content: space-between;
  159. .sex-item{
  160. .item-img{
  161. width: 160rpx;
  162. height: 160rpx;
  163. position: relative;
  164. .sex-img-box{
  165. .sex-img{
  166. width: 160rpx;
  167. height: 160rpx;
  168. }
  169. }
  170. .ok-img-box{
  171. position: absolute;
  172. bottom: 0;
  173. right: 10rpx;
  174. .ok-img{
  175. width: 32rpx;
  176. height: 32rpx;
  177. }
  178. }
  179. }
  180. .item-text{
  181. width: 160rpx;
  182. height: 44rpx;
  183. line-height: 44rpx;
  184. text-align: center;
  185. font-size: 28rpx;
  186. }
  187. }
  188. }
  189. .age-data{
  190. margin-top: 32rpx;
  191. display: flex;
  192. justify-content: space-between;
  193. .age-item{
  194. display: flex;
  195. justify-content: flex-start;
  196. .age-input{
  197. height: 44rpx;
  198. margin-right: 24rpx;
  199. .input-one{
  200. width: 80rpx;
  201. }
  202. input{
  203. width: 40rpx;
  204. line-height: 44rpx;
  205. font-size: 32rpx;
  206. font-weight: 400;
  207. }
  208. input::placeholder{
  209. color: #BDBDBD;
  210. font-size: 32rpx;
  211. font-weight: 400;
  212. }
  213. }
  214. .age-text{
  215. font-size: 32rpx;
  216. font-weight: 400;
  217. line-height: 44rpx;
  218. height: 44rpx;
  219. }
  220. }
  221. }
  222. .local-txt{
  223. padding-top: 24rpx;
  224. font-size: 28rpx;
  225. text-align: left;
  226. }
  227. }
  228. .login-bottom{
  229. padding-bottom: calc(58rpx + env(safe-area-inset-bottom));
  230. position: absolute;
  231. bottom: 0;
  232. left: 68rpx;
  233. width:calc(100vw - 136rpx);
  234. .login-but{
  235. margin-top: 120rpx;
  236. }
  237. }
  238. }
  239. </style>