Commit 1f2a4dd1 by Jaxon

feat: regionPicker 设置默认值

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