123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <template>
- <view class="u-collapse">
- <u-line v-if="border"></u-line>
- <slot />
- </view>
- </template>
- <script>
- import props from './props.js';
-
- export default {
- name: "u-collapse",
- mixins: [uni.$u.mpMixin, uni.$u.mixin,props],
- watch: {
- needInit() {
- this.init()
- }
- },
- created() {
- this.children = []
- },
- computed: {
- needInit() {
-
-
- return [this.accordion, this.value]
- }
- },
- watch: {
-
- parentData() {
- if (this.children.length) {
- this.children.map(child => {
-
- typeof(child.updateParentData) === 'function' && child.updateParentData()
- })
- }
- },
- },
- 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>
|