pickTime.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <view class="contentBox">
  3. <view class="timeHead">
  4. <view class="timeTitle">{{year}}年{{month}}月</view>
  5. <!-- <view class="payMoney">支出¥136.00</view> -->
  6. </view>
  7. <view class="pickTimeBox">
  8. <view class="line line1"></view>
  9. <view class="line line2"></view>
  10. <picker-view class="pickerView" @change="bindChange" :value="value">
  11. <picker-view-column>
  12. <view class="item" style="text-align: right;" v-for="(item,index) in years" :key="index">{{item}}</view>
  13. </picker-view-column>
  14. <picker-view-column class="pickMonth">
  15. <view class="item" style="text-align: left;" v-for="(item,index) in months" :key="index">{{item}}</view>
  16. </picker-view-column>
  17. </picker-view>
  18. </view>
  19. <view class="btnBox">
  20. <text @click="handCancle">取消</text>
  21. <text @click="handSure">确定</text>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. export default{
  27. data(){
  28. const date = new Date()
  29. const years = []
  30. const year = date.getFullYear();
  31. const months = []
  32. const month = date.getMonth() + 1
  33. for (let i = year-1; i <= year+1; i++) {
  34. years.push(i)
  35. }
  36. for (let i = 1; i <= 12; i++) {
  37. months.push(i)
  38. }
  39. const y_i=this.year-year
  40. const m_i=this.month-month
  41. return {
  42. year,
  43. month,
  44. years,
  45. months,
  46. y_i,
  47. m_i,
  48. value:[]
  49. }
  50. },
  51. onLoad(options){
  52. const { date } = options
  53. const arr = date.split("-")
  54. this.y_i=Number(arr[0])-this.year+1
  55. this.x_i=Number(arr[1])-1
  56. this.value=[this.y_i,this.x_i]
  57. this.year = arr[0]
  58. this.month = arr[1]
  59. },
  60. methods:{
  61. bindChange(e){
  62. const val = e.detail.value
  63. this.year = this.years[val[0]];
  64. this.month = this.months[val[1]];
  65. },
  66. handCancle(){
  67. uni.navigateBack({
  68. delta: 1
  69. });
  70. },
  71. handSure(){
  72. try{
  73. this.month = Number(this.month)
  74. this.month = this.month > 10 ? this.month : '0'+this.month
  75. }catch(e){
  76. this.month = this.month
  77. }
  78. uni.redirectTo({
  79. url:`/pages/payList/payList?year=${this.year}&month=${this.month}`
  80. })
  81. }
  82. }
  83. }
  84. </script>
  85. <style scoped lang="scss">
  86. page{
  87. width: 100%;
  88. height: 100%;
  89. background: $uni-bg-color-normal;
  90. overflow: hidden;
  91. }
  92. .contentBox{
  93. margin-top: 12rpx;
  94. background: $uni-bg-color;
  95. padding: 0 53rpx;
  96. }
  97. .timeHead{
  98. height:70rpx;
  99. width: calc(100% - 19rpx);
  100. display: flex;
  101. justify-content: space-between;
  102. align-items: center;
  103. padding-left: 19rpx;
  104. }
  105. .timeTitle{
  106. font-size: 32rpx;
  107. color:#2A2A2A;
  108. display: flex;
  109. justify-content: flex-start;
  110. align-items: center;
  111. }
  112. .timeTitle::after{
  113. content: "";
  114. display: block;
  115. width: 26rpx;
  116. height: 15rpx;
  117. background: url(../../static/arrow_down.jpg);
  118. background-size: 100% 100%;
  119. margin-left: 16rpx;
  120. }
  121. .payMoney{
  122. font-size: 24rpx;
  123. color: #999999;
  124. }
  125. .pickTimeBox{
  126. width: 100%;
  127. height: 300rpx;
  128. display: flex;
  129. justify-content: center;
  130. position: relative;
  131. margin-bottom: 25rpx;
  132. }
  133. .pickerView{
  134. width: 100%;
  135. height: 300rpx;
  136. font-size: 28rpx;
  137. color: #999999;
  138. text-align: center;
  139. }
  140. .pickerView .item{
  141. width: 100%;
  142. line-height: 34px;
  143. position: relative;
  144. }
  145. .pickMonth .item{
  146. width: 100%;
  147. margin-left: 35rpx;
  148. text-align: center;
  149. }
  150. .picker-box,.uni-picker-view-indicator{
  151. border-bottom: 1px solid #2E8BFC;
  152. border-top: 1px solid #2E8BFC;
  153. font-size: 34rpx !important;
  154. }
  155. .line{
  156. width: 175rpx;
  157. height: 1px;
  158. background: #2E8BFC;
  159. position: absolute;
  160. left: 237rpx;
  161. z-index: 999;
  162. }
  163. .line::after{
  164. content: "";
  165. display: block;
  166. width: 30rpx;
  167. height: 1px;
  168. background: #FFFFFF;
  169. margin-left: 90rpx;
  170. }
  171. .line1{
  172. top: 118rpx;
  173. }
  174. .line2{
  175. top: 180rpx;
  176. }
  177. .btnBox{
  178. display: flex;
  179. justify-content: space-between;
  180. align-items: center;
  181. font-size: 28rpx;
  182. color: #2A2A2A;
  183. }
  184. </style>