index.vue
1.41 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
<!--
* @Date: 2022-09-08 15:47:54
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-09-08 16:20:11
* @FilePath: /data-table/src/components/RatePickerField/index.vue
* @Description: 文件描述
-->
<template>
<div class="rate-field">
<div class="label">{{ item.label }}<span v-if="item.required"> *</span></div>
<van-rate v-model="rate_value" :count="item.component_props.count" @change="onChange" style="padding: 1rem;" />
<div v-if="show_empty" class="van-field__error-message" style="padding: 0 1rem 1rem 1rem;">评分不能为空</div>
</div>
</template>
<script setup>
const props = defineProps({
item: Object
});
const emit = defineEmits(['active']);
const show_empty = ref(false);
const rate_value = ref(0);
const onChange = () => {
props.item.value = { key: 'rate', value: rate_value.value };
emit('active', props.item.value);
}
onMounted(() => {
props.item.value = { key: 'rate', value: rate_value.value };
emit('active', props.item.value);
});
const validRate = () => {
// 必填项
if (props.item.component_props.required && !rate_value.value) {
show_empty.value = true;
} else {
show_empty.value = false;
}
return !show_empty.value
}
defineExpose({ validRate });
</script>
<style lang="less" scoped>
.rate-field {
.label {
padding: 1rem 1rem 0 1rem;
font-size: 0.9rem;
font-weight: bold;
span {
color: red;
}
}
}
</style>