123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <template>
- <view class="u-dropdown-item" v-if="active" @touchmove.stop.prevent="() => {}" @tap.stop.prevent="() => {}">
- <block v-if="!$slots.default && !$slots.$default">
- <scroll-view class="u-dropdown-item__scroll" scroll-y="true" :style="{
- height: addUnit(height)
- }">
- <view class="u-dropdown-item__options">
- <up-cell-group>
- <up-cell @click="cellClick(item.value)" :arrow="false" :title="item.label" v-for="(item, index) in options"
- :key="index" :title-style="{
- color: modelValue == item.value ? activeColor : inactiveColor
- }">
- <up-icon v-if="modelValue == item.value" name="checkbox-mark" :color="activeColor" size="32"></up-icon>
- </up-cell>
- </up-cell-group>
- </view>
- </scroll-view>
- </block>
- <slot v-else />
- </view>
- </template>
- <script>
- import { props } from './props';
- import { mpMixin } from '../../libs/mixin/mpMixin';
- import { mixin } from '../../libs/mixin/mixin';
- import { addUnit, $parent } from '../../libs/function/index';
-
- export default {
- name: 'u-dropdown-item',
- mixins: [mpMixin, mixin, props],
- options: {
- styleIsolation: 'shared',
- },
- data() {
- return {
- active: false,
- activeColor: '#2979ff',
- inactiveColor: '#606266',
- }
- },
- computed: {
-
- propsChange() {
- return `${this.title}-${this.disabled}`;
- }
- },
- watch: {
- propsChange(n) {
-
-
- if (this.parent) this.parent.init();
- }
- },
- created() {
-
- this.parent = false;
- },
- emits: ['update:modelValue', 'change'],
- methods: {
- addUnit,
- init() {
-
- let parent = $parent.call(this, 'u-dropdown');
- if (parent) {
- this.parent = parent;
-
- this.activeColor = parent.activeColor;
- this.inactiveColor = parent.inactiveColor;
-
-
- let exist = parent.children.find(val => {
- return this === val;
- })
- if (!exist) parent.children.push(this);
- if (parent.children.length == 1) this.active = true;
-
- parent.menuList.push({
- title: this.title,
- disabled: this.disabled
- });
- }
- },
-
- cellClick(value) {
-
-
- this.$emit('input', value);
-
-
- this.$emit('update:modelValue', value);
-
-
- this.parent.close();
-
- this.$emit('change', value);
- }
- },
- mounted() {
- this.init();
- }
- }
- </script>
- <style scoped lang="scss">
- @import "../../libs/css/components.scss";
- .u-dropdown-item__scroll {
- background: #ffffff;
- }
- </style>
|