dmDateScreen.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <view class="dateContainer">
  3. <view class="topSection">
  4. <view class="title">{{title}}</view>
  5. <view class="dateItems">
  6. <view class="item" v-for="(item, idx) in dateItems" :key="idx" :style="`color: ${item.value == defaultParameter.dateType ? '#454545' : '#999999'};`"
  7. @click="screenAction(item.value)">
  8. {{item.title}}
  9. </view>
  10. </view>
  11. </view>
  12. <view class="botttomSection" @click="screenAction(4)">
  13. <view class="bottomItem">
  14. <view class="leftText">起</view>
  15. <view class="dateText">{{beginDate | visitTimeFilter}}</view>
  16. <image class="rightIcon" src="../../static/icons/more.png" mode=""></image>
  17. </view>
  18. <view class="bottomItem">
  19. <view class="leftText">终</view>
  20. <view class="dateText">{{endDate | visitTimeFilter}}</view>
  21. <image class="rightIcon" src="../../static/icons/more.png" mode=""></image>
  22. </view>
  23. </view>
  24. <dm-calendar-picker-view ref='calendarPickerView' @confirmSelDate='confirmSelDate'></dm-calendar-picker-view>
  25. </view>
  26. </template>
  27. <script>
  28. import dmCalendarPickerView from './dmCalendarPickerView.vue'
  29. import moment from '../../static/moment.min.js'
  30. import {
  31. displayDateFormatChi
  32. } from '../../static/format.js'
  33. export default {
  34. props: {
  35. title: {
  36. type: String,
  37. default: '筛选日期'
  38. },
  39. defaultParameter: {
  40. type: Object,
  41. default () {
  42. return {
  43. 'dateType': '1',
  44. 'startDate': '',
  45. 'endDate': '',
  46. 'terminal': '0'
  47. }
  48. }
  49. },
  50. modelValue: {
  51. type: [Number, String],
  52. default: '0'
  53. },
  54. },
  55. data() {
  56. return {
  57. dateItems: [{
  58. title: '今日',
  59. value: 1
  60. },
  61. {
  62. title: '近7日',
  63. value: 2
  64. },
  65. {
  66. title: '近30天',
  67. value: 3
  68. },
  69. ],
  70. beginDate: null,
  71. endDate: null
  72. }
  73. },
  74. mounted() {
  75. },
  76. methods: {
  77. screenAction(val) {
  78. if (val < 4) {
  79. this.$emit('screenDateAction', val)
  80. } else {
  81. this.$refs.calendarPickerView.show()
  82. }
  83. },
  84. confirmSelDate(e) {
  85. const startDate = e.startDate;
  86. const endDate = e.endDate;
  87. var start = ''
  88. var end = ''
  89. if (moment(startDate).isBefore(endDate)) {
  90. start = startDate;
  91. end = endDate;
  92. } else {
  93. start = endDate;
  94. end = startDate;
  95. }
  96. this.$emit('screenDateAction', 4, start, end)
  97. },
  98. displayDate() {
  99. var dateType = parseInt(this.defaultParameter.dateType)
  100. let curDate = (new Date()).getTime();
  101. this.beginDate = null
  102. this.endDate = null
  103. if (dateType == 1) {
  104. this.beginDate = curDate
  105. this.endDate = curDate
  106. } else if (dateType == 2) {
  107. this.endDate = curDate
  108. this.beginDate = this.getBeginDate(6)
  109. } else if (dateType == 3) {
  110. this.endDate = curDate
  111. this.beginDate = this.getBeginDate(29)
  112. } else if (dateType == 4) {
  113. this.beginDate = this.stringToStamp(this.defaultParameter.startDate)
  114. this.endDate = this.stringToStamp(this.defaultParameter.endDate)
  115. }
  116. },
  117. getBeginDate(days) {
  118. let curDate = (new Date()).getTime();
  119. let beginDay = curDate - days * 24 * 60 * 60 * 1000
  120. return beginDay
  121. },
  122. stringToStamp(val) {
  123. // var timeStr = val.replace('-', '/') + ' ' + '00:00:00'
  124. var timeStr = val.replace(/-/g,'/') + " " + '00:00:00'
  125. var stamp = new Date(timeStr).getTime()
  126. return stamp
  127. }
  128. },
  129. filters: {
  130. visitTimeFilter(val) {
  131. return displayDateFormatChi(val)
  132. },
  133. },
  134. watch: {
  135. defaultParameter: {
  136. handler(e) {
  137. this.displayDate()
  138. },
  139. deep: true,
  140. immediate: true
  141. }
  142. },
  143. components: {
  144. dmCalendarPickerView
  145. }
  146. }
  147. </script>
  148. <style scoped lang="scss">
  149. .dateContainer {
  150. width: 100%;
  151. font-family: Verdana;
  152. padding: 0 30rpx;
  153. box-sizing: border-box;
  154. .topSection {
  155. width: 100%;
  156. display: flex;
  157. justify-content: space-between;
  158. align-items: center;
  159. .title {
  160. color: #454545;
  161. font-size: 32rpx;
  162. font-weight: bold;
  163. }
  164. .dateItems {
  165. display: flex;
  166. justify-content: flex-end;
  167. font-size: 28rpx;
  168. color: #999999;
  169. .item {
  170. margin-left: 20rpx;
  171. }
  172. }
  173. }
  174. .botttomSection {
  175. background-color: #F1F5F9;
  176. border-radius: 16rpx;
  177. width: 100%;
  178. height: 94rpx;
  179. display: flex;
  180. justify-content: space-between;
  181. padding: 0 30rpx;
  182. box-sizing: border-box;
  183. margin-top: 22rpx;
  184. .bottomItem {
  185. display: flex;
  186. justify-content: flex-start;
  187. align-items: center;
  188. .leftText {
  189. color: #999999;
  190. font-size: 28rpx;
  191. font-weight: bold;
  192. margin-right: 12rpx;
  193. }
  194. .dateText {
  195. color: #333333;
  196. font-size: 28rpx;
  197. margin-right: 20rpx;
  198. }
  199. .rightIcon {
  200. width: 15rpx;
  201. height: 24rpx;
  202. }
  203. }
  204. }
  205. }
  206. </style>