| | |
| | | <template> |
| | | <up-popup :show="popupShow" mode="bottom" :popup="false" |
| | | :mask="true" :closeable="true" :safe-area-inset-bottom="true" |
| | | :mask="true" :closeable="closeable" :safe-area-inset-bottom="true" |
| | | close-icon-color="#ffffff" :z-index="uZIndex" |
| | | :maskCloseAble="maskCloseAble" @close="close"> |
| | | <view class="up-p-t-30 up-p-l-20 up-m-b-10" v-if="headerDirection =='column'"> |
| | | <view class="up-p-t-30 up-p-l-20 up-m-b-10" v-if="headerDirection ==='column'"> |
| | | <up-steps v-if="popupShow" dot direction="column" v-model:current="tabsIndex"> |
| | | <up-steps-item v-for="(item, index) in genTabsList" |
| | | @click="tabsIndex = index" :title="item.name"></up-steps-item> |
| | | <view v-for="(item, index) in genTabsList" @click="toFatherIndex(index)"> |
| | | <up-steps-item |
| | | :title="item.name"/> |
| | | </view> |
| | | </up-steps> |
| | | </view> |
| | | <view class="up-p-t-20 up-m-b-10" v-else> |
| | |
| | | * @property {String} labelKey 指定选项标签为选项对象中的哪个属性值 |
| | | * @property {String} childrenKey 指定选项的子选项为选项对象中的哪个属性值 |
| | | * @property {Boolean} autoClose 是否在选择最后一级时自动关闭并触发confirm(默认false) |
| | | * @property {Boolean} closeable 是否显示关闭图标(默认true) |
| | | */ |
| | | import { t } from '../../libs/i18n' |
| | | export default { |
| | |
| | | optionsCols: { |
| | | type: [Number], |
| | | default: 2 |
| | | }, |
| | | // 是否显示关闭图标 |
| | | closeable: { |
| | | type: Boolean, |
| | | default: true |
| | | } |
| | | }, |
| | | data() { |
| | |
| | | data: { |
| | | handler() { |
| | | this.initLevelList(); |
| | | this.setDefaultValue(); |
| | | }, |
| | | immediate: true |
| | | }, |
| | |
| | | }, |
| | | modelValue: { |
| | | handler() { |
| | | this.init(); |
| | | // 初始化选中值 |
| | | this.setDefaultValue(); |
| | | }, |
| | | immediate: true |
| | | } |
| | |
| | | } |
| | | }, |
| | | // 新增confirm事件 |
| | | emits: ['update:modelValue', 'change', 'confirm'], |
| | | emits: ['update:modelValue', 'update:show', 'change', 'confirm', 'cancel'], |
| | | methods: { |
| | | t, |
| | | init() { |
| | | // 初始化选中值 |
| | | if (this.modelValue && this.modelValue.length > 0) { |
| | | this.setDefaultValue(); |
| | | } |
| | | }, |
| | | initLevelList() { |
| | | // 初始化第一级数据 |
| | | if (this.data && this.data.length > 0) { |
| | |
| | | } |
| | | }, |
| | | setDefaultValue() { |
| | | // 检查data是否为空 |
| | | if (!this.data || this.data.length == 0) return; |
| | | // 检查modelValue是否为空 |
| | | if (!this.modelValue || this.modelValue.length == 0) return; |
| | | // 根据默认值设置选中项 |
| | | // 根据modelValue获取indexs给selectedValueIndexs |
| | | this.selectedValueIndexs = []; |
| | | this.levelList = []; // 设置层级数据为空 |
| | | let currentLevelData = this.data; |
| | | |
| | | for (let i = 0; i < this.modelValue.length; i++) { |
| | | const value = this.modelValue[i]; |
| | | const index = currentLevelData.findIndex(item => item[this.valueKey] === value); |
| | | this.levelList[i] = currentLevelData; // 设置每一层级的数据 |
| | | |
| | | if (index !== -1) { |
| | | this.selectedValueIndexs.push(index); |
| | |
| | | } |
| | | }, |
| | | close() { |
| | | this.$emit('cancel'); |
| | | this.$emit('update:show', false); |
| | | }, |
| | | tabsChange(item) { |
| | |
| | | if (this.autoClose) { |
| | | // 如果启用自动关闭,则触发change事件并关闭 |
| | | this.emitChange(); |
| | | this.handleConfirm(); |
| | | } else { |
| | | // 否则只触发change事件,不关闭 |
| | | this.emitChange(false); |
| | |
| | | this.$emit('update:modelValue', this.confirmValues); |
| | | this.$emit('confirm', this.confirmValues); |
| | | this.close(); |
| | | } |
| | | }, |
| | | // 跳转父节点 |
| | | toFatherIndex(index){ |
| | | this.tabsIndex = index; |
| | | }, |
| | | } |
| | | } |
| | | </script> |