picker-view-set.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <view class="zhezhao" v-show="shixian">
  3. <view class="xuanzeqi">
  4. <view class="quxiaoqueren">
  5. <view class="quniu" @click="quxiaobutton">取消</view>
  6. <view class="queniu" @click="quedingbutton">确定</view>
  7. </view>
  8. <picker-view v-if="visible" class="shigun" :indicator-style="indicatorStyle" :value="values" @change="bindChange">
  9. <picker-view-column>
  10. <view class="itemd" v-for="(item,index) in years" :key="index">{{item}}年</view>
  11. </picker-view-column>
  12. <picker-view-column>
  13. <view class="itemd" v-for="(item,index1) in months" :key="index1">{{item > 9 ? item : '0' + item}}月</view>
  14. </picker-view-column>
  15. <picker-view-column>
  16. <view class="itemd" v-for="(item,index2) in days" :key="index2">{{item > 9 ? item : '0' + item}}日</view>
  17. </picker-view-column>
  18. </picker-view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. props: {
  25. shixian : Boolean
  26. },
  27. data() {
  28. const date = new Date();
  29. const years = [];
  30. const year = date.getFullYear()
  31. const months = []
  32. let month = date.getMonth() + 1
  33. const days = []
  34. let day = date.getDate()
  35. for (let i = 1940; i <= date.getFullYear(); i++) {
  36. years.push(i)
  37. }
  38. for (let i = 1; i <= 12; i++) {
  39. months.push(i)
  40. }
  41. for (let i = 1; i <= 31; i++) {
  42. days.push(i)
  43. }
  44. return {
  45. title: 'picker-view',
  46. years,
  47. year,
  48. months,
  49. month,
  50. days,
  51. day,
  52. values: [],
  53. visible: true,
  54. indicatorStyle: `height: ${Math.round(uni.getSystemInfoSync().screenWidth/(750/100))}px;`
  55. };
  56. },
  57. methods: {
  58. confirm(value){
  59. var dates = value.split("-");
  60. this.values[0] = dates[0] - 1940;
  61. this.values[1] = dates[1] - 1;
  62. this.values[2] = dates[2] - 1;
  63. this.year = dates[0];
  64. this.month = dates[1];
  65. this.day = dates[2];
  66. },
  67. bindChange: function (e) {
  68. const val = e.detail.value
  69. if( val.length > 0 ){
  70. this.year = this.years[val[0]]
  71. // this.month = this.months[val[1]] > 9 ? this.month : '0' + this.months[val[1]];
  72. if (this.months[val[1]] > 9) {
  73. this.month = this.months[val[1]];
  74. }else{
  75. this.month = '0' + this.months[val[1]];
  76. }
  77. // this.day = this.days[val[2]] > 9 ? this.month : '0' + this.days[val[2]];
  78. if (this.days[val[2]] > 9) {
  79. this.day = this.days[val[2]];
  80. }else{
  81. this.day = '0' + this.days[val[2]];
  82. }
  83. }
  84. },
  85. quxiaobutton () {
  86. this.values = [9999, this.month - 1, this.day - 1];
  87. this.$emit('quxiaoButton');
  88. },
  89. quedingbutton () {
  90. this.values = [9999, this.month - 1, this.day - 1];
  91. console.log(this.year,this.month,this.day)
  92. this.$emit('quedingButton',this.year,this.month,this.day);
  93. }
  94. }
  95. }
  96. </script>
  97. <style lang="scss" scoped>
  98. .zhezhao{
  99. position: fixed;
  100. width: 100%;
  101. height: 100%;
  102. top: 0upx;
  103. right: 0upx;
  104. bottom: 0upx;
  105. left: 0upx;
  106. -webkit-transition: 0.15s;
  107. background: rgba(0,0,0,.5);
  108. z-index: 10;
  109. }
  110. .xuanzeqi{
  111. width: 100%;
  112. background-color: #FFF;
  113. height: 500upx;
  114. position: absolute;
  115. bottom: 0upx;
  116. left: 0upx;
  117. z-index: 20;
  118. display: block;
  119. }
  120. .quxiaoqueren{
  121. height: 80upx;
  122. width: 100%;
  123. display: block;
  124. border-bottom: 1px solid #D8D8D8;
  125. position: relative;
  126. top: 0upx;
  127. left: 0upx;
  128. }
  129. .quniu{
  130. width: 80upx;
  131. border-radius: 6upx;
  132. height:50upx;
  133. line-height: 50upx;
  134. text-align: center;
  135. color: #000;
  136. float: left;
  137. margin-left: 20upx;
  138. font-size: 30upx;
  139. display: block;
  140. margin-top: 15upx;
  141. }
  142. .queniu{
  143. width: 80upx;
  144. border-radius: 6upx;
  145. height:50upx;
  146. line-height: 50upx;
  147. background-color: #19B955;
  148. text-align: center;
  149. color: #FFF;
  150. float: right;
  151. display: block;
  152. font-size: 30upx;
  153. margin-right: 20upx;
  154. margin-top: 15upx;
  155. }
  156. .shigun{
  157. background-color: #FFF;
  158. width: 80%;
  159. display: block;
  160. height: 500upx;
  161. margin: 0 auto;
  162. }
  163. .itemd{
  164. text-align: center;
  165. justify-content: center;
  166. }
  167. </style>