sexAndAge.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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.setStorageSync('dateOfBirth', this.ageObj.year+'-'+this.ageObj.month+'-'+this.ageObj.day)
  136. uni.setStorageSync('gender', this.sex)
  137. uni.navigateTo({
  138. 'url':'/pages/perfect/nickname'
  139. })
  140. }else {
  141. tools.error('请完善信息')
  142. this.isShakeBut=true
  143. setTimeout(()=>{
  144. this.isShakeBut=false
  145. },500)
  146. }
  147. },
  148. verifyAge(){
  149. if(this.ageObj.year!=='' ){
  150. if(this.ageObj.year > this.maxYear || this.ageObj.year < this.mixYear){
  151. this.setShake()
  152. this.ageObj.year=''
  153. this.setFocus(1)
  154. }else {
  155. if(this.ageObj.month!=='' ){
  156. if( this.ageObj.month > 12 || this.ageObj.month < 1){
  157. this.setShake()
  158. this.ageObj.month=''
  159. this.ageObj.day=''
  160. this.setFocus(2)
  161. }else {
  162. this.maxDay=tools.getCountDays(this.ageObj.year+'-'+this.ageObj.month)
  163. if(this.ageObj.day!==''){
  164. if(this.ageObj.day > this.maxDay || this.ageObj.day < 1){
  165. this.setShake()
  166. this.ageObj.day=''
  167. this.setFocus(3)
  168. }else {
  169. this.age=this.ageObj.year+'-'+this.ageObj.month+'-'+this.ageObj.day
  170. }
  171. }else {
  172. this.age=''
  173. }
  174. }
  175. }else {
  176. this.age=''
  177. }
  178. }
  179. }else {
  180. this.age=''
  181. }
  182. },
  183. setShake(){
  184. this.isShake=true
  185. setTimeout(()=>{
  186. this.isShake=false
  187. },500)
  188. },
  189. setSex(sex){
  190. console.log(sex)
  191. uni.setStorageSync('sex', sex+'')
  192. this.sex=sex
  193. },
  194. verifyIsOK(){
  195. this.isOK = this.age!=='' && this.sex !== '';
  196. },
  197. setNavHeight(navHeight){
  198. this.navHeight=navHeight+41
  199. },
  200. }
  201. }
  202. </script>
  203. <style scoped lang="scss">
  204. @import "/static/css/shake.css";
  205. .sex-box{
  206. .login-top{
  207. padding:0 80rpx;
  208. margin-top: 80rpx;
  209. .login-title{
  210. .title-item{
  211. font-size: 48rpx;
  212. }
  213. }
  214. .sex-data{
  215. padding: 80rpx 64rpx;
  216. display: flex;
  217. justify-content: space-between;
  218. .sex-item{
  219. .item-img{
  220. width: 160rpx;
  221. height: 160rpx;
  222. position: relative;
  223. .sex-img-box{
  224. .sex-img{
  225. width: 160rpx;
  226. height: 160rpx;
  227. }
  228. }
  229. .ok-img-box{
  230. position: absolute;
  231. bottom: 0;
  232. right: 10rpx;
  233. .ok-img{
  234. width: 32rpx;
  235. height: 32rpx;
  236. }
  237. }
  238. }
  239. .item-text{
  240. width: 160rpx;
  241. height: 44rpx;
  242. line-height: 44rpx;
  243. text-align: center;
  244. font-size: 28rpx;
  245. }
  246. }
  247. }
  248. .age-data{
  249. margin-top: 32rpx;
  250. display: flex;
  251. justify-content: space-between;
  252. .age-item{
  253. display: flex;
  254. justify-content: flex-start;
  255. .age-input{
  256. height: 44rpx;
  257. margin-right: 24rpx;
  258. .input-one{
  259. width: 80rpx;
  260. }
  261. input{
  262. width: 40rpx;
  263. line-height: 44rpx;
  264. font-size: 32rpx;
  265. font-weight: 400;
  266. }
  267. input::placeholder{
  268. color: #BDBDBD;
  269. font-size: 32rpx;
  270. font-weight: 400;
  271. }
  272. }
  273. .age-text{
  274. font-size: 32rpx;
  275. font-weight: 400;
  276. line-height: 44rpx;
  277. height: 44rpx;
  278. }
  279. }
  280. }
  281. .local-txt{
  282. padding-top: 24rpx;
  283. font-size: 28rpx;
  284. text-align: left;
  285. }
  286. }
  287. .login-bottom{
  288. padding-bottom: calc(58rpx + env(safe-area-inset-bottom));
  289. position: absolute;
  290. bottom: 0;
  291. left: 68rpx;
  292. width:calc(100vw - 136rpx);
  293. .login-but{
  294. margin-top: 120rpx;
  295. }
  296. }
  297. }
  298. </style>