filter.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <view class="page-wrap">
  3. <view class="filter-item">
  4. <view class="label">开票状态</view>
  5. <view class="tag-group">
  6. <view :class="{ item: true, active: filterForm.type === item }" v-for="(item, index) in typeOption" :key="index" @click="filterForm.type = item">
  7. {{ item }}
  8. </view>
  9. </view>
  10. </view>
  11. <view class="filter-item">
  12. <view class="label">日期范围</view>
  13. <view class="tag-group">
  14. <view :class="{ item: true, active: filterForm.date === item }" v-for="(item, index) in dateOption" :key="index" @click="filterForm.date = item">
  15. {{ item }}
  16. </view>
  17. <uni-datetime-picker v-model="filterForm.dateRanges" type="daterange">
  18. <view :class="{ item: true, active: filterForm.date === '自定义' }" @click="filterForm.date = '自定义'">
  19. 自定义 {{ filterForm.dateRanges.length ? filterForm.dateRanges[0] + ' 至 ' + filterForm.dateRanges[1] : '' }}
  20. </view>
  21. </uni-datetime-picker>
  22. </view>
  23. </view>
  24. <view class="filter-item">
  25. <view class="label">日期排序</view>
  26. <view class="tag-group">
  27. <view :class="{ item: true, active: item.value === filterForm.sort }" v-for="(item, index) in sortOption" :key="index" @click="filterForm.sort = item.value">
  28. {{ item.label }}
  29. </view>
  30. </view>
  31. </view>
  32. <view class="btn-group">
  33. <button class="btn btn-1" @click="handleReset">重置</button>
  34. <button class="btn" @click="handleSubmit">确定</button>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. export default {
  40. data() {
  41. return {
  42. filterForm: {
  43. keyword: '',
  44. type: '全部',
  45. date: '最近30天',
  46. dateRanges: [],
  47. sort: 'asc'
  48. },
  49. typeOption: ['全部', '应付账单', '应收账单'],
  50. dateOption: ['最近30天', '最近90天', '本季度', '本年度'],
  51. sortOption: [
  52. {
  53. label: '正序',
  54. value: 'asc'
  55. },
  56. {
  57. label: '倒序',
  58. value: 'desc'
  59. }
  60. ]
  61. };
  62. },
  63. onLoad(option) {
  64. const eventChannel = this.getOpenerEventChannel();
  65. eventChannel.on('updateData', (data) => {
  66. const isCustomDate = data.date.indexOf('至') > -1;
  67. this.filterForm = {
  68. keyword: data.keyword,
  69. type: data.type === '' ? '全部' : data.type,
  70. date: isCustomDate ? '自定义' : data.date,
  71. dateRanges: isCustomDate ? data.date.split('至') : [],
  72. sort: data.sort
  73. };
  74. });
  75. },
  76. methods: {
  77. handleSubmit() {
  78. const { keyword, type, date, dateRanges, sort } = this.filterForm;
  79. if (date === '自定义' && !dateRanges.length) {
  80. uni.showToast({
  81. title: '请选择自定义日期',
  82. icon: 'none'
  83. });
  84. return;
  85. }
  86. uni.$emit('updateData', {
  87. keyword,
  88. type: type === '全部' ? '' : type,
  89. date: date === '自定义' ? dateRanges.join('至') : date,
  90. sort
  91. });
  92. uni.navigateBack();
  93. },
  94. handleReset() {
  95. this.filterForm = {
  96. keyword: this.filterForm.keyword,
  97. type: '全部',
  98. date: '最近30天',
  99. dateRanges: [],
  100. sort: 'asc'
  101. };
  102. }
  103. }
  104. };
  105. </script>
  106. <style lang="scss" scoped>
  107. .page-wrap {
  108. padding: 41.21rpx 27.47rpx;
  109. }
  110. .filter-item {
  111. font-size: 27.47rpx;
  112. margin-bottom: 41.21rpx;
  113. .label {
  114. color: #666;
  115. }
  116. }
  117. .tag-group {
  118. display: flex;
  119. flex-wrap: wrap;
  120. .item {
  121. min-width: 157.97rpx;
  122. box-sizing: border-box;
  123. color: #999;
  124. height: 68.68rpx;
  125. line-height: 65.93rpx;
  126. white-space: nowrap;
  127. overflow: hidden;
  128. text-overflow: ellipsis;
  129. max-width: 100%;
  130. border: 1rpx solid #dcdcdc;
  131. border-radius: 5.49rpx;
  132. text-align: center;
  133. margin: 13.74rpx 13.74rpx 0 0;
  134. background: #fff;
  135. padding: 0 20.6rpx;
  136. }
  137. .active {
  138. color: #00bcd2;
  139. border-color: #00bcd2;
  140. background: #eafffd;
  141. }
  142. }
  143. .btn-group {
  144. display: flex;
  145. justify-content: center;
  146. margin-top: 156.59rpx;
  147. .btn {
  148. width: 247.25rpx;
  149. height: 75.55rpx;
  150. background: #079eff;
  151. font-size: 27.47rpx;
  152. color: #fff;
  153. border-radius: 8.24rpx;
  154. border: none;
  155. margin: 0 13.74rpx;
  156. line-height: 75.55rpx;
  157. &-1 {
  158. color: #040404;
  159. background: #ccc;
  160. }
  161. }
  162. }
  163. </style>