timeHorizon.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template>
  2. <view class="time-horizon">
  3. <view class="placeholder" @click="show = true">
  4. {{ showTitle || placeholder }}
  5. </view>
  6. <u-popup :show="show" mode="bottom" :safeAreaInsetBottom="true" @close="show = false">
  7. <view class="title">
  8. 快捷查询日期范围
  9. </view>
  10. <scroll-view :scroll-x="true">
  11. <view class="options">
  12. <view class="item" :class="day == 1 ? 'active' : ''" @click="fast(1)">
  13. 今天
  14. </view>
  15. <view class="item" :class="day == 7 ? 'active' : ''" @click="fast(7)">
  16. 7天
  17. </view>
  18. <view class="item" :class="day == 30 ? 'active' : ''" @click="fast(30)">
  19. 30天
  20. </view>
  21. <view class="item" :class="day == 60 ? 'active' : ''" @click="fast(60)">
  22. 60天
  23. </view>
  24. <view style="width: 10px;" />
  25. <u-number-box :value="day" @change="valChange" />
  26. </view>
  27. </scroll-view>
  28. <view class="title">
  29. 自定义日期范围
  30. </view>
  31. <view class="row">
  32. <picker mode="date" class="date-box" :style="{ color: begindate ? '#333' : '#ddd' }" :value="begindate"
  33. data-name="begindate" :end="enddate" @change="onDateChange">
  34. {{ begindate || '开始日期' }}
  35. </picker>
  36. <view style="padding: 0 10px;">
  37. -
  38. </view>
  39. <picker mode="date" class="date-box" :style="{ color: enddate ? '#333' : '#ddd' }" :value="enddate"
  40. data-name="enddate" @change="onDateChange" :start="begindate">
  41. {{ enddate || '结束日期' }}
  42. </picker>
  43. </view>
  44. <view class="bottom">
  45. <view class="bot" @click="show = false" hover-class="navigator-hover">
  46. 关闭
  47. </view>
  48. <view @click="reset" class="bot reset" hover-class="navigator-hover">
  49. 重置
  50. </view>
  51. <view v-if="loading" class="bot confirm" hover-class="navigator-hover">
  52. <u-loading-icon color="#007aff" mode="semicircle" /> 查询中...
  53. </view>
  54. <view v-else class="bot confirm" @click="confirm" hover-class="navigator-hover">
  55. 查询
  56. </view><!-- :class="begindate && enddate ? '' : 'disabled'" -->
  57. </view>
  58. </u-popup>
  59. </view>
  60. </template>
  61. <script>
  62. import { formatTime } from "../utils/getTime";
  63. export default {
  64. name: "timeHorizon",
  65. props: {
  66. placeholder: {
  67. type: String,
  68. default: "查询日期范围"
  69. },
  70. onConfirm: Function
  71. },
  72. data() {
  73. return {
  74. loading: false,
  75. show: false,
  76. day: 0,
  77. begindate: "",
  78. enddate: '',
  79. showTitle: ""
  80. }
  81. },
  82. created() {
  83. },
  84. methods: {
  85. fast(num) {
  86. this.day = num;
  87. let now = new Date().getTime(),
  88. end = now + 86400000,
  89. beg = end - (num * 86400000);
  90. this.begindate = formatTime(new Date(beg)).split(' ')[0];
  91. this.enddate = formatTime(new Date(end)).split(' ')[0];
  92. },
  93. valChange(e) {
  94. this.fast(e.value)
  95. },
  96. onDateChange(e) {
  97. this[e.target.dataset.name] = e.detail.value;
  98. if (this.begindate && this.enddate) {
  99. let end = new Date(this.enddate).getTime(),
  100. beg = new Date(this.begindate).getTime();
  101. this.day = (end - beg) / 86400000;
  102. }
  103. },
  104. reset() {
  105. this.day = 0;
  106. this.begindate = "";
  107. this.enddate = "";
  108. },
  109. confirm() {
  110. this.loading = true;
  111. this.$emit('onConfirm', [this.begindate, this.enddate], () => {
  112. this.loading = false;
  113. this.show = false;
  114. this.showTitle = this.begindate && this.enddate ? this.begindate + ' 至 ' + this.enddate : ""
  115. })
  116. }
  117. },
  118. }
  119. </script>
  120. <style lang="scss" scoped>
  121. .disabled {
  122. opacity: .7;
  123. }
  124. .placeholder {
  125. font-weight: bold;
  126. color: #fff;
  127. }
  128. .title {
  129. width: 100%;
  130. text-align: center;
  131. font-size: 16px;
  132. font-weight: bold;
  133. color: #333;
  134. line-height: 45px;
  135. }
  136. .options {
  137. display: flex;
  138. .item {
  139. display: flex;
  140. align-items: center;
  141. justify-content: center;
  142. background: #F5F5F5;
  143. border-radius: 4px;
  144. margin-left: 10px;
  145. font-size: 14px;
  146. color: #333333;
  147. overflow: hidden;
  148. box-sizing: border-box;
  149. padding: 6px 12px;
  150. flex-shrink: 0;
  151. }
  152. .active {
  153. background: #0B3F7E !important;
  154. color: #FFFFFF !important;
  155. }
  156. /deep/ .u-number-box__minus,
  157. /deep/.u-number-box__input,
  158. /deep/.u-number-box__plus {
  159. height: 30px !important;
  160. }
  161. /deep/ .u-number-box__input {
  162. width: 35px !important;
  163. }
  164. }
  165. .row {
  166. display: flex;
  167. align-items: center;
  168. font-size: 14px;
  169. color: #646566;
  170. padding: 10px;
  171. padding-top: 0;
  172. border-bottom: 1px solid #ddd;
  173. box-sizing: border-box;
  174. .date-box {
  175. flex: 1;
  176. height: 35px;
  177. line-height: 35px;
  178. background: #FFFFFF;
  179. border-radius: 4px;
  180. border: 1px solid #CCCCCC;
  181. font-size: 14px;
  182. padding-left: 10px;
  183. }
  184. }
  185. .bottom {
  186. display: flex;
  187. justify-content: space-between;
  188. align-content: center;
  189. width: 100%;
  190. border-top: 1px solid #ddd;
  191. padding: 10px;
  192. box-sizing: border-box;
  193. .bot {
  194. display: flex;
  195. justify-content: center;
  196. align-items: center;
  197. width: 100px;
  198. height: 40px;
  199. background: #FFFFFF;
  200. border-radius: 4px;
  201. border: 1px solid #CCCCCC;
  202. font-size: 15px;
  203. color: #666666;
  204. }
  205. .reset {
  206. border-color: #0B3F7E;
  207. color: #0B3F7E;
  208. }
  209. .confirm {
  210. border-color: #0B3F7E;
  211. background-color: #0B3F7E;
  212. color: #FFFFFF;
  213. }
  214. /deep/ .u-button {
  215. background: #FFFFFF;
  216. border-radius: 4px;
  217. margin: 0 !important;
  218. }
  219. /deep/ .u-button__text {
  220. font-size: 14px !important;
  221. }
  222. }
  223. </style>