uView折叠面板修改版

uView折叠面板修改版_第1张图片
写了一个折叠面板,代码如下

<template>
	<view>
		<u-collapse>
			<u-collapse-item name="guide" v-for="(item,i) in collapseList" :key="i">
				<text slot="value" class="u-page__item__title__slot-title clickAllBtn" @click.stop="clickAll(item)">全选</text>
				<text slot="title" class="u-page__item__title__slot-title">{{item.name}} <text
						style="font-size: 28rpx;">(已选择:<text style="color: #5590F6;">{{item.selectedLength?item.selectedLength:0}}</text>/{{item.children.length}}</text></text>
				<view class="u-collapse-content"
					style="height: 84rpx;border-bottom: 1px solid rgba(112, 112, 112, 0.09);position: relative;"
					v-for="(children,index) in item.children" :key="index">
					<text
						style="font-size: 28rpx;color: #419AF1;font-weight: 400;margin:32rpx 40rpx 24rpx 32rpx ;line-height: 84rpx;">{{children.peopleName}}</text>
					<text>{{children.address}}</text>

					<text class="select" @click="unchoose(children,item)" v-if="children.selected"
						style="color: #EB6326;border: 1px solid #EB6326;">已选择</text>
					<text class="select" @click="choose(children,item)" v-else>选择</text>
				</view>
			</u-collapse-item>
		</u-collapse>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				collapseList: [{
						name: '第一幢',
						children: [{
								peopleName: '张翼1',
								address: '德馨园44幢四单元401',
								id:1
							},
							{
								peopleName: '张翼2',
								address: '德馨园44幢四单元402',
								id:2
							},
							{
								peopleName: '张翼3',
								address: '德馨园44幢四单元403',
								id:3
							},
							{
								peopleName: '张翼4',
								address: '德馨园44幢四单元404',
								id:4
							},
						]
					},
					{
						name: '第二幢',
						children: [{
								peopleName: '张翼5',
								address: '德馨园44幢四单元401',
								id:5
							},
							{
								peopleName: '张翼6',
								address: '德馨园44幢四单元402',
								id:6
							},
							{
								peopleName: '张翼德',
								address: '德馨园44幢四单元403',
								id:7
							},
						]
					}
				]
			}
		},
		methods: {
			choose(children,item) {
				this.$set(children, 'selected', true)
				this.$set(item, 'selectedLength', item.children.filter(it=>it.selected==true).length) 
			},
			unchoose(children,item) {
				this.$set(children, 'selected', false)
				this.$set(item, 'selectedLength', item.children.filter(it=>it.selected==true).length) 
			},
			clickAll(item) {
				item.children.forEach(it =>
					this.$set(it, 'selected', true)
				)
				this.$set(item, 'selectedLength', item.children.filter(it=>it.selected==true).length) 
			},
		}
	}
</script>

<style lang="scss" scoped>
	/deep/ .u-collapse-item__content__text {
		padding: 0;
	}

	/deep/ .u-cell__right-icon-wrap {
		position: absolute;
		left: 20rpx;
		// left: 32rpx;
	}

	/deep/ .u-cell__title {
		position: absolute;
		left: 70rpx;
	}

	/deep/ .u-icon__icon {
		font-size: 12rpx !important;
		// color: #3380EB;
	}

	.select {
		width: 120rpx;
		height: 48rpx;
		display: inline-block;
		line-height: 48rpx;
		text-align: center;
		background: rgba(255, 255, 255, 0);
		color: #2680EB;
		border: 1px solid #2680EB;
		margin-top: 18rpx;
		cursor: pointer;
		border-radius: 4rpx;
		position: absolute;
		right: 32rpx;
	}

	.clickAllBtn {
		width: 120rpx;
		height: 48rpx;
		background: #3380EB;
		color: #FFFFFF;
		line-height: 48rpx;
		text-align: center;
		font-size: 28rpx;
		border: 1px solid #2680EB;
		border-radius: 4rpx;
		cursor: pointer;
	}
</style>

你可能感兴趣的:(vue,uni-app,js,javascript,css3,css)