sexAndAge.vue 8.2 KB

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