sexAndAge.vue 8.4 KB

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