vant H5 地址编辑框

embedded/2024/10/19 15:44:11/

vant H5 地址编辑框

效果图:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

上代码:

<!-- 地区选择 -->
<template><div class="page-content"><van-fieldv-model="formNationaAll"is-linkreadonlyrequiredname="国家/地区"label="国家/地区"placeholder="请选择":rules="[{ required: true, message: '请选择' }]"@click="opendistrictPopup({nation: formNation,province: formProvince,city: formCity,area: formArea,detailedAddress: formDetailedAddress,})"><template #input><span>{{ formNationaAll }}</span><span class="color-warn" v-show="showPlaceholderFun(formNationaAll)">请选择</span></template></van-field><van-fieldv-model="formDetailedAddress"requiredreadonlyname="详细地址"label="详细地址"placeholder="请输入":rules="[{ required: true, message: '请输入详细地址到门牌号' }]"@click="opendistrictPopup({nation: formNation,province: formProvince,city: formCity,area: formArea,detailedAddress: formDetailedAddress,})"></van-field><van-popupv-model="districtPopup"roundposition="top":close-on-click-overlay="false":style="{ height: '30%' }"><van-dropdown-menu><van-dropdown-itemv-model="nation":options="nationList"@change="changenation"><template #title><span v-if="showPlaceholderFun(nation)">国家</span><span v-else>{{ nationName }}</span></template></van-dropdown-item><van-dropdown-itemv-model="province":options="provinceList"@change="changeprovince":disabled="showPlaceholderFun(nation)"><template #title><span v-if="showPlaceholderFun(province)">省份</span><span v-else>{{ provinceName }}</span></template></van-dropdown-item><van-dropdown-itemv-model="city":options="cityList"@change="changecity":disabled="showPlaceholderFun(province)"><template #title><span v-if="showPlaceholderFun(city)">城市</span><span v-else>{{ cityName }}</span></template></van-dropdown-item><van-dropdown-itemv-model="area":options="areaList"@change="changearea":disabled="showPlaceholderFun(city)"><template #title><span v-if="showPlaceholderFun(area)">区县</span><span v-else>{{ areaName }}</span></template></van-dropdown-item></van-dropdown-menu><van-fieldv-model.trim="detailedAddress"reareairedname="详细地址"label="详细地址"placeholder="请输入详细地址到门牌号"rows="2"type="textarea"></van-field><div class="btns"><van-button class="infobtn" round @click="closePopup" v-preventReClick>取消</van-button><van-button type="primary" round @click="confirmPopup" v-preventReClick>确定</van-button></div></van-popup></div>
</template>
<script>
import { ProvincesAndMunicipalities } from "@/apis/insus/insusHome";
import { Notify } from "vant";
export default {name: "DistrictSelect",data() {return {// 表单字段formNationaAll: "",formNation: "",formProvince: "",formCity: "",formArea: "",formDetailedAddress: "",// 组件字段districtPopup: false,nation: "",nationName: "",nationList: [{ text: "中国", value: "CHN", code: "CHN" }],province: "",provinceName: "",provinceList: [],city: "",cityName: "",cityList: [],area: "",areaName: "",areaList: [],detailedAddress: "",};},methods: {//打开地区async opendistrictPopup(obj) {if (obj && obj.nation) {this.nation = obj.nation;await this.changenation();}this.provinceList = await this.getProvincesAndMunicipalitiesFun(0);if (obj && obj.province) {this.province = obj.province;await this.changeprovince();}if (obj && obj.city) {this.city = obj.city;await this.changecity();}if (obj && obj.area) {this.area = obj.area;await this.changearea();}if (obj && obj.detailedAddress) {this.detailedAddress = obj.detailedAddress;}this.districtPopup = true;},// 获取省市区async getProvincesAndMunicipalitiesFun(ins) {let res = await ProvincesAndMunicipalities({ parentId: ins });if (res && res.cityList && res.cityList.length > 0) {return res.cityList.map((item) => {return { text: item.name, value: item.code, ...item };});} else {return [];}},showPlaceholderFun(val) {if (!!val) {return false;} else {if (val === 0) {return false;} else {return true;}}},// 选择国家async changenation() {let obj = await this.findByCode(this.nationList, this.nation);this.nationName = obj.text;},// 选择省份async changeprovince() {let obj = await this.findByCode(this.provinceList, this.province);this.provinceName = obj.text;if (obj.code === this.province) {this.cityList = await this.getProvincesAndMunicipalitiesFun(obj.id);this.city = "";this.area = "";}},// 选择市async changecity() {let obj = await this.findByCode(this.cityList, this.city);this.cityName = obj.text;if (obj.code === this.city) {this.areaList = await this.getProvincesAndMunicipalitiesFun(obj.id);this.area = "";}},// 选择区async changearea() {let obj = await this.findByCode(this.areaList, this.area);this.areaName = obj.text;},findByCode(tree, code) {for (let i = 0; i < tree.length; i++) {if (tree[i].code === code) {return tree[i];}}return null;},confirmPopup() {if (this.showPlaceholderFun(this.nation) ||this.showPlaceholderFun(this.province) ||this.showPlaceholderFun(this.city) ||this.showPlaceholderFun(this.area) ||this.showPlaceholderFun(this.detailedAddress)) {Notify({message: "请填写完所有信息!",duration: 2000,background: "#ed3e48",});} else {this.formNationaAll = `${this.nationName}/${this.provinceName}/${this.cityName}/${this.areaName}`; //国家地区this.formNation = this.nation;this.formProvince = this.province;this.formCity = this.city;this.formArea = this.area;this.formDetailedAddress = this.detailedAddress;this.$emit("confirmDistrict", {formNationaAll: this.formNationaAll,nation: this.nation,nationName: this.nationName,province: this.province,provinceName: this.provinceName,city: this.city,cityName: this.cityName,area: this.area,areaName: this.areaName,detailedAddress: this.detailedAddress,});this.closePopup();}},closePopup() {this.nation = "";this.nationName = "";this.province = "";this.provinceName = "";this.city = "";this.cityName = "";this.area = "";this.areaName = "";this.detailedAddress = "";this.districtPopup = false;},},mounted() {},created() {},
};
</script><style scoped lang="less">
.page-content {.van-popup {.btns {display: flex;align-items: center;justify-content: space-around;margin-top: @margin-32;:deep(.van-button) {width: 40%;}.van-button--normal {height: 68px;}.infobtn {background-color: @-color-fff;border: 1px solid @-color-primary;color: @-color-primary;}}}:deep(.van-dropdown-item__content) {max-height: 100%;}
}
</style>

http://www.ppmy.cn/embedded/35417.html

相关文章

pptx 文件版面分析-- python-pptx(python 文档解析提取)

安装 pip install python-pptx -i https://pypi.tuna.tsinghua.edu.cn/simple --ignore-installedpptx 解析代码实现 from pptx import Presentation file_name "rag_pptx/test1.pptx" # 打开.pptx文件 ppt Presentation(file_name) for slide in ppt.slides:#pr…

上海计算机学会2021年1月月赛C++丙组T2康托表

题目背景 康托是一名数学家&#xff0c;他证明了一个重要的定理&#xff0c;需要使用一张表&#xff1a; 这个表的规律是&#xff1a; 从上到下&#xff1a;每一行的分子依次增大&#xff1b;从左到右&#xff1a;每一列的分母依次增大。 康托以一种不重复、不遗漏的方式&am…

AIGC-音频生产十大主流模型技术原理及优缺点

音频生成(Audio Generation)指的是利用机器学习和人工智能技术&#xff0c;从文本、语音或其他源自动生成音频的过程。 音频生成行业是AIGC技术主要渗透的领域之一。AI音频生成行业是指利用人工智能技术和算法来生成音频内容的领域。按照输入数据类型不同可以分为&#xff1a;根…

一起了解开源自定义表单的优势表现

随着社会的进步和科技的发展&#xff0c;越来越多的中小企业希望采用更为先进的软件平台&#xff0c;助力企业实现高效率的流程化管理。低代码技术平台、开源自定义表单已经慢慢走入大众视野&#xff0c;成为一款灵活、高效的数字化转型工具。流辰信息专注于低代码技术平台的研…

第08章 IP分类编址和无分类编址

8.1 本章目标 了解IP地址的用途和种类了解分类编址和无分类编址区别掌握IP地址、子网掩码、网关概念及使用掌握子网划分及超网划分方法掌握无分类编址的改变和使用 8.2 IP地址的用途和种类 分类编址&#xff1a;造成地址的浪费&#xff0c;以及地址不够用&#xff1b;无分类编…

大数据面试SQL每日一题系列:最高峰同时在线主播人数。字节,快手等大厂高频面试题

之后会不定期更新每日一题sql系列。 SQL面试题每日一题系列内容均来自于网络以及实际使用情况收集&#xff0c;如有雷同&#xff0c;纯属巧合。 1.题目 **问题1&#xff1a;**如下为某直播平台各主播的开播及关播时间数据明细&#xff0c;现在需要计算该平台最高峰期同时在线…

自定义类型②③——联合体和枚举

自定义类型②③——联合体和枚举 1.联合体1.1 联合体类型的声明1.2 联合体的特点1.3 相同成员结构体和联合体的对比1.4 联合体大小的计算1.5 联合体的应用①1.5 联合体的应用② 2. 枚举2.1 枚举类型的声明2.2 枚举类型的特点2.3 枚举的优点 1.联合体 1.1 联合体类型的声明 关…

Leetcode—1235. 规划兼职工作【困难】(upper_bound、自定义排序规则)

2024每日刷题&#xff08;125&#xff09; Leetcode—1235. 规划兼职工作 算法思想 实现代码 class Solution { public:int jobScheduling(vector<int>& startTime, vector<int>& endTime, vector<int>& profit) {int n startTime.size();vec…