sexAndAge.vue 8.2 KB

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