buttonSelect.vue
3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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
<script setup lang="ts">
import { computed, onMounted, ref, watch } from "vue";
const props = defineProps({
item: {
type: Object,
default: () => { },
}
});
const emit = defineEmits(["update"]);
const pickerValue = ref([]);
// 页面加载时初始化数据
onMounted(() => {
initData();
});
// 初始化数据
function initData() {
pickerValue.value = [];
if (props?.item?.inspectionResultVO) {
const inspectionValueList = props?.item?.inspectionResultVO?.inspectionValueList || [];
for (const i of inspectionValueList) {
if (i.valueText && i.interactionType == "button_select") { pickerValue.value.push(i.valueKey); }
}
}
setupdate();
}
// 计算属性
const columnsList = computed(() => {
const optionsList = JSON.parse(props.item.options || "[]").map(item => {
const valueList = (item || "").split("-");
return {
text: valueList[1] || "",
value: valueList[0] || "",
};
});
return optionsList;
});
// 监听item.resultStatus变化
watch(() => props.item.resultStatus, (newVal) => {
if (newVal) {
pickerValue.value = [];
setupdate();
}
});
function handleBut(item: { value: string }) {
if (item.value) {
props.item.resultStatus = false;
}
if (pickerValue.value.includes(item.value)) {
pickerValue.value = pickerValue.value.filter((i) => i !== item.value);
} else {
pickerValue.value.push(item.value);
}
setupdate();
}
function setupdate() {
const valueList = (pickerValue.value || []).map(item => {
const object = (columnsList.value || []).find(finditem => finditem.value == item) || {};
return {
valueText: object.text || "",
valueKey: item || "",
};
});
if (valueList.length > 0) {
emit("update", JSON.stringify(valueList || []));
} else {
emit("update", "");
}
}
</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="(col, index) in columnsList" :key="index" class="selectBut"
:class="{ 'pitchOn': pickerValue.includes(col.value) }" @click="handleBut(col)">
{{ col.text }}
<div v-if="pickerValue.includes(col.value)" class="pitchImg"></div>
</div>
</div>
</div>
</template>
<style lang="scss" scoped>
.buttonSelect {
float: left;
width: 100%;
background: #fff;
}
.title {
float: left;
width: 100%;
height: 24px;
padding-left: 16px;
margin-top: 16px;
margin-bottom: 10px;
font-size: 14px;
line-height: 24px;
color: #141e34;
}
.isRequired {
padding-right: 2px;
font-size: 14px;
color: #ee3040;
}
.selectList {
width: 100%;
}
.selectBut {
position: relative;
float: left;
height: 36px;
margin-right: 6px;
margin-bottom: 12px;
margin-left: 6px;
font-size: 14px;
font-weight: 400;
line-height: 36px;
color: #333;
text-align: center;
cursor: pointer;
background: #f9f9f9;
border: 1px solid #f9f9f9;
border-radius: 6px;
padding: 0 16px;
min-width: 30%;
}
.pitchOn {
color: #185EFE !important;
background: #ecf1ff !important;
border: 1px solid #185efe !important;
}
.pitchImg {
position: absolute;
top: 0;
right: 0;
z-index: 99;
width: 16px;
height: 16px;
background-image: url("https://img02.glsx.com.cn/aus/images/preference/pitchOn.png");
background-repeat: no-repeat;
background-size: 100%;
}
</style>