buttonSelect.vue 2.52 KB
<script setup lang="ts">
import { computed, ref } from "vue";

const props = defineProps({
	item: {
		type: Object,
		default: () => { },
	},
});

const emit = defineEmits(["update"]);

const pickerValue = ref([]);

const columnsList = ref([
	{ label: '精品', value: '1' },
	{ label: '瑕疵', value: '2' },
	{ label: '重大', value: '3' },
	{ label: '精品', value: '5' },
	{ label: '瑕疵', value: '6' },
	{ label: '重大', value: '7' },
	{ label: '瑕疵', value: '8' },
	{ label: '钣金修复', value: '9' }
])

// 计算属性
// const columnsList = computed(() => {
// 	return columns;
// });

function handleBut(item: { value: string }) {
	if (pickerValue.value.includes(item.value)) {
		pickerValue.value = pickerValue.value.filter((i) => i !== item.value);
	} else {
		pickerValue.value.push(item.value);
	}
	props.item.value = pickerValue.value.join(',');
	emit("update", pickerValue.value.join(','));
}

</script>

<template>
	<div class="buttonSelect">
		<div class="title">
			<span v-if="item.required === 1" class="isRequired">*</span>
			<span>{{ item.nodeName }}</span>
		</div>
		<div class="selectList">
			<div v-for="(item, index) in columnsList" :key="index" @click="handleBut(item)" class="selectBut"
				:class="{ 'pitchOn': pickerValue.includes(item.value) }">
				{{ item.label }}
				<div v-if="pickerValue.includes(item.value)" class="pitchImg"></div>
			</div>
		</div>
	</div>
</template>

<style lang="scss" scoped>
.buttonSelect {
	width: 100%;
	background: #ffffff;
	float: left;
}

.title {
	width: 100%;
	height: 24px;
	color: #141e34;
	font-size: 14px;
	line-height: 24px;
	float: left;
	margin-top: 16px;
	margin-bottom: 10px;
	padding-left: 16px;
}

.isRequired {
	color: #ee3040;
	font-size: 14px;
	padding-right: 2px;
}

.selectList {
	width: 100%;
}

.selectBut {
	width: -webkit-calc(33.333% - 12px);
	width: -moz-calc(33.333% - 12px);
	width: calc(33.333% - 12px);
	height: 36px;
	line-height: 36px;
	border-radius: 6px;
	background: #f9f9f9;
	font-size: 14px;
	font-weight: 400;
	text-align: center;
	color: #333333;
	float: left;
	cursor: pointer;
	position: relative;
	margin-bottom: 12px;
	margin-left: 6px;
	margin-right: 6px;
	border: 1px solid #f9f9f9;
}

.pitchOn {
	background: #ecf1ff !important;
	color: #185EFE !important;
	border: 1px solid #185efe !important;
}

.pitchImg {
	position: absolute;
	top: 0;
	right: 0;
	width: 16px;
	height: 16px;
	z-index: 99;
	background-image: url("https://img02.glsx.com.cn/aus/images/preference/pitchOn.png");
	background-repeat: no-repeat;
	background-size: 100%;
}
</style>