Commit 1f2a4dd1 by Jaxon

feat: regionPicker 设置默认值

1 parent f5f7d599
<template> <template>
<van-action-sheet :close-on-click-action="false" <van-action-sheet get-container="body"
:close-on-click-action="false"
:close-on-click-overlay="false"
:closeable="false"
:title="title"
:value="visible" :value="visible"
@closed="handleClosed" @closed="handleClosed"
@input="updateVisible"> @input="updateVisible">
...@@ -50,9 +54,18 @@ ...@@ -50,9 +54,18 @@
</template> </template>
<script> <script>
import { ActionSheet } from "vant";
export default { export default {
name: "RegionPicker", name: "RegionPicker",
components: {
[ActionSheet.name]: ActionSheet,
},
props: { props: {
title: {
type: String,
default: "门店区域",
},
value: { value: {
type: [String, Number], type: [String, Number],
default: "", default: "",
...@@ -73,11 +86,11 @@ export default { ...@@ -73,11 +86,11 @@ export default {
}, },
labelKey: { labelKey: {
type: String, type: String,
default: "name", default: "label",
}, },
valueKey: { valueKey: {
type: String, type: String,
default: "code", default: "value",
}, },
}, },
data() { data() {
...@@ -124,6 +137,8 @@ export default { ...@@ -124,6 +137,8 @@ export default {
visible: { visible: {
immediate: true, immediate: true,
handler(val) { handler(val) {
console.log(val);
if (val) { if (val) {
this.initPanelState(); this.initPanelState();
} }
...@@ -152,8 +167,9 @@ export default { ...@@ -152,8 +167,9 @@ export default {
return this.normalizedOptions.find(item => item.value === value) || null; return this.normalizedOptions.find(item => item.value === value) || null;
}, },
handleSelect(item) { handleSelect(item) {
this.tempValue = item.value; const isSameRegion = this.tempValue === item.value;
this.$emit("select", item); this.tempValue = isSameRegion ? "" : item.value;
this.$emit("select", isSameRegion ? null : item);
}, },
handleCancel() { handleCancel() {
this.keyword = ""; this.keyword = "";
...@@ -184,6 +200,16 @@ export default { ...@@ -184,6 +200,16 @@ export default {
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
::v-deep .van-action-sheet {
&__header {
font-weight: 500;
font-size: 16px;
line-height: 20px;
text-align: center;
color: #000000e5;
padding: 16px;
}
}
.region-sheet { .region-sheet {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
...@@ -191,13 +217,15 @@ export default { ...@@ -191,13 +217,15 @@ export default {
background: #ffffff; background: #ffffff;
&__search { &__search {
padding: 12px 12px 0; ::v-deep .van-search {
padding: 12px 16px 4px !important;
}
} }
&__list { &__list {
flex: 1; flex: 1;
overflow-y: auto; overflow-y: auto;
padding: 8px 12px 16px; padding: 0px 16px 12px;
} }
&__item { &__item {
...@@ -231,8 +259,7 @@ export default { ...@@ -231,8 +259,7 @@ export default {
&__footer { &__footer {
display: flex; display: flex;
column-gap: 12px; column-gap: 12px;
padding: 12px; padding: 8px 16px;
border-top: 1px solid #f2f3f5;
} }
&__button { &__button {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!