123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- <template>
- <view class="drop" @click.stop>
- <view class="drop-control" @click="handleOpenFilter">
- <view class="drop-label">
- {{ activeLabel }}
- </view>
- <view ref="icon" class="drop-icon">
- <text class="wk wk-arrow-right icon" />
- </view>
- </view>
- <uni-popup
- ref="popupBottom"
- radius="10rpx 10rpx 0 0"
- type="bottom">
- <view class="filter-popup">
- <view class="popup-header">
- <view class="text">
- {{ title }}
- </view>
- <text class="wk wk-close icon" @click="handleCloseFilter" />
- </view>
- <view class="popup-content">
- <view class="list">
- <view
- v-for="item in list"
- :key="item[valueField]"
- :class="{active: value === item[valueField]}"
- class="list-item"
- @click="handleSelect(item)">
- <text class="text">
- {{ item[labelField] }}
- </text>
- <text v-show="value === item[valueField]" class="wk wk-check icon" />
- </view>
- </view>
- </view>
- </view>
- </uni-popup>
- </view>
- </template>
- <script>
- export default {
- name: 'WkDropDown',
- props: {
- list: {
- type: Array,
- default: () => []
- },
- labelField: {
- type: String,
- default: 'label'
- },
- valueField: {
- type: String,
- default: 'value'
- },
- value: {
- type: [Object, String, Array, Number],
- default: null
- },
- title: {
- type: String,
- default: '筛选'
- }
- },
- data() {
- return {}
- },
- computed: {
- activeLabel() {
- if (this.value) {
- const findRes = this.list.find(o => o[this.valueField] === this.value)
- if (findRes) {
- return findRes[this.labelField]
- } else {
- this.emitValue(this.list[0])
- }
- } else {
- this.emitValue(this.list[0])
- }
- return ''
- }
- },
- methods: {
- handleOpenFilter() {
- this.$refs.popupBottom.open()
- },
- handleCloseFilter() {
- this.$refs.popupBottom.close()
- this.$emit('close')
- },
- emitValue(item) {
- const value = item[this.valueField]
- this.$emit('input', value)
- this.$emit('change', value)
- },
- handleSelect(item) {
- this.emitValue(item)
- this.handleCloseFilter()
- }
- }
- }
- </script>
- <style scoped lang="scss">
- .drop {
- position: relative;
- font-size: 26rpx;
- .drop-control {
- background-color: #F5F5F5;
- border-radius: 4rpx;
- padding: 8rpx 15rpx;
- @include left;
- .drop-label {
- color: $gray;
- margin-right: 15rpx;
- line-height: 1;
- }
- .drop-icon {
- will-change: transform;
- transition: all ease .2s;
- @include center;
- .icon {
- line-height: 1;
- font-size: 24rpx;
- transform: rotate(90deg);
- }
- &.active {
- transform: rotate(180deg);
- }
- }
- }
- .filter-popup {
- padding: 36rpx;
- .popup-header {
- position: relative;
- @include center;
- .text {
- font-size: $wk-font-large;
- }
- .icon {
- position: absolute;
- left: 0;
- top: 50%;
- transform: translateY(-50%);
- color: $gray;
- font-size: $wk-font-medium;
- }
- }
- .popup-content {
- width: 100%;
- min-height: 500rpx;
- max-height: 700rpx;
- overflow: auto;
- margin-top: 38rpx;
- .list {
- width: 100%;
- .list-item {
- color: $dark;
- font-size: $wk-font-base;
- border-bottom: 1rpx solid $border-color;
- padding: 22rpx 0;
- @include left;
- .text {
- flex: 1;
- }
- .icon {
- font-size: $wk-font-medium;
- color: inherit;
- line-height: 1;
- }
- &.active {
- color: $theme-color;
- }
- }
- }
- }
- }
- }
- </style>
|