ren-time.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <template>
  2. <view class="filter-wrapper"
  3. :style="{top: top,'border-top':border?'1rpx solid #f2f2f2':'none' }"
  4. @touchmove.stop.prevent="discard">
  5. <view class="inner-wrapper">
  6. <view class="mask" :class="showMask ? 'show' : 'hide'" @tap="tapMask"></view>
  7. <view class="navs" :style="stylesData">
  8. <!-- <view class="c-flex-align" :class="{ 'c-flex-center': index > 0, actNav: index === actNav }"
  9. v-for="(item, index) in navData" :key="index" @click="navClick(index)">
  10. <view v-for="(child, childx) in item" :key="childx" v-if="child.select">{{ child.text }}</view>
  11. <image src="https://i.loli.net/2020/07/15/QsHxlr1gbSImvWt.png" mode="" class="icon-triangle"
  12. v-if="index === actNav"></image>
  13. <image src="https://i.loli.net/2020/07/15/xjVSvzWcH9NO7al.png" mode="" class="icon-triangle" v-else>
  14. </image>
  15. </view> -->
  16. <view class="date-wrapper">
  17. <picker mode="date" @change="handleDate">
  18. <view class="date c-flex-align" :style="{ height: height + 'rpx' }" @click="dateClick">
  19. <view>{{ selDate }}</view>
  20. <image src="https://i.loli.net/2020/07/15/xjVSvzWcH9NO7al.png" mode="" class="icon-triangle"></image>
  21. </view>
  22. </picker>
  23. </view>
  24. </view>
  25. <scroll-view scroll-y="true" class="popup" :class="popupShow ? 'popupShow' : ''">
  26. <view class="item-opt c-flex-align" :class="item.select ? 'actOpt' : ''"
  27. v-for="(item, index) in navData[actNav]" :key="index" @click="handleOpt(index)">
  28. {{ item.text }}
  29. </view>
  30. </scroll-view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. // import { getCurDateTime } from '@/libs/utils.js';
  36. export default {
  37. props: {
  38. height: {
  39. type: Number,
  40. default: 108
  41. },
  42. top: {
  43. type: String,
  44. default: 'calc(var(--window-statsu-bar) + 44px)'
  45. },
  46. border: {
  47. type: Boolean,
  48. default: false
  49. },
  50. stylesData:{
  51. type: Object,
  52. default: {}
  53. },
  54. filterData: {
  55. //必填
  56. type: Array,
  57. default: () => {
  58. return [];
  59. }
  60. // default: () => {
  61. // return [
  62. // [{ text: '全部状态', value: '' }, { text: '状态1', value: 1 }, { text: '状态2', value: 2 }, { text: '状态3', value: 3 }],
  63. // [{ text: '全部类型', value: '' }, { text: '类型1', value: 1 }, { text: '类型2', value: 2 }, { text: '类型3', value: 3 }]
  64. // ];
  65. // }
  66. },
  67. defaultIndex: {
  68. //默认选中条件索引,超出一类时必填
  69. type: Array,
  70. default: () => {
  71. return [0];
  72. }
  73. }
  74. },
  75. data() {
  76. return {
  77. navData: [],
  78. popupShow: false,
  79. showMask: false,
  80. actNav: null,
  81. selDate: '选择日期',
  82. selIndex: [] //选中条件索引
  83. };
  84. },
  85. created() {
  86. },
  87. mounted() {
  88. // this.selDate = getCurDateTime().formatDate;
  89. },
  90. methods: {
  91. keepStatus() {
  92. this.navData.forEach(itemnavData => {
  93. itemnavData.map(child => {
  94. child.select = false;
  95. });
  96. return itemnavData;
  97. });
  98. for (let i = 0; i < this.selIndex.length; i++) {
  99. let selindex = this.selIndex[i];
  100. this.navData[i][selindex].select = true;
  101. }
  102. },
  103. navClick(index) {
  104. if (index === this.actNav) {
  105. this.tapMask();
  106. return;
  107. }
  108. this.popupShow = true;
  109. this.showMask = true;
  110. this.actNav = index;
  111. },
  112. handleOpt(index) {
  113. this.selIndex[this.actNav] = index;
  114. this.keepStatus();
  115. setTimeout(() => {
  116. this.tapMask();
  117. }, 100);
  118. let data = [];
  119. let res = this.navData.forEach(item => {
  120. let sel = item.filter(child => child.select);
  121. data.push(sel);
  122. });
  123. console.log(data);
  124. this.$emit('onSelected', data);
  125. },
  126. dateClick() {
  127. this.tapMask();
  128. },
  129. tapMask() {
  130. this.showMask = false;
  131. this.popupShow = false;
  132. this.actNav = null;
  133. },
  134. handleDate(e) {
  135. let d = e.detail.value;
  136. this.selDate = d;
  137. this.$emit('dateChange', d);
  138. },
  139. discard() {}
  140. }
  141. };
  142. </script>
  143. <style lang="scss" scoped>
  144. page {
  145. font-size: 28rpx;
  146. }
  147. .c-flex-align {
  148. display: flex;
  149. align-items: center;
  150. color: rgba(16, 16, 16, 1);
  151. }
  152. .c-flex-center {
  153. display: flex;
  154. align-items: center;
  155. justify-content: center;
  156. flex-direction: column;
  157. }
  158. .filter-wrapper {
  159. position: absolute;
  160. left: 0;
  161. top:0;
  162. width: 100%;
  163. z-index: 50;
  164. height:100rpx;
  165. border-radius: 20rpx;
  166. .inner-wrapper {
  167. // position: relative;
  168. .navs {
  169. position: relative;
  170. height: 100rpx;
  171. padding: 0 0 0 580rpx;
  172. display: flex;
  173. align-items: center;
  174. justify-content: space-between;
  175. background-color: #fff;
  176. border-bottom: 2rpx solid #f5f6f9;
  177. color: #8b9aae;
  178. z-index: 999;
  179. box-sizing: border-box;
  180. &>view {
  181. flex: 1;
  182. height: 100%;
  183. flex-direction: row;
  184. z-index: 999;
  185. }
  186. .date {
  187. // justify-content: flex-end;
  188. width:220rpx;
  189. }
  190. .actNav {
  191. color: #4d7df9;
  192. font-weight: bold;
  193. }
  194. .date-wrapper{
  195. margin-right:30rpx;
  196. }
  197. }
  198. .mask {
  199. z-index: 666;
  200. position: fixed;
  201. top: calc(var(--status-bar-height) + 44px);
  202. left: 0;
  203. right: 0;
  204. bottom: 0;
  205. background-color: rgba(0, 0, 0, 0);
  206. transition: background-color 0.15s linear;
  207. &.show {
  208. background-color: rgba(0, 0, 0, 0.4);
  209. }
  210. &.hide {
  211. display: none;
  212. }
  213. }
  214. .popup {
  215. position: relative;
  216. max-height: 500rpx;
  217. background-color: #fff;
  218. border-bottom-left-radius: 20rpx;
  219. border-bottom-right-radius: 20rpx;
  220. overflow: scroll;
  221. z-index: 999;
  222. transition: all 1s linear;
  223. opacity: 0;
  224. display: none;
  225. .item-opt {
  226. height: 100rpx;
  227. padding: 0 40rpx;
  228. color: #8b9aae;
  229. border-bottom: 2rpx solid #f5f6f9;
  230. }
  231. .actOpt {
  232. color: #4d7df9;
  233. font-weight: bold;
  234. position: relative;
  235. &::after {
  236. content: '✓';
  237. font-weight: bold;
  238. font-size: 36rpx;
  239. position: absolute;
  240. right: 40rpx;
  241. }
  242. }
  243. }
  244. .popupShow {
  245. display: block;
  246. opacity: 1;
  247. }
  248. }
  249. .icon-triangle {
  250. width: 16rpx;
  251. height: 16rpx;
  252. margin-left: 10rpx;
  253. }
  254. }
  255. </style>