uni-goods-nav.vue 4.8 KB
Newer Older
M
mehaotian 已提交
1
<template>
2
	<view class="uni-goods-nav">
M
mehaotian 已提交
3 4 5
		<!-- 底部占位 -->
		<view class="uni-tab__seat" />
		<view class="uni-tab__cart-box flex">
雪洛's avatar
雪洛 已提交
6
			<view class="flex uni-tab__cart-sub-left">
M
mehaotian 已提交
7 8
				<view v-for="(item,index) in options" :key="index" class="flex uni-tab__cart-button-left uni-tab__shop-cart" @click="onClick(index,item)">
					<view class="uni-tab__icon">
雪洛's avatar
雪洛 已提交
9 10
						<uni-icons :type="item.icon" size="20" color="#646566"></uni-icons>
						<!-- <image class="image" :src="item.icon" mode="widthFix" /> -->
M
mehaotian 已提交
11 12 13
					</view>
					<text class="uni-tab__text">{{ item.text }}</text>
					<view class="flex uni-tab__dot-box">
14 15 16
						<text v-if="item.info" :class="{ 'uni-tab__dots': item.info > 9 }" class="uni-tab__dot " :style="{'backgroundColor':item.infoBackgroundColor?item.infoBackgroundColor:'#ff0000',
						color:item.infoColor?item.infoColor:'#fff'
						}">{{ item.info }}</text>
M
mehaotian 已提交
17 18 19
					</view>
				</view>
			</view>
雪洛's avatar
雪洛 已提交
20
			<view :class="{'uni-tab__right':fill}" class="flex uni-tab__cart-sub-right ">
21
				<view v-for="(item,index) in buttonGroup" :key="index" :style="{backgroundColor:item.backgroundColor,color:item.color}" class="flex uni-tab__cart-button-right" @click="buttonClick(index,item)"><text :style="{color:item.color}" class="uni-tab__cart-button-right-text">{{ item.text }}</text></view>
M
mehaotian 已提交
22 23 24 25 26 27
			</view>
		</view>
	</view>
</template>

<script>
雪洛's avatar
雪洛 已提交
28
	import uniIcons from '../uni-icons/uni-icons.vue'
29 30 31 32 33 34 35 36 37 38 39
	/**
	 * GoodsNav 商品导航
	 * @description 商品加入购物车、立即购买等
	 * @tutorial https://ext.dcloud.net.cn/plugin?id=865
	 * @property {Array} options 组件参数
	 * @property {Array} buttonGroup 组件按钮组参数
	 * @property {Boolean} fill = [true | false] 组件按钮组参数
	 * @event {Function} click 左侧点击事件
	 * @event {Function} buttonClick 右侧按钮组点击事件
	 * @example <uni-goods-nav :fill="true"  options="" buttonGroup="buttonGroup"  @click="" @buttonClick="" />
	 */
M
mehaotian 已提交
40 41
	export default {
		name: 'UniGoodsNav',
雪洛's avatar
雪洛 已提交
42 43 44
		components: {
			uniIcons
		},
M
mehaotian 已提交
45 46 47 48 49
		props: {
			options: {
				type: Array,
				default () {
					return [{
雪洛's avatar
雪洛 已提交
50
						icon: 'shop',
51
						text: '店铺',
M
mehaotian 已提交
52
					}, {
雪洛's avatar
雪洛 已提交
53
						icon: 'cart',
M
mehaotian 已提交
54 55 56 57 58 59 60 61 62
						text: '购物车'
					}]
				}
			},
			buttonGroup: {
				type: Array,
				default () {
					return [{
							text: '加入购物车',
雪洛's avatar
雪洛 已提交
63
							backgroundColor: '#ffa200',
M
mehaotian 已提交
64 65 66 67
							color: '#fff'
						},
						{
							text: '立即购买',
雪洛's avatar
雪洛 已提交
68
							backgroundColor: '#ff0000',
M
mehaotian 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82
							color: '#fff'
						}
					]
				}
			},
			fill: {
				type: Boolean,
				default: false
			}
		},
		methods: {
			onClick(index, item) {
				this.$emit('click', {
					index,
雪洛's avatar
雪洛 已提交
83 84
					content: item,

M
mehaotian 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
				})
			},
			buttonClick(index, item) {
				if (uni.report) {
					uni.report(item.text, item.text)
				}
				this.$emit('buttonClick', {
					index,
					content: item
				})
			}
		}
	}
</script>

100
<style scoped>
M
mehaotian 已提交
101
	.flex {
102 103 104 105 106 107 108 109
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
	}

	.uni-goods-nav {
		/* #ifndef APP-NVUE */
M
mehaotian 已提交
110
		display: flex;
111 112 113
		/* #endif */
		flex: 1;
		flex-direction: row;
M
mehaotian 已提交
114 115 116
	}

	.uni-tab__cart-box {
117
		flex: 1;
雪洛's avatar
雪洛 已提交
118
		height: 50px;
119
		background-color: #fff;
M
mehaotian 已提交
120 121 122
		z-index: 900;
	}

雪洛's avatar
雪洛 已提交
123 124 125 126 127
	.uni-tab__cart-sub-left {
		padding: 0 5px;
	}

	.uni-tab__cart-sub-right {
128
		flex: 1;
M
mehaotian 已提交
129 130 131 132 133 134 135 136 137 138
	}

	.uni-tab__right {
		margin: 5px 0;
		margin-right: 10px;
		border-radius: 100px;
		overflow: hidden;
	}

	.uni-tab__cart-button-left {
139 140 141
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
M
mehaotian 已提交
142 143 144 145
		position: relative;
		justify-content: center;
		align-items: center;
		flex-direction: column;
雪洛's avatar
雪洛 已提交
146
		margin: 0 10px;
inkwalk's avatar
inkwalk 已提交
147 148 149
		/* #ifdef H5 */
		cursor: pointer;
		/* #endif */
M
mehaotian 已提交
150 151 152
	}

	.uni-tab__icon {
雪洛's avatar
雪洛 已提交
153 154
		width: 18px;
		height: 18px;
M
mehaotian 已提交
155 156
	}

157
	.image {
雪洛's avatar
雪洛 已提交
158 159
		width: 18px;
		height: 18px;
M
mehaotian 已提交
160 161
	}

162
	.uni-tab__text {
163
		margin-top: 3px;
164
		font-size: 12px;
雪洛's avatar
雪洛 已提交
165
		color: #646566;
M
mehaotian 已提交
166 167 168
	}

	.uni-tab__cart-button-right {
169 170 171 172 173
		/* #ifndef APP-NVUE */
		display: flex;
		flex-direction: column;
		/* #endif */
		flex: 1;
M
mehaotian 已提交
174 175
		justify-content: center;
		align-items: center;
inkwalk's avatar
inkwalk 已提交
176 177 178
		/* #ifdef H5 */
		cursor: pointer;
		/* #endif */
179 180 181
	}

	.uni-tab__cart-button-right-text {
182
		font-size: 14px;
M
mehaotian 已提交
183 184 185 186 187 188 189
		color: #fff;
	}

	.uni-tab__cart-button-right:active {
		opacity: 0.7;
	}

190 191 192 193 194
	.uni-tab__dot-box {
		/* #ifndef APP-NVUE */
		display: flex;
		flex-direction: column;
		/* #endif */
M
mehaotian 已提交
195
		position: absolute;
雪洛's avatar
雪洛 已提交
196 197
		right: -2px;
		top: 2px;
M
mehaotian 已提交
198 199 200 201
		justify-content: center;
		align-items: center;
	}

202
	.uni-tab__dot {
203 204
		padding: 0 4px;
		line-height: 15px;
M
mehaotian 已提交
205 206 207
		color: #ffffff;
		text-align: center;
		font-size: 12px;
208
		background-color: #ff0000;
209
		border-radius: 15px;
M
mehaotian 已提交
210 211
	}

212
	.uni-tab__dots {
213 214
		padding: 0 4px;
		border-radius: 15px;
M
mehaotian 已提交
215 216 217
	}

	.uni-tab__color-y {
218
		background-color: #ffa200;
M
mehaotian 已提交
219 220 221
	}

	.uni-tab__color-r {
222
		background-color: #ff0000;
M
mehaotian 已提交
223 224
	}
</style>