dateSearch.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <view class="date-search">
  3. <z-slide :visible.sync="show" ref="slide">
  4. <view class="data-search-title mt-30">开始时间</view>
  5. <view class="flex-n fac fjb data-search-area">
  6. <view class="data-search-item" :class="choose==0?'data-select':''" @click="chooseArea(0)">今天</view>
  7. <view class="data-search-item" :class="choose==1?'data-select':''" @click="chooseArea(1)">昨天</view>
  8. <view class="data-search-item" :class="choose==2?'data-select':''" @click="chooseArea(2)">本周</view>
  9. </view>
  10. <view class="flex-n fac fjb data-search-area">
  11. <view class="data-search-item" :class="choose==3?'data-select':''" @click="chooseArea(3)">上周</view>
  12. <view class="data-search-item" :class="choose==4?'data-select':''" @click="chooseArea(4)">本月</view>
  13. <view class="data-search-item" :class="choose==5?'data-select':''" @click="chooseArea(5)">上月</view>
  14. </view>
  15. <view class="data-search-title mt-30">自定义时间段</view>
  16. <view class="flex-n fac data-search-range mt-10">
  17. <image class="common_icon" src="../../../../static/icon_time.png"></image>
  18. <view class="flex-n fac fjb">
  19. <view class="data-search-range-item" @click="lookBeginTime=true" v-if="!beginTime">开始日期</view>
  20. <div class="data-search-range-itemselect" @click="lookBeginTime=true" v-else>{{beginTime}}</div>
  21. <view class="">
  22. -
  23. </view>
  24. <view class="data-search-range-item" @click="lookEndTime=true" v-if="!endTime">结束日期</view>
  25. <div class="data-search-range-itemselect" @click="lookEndTime=true" v-else>{{endTime}}</div>
  26. </view>
  27. <view class="iconfont iconjuxing27kaobei" v-if="beginTime||endTime" @click="beginTime='';endTime=''"></view>
  28. </view>
  29. <view class="data-search-btn" @click="submit">
  30. 确定
  31. </view>
  32. <z-date-select :visible.sync="lookBeginTime" v-model="beginTime" :endDate="endTime"></z-date-select>
  33. <z-date-select :visible.sync="lookEndTime" v-model="endTime" :startDate="beginTime"></z-date-select>
  34. </z-slide>
  35. <z-date-select></z-date-select>
  36. </view>
  37. </template>
  38. <script>
  39. export default {
  40. name: 'dateSearch',
  41. props: {
  42. visible: Boolean,
  43. select:Number
  44. },
  45. data() {
  46. return {
  47. show: false,
  48. lookBeginTime: false,
  49. lookEndTime: false,
  50. beginTime: '',
  51. endTime: '',
  52. choose: -1
  53. }
  54. },
  55. watch: {
  56. show(newval, oldval) {
  57. this.$emit('update:visible', this.show);
  58. },
  59. visible(newval, oldval) {
  60. this.show = this.visible;
  61. if(newval){
  62. this.choose=this.select;
  63. }
  64. },
  65. beginTime(newval, oldval) {
  66. if (newval) {
  67. this.choose = -1;
  68. }
  69. },
  70. endTime(newval, oldval) {
  71. if (newval) {
  72. this.choose = -1;
  73. }
  74. }
  75. },
  76. methods: {
  77. chooseArea(num) {
  78. if (num == this.choose) {
  79. this.choose = -1;
  80. } else {
  81. this.choose = num;
  82. }
  83. },
  84. submit() {
  85. console.log(111)
  86. var beginDate = '',
  87. endDate = '';
  88. if (this.beginTime != '' && this.endTime == '' || this.beginTime == '' && this.endTime != '') {
  89. return uni.showToast({
  90. title: '请选择完整时间段',
  91. icon: 'none'
  92. })
  93. }
  94. var end = '';
  95. var start = '';
  96. if (this.choose == 0) {
  97. start = new Date();
  98. beginDate = start.getFullYear() + '-' + (start.getMonth() + 1) + '-' + start.getDate();
  99. endDate = beginDate;
  100. }
  101. if (this.choose == 1) {
  102. start = new Date();
  103. start.setTime(start.getTime() - 3600 * 1000 * 24);
  104. beginDate = start.getFullYear() + '-' + (start.getMonth() + 1) + '-' + start.getDate();
  105. endDate = beginDate;
  106. }
  107. if (this.choose == 2) {
  108. end = new Date();
  109. start = new Date();
  110. var num = start.getDay();
  111. if (num == 0) {
  112. num = 7;
  113. }
  114. start.setTime(start.getTime() - 3600 * 1000 * 24 * (num - 1));
  115. end.setTime(end.getTime() + 3600 * 1000 * 24 * (7 - num));
  116. beginDate = start.getFullYear() + '-' + (start.getMonth() + 1) + '-' + start.getDate();
  117. endDate = end.getFullYear() + '-' + (end.getMonth() + 1) + '-' + end.getDate();
  118. }
  119. if (this.choose == 3) {
  120. end = new Date();
  121. start = new Date();
  122. var num = start.getDay();
  123. if (num == 0) {
  124. num = 7;
  125. }
  126. start.setTime(start.getTime() - 3600 * 1000 * 24 * (num + 6));
  127. end.setTime(end.getTime() - 3600 * 1000 * 24 * num);
  128. beginDate = start.getFullYear() + '-' + (start.getMonth() + 1) + '-' + start.getDate();
  129. endDate = end.getFullYear() + '-' + (end.getMonth() + 1) + '-' + end.getDate();
  130. }
  131. if (this.choose == 4) {
  132. start = new Date();
  133. var year = start.getFullYear(),
  134. month = start.getMonth() + 1;
  135. var start = new Date(year + '-' + month + '-1');
  136. var length = this.$DateTime.getMonthArea().length - 1;
  137. var dd = this.$DateTime.getMonthArea()[length].dd;
  138. end = new Date(this.$DateTime.getMonthArea()[length - (dd < 7 ? dd : 0)].date);
  139. beginDate = start.getFullYear() + '-' + (start.getMonth() + 1) + '-' + start.getDate();
  140. endDate = end.getFullYear() + '-' + (end.getMonth() + 1) + '-' + end.getDate();
  141. }
  142. if (this.choose == 5) {
  143. start = new Date();
  144. var month=this.$DateTime.beforeMouth({yy:start.getFullYear(),mm:start.getMonth()+1,dd:1})[15].mm,
  145. year=this.$DateTime.beforeMouth({yy:start.getFullYear(),mm:start.getMonth()+1,dd:1})[15].yy;
  146. start=new Date(year+'-'+month+'-1');
  147. beginDate =year + '-' + month + '-' + 1;
  148. endDate = year + '-' + month + '-' + this.$DateTime.getMonthDayNum(year,month);
  149. }
  150. if(this.choose==-1&&this.beginTime != '' && this.endTime != ''){
  151. beginDate =this.beginTime.replace(/\//g,"-");
  152. endDate = this.endTime.replace(/\//g,"-");
  153. }
  154. console.log(beginDate,endDate)
  155. this.$emit('searchDate',{beginDate:beginDate,endDate:endDate});
  156. this.$refs.slide.close();
  157. }
  158. }
  159. }
  160. </script>
  161. <style scoped lang="scss">
  162. .date-search {
  163. .data-search-title {
  164. color: #999999;
  165. font-size: 28rpx;
  166. line-height: 60rpx;
  167. padding: {
  168. left: 50rpx;
  169. right: 50rpx;
  170. }
  171. ;
  172. }
  173. .data-search-btn {
  174. width: calc(100% - 80rpx);
  175. margin-left: 40rpx;
  176. margin-top: 50rpx;
  177. height: 80rpx;
  178. line-height: 80rpx;
  179. color: white;
  180. font-size: 32rpx;
  181. text-align: center;
  182. background-color: #007AFF;
  183. }
  184. .data-search-area {
  185. width: calc(100% - 80rpx);
  186. margin-left: 40rpx;
  187. margin-top: 20rpx;
  188. .data-search-item {
  189. color: #999999;
  190. border: 1px solid #f2f2f2;
  191. width: 160rpx;
  192. height: 60rpx;
  193. line-height: 60rpx;
  194. text-align: center;
  195. font-size: 32rpx;
  196. }
  197. .data-select {
  198. border: 1px solid #52c1f5 !important;
  199. color: #52c1f5 !important;
  200. background: #f8fbff !important;
  201. }
  202. }
  203. }
  204. .data-search-range {
  205. margin-left: 40rpx;
  206. width: calc(100% - 80rpx);
  207. padding: 10rpx 0;
  208. background: #eff1f6;
  209. .data-search-range-item {
  210. color: #ccc;
  211. font-size: 32rpx;
  212. width: 200rpx;
  213. text-align: center;
  214. }
  215. .data-search-range-itemselect {
  216. font-size: 32rpx;
  217. width: 200rpx;
  218. text-align: center;
  219. }
  220. }
  221. .common_icon {
  222. width: 58rpx;
  223. height: 58rpx;
  224. min-width: 58rpx;
  225. }
  226. </style>