filter.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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.value }" v-for="(item, index) in typeOption" :key="index" @click="filterForm.type = item.value">
  7. {{ item.label }}
  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. {
  51. label: '全部',
  52. value: ''
  53. },
  54. {
  55. label: '应付账单',
  56. value: '应付'
  57. },
  58. {
  59. label: '应收账单',
  60. value: '应收'
  61. }
  62. ],
  63. dateOption: ['最近30天', '最近90天', '本季度', '本年度'],
  64. sortOption: [
  65. {
  66. label: '正序',
  67. value: 'asc'
  68. },
  69. {
  70. label: '倒序',
  71. value: 'desc'
  72. }
  73. ]
  74. };
  75. },
  76. onLoad(option) {
  77. const eventChannel = this.getOpenerEventChannel();
  78. eventChannel.on('updateData', (data) => {
  79. const isCustomDate = data.date.indexOf('至') > -1;
  80. this.filterForm = {
  81. keyword: data.keyword,
  82. type: data.type,
  83. date: isCustomDate ? '自定义' : data.date,
  84. dateRanges: isCustomDate ? data.date.split('至') : [],
  85. sort: data.sort
  86. };
  87. });
  88. },
  89. methods: {
  90. handleSubmit() {
  91. const { keyword, type, date, dateRanges, sort } = this.filterForm;
  92. if (date === '自定义' && !dateRanges.length) {
  93. uni.showToast({
  94. title: '请选择自定义日期',
  95. icon: 'none'
  96. });
  97. return;
  98. }
  99. uni.$emit('updateData', {
  100. keyword,
  101. type,
  102. date: date === '自定义' ? dateRanges.join('至') : date,
  103. sort
  104. });
  105. uni.navigateBack();
  106. },
  107. handleReset() {
  108. this.filterForm = {
  109. keyword: this.filterForm.keyword,
  110. type: '',
  111. date: '最近30天',
  112. dateRanges: [],
  113. sort: 'asc'
  114. };
  115. }
  116. }
  117. };
  118. </script>
  119. <style lang="scss" scoped>
  120. .page-wrap {
  121. padding: 41.21rpx 27.47rpx;
  122. }
  123. .filter-item {
  124. font-size: 27.47rpx;
  125. margin-bottom: 41.21rpx;
  126. .label {
  127. color: #666;
  128. }
  129. }
  130. .tag-group {
  131. display: flex;
  132. flex-wrap: wrap;
  133. .item {
  134. min-width: 157.97rpx;
  135. box-sizing: border-box;
  136. color: #999;
  137. height: 68.68rpx;
  138. line-height: 65.93rpx;
  139. white-space: nowrap;
  140. overflow: hidden;
  141. text-overflow: ellipsis;
  142. max-width: 100%;
  143. border: 1rpx solid #dcdcdc;
  144. border-radius: 5.49rpx;
  145. text-align: center;
  146. margin: 13.74rpx 13.74rpx 0 0;
  147. background: #fff;
  148. padding: 0 20.6rpx;
  149. }
  150. .active {
  151. color: #00bcd2;
  152. border-color: #00bcd2;
  153. background: #eafffd;
  154. }
  155. }
  156. .btn-group {
  157. display: flex;
  158. justify-content: center;
  159. margin-top: 156.59rpx;
  160. .btn {
  161. width: 247.25rpx;
  162. height: 75.55rpx;
  163. background: #079eff;
  164. font-size: 27.47rpx;
  165. color: #fff;
  166. border-radius: 8.24rpx;
  167. border: none;
  168. margin: 0 13.74rpx;
  169. line-height: 75.55rpx;
  170. &-1 {
  171. color: #040404;
  172. background: #ccc;
  173. }
  174. }
  175. }
  176. </style>