123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- <template>
- <view class="u-collapse-item" :style="[itemStyle]">
- <view :hover-stay-time="200" class="u-collapse-head" @tap.stop="headClick" :hover-class="hoverClass" :style="[headStyle]">
- <block v-if="!$slots['title-all']">
- <view v-if="!$slots['title']" class="u-collapse-title u-line-1" :style="[{ textAlign: align ? align : 'left' },
- isShow && activeStyle && !arrow ? activeStyle : '']">
- {{ title }}
- </view>
- <slot v-else name="title" />
- <view class="u-icon-wrap">
- <u-icon v-if="arrow" :color="arrowColor" :class="{ 'u-arrow-down-icon-active': isShow }"
- class="u-arrow-down-icon" name="arrow-down"></u-icon>
- </view>
- </block>
- <slot v-else name="title-all" />
- </view>
- <view class="u-collapse-body" :style="[{
- height: isShow ? height + 'px' : '0'
- }]">
- <view class="u-collapse-content" :id="elId" :style="[bodyStyle]">
- <slot></slot>
- </view>
- </view>
- </view>
- </template>
- <script>
-
- export default {
- name: "u-collapse-item",
- props: {
-
- title: {
- type: String,
- default: ''
- },
-
- align: {
- type: String,
- default: 'left'
- },
-
- disabled: {
- type: Boolean,
- default: false
- },
-
- open: {
- type: Boolean,
- default: false
- },
-
- name: {
- type: [Number, String],
- default: ''
- },
-
- activeStyle: {
- type: Object,
- default () {
- return {}
- }
- },
-
- index: {
- type: [String, Number],
- default: ''
- }
- },
- data() {
- return {
- isShow: false,
- elId: this.$u.guid(),
- height: 0,
- headStyle: {},
- bodyStyle: {},
- itemStyle: {},
- arrowColor: '',
- hoverClass: '',
- arrow: true,
-
- };
- },
- watch: {
- open(val) {
- this.isShow = val;
- }
- },
- created() {
- this.parent = false;
-
- this.isShow = this.open;
- },
- methods: {
-
- init() {
- this.parent = this.$u.$parent.call(this, 'u-collapse');
- if(this.parent) {
- this.nameSync = this.name ? this.name : this.parent.childrens.length;
- this.parent.childrens.push(this);
- this.headStyle = this.parent.headStyle;
- this.bodyStyle = this.parent.bodyStyle;
- this.arrowColor = this.parent.arrowColor;
- this.hoverClass = this.parent.hoverClass;
- this.arrow = this.parent.arrow;
- this.itemStyle = this.parent.itemStyle;
- }
- this.$nextTick(() => {
- this.queryRect();
- });
- },
-
- headClick() {
- if (this.disabled) return;
- if (this.parent && this.parent.accordion == true) {
- this.parent.childrens.map(val => {
-
- if (this != val) {
- val.isShow = false;
- }
- });
- }
- this.isShow = !this.isShow;
-
- this.$emit('change', {
- index: this.index,
- show: this.isShow
- })
-
- if (this.isShow) this.parent && this.parent.onChange();
- this.$forceUpdate();
- },
-
- queryRect() {
-
-
- this.$uGetRect('#' + this.elId).then(res => {
- this.height = res.height;
- })
- }
- },
- mounted() {
- this.init();
- }
- };
- </script>
- <style lang="scss" scoped>
- @import "../../libs/css/style.components.scss";
-
- .u-collapse-head {
- position: relative;
- @include vue-flex;
- justify-content: space-between;
- align-items: center;
- color: $u-main-color;
- font-size: 30rpx;
- line-height: 1;
- padding: 24rpx 0;
- text-align: left;
- }
- .u-collapse-title {
- flex: 1;
- overflow: hidden;
- }
- .u-arrow-down-icon {
- transition: all 0.3s;
- margin-right: 20rpx;
- margin-left: 14rpx;
- }
- .u-arrow-down-icon-active {
- transform: rotate(180deg);
- transform-origin: center center;
- }
- .u-collapse-body {
- overflow: hidden;
- transition: all 0.3s;
- }
- .u-collapse-content {
- overflow: hidden;
- font-size: 28rpx;
- color: $u-tips-color;
- text-align: left;
- }
- </style>
|