12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <template>
- <view class="u-collapse">
- <u-line v-if="border"></u-line>
- <slot />
- </view>
- </template>
- <script>
- import { props } from './props';
- import { mpMixin } from '../../libs/mixin/mpMixin';
- import { mixin } from '../../libs/mixin/mixin';
-
- export default {
- name: "u-collapse",
- mixins: [mpMixin, mixin,props],
- watch: {
- needInit() {
- this.init()
- },
-
- parentData() {
- if (this.children.length) {
- this.children.map(child => {
-
- typeof(child.updateParentData) === 'function' && child.updateParentData()
- })
- }
- }
- },
- created() {
- this.children = []
- },
- computed: {
- needInit() {
-
-
- return [this.accordion, this.value]
- }
- },
- emits: ["open", "close", "change"],
- methods: {
-
- init() {
- this.children.map(child => {
- child.init()
- })
- },
-
- onChange(target) {
- let changeArr = []
- this.children.map((child, index) => {
-
- if (this.accordion) {
- child.expanded = child === target ? !target.expanded : false
- child.setContentAnimate()
- } else {
- if(child === target) {
- child.expanded = !child.expanded
- child.setContentAnimate()
- }
- }
-
- changeArr.push({
-
- name: child.name || index,
- status: child.expanded ? 'open' : 'close'
- })
- })
- this.$emit('change', changeArr)
- this.$emit(target.expanded ? 'open' : 'close', target.name)
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @import "../../libs/css/components.scss";
- </style>
|