index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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-xiangxia 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. console.log(e)
  60. let self = this
  61. let star, stop;
  62. if (e.range.after && e.range.before) {
  63. if (e.range.before > e.range.after) {
  64. star = new Date(e.range.after + ' 00:00:00').getTime() / 1000
  65. stop = new Date(e.range.before + ' 23:59:59').getTime() / 1000
  66. } else {
  67. star = new Date(e.range.before + ' 00:00:00').getTime() / 1000
  68. stop = new Date(e.range.after + ' 23:59:59').getTime() / 1000
  69. }
  70. self.where.start = star
  71. self.where.stop = stop
  72. self.loaded = false;
  73. self.loading = false;
  74. // Promise.all();
  75. this.$emit('changeTime', this.where)
  76. }
  77. },
  78. dateTitle() {
  79. this.$refs.calendar.open()
  80. this.time = 'date'
  81. },
  82. setTime(time) {
  83. let self = this
  84. this.time = time;
  85. var year = new Date().getFullYear(),
  86. month = new Date().getMonth() + 1,
  87. day = new Date().getDate();
  88. this.tip = 1
  89. this.loaded = false;
  90. this.loading = false;
  91. switch (time) {
  92. case "all":
  93. this.where.start = 0
  94. this.where.stop = 0
  95. this.title = "全部";
  96. this.$emit('changeTime', this.where)
  97. break;
  98. case "today":
  99. this.where.start =
  100. new Date(Date.parse(year + "/" + month + "/" + day)).getTime() /
  101. 1000;
  102. this.where.stop =
  103. new Date(Date.parse(year + "/" + month + "/" + day)).getTime() /
  104. 1000 +
  105. 24 * 60 * 60 -
  106. 1;
  107. this.title = "今日";
  108. this.$emit('changeTime', this.where)
  109. break;
  110. case "yesterday":
  111. this.where.start =
  112. new Date(Date.parse(year + "/" + month + "/" + day)).getTime() /
  113. 1000 -
  114. 24 * 60 * 60;
  115. this.where.stop =
  116. new Date(Date.parse(year + "/" + month + "/" + day)).getTime() /
  117. 1000 -
  118. 1;
  119. this.title = "昨日";
  120. this.$emit('changeTime', this.where)
  121. break;
  122. case "month":
  123. this.where.start =
  124. new Date(year, new Date().getMonth(), 1).getTime() / 1000;
  125. this.where.stop = new Date(year, month, 1).getTime() / 1000 - 1;
  126. this.title = "本月";
  127. this.$emit('changeTime', this.where)
  128. break;
  129. case "seven":
  130. this.where.start =
  131. new Date(Date.parse(year + "/" + month + "/" + day)).getTime() /
  132. 1000 +
  133. 24 * 60 * 60 -
  134. 7 * 3600 * 24;
  135. this.where.stop =
  136. new Date(Date.parse(year + "/" + month + "/" + day)).getTime() /
  137. 1000 +
  138. 24 * 60 * 60 -
  139. 1;
  140. this.title = "七日";
  141. this.$emit('changeTime', this.where)
  142. break;
  143. // #ifdef MP
  144. case "date":
  145. let star = new Date(self.before).getTime() / 1000
  146. let stop = new Date(self.after).getTime() / 1000
  147. self.where.start = star
  148. self.where.stop = stop
  149. Promise.all([self.getList()]);
  150. this.$emit('changeTime', this.where)
  151. break;
  152. // #endif
  153. }
  154. },
  155. }
  156. }
  157. </script>
  158. <style lang="scss" scoped>
  159. .dataList {
  160. display: flex;
  161. justify-content: space-between;
  162. padding: 24rpx 30rpx;
  163. background-color: #fff;
  164. color: #666666;
  165. font-size: 26rpx;
  166. width: 100%;
  167. box-sizing: border-box;
  168. .times {
  169. display: flex;
  170. .item {
  171. margin-right: 20rpx;
  172. background: #F5F5F5;
  173. padding: 10rpx 20rpx;
  174. border-radius: 30rpx;
  175. }
  176. .item.on {
  177. color: var(--view-theme);
  178. background-color: var(--view-minorColorT);
  179. }
  180. }
  181. .item{
  182. padding: 10rpx 0rpx;
  183. }
  184. }
  185. .aaa {
  186. padding-left: 10rpx;
  187. font-size: 20rpx !important;
  188. }
  189. </style>