sexAndAge.vue 7.1 KB

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