vue地址解析+虚拟手机号解析

news/2024/12/12 16:19:28/

(1)安装 address-parse模块

npm install address-parse --save

(2)地址修改-弹窗页面

javascript"><template><div><el-dialog title="修改收货地址" :visible.sync="dialogVisible" width="45%"><el-form ref="form" :model="formData"  :rules="rules" label-width="120px" style="margin-right:20px;height:400px;"><el-form-item><el-input type="textarea" :rows="2" placeholder="粘贴收货信息,(格式:姓名 电话 地址)" v-model="addressInfo" @input="parseAddress"></el-input></el-form-item><el-form-item label="收货人名称" prop="recipientName"><el-input v-model="formData.recipientName"></el-input></el-form-item><el-form-item label="收货人手机号码" prop="recipientMobile"><el-input v-model="formData.recipientMobile"></el-input></el-form-item><el-form-item label="省" prop="recipientProvinceName"><el-input v-model="formData.recipientProvinceName"></el-input></el-form-item><el-form-item label="市" prop="recipientCityName"><el-input v-model="formData.recipientCityName"></el-input></el-form-item><el-form-item label="区" prop="recipientCountyName"><el-input v-model="formData.recipientCountyName"></el-input></el-form-item><el-form-item label="收货人详细地址" prop="recipientAddress"><el-input v-model="formData.recipientAddress"></el-input></el-form-item></el-form><div style="text-align:center;margin-top:50px;"><el-button type="primary" @click="onConfirm()">确定</el-button><el-button @click="dialogVisible = false">取消</el-button></div></el-dialog></div>
</template><script>import OrderApi from '@/api/OrderApi'
import AddressParse from 'address-parse';
export default {components: {},data() {return {dialogVisible:false,formData: {recipientName:null,recipientMobile:null,recipientProvinceName:null,recipientCityName:null,recipientCountyName:null,recipientAddress:null,},rules: {recipientName: [{ required: true, message: '请输入收货人名称', trigger: 'blur' }],recipientMobile: [{ required: true, message: '请输入收货人手机号码', trigger: 'blur' }],recipientProvinceName: [{ required: true, message: '请输入省', trigger: 'blur' }],recipientCityName: [{ required: true, message: '请输入市', trigger: 'blur' }],recipientCountyName: [{ required: true, message: '请输入区', trigger: 'blur' }],recipientAddress: [{ required: true, message: '请输入收货人详细地址', trigger: 'blur' }],},addressInfo:null,}},created() {},methods: {show(data) {this.addressInfo = null;this.$refs['form'] && this.$refs['form'].resetFields();this.formData.orderId = data.id;this.formData.recipientName = data.recipientName;this.formData.recipientMobile = data.recipientMobile;this.formData.recipientProvinceName = data.recipientProvinceName;this.formData.recipientCityName = data.recipientCityName;this.formData.recipientCountyName = data.recipientCountyName;this.formData.recipientAddress = data.recipientAddress;this.dialogVisible = true},onConfirm() {this.$refs['form'].validate((valid) => {if (valid) {OrderApi.updateAddress(this.formData).then(res => {this.$message.success('修改成功')this.dialogVisible = falsethis.$emit('s')})} else {return false;}});},parseAddress(value) { //地址解析if (value != '') {// 虚拟手机号码const numbers = value.match(/\d{11,}-{0,1}\d{4}/);if(numbers){this.$set(this.formData, 'recipientMobile', numbers[0]);value = value.replace(numbers[0],'');}const result = AddressParse.parse(value);this.$set(this.formData, 'recipientProvinceName', result[0].province)this.$set(this.formData, 'recipientCityName', result[0].city)this.$set(this.formData, 'recipientCountyName', result[0].area)this.$set(this.formData, 'recipientAddress', result[0].details)this.$set(this.formData, 'recipientName', result[0].name)if(result[0].mobile){this.$set(this.formData, 'recipientMobile', result[0].mobile)}}},}
}
</script><style scoped>
</style>

(3)按钮

javascript"><el-button type="primary" size="mini" @click="$refs.addressEditForm.show(row)">修改收货地址</el-button>


http://www.ppmy.cn/news/1554540.html

相关文章

群控系统服务端开发模式-应用开发-登录退出发送邮件

一、登录成功发送邮件 在根目录下app文件夹下controller文件夹下common文件夹下&#xff0c;修改Login.php&#xff0c;代码如下 <?php /*** 登录退出操作* User: 龙哥三年风水* Date: 2024/10/29* Time: 15:53*/ namespace app\controller\common; use app\controller\Em…

单元测试SpringBoot

添加测试专用属性 加载测试专用bean Web环境模拟测试 数据层测试回滚 测试用例数据设定

Rust快速入门(二)

三个指令&#xff1a; cargo run 执行 --release&#xff1a; 由于使用run命令rust默认为debug模式&#xff0c;代码中很多debug数据就会打印&#xff0c;于是我们使用relsase参数就可以不输出debug的代码。 cargo check 校验是否能够通过编译 cargo build 打包为可执行文件 …

【jvm】GC Roots有哪些

目录 1. 说明2. 虚拟机栈&#xff08;栈帧中的局部变量表&#xff09;中的引用3. 方法区中的类静态属性引用4. 本地方法栈&#xff08;Native方法栈&#xff09;中JNI&#xff08;Java Native Interface&#xff09;的引用5. 活跃线程&#xff08;Active Threads&#xff09;6.…

Scala的正则表达式(1)

package hfd //正则表达式的应用场景 //1.查找 findAllin //2.验证 matches //3.替换//验证用户名十分合法 //规则&#xff1a; //1.长度在6-12之间 //2.不能数字开头 //3.只能包含数字&#xff0c;大小写字母&#xff0c;下划线 object Test36 {def main(args: Array[String])…

ubuntu 18.04 server常用配置

1. 配置静态ip 编辑/etc/netplan目录下的配置文件。以下是步骤和示例配置&#xff1a; 找到Netplan配置文件&#xff0c;通常命名为01-netcfg.yaml&#xff0c;50-cloud-init.yaml或类似。 使用文本编辑器编辑该文件&#xff0c;比如使用nano或vim。 修改配置文件以设置静态…

top命令和系统负载

1 top中的字段说明 top是一个实时系统监视工具&#xff0c;可以动态展现出 CPU 使用率、内存使用情况、进程状态等信息&#xff0c;注意这些显示的文本不能直接使用 > 追加到文件中。 [rootvv~]# top -bn 1 | head top - 20:08:28 up 138 days, 10:29, 4 users, load av…

后端处理跨域问题

1. CORS&#xff08;跨域资源共享&#xff09; 操作步骤&#xff1a; 设置CORS头部&#xff1a; 对于简单的GET、POST或HEAD请求&#xff0c;服务端需要在HTTP响应中添加Access-Control-Allow-Origin头部&#xff0c;以指定允许访问的源。例如&#xff0c;在Node.js中使用Expr…