Blame view

src/components/UniCollapseItem/UniCollapseItem.vue 6.2 KB
71166190e   BigBoss   add purchase
1
2
3
4
  <template>
  	<view :class="{ 'uni-collapse-cell--disabled': disabled,'uni-collapse-cell--notdisabled': !disabled, 'uni-collapse-cell--open': isOpen,'uni-collapse-cell--hide':!isOpen }"
  	 class="uni-collapse-cell">
  		<view class="uni-collapse-cell__title" @click="onClick">
5b513503f   BigBoss   验光数据页面
5
  			<view v-if="iconText" class="uni-collapse-cell__title-iconText" v-bind:style="{background:background}">{{iconText}}</view>
71166190e   BigBoss   add purchase
6
7
  			<image v-if="thumb" :src="thumb" class="uni-collapse-cell__title-img" />
  			<text class="uni-collapse-cell__title-text">{{ title }}</text>
5b513503f   BigBoss   验光数据页面
8
  			<text class="uni-collapse-cell__time-text">{{ time }}</text>
71166190e   BigBoss   add purchase
9
10
11
12
13
14
15
16
17
18
19
20
  			<!-- #ifdef MP-ALIPAY -->
  			<view :class="{ 'uni-collapse-cell__title-arrow-active': isOpen, 'uni-collapse-cell--animation': showAnimation === true }"
  			 class="uni-collapse-cell__title-arrow">
  				<uni-icons color="#bbb" size="20" type="arrowdown" />
  			</view>
  			<!-- #endif -->
  			<!-- #ifndef MP-ALIPAY -->
  			<uni-icons :class="{ 'uni-collapse-cell__title-arrow-active': isOpen, 'uni-collapse-cell--animation': showAnimation === true }"
  			 class="uni-collapse-cell__title-arrow" color="#bbb" size="20" type="arrowdown" />
  			<!-- #endif -->
  		</view>
  		<view :class="{'uni-collapse-cell__content--hide':!isOpen}" class="uni-collapse-cell__content">
c338b4909   BigBoss   完善页面跳转逻辑
21
  			<view :class="{ 'uni-collapse-cell--animation': showAnimation === true }" class="uni-collapse-cell__wrapper" 
5b513503f   BigBoss   验光数据页面
22
  			:style="{'transform':isOpen?'translateY(0)':'translateY(-100%)','-webkit-transform':isOpen?'translateY(0)':'translateY(-100%)'}">
71166190e   BigBoss   add purchase
23
24
25
26
27
28
29
  				<slot />
  			</view>
  		</view>
  	</view>
  </template>
  
  <script>
9ff2df1bf   范牧   文件名称规范
30
  	import UniIcons from '../UniIcons/UniIcons.vue'
71166190e   BigBoss   add purchase
31
32
33
  	export default {
  		name: 'UniCollapseItem',
  		components: {
9ff2df1bf   范牧   文件名称规范
34
  			UniIcons
71166190e   BigBoss   add purchase
35
36
37
38
39
40
41
  		},
  		props: {
  			title: {
  				// 列表标题
  				type: String,
  				default: ''
  			},
5b513503f   BigBoss   验光数据页面
42
43
44
45
46
  			time: {
  				// 列表时间 朱海涛加的,验光数据需要
  				type: String,
  				default: ''
  			},
71166190e   BigBoss   add purchase
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  			name: {
  				// 唯一标识符
  				type: [Number, String],
  				default: 0
  			},
  			disabled: {
  				// 是否禁用
  				type: Boolean,
  				default: false
  			},
  			showAnimation: {
  				// 是否显示动画
  				type: Boolean,
  				default: false
  			},
  			open: {
  				// 是否展开
  				type: Boolean,
  				default: false
  			},
  			thumb: {
  				// 缩略图
  				type: String,
  				default: ''
5b513503f   BigBoss   验光数据页面
71
72
73
74
75
  			},
  			iconText:{
  				//名字头像
  				type:String,
  				default:''
71166190e   BigBoss   add purchase
76
77
78
79
  			}
  		},
  		data() {
  			return {
5b513503f   BigBoss   验光数据页面
80
81
82
  				isOpen: false,
  				background: ''
  				 
71166190e   BigBoss   add purchase
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
  			}
  		},
  		watch: {
  			open(val) {
  				this.isOpen = val
  			}
  		},
  		inject: ['collapse'],
  		created() {
  			this.isOpen = this.open
  			this.nameSync = this.name ? this.name : this.collapse.childrens.length
  			this.collapse.childrens.push(this)
  			if (String(this.collapse.accordion) === 'true') {
  				if (this.isOpen) {
  					let lastEl = this.collapse.childrens[this.collapse.childrens.length - 2]
  					if (lastEl) {
  						this.collapse.childrens[this.collapse.childrens.length - 2].isOpen = false
  					}
  				}
  			}
  		},
5b513503f   BigBoss   验光数据页面
104
105
106
107
108
109
110
111
112
113
114
  		computed:{
  			//给头像搞个随机背景颜色,验光数据页面需要
  			getRandomColor(){
  				let r = Math.floor(Math.random()*256);
  				let g = Math.floor(Math.random()*256);
  				let b = Math.floor(Math.random()*256);
  				let color = '#'+r.toString(16)+g.toString(16)+b.toString(16);
  				this.background = color
  				// return color;
  			}
  		},
71166190e   BigBoss   add purchase
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
  		methods: {
  			onClick() {
  				if (this.disabled) {
  					return
  				}
  				if (String(this.collapse.accordion) === 'true') {
  					this.collapse.childrens.forEach(vm => {
  						if (vm === this) {
  							return
  						}
  						vm.isOpen = false
  					})
  				}
  				this.isOpen = !this.isOpen
  				this.collapse.onChange && this.collapse.onChange()
  				this.$forceUpdate()
5b513503f   BigBoss   验光数据页面
131
132
  				// console.log(this.isOpen)
  			},
71166190e   BigBoss   add purchase
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
  		}
  	}
  </script>
  
  <style lang="scss" scoped>
  	@import '@/uni.scss';
  
  	.uni-collapse-cell {
  		flex-direction: column;
  		border-color: #FFFFFF;
  		border-bottom-width: 1px;
  		border-bottom-style: solid;
  	}
  
  
  	.uni-collapse-cell--hover {
  		background-color: #FFFFFF;
  	}
  
  	.uni-collapse-cell--open {
  		background-color: #FFFFFF;
  	}
  
  	.uni-collapse-cell--disabled {
  		background-color: #FFFFFF;
  		// opacity: 0.3;
  	}
  
  
  	.uni-collapse-cell--hide {
  		height: 48px;
  	}
  
  	.uni-collapse-cell--animation {
5b513503f   BigBoss   验光数据页面
167
  		transition: transform all 0.3s ease;
71166190e   BigBoss   add purchase
168
  		transition-property: transform;
5b513503f   BigBoss   验光数据页面
169
  		transition-duration: 0.3s;
71166190e   BigBoss   add purchase
170
171
172
173
174
  		transition-timing-function: ease;
  	}
  
  	.uni-collapse-cell__title {
  		// padding: 12px 12px;
9ff2df1bf   范牧   文件名称规范
175
  		font-size: 16px;
71166190e   BigBoss   add purchase
176
177
178
179
180
181
182
183
184
185
186
187
188
  		color: #333333;
  		position: relative;
  		/* #ifndef APP-NVUE */
  		display: flex;
  		width: 100%;
  		box-sizing: border-box;
  		/* #endif */
  		height: 48px;
  		line-height: 24px;
  		flex-direction: row;
  		justify-content: space-between;
  		align-items: center;
  	}
5b513503f   BigBoss   验光数据页面
189
190
191
192
193
194
195
196
197
198
199
200
  	.uni-collapse-cell__title-iconText{
  		border: 1px solid #FFFFFF;
  		height: 50rpx;
  		width: 50rpx;
  		border-radius: 26rpx;
  		// background-color: #47A6F0;
  		font-size: 12px;
  		color: #FFFFFF;
  		line-height: 50rpx;
  		text-align: center;
  		margin-right: 20rpx;
  	}
71166190e   BigBoss   add purchase
201
202
203
204
205
206
207
208
  	.uni-collapse-cell__title:active {
  		background-color: #FFFFFF;
  	}
  
  	.uni-collapse-cell__title-img {
  		height: $uni-img-size-base;
  		width: $uni-img-size-base;
  		margin-right: 10px;
5b513503f   BigBoss   验光数据页面
209
210
211
212
  		// height: 50rpx;
  		// width: 50rpx;
  		// border-radius: 25rpx;
  		// border-radius: 25rpx;
71166190e   BigBoss   add purchase
213
214
215
216
217
  	}
  
  	.uni-collapse-cell__title-arrow {
  		width: 20px;
  		height: 20px;
5b513503f   BigBoss   验光数据页面
218
  		transform: rotate(-90deg);
71166190e   BigBoss   add purchase
219
220
221
222
223
  		transform-origin: center center;
  
  	}
  
  	.uni-collapse-cell__title-arrow-active {
5b513503f   BigBoss   验光数据页面
224
  		transform: rotate(0deg);
71166190e   BigBoss   add purchase
225
226
227
228
229
230
231
232
233
234
235
236
237
238
  	}
  
  	.uni-collapse-cell__title-text {
  		flex: 1;
  		font-size: $uni-font-size-base;
  		/* #ifndef APP-NVUE */
  		white-space: nowrap;
  		color: inherit;
  		/* #endif */
  		/* #ifdef APP-NVUE */
  		lines: 1;
  		/* #endif */
  		overflow: hidden;
  		text-overflow: ellipsis;
5b513503f   BigBoss   验光数据页面
239
240
241
242
243
244
245
  		font-size: 12px;
  		color: #333333;
  	}
  	.uni-collapse-cell__time-text{
  		font-size: 12px;
  		color: #999999;
  		margin-right: 20rpx;
71166190e   BigBoss   add purchase
246
  	}
71166190e   BigBoss   add purchase
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
  	.uni-collapse-cell__content {
  		overflow: hidden;
  	}
  
  	.uni-collapse-cell__wrapper {
  		/* #ifndef APP-NVUE */
  		display: flex;
  		/* #endif */
  		flex-direction: column;
  	}
  
  	.uni-collapse-cell__content--hide {
  		// height: 0px;
  		// line-height: 0px;
  	}
  </style>