index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <!-- 日期组件 -->
  3. <view>
  4. <view class="dataList">
  5. <view class="times">
  6. <view class="item" :class="time == 'all' ? 'on' : ''" @click="setTime('all')">全部</view>
  7. <view class="item" :class="time == 'today' ? 'on' : ''" @click="setTime('today')">今日</view>
  8. <view class="item" :class="time == 'yesterday' ? 'on' : ''" @click="setTime('yesterday')">昨日</view>
  9. <view class="item" :class="time == 'seven' ? 'on' : ''" @click="setTime('seven')">近7日</view>
  10. </view>
  11. <view class="item" :class="time == 'date' ? 'on' : ''" @click="dateTitle">自定义时间 <text
  12. class="iconfont icon-ic_downarrow aaa"></text></view>
  13. </view>
  14. <uni-calendar ref="calendar" :date="info.date" :insert="info.insert" :lunar="info.lunar"
  15. :startDate="info.startDate" :endDate="info.endDate" :range="info.range" @confirm="confirm"
  16. :showMonth="info.showMonth" />
  17. <view class="mask" @touchmove.prevent v-show="current === true" @click="close"></view>
  18. <Loading :loaded="loaded" :loading="loading"></Loading>
  19. </view>
  20. </template>
  21. <script>
  22. import Loading from '@/components/Loading/index.vue'
  23. import uniCalendar from '@/components/uni-calendar/uni-calendar.vue'
  24. const year = new Date().getFullYear();
  25. const month = new Date().getMonth() + 1;
  26. const day = new Date().getDate();
  27. export default {
  28. components: {
  29. uniCalendar,
  30. Loading
  31. },
  32. data() {
  33. return {
  34. time:'all',
  35. current: false,
  36. loaded: false,
  37. loading: false,
  38. info: {
  39. startDate: '',
  40. endDate: '',
  41. lunar: false,
  42. range: true,
  43. insert: false,
  44. selected: [],
  45. showMonth: false
  46. },
  47. where: {
  48. start: "",
  49. stop: "",
  50. },
  51. }
  52. },
  53. methods: {
  54. close() {
  55. this.current = false;
  56. },
  57. // 日历确定
  58. confirm(e) {
  59. let self = this
  60. let star, stop;
  61. if (e.range.after && e.range.before) {
  62. if (e.range.before > e.range.after) {
  63. star = new Date(e.range.after + ' 00:00:00').getTime() / 1000
  64. stop = new Date(e.range.before + ' 23:59:59').getTime() / 1000
  65. } else {
  66. star = new Date(e.range.before + ' 00:00:00').getTime() / 1000
  67. stop = new Date(e.range.after + ' 23:59:59').getTime() / 1000
  68. }
  69. self.where.start = star
  70. self.where.stop = stop
  71. self.loaded = false;
  72. self.loading = false;
  73. // Promise.all();
  74. this.$emit('changeTime', this.where)
  75. }else{
  76. star = new Date(e.fulldate + ' 00:00:00').getTime() / 1000
  77. stop = new Date(e.fulldate + ' 23:59:59').getTime() / 1000
  78. self.where.start = star
  79. self.where.stop = stop
  80. self.loaded = false;
  81. self.loading = false;
  82. this.$emit('changeTime', this.where)
  83. }
  84. },
  85. dateTitle() {
  86. this.$refs.calendar.open()
  87. this.time = 'date'
  88. },
  89. setTime(time) {
  90. let self = this
  91. this.time = time;
  92. var year = new Date().getFullYear(),
  93. month = new Date().getMonth() + 1,
  94. day = new Date().getDate();
  95. this.tip = 1
  96. this.loaded = false;
  97. this.loading = false;
  98. switch (time) {
  99. case "all":
  100. this.where.start = 0
  101. this.where.stop = 0
  102. this.title = "全部";
  103. this.$emit('changeTime', this.where)
  104. break;
  105. case "today":
  106. this.where.start =
  107. new Date(Date.parse(year + "/" + month + "/" + day)).getTime() /
  108. 1000;
  109. this.where.stop =
  110. new Date(Date.parse(year + "/" + month + "/" + day)).getTime() /
  111. 1000 +
  112. 24 * 60 * 60 -
  113. 1;
  114. this.title = "今日";
  115. this.$emit('changeTime', this.where)
  116. break;
  117. case "yesterday":
  118. this.where.start =
  119. new Date(Date.parse(year + "/" + month + "/" + day)).getTime() /
  120. 1000 -
  121. 24 * 60 * 60;
  122. this.where.stop =
  123. new Date(Date.parse(year + "/" + month + "/" + day)).getTime() /
  124. 1000 -
  125. 1;
  126. this.title = "昨日";
  127. this.$emit('changeTime', this.where)
  128. break;
  129. case "month":
  130. this.where.start =
  131. new Date(year, new Date().getMonth(), 1).getTime() / 1000;
  132. this.where.stop = new Date(year, month, 1).getTime() / 1000 - 1;
  133. this.title = "本月";
  134. this.$emit('changeTime', this.where)
  135. break;
  136. case "seven":
  137. this.where.start =
  138. new Date(Date.parse(year + "/" + month + "/" + day)).getTime() /
  139. 1000 +
  140. 24 * 60 * 60 -
  141. 7 * 3600 * 24;
  142. this.where.stop =
  143. new Date(Date.parse(year + "/" + month + "/" + day)).getTime() /
  144. 1000 +
  145. 24 * 60 * 60 -
  146. 1;
  147. this.title = "七日";
  148. this.$emit('changeTime', this.where)
  149. break;
  150. // #ifdef MP
  151. case "date":
  152. let star = new Date(self.before).getTime() / 1000
  153. let stop = new Date(self.after).getTime() / 1000
  154. self.where.start = star
  155. self.where.stop = stop
  156. Promise.all([self.getList()]);
  157. this.$emit('changeTime', this.where)
  158. break;
  159. // #endif
  160. }
  161. },
  162. }
  163. }
  164. </script>
  165. <style lang="scss" scoped>
  166. .dataList {
  167. display: flex;
  168. justify-content: space-between;
  169. padding: 24rpx 20rpx;
  170. background-color: #fff;
  171. color: #999;
  172. font-size: 24rpx;
  173. width: 100%;
  174. box-sizing: border-box;
  175. .times {
  176. display: flex;
  177. .item {
  178. margin-right: 20rpx;
  179. background: #F5F5F5;
  180. padding: 8rpx 24rpx;
  181. border-radius: 30rpx;
  182. }
  183. .item.on {
  184. color: var(--view-theme);
  185. background-color: var(--view-minorColorT);
  186. }
  187. }
  188. .item{
  189. padding: 10rpx 0rpx;
  190. }
  191. }
  192. .aaa {
  193. padding-left: 10rpx;
  194. font-size: 26rpx !important;
  195. }
  196. </style>