123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <template>
- <view class="u-dropdown-item" v-if="active" @touchmove.stop.prevent @tap.stop.prevent>
- <view class="u-dropdown-item__options" v-if="!$slots.default">
- <u-cell-group>
- <u-cell-item @click="cellClick(item.value)" :arrow="false" :title="item.label" v-for="(item, index) in options" :key="index" :title-style="{
- color: value == item.value ? activeColor : inactiveColor
- }">
- <u-icon v-if="value == item.value" name="checkbox-mark" :color="activeColor" size="32"></u-icon>
- </u-cell-item>
- </u-cell-group>
- </view>
- <slot v-else />
- </view>
- </template>
- <script>
- export default {
- name: 'u-dropdown-item',
- props: {
-
- value: {
- type: [Number, String, Array],
- default: ''
- },
-
- title: {
- type: [String, Number],
- default: ''
- },
-
- options: {
- type: Array,
- default () {
- return []
- }
- },
-
- disabled: {
- type: Boolean,
- default: false
- },
- },
- 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;
- },
- methods: {
- init() {
-
- let parent = this.$u.$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.parent.close();
-
- this.$emit('change', value);
- }
- },
- mounted() {
- this.init();
- }
- }
- </script>
- <style scoped lang="scss">
- @import "../../libs/css/style.components.scss";
- </style>
|