17 changed files with 1422 additions and 726 deletions
@ -0,0 +1,317 @@ |
|||||
|
<template> |
||||
|
<el-dialog |
||||
|
:title="`${type === 'add' ? '新增' : '编辑'}收货地址`" |
||||
|
:visible="visible" |
||||
|
width="700px" |
||||
|
@close="handleClose" |
||||
|
> |
||||
|
<el-form |
||||
|
:model="form" |
||||
|
:rules="rules" |
||||
|
ref="addressForm" |
||||
|
label-width="100px" |
||||
|
size="small" |
||||
|
> |
||||
|
<el-form-item label="收货人" prop="username"> |
||||
|
<el-input |
||||
|
v-model="form.username" |
||||
|
placeholder="请填写收货人姓名,限制10个字符" |
||||
|
maxlength="10" |
||||
|
></el-input> |
||||
|
</el-form-item> |
||||
|
<el-form-item label="所在地区" prop="region"> |
||||
|
<div class="region-selector"> |
||||
|
<el-select |
||||
|
v-model="form.province_id" |
||||
|
placeholder="选择省份/直辖市" |
||||
|
@change="handleProvinceChange" |
||||
|
class="region-select" |
||||
|
> |
||||
|
<el-option |
||||
|
v-for="province in provinces" |
||||
|
:key="province.id" |
||||
|
:label="province.name" |
||||
|
:value="province.id" |
||||
|
></el-option> |
||||
|
</el-select> |
||||
|
|
||||
|
<el-select |
||||
|
v-model="form.city_id" |
||||
|
placeholder="选择城市" |
||||
|
@change="handleCityChange" |
||||
|
class="region-select" |
||||
|
:disabled="!form.province_id" |
||||
|
> |
||||
|
<el-option |
||||
|
v-for="city in cities" |
||||
|
:key="city.id" |
||||
|
:label="city.name" |
||||
|
:value="city.id" |
||||
|
></el-option> |
||||
|
</el-select> |
||||
|
|
||||
|
<el-select |
||||
|
v-model="form.district_id" |
||||
|
placeholder="选择县区" |
||||
|
class="region-select" |
||||
|
:disabled="!form.city_id" |
||||
|
> |
||||
|
<el-option |
||||
|
v-for="district in districts" |
||||
|
:key="district.id" |
||||
|
:label="district.name" |
||||
|
:value="district.id" |
||||
|
></el-option> |
||||
|
</el-select> |
||||
|
</div> |
||||
|
</el-form-item> |
||||
|
<el-form-item label="详细地址" prop="detail_addr"> |
||||
|
<el-input |
||||
|
v-model="form.detail_addr" |
||||
|
placeholder="请填写详细地址,限制500个字符" |
||||
|
maxlength="500" |
||||
|
></el-input> |
||||
|
</el-form-item> |
||||
|
<el-form-item label="手机号码" prop="mobile"> |
||||
|
<el-input |
||||
|
v-model="form.mobile" |
||||
|
placeholder="请填写手机号码,限制11位数字" |
||||
|
maxlength="11" |
||||
|
oninput="value=value.replace(/[^\d]/g,'')" |
||||
|
></el-input> |
||||
|
</el-form-item> |
||||
|
</el-form> |
||||
|
<div slot="footer" class="dialog-footer"> |
||||
|
<el-button size="small" @click="handleClose">取消</el-button> |
||||
|
<el-button size="small" type="primary" @click="saveAddress" |
||||
|
>保存</el-button |
||||
|
> |
||||
|
</div> |
||||
|
</el-dialog> |
||||
|
</template> |
||||
|
|
||||
|
<script> |
||||
|
export default { |
||||
|
name: "AddressFormDialog", |
||||
|
props: { |
||||
|
visible: { |
||||
|
type: Boolean, |
||||
|
default: false, |
||||
|
}, |
||||
|
type: { |
||||
|
type: String, |
||||
|
required: true, |
||||
|
validator: (val) => ["add", "edit"].includes(val), |
||||
|
}, |
||||
|
initialData: { |
||||
|
type: Object, |
||||
|
default: () => ({}), |
||||
|
}, |
||||
|
}, |
||||
|
data() { |
||||
|
const validateMobile = (rule, value, callback) => { |
||||
|
if (!value) { |
||||
|
return callback(new Error("请输入手机号码")); |
||||
|
} else if (!/^1[3-9]\d{9}$/.test(value)) { |
||||
|
return callback(new Error("请输入正确的11位手机号码")); |
||||
|
} else { |
||||
|
callback(); |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
const validateRegion = (rule, value, callback) => { |
||||
|
if ( |
||||
|
!this.form.province_id || |
||||
|
!this.form.city_id || |
||||
|
!this.form.district_id |
||||
|
) { |
||||
|
return callback(new Error("请完整选择省市区")); |
||||
|
} |
||||
|
callback(); |
||||
|
}; |
||||
|
|
||||
|
return { |
||||
|
form: { |
||||
|
id: null, |
||||
|
username: "", |
||||
|
detail_addr: "", |
||||
|
mobile: "", |
||||
|
province_id: null, |
||||
|
city_id: null, |
||||
|
district_id: null, |
||||
|
region: "", |
||||
|
}, |
||||
|
rules: { |
||||
|
username: [ |
||||
|
{ required: true, message: "请输入收货人姓名", trigger: "blur" }, |
||||
|
{ max: 10, message: "姓名不能超过10个字符", trigger: "blur" }, |
||||
|
], |
||||
|
region: [ |
||||
|
{ required: true, validator: validateRegion, trigger: "change" }, |
||||
|
], |
||||
|
detail_addr: [ |
||||
|
{ required: true, message: "请输入详细地址", trigger: "blur" }, |
||||
|
{ max: 500, message: "详细地址不能超过500个字符", trigger: "blur" }, |
||||
|
], |
||||
|
mobile: [ |
||||
|
{ required: true, validator: validateMobile, trigger: "blur" }, |
||||
|
], |
||||
|
}, |
||||
|
regionData: [] |
||||
|
}; |
||||
|
}, |
||||
|
computed: { |
||||
|
provinces() { |
||||
|
return this.regionData.filter((item) => item.level === 1); |
||||
|
}, |
||||
|
cities() { |
||||
|
if (!this.form.province_id) return []; |
||||
|
return this.regionData.filter( |
||||
|
(item) => item.level === 2 && item.pid === this.form.province_id |
||||
|
); |
||||
|
}, |
||||
|
districts() { |
||||
|
if (!this.form.city_id) return []; |
||||
|
return this.regionData.filter( |
||||
|
(item) => item.level === 3 && item.pid === this.form.city_id |
||||
|
); |
||||
|
}, |
||||
|
}, |
||||
|
watch: { |
||||
|
visible(val) { |
||||
|
if (val) { |
||||
|
this.initForm(); |
||||
|
} |
||||
|
}, |
||||
|
initialData: { |
||||
|
handler() { |
||||
|
if (this.visible) { |
||||
|
this.initForm(); |
||||
|
} |
||||
|
}, |
||||
|
deep: true, |
||||
|
}, |
||||
|
}, |
||||
|
mounted() { |
||||
|
this.getRegionData(); |
||||
|
}, |
||||
|
methods: { |
||||
|
// 获取地区数据 |
||||
|
async getRegionData() { |
||||
|
try { |
||||
|
const res = await this.post({}, "/api/uservice/user/getAreas"); |
||||
|
if (res && res.data) { |
||||
|
this.regionData = res.data; |
||||
|
} else { |
||||
|
this.$message.error("获取地区数据失败"); |
||||
|
} |
||||
|
} catch (error) { |
||||
|
console.error("获取地区数据出错:", error); |
||||
|
this.$message.error("获取地区数据时发生错误"); |
||||
|
} |
||||
|
}, |
||||
|
initForm() { |
||||
|
this.$nextTick(() => { |
||||
|
if (this.$refs.addressForm) { |
||||
|
this.$refs.addressForm.resetFields(); |
||||
|
} |
||||
|
|
||||
|
this.form = { |
||||
|
id: this.type === "edit" ? this.initialData.id : null, |
||||
|
username: this.initialData.username || "", |
||||
|
detail_addr: this.initialData.detail_addr || "", |
||||
|
mobile: this.initialData.mobile || "", |
||||
|
province_id: this.initialData.province_id || null, |
||||
|
city_id: this.initialData.city_id || null, |
||||
|
district_id: this.initialData.district_id || null, |
||||
|
region: this.initialData.region || "", |
||||
|
}; |
||||
|
|
||||
|
// 如果没有ID信息再尝试通过文本匹配 |
||||
|
if ( |
||||
|
this.type === "edit" && |
||||
|
this.initialData.region && |
||||
|
!this.form.province_id |
||||
|
) { |
||||
|
this.echoRegionSelection(this.initialData.region); |
||||
|
} |
||||
|
}); |
||||
|
}, |
||||
|
echoRegionSelection(regionText) { |
||||
|
const regions = regionText.split(" "); |
||||
|
if (regions.length < 3) return; |
||||
|
|
||||
|
const province = this.provinces.find((p) => p.name === regions[0]); |
||||
|
if (province) { |
||||
|
this.form.province_id = province.id; |
||||
|
|
||||
|
this.$nextTick(() => { |
||||
|
const city = this.cities.find((c) => c.name === regions[1]); |
||||
|
if (city) { |
||||
|
this.form.city_id = city.id; |
||||
|
|
||||
|
this.$nextTick(() => { |
||||
|
const district = this.districts.find( |
||||
|
(d) => d.name === regions[2] |
||||
|
); |
||||
|
if (district) { |
||||
|
this.form.district_id = district.id; |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
}, |
||||
|
handleProvinceChange() { |
||||
|
this.form.city_id = null; |
||||
|
this.form.district_id = null; |
||||
|
}, |
||||
|
handleCityChange() { |
||||
|
this.form.district_id = null; |
||||
|
}, |
||||
|
saveAddress() { |
||||
|
this.$refs.addressForm.validate(async (valid) => { |
||||
|
if (!valid) return; |
||||
|
|
||||
|
const province = this.provinces.find( |
||||
|
(p) => p.id === this.form.province_id |
||||
|
); |
||||
|
const city = this.cities.find((c) => c.id === this.form.city_id); |
||||
|
const district = this.districts.find( |
||||
|
(d) => d.id === this.form.district_id |
||||
|
); |
||||
|
|
||||
|
if (!(province && city && district)) { |
||||
|
this.$message.warning("地区信息不完整"); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
const formData = { |
||||
|
...this.form, |
||||
|
region: `${province.name} ${city.name} ${district.name}`, |
||||
|
}; |
||||
|
|
||||
|
this.$emit("save", formData); |
||||
|
this.handleClose(); |
||||
|
}); |
||||
|
}, |
||||
|
handleClose() { |
||||
|
this.$emit("update:visible", false); |
||||
|
}, |
||||
|
}, |
||||
|
}; |
||||
|
</script> |
||||
|
|
||||
|
<style lang="scss" scoped> |
||||
|
.region-selector { |
||||
|
display: flex; |
||||
|
gap: 10px; |
||||
|
flex-wrap: wrap; |
||||
|
} |
||||
|
|
||||
|
.region-select { |
||||
|
min-width: 180px; |
||||
|
flex: 1; |
||||
|
max-width: 30%; |
||||
|
} |
||||
|
</style> |
@ -0,0 +1,213 @@ |
|||||
|
<template> |
||||
|
<!-- 加入购物车弹框 --> |
||||
|
<el-dialog |
||||
|
title="加入购物车" |
||||
|
:visible.sync="dialogVisible" |
||||
|
width="360px" |
||||
|
:close-on-click-modal="false" |
||||
|
:show-close="false" |
||||
|
> |
||||
|
<!-- 商品信息 --> |
||||
|
<div class="cart-dialog__product"> |
||||
|
<img v-lazy="product.headimg" alt="商品图片" class="product-img" /> |
||||
|
<div class="product-info"> |
||||
|
<h4 class="product-name">{{ product.sku_name || "商品名称" }}</h4> |
||||
|
<p class="product-price">¥{{ product.price / 100 }}</p> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
<!-- 数量选择器 --> |
||||
|
<div class="cart-dialog__quantity"> |
||||
|
<label>购买数量:</label> |
||||
|
<el-input-number |
||||
|
v-model="buyQuantity" |
||||
|
:min="1" |
||||
|
:max="product.stock" |
||||
|
:step="1" |
||||
|
class="quantity-input" |
||||
|
@change="handleQuantityChange" |
||||
|
></el-input-number> |
||||
|
<span class="stock-tip" v-if="product.stock"> |
||||
|
库存仅剩 {{ product.stock }} 件 |
||||
|
</span> |
||||
|
</div> |
||||
|
|
||||
|
<!-- 底部按钮区 --> |
||||
|
<span slot="footer" class="dialog-footer"> |
||||
|
<el-button @click="dialogVisible = false" class="cancel-btn"> |
||||
|
取消 |
||||
|
</el-button> |
||||
|
<el-button |
||||
|
type="primary" |
||||
|
@click="handleAddToCart" |
||||
|
:loading="loading" |
||||
|
class="confirm-btn" |
||||
|
> |
||||
|
加入购物车 |
||||
|
</el-button> |
||||
|
</span> |
||||
|
</el-dialog> |
||||
|
</template> |
||||
|
|
||||
|
<script> |
||||
|
import { mapActions } from "vuex"; |
||||
|
|
||||
|
export default { |
||||
|
name: "AddToCartDialog", |
||||
|
props: { |
||||
|
// 接收父组件传入的商品数据(必填) |
||||
|
product: { |
||||
|
type: Object, |
||||
|
required: true, |
||||
|
default: () => ({ |
||||
|
id: "", |
||||
|
name: "", |
||||
|
price: 0, |
||||
|
avatar: "https://picsum.photos/100", // 默认占位图 |
||||
|
stock: 99, // 默认库存 |
||||
|
}), |
||||
|
}, |
||||
|
// 控制弹框显示/隐藏 |
||||
|
visible: { |
||||
|
type: Boolean, |
||||
|
default: false, |
||||
|
}, |
||||
|
buyQuantity: { |
||||
|
type: Number, |
||||
|
default: false, |
||||
|
}, |
||||
|
}, |
||||
|
data() { |
||||
|
return { |
||||
|
loading: false, // 按钮加载状态 |
||||
|
}; |
||||
|
}, |
||||
|
computed: { |
||||
|
// 双向绑定弹框显示状态 |
||||
|
dialogVisible: { |
||||
|
get() { |
||||
|
return this.visible; |
||||
|
}, |
||||
|
set(val) { |
||||
|
this.$emit("update:visible", val); |
||||
|
}, |
||||
|
}, |
||||
|
}, |
||||
|
methods: { |
||||
|
// 映射 Vuex 的加入购物车 action |
||||
|
...mapActions(["addToCart"]), |
||||
|
|
||||
|
// 数量变更时校验 |
||||
|
handleQuantityChange(val) { |
||||
|
if (val > this.product.stock) { |
||||
|
this.buyQuantity = this.product.stock; |
||||
|
this.$message.warning(`库存不足,最多可购买 ${this.product.stock} 件`); |
||||
|
} |
||||
|
}, |
||||
|
|
||||
|
// 加入购物车逻辑 |
||||
|
async handleAddToCart() { |
||||
|
this.loading = true; |
||||
|
try { |
||||
|
// 调用 Vuex action 加入购物车(携带数量) |
||||
|
await this.addToCart({ |
||||
|
...this.product, |
||||
|
quantity: this.buyQuantity, |
||||
|
}); |
||||
|
|
||||
|
// 关闭弹框 |
||||
|
this.dialogVisible = false; |
||||
|
|
||||
|
// 重置状态(下次打开时恢复默认) |
||||
|
this.buyQuantity = 1; |
||||
|
} catch (err) { |
||||
|
this.$message.error(err.message || "加入购物车失败,请重试"); |
||||
|
} finally { |
||||
|
this.loading = false; |
||||
|
} |
||||
|
}, |
||||
|
}, |
||||
|
}; |
||||
|
</script> |
||||
|
|
||||
|
<style lang="scss" scoped> |
||||
|
.cart-dialog__product { |
||||
|
display: flex; |
||||
|
align-items: center; |
||||
|
margin-bottom: 20px; |
||||
|
padding-bottom: 15px; |
||||
|
border-bottom: 1px solid #f5f5f5; |
||||
|
|
||||
|
.product-img { |
||||
|
width: 80px; |
||||
|
height: 80px; |
||||
|
object-fit: cover; |
||||
|
border-radius: 4px; |
||||
|
margin-right: 15px; |
||||
|
} |
||||
|
|
||||
|
.product-info { |
||||
|
flex: 1; |
||||
|
|
||||
|
.product-name { |
||||
|
font-size: 16px; |
||||
|
color: #333; |
||||
|
margin: 0 0 8px; |
||||
|
white-space: nowrap; |
||||
|
overflow: hidden; |
||||
|
text-overflow: ellipsis; |
||||
|
} |
||||
|
|
||||
|
.product-price { |
||||
|
font-size: 18px; |
||||
|
color: #ff4400; |
||||
|
margin: 0; |
||||
|
font-weight: 500; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
.cart-dialog__quantity { |
||||
|
display: flex; |
||||
|
align-items: center; |
||||
|
margin-bottom: 10px; |
||||
|
|
||||
|
label { |
||||
|
font-size: 14px; |
||||
|
color: #666; |
||||
|
margin-right: 15px; |
||||
|
} |
||||
|
|
||||
|
.quantity-input { |
||||
|
width: 120px; |
||||
|
} |
||||
|
|
||||
|
.stock-tip { |
||||
|
font-size: 12px; |
||||
|
color: #999; |
||||
|
margin-left: 15px; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
.dialog-footer { |
||||
|
display: flex; |
||||
|
justify-content: center; |
||||
|
padding-top: 10px; |
||||
|
|
||||
|
.cancel-btn { |
||||
|
margin-right: 10px; |
||||
|
border-color: #e5e5e5; |
||||
|
color: #666; |
||||
|
} |
||||
|
|
||||
|
.confirm-btn { |
||||
|
background-color: #6a8a27; |
||||
|
border-color: #6a8a27; |
||||
|
|
||||
|
&:hover { |
||||
|
background-color: #5a7a1f; |
||||
|
border-color: #5a7a1f; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
</style> |
@ -1,201 +1,198 @@ |
|||||
<template> |
<template> |
||||
<div class="bg"> |
<div class="bg"> |
||||
<el-card style="width: 100%;"> |
<el-card style="width: 100%"> |
||||
<div slot="header" class="clearfix flex-between"> |
<div slot="header" class="clearfix flex-between"> |
||||
<div> |
<div> |
||||
收货地址 |
收货地址 |
||||
<span style="font-size: 12px;color:#666">收票人地址统一使用该地址管理设置</span> |
<span style="font-size: 12px; color: #666" |
||||
</div> |
>收票人地址统一使用该地址管理设置</span |
||||
|
> |
||||
<el-button size="small" style="float: right;" type="primary" @click="openDialog('add', {})">新增地址</el-button> |
|
||||
</div> |
</div> |
||||
|
|
||||
<el-table :data="addresses" border style="width: 100%;"> |
<el-button |
||||
<el-table-column prop="receiver" label="收货人" width="120"></el-table-column> |
size="small" |
||||
<el-table-column prop="region" label="所在地区" width="120"></el-table-column> |
style="float: right" |
||||
<el-table-column prop="detailAddress" label="详细地址" width="300"></el-table-column> |
type="primary" |
||||
<el-table-column prop="phone" label="手机号码" width="150"></el-table-column> |
@click="openDialog('add', {})" |
||||
<el-table-column prop="fixedPhone" label="固定电话" width="150"></el-table-column> |
>新增地址</el-button |
||||
<el-table-column prop="alias" label="地区别名" width="120"></el-table-column> |
> |
||||
<el-table-column label="操作" width="200"> |
</div> |
||||
<template slot-scope="scope"> |
|
||||
<el-button size="mini" @click="handleEdit(scope.row)">编辑</el-button> |
|
||||
<el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button> |
|
||||
</template> |
|
||||
</el-table-column> |
|
||||
</el-table> |
|
||||
|
|
||||
<!-- 分页 --> |
|
||||
<div style="text-align: right; margin-top: 20px;"> |
|
||||
<el-pagination |
|
||||
@size-change="handleSizeChange" |
|
||||
@current-change="handleCurrentChange" |
|
||||
:current-page="searchParam.currentPage" |
|
||||
:page-sizes="[5, 10, 20]" |
|
||||
:page-size="searchParam.pageSize" |
|
||||
layout="total, sizes, prev, pager, next, jumper" |
|
||||
:total="searchParam.total" |
|
||||
></el-pagination> |
|
||||
</div> |
|
||||
|
|
||||
|
<el-table :data="addresses" border style="width: 100%"> |
||||
|
<el-table-column |
||||
|
prop="name" |
||||
|
label="收货人" |
||||
|
width="120" |
||||
|
></el-table-column> |
||||
|
<el-table-column |
||||
|
prop="address" |
||||
|
label="收货地址" |
||||
|
width="auto" |
||||
|
></el-table-column> |
||||
|
<el-table-column |
||||
|
prop="tel" |
||||
|
label="手机号码" |
||||
|
width="150" |
||||
|
></el-table-column> |
||||
|
<el-table-column label="操作" width="200"> |
||||
|
<template slot-scope="scope"> |
||||
|
<el-button size="mini" @click="handleEdit(scope.row)" |
||||
|
>编辑</el-button |
||||
|
> |
||||
|
<el-button |
||||
|
size="mini" |
||||
|
type="danger" |
||||
|
@click="handleDelete(scope.row)" |
||||
|
>删除</el-button |
||||
|
> |
||||
|
</template> |
||||
|
</el-table-column> |
||||
|
</el-table> |
||||
|
|
||||
|
<!-- 分页 --> |
||||
|
<div style="text-align: right; margin-top: 20px"> |
||||
|
<el-pagination |
||||
|
@size-change="handleSizeChange" |
||||
|
@current-change="handleCurrentChange" |
||||
|
:current-page="searchParam.currentPage" |
||||
|
:page-sizes="[5, 10, 20]" |
||||
|
:page-size="searchParam.pageSize" |
||||
|
layout="total, sizes, prev, pager, next, jumper" |
||||
|
:total="searchParam.total" |
||||
|
></el-pagination> |
||||
|
</div> |
||||
</el-card> |
</el-card> |
||||
|
|
||||
|
<!-- 引入地址编辑组件 --> |
||||
<el-dialog :title="`${address.type === 'add' ? '新增' : '编辑'}收货地址`" :visible.sync="dialogVisible" width="700px"> |
<AddressFormDialog |
||||
<el-form :model="address" label-width="100px" size="small"> |
:visible="dialogVisible" |
||||
<el-form-item label="*收货人"> |
:type="dialogType" |
||||
<el-input v-model="address.receiver" placeholder="请填写收货人姓名,限制40个字符"></el-input> |
:initial-data="dialogData" |
||||
</el-form-item> |
@update:visible="dialogVisible = $event" |
||||
<el-form-item label="*所在地区"> |
@save="handleSaveAddress" |
||||
<el-select v-model="address.region" placeholder="请选择所在地区"> |
/> |
||||
<el-option label="北京" value="北京"></el-option> |
|
||||
<el-option label="上海" value="上海"></el-option> |
|
||||
<el-option label="广州" value="广州"></el-option> |
|
||||
<el-option label="深圳" value="深圳"></el-option> |
|
||||
</el-select> |
|
||||
</el-form-item> |
|
||||
<el-form-item label="*详细地址"> |
|
||||
<el-input v-model="address.detailAddress" placeholder="请填写详细地址,限制500个字符"></el-input> |
|
||||
</el-form-item> |
|
||||
<el-form-item label="*手机号码"> |
|
||||
<el-input v-model="address.phone" placeholder="请填写手机号码,限制11位数字"></el-input> |
|
||||
</el-form-item> |
|
||||
<el-form-item label="固定电话"> |
|
||||
<el-input v-model="address.fixedPhone" placeholder="请填写固定号码,限制40个字符"></el-input> |
|
||||
</el-form-item> |
|
||||
<el-form-item label="地区别名"> |
|
||||
<el-input v-model="address.alias" placeholder="请填写常用名称,限制40个字符"></el-input> |
|
||||
</el-form-item> |
|
||||
</el-form> |
|
||||
<div slot="footer" class="dialog-footer"> |
|
||||
<el-button size="small" @click="dialogVisible = false">取消</el-button> |
|
||||
<el-button size="small" type="primary" @click="saveAddress">保存</el-button> |
|
||||
</div> |
|
||||
</el-dialog> |
|
||||
</div> |
</div> |
||||
</template> |
</template> |
||||
|
|
||||
<script> |
<script> |
||||
|
import AddressFormDialog from "@/components/common/AddressFormDialog.vue"; // 引入组件 |
||||
|
|
||||
export default { |
export default { |
||||
name: 'UserInfo', |
name: "AddressManagement", |
||||
|
components: { |
||||
|
AddressFormDialog, // 注册组件 |
||||
|
}, |
||||
data() { |
data() { |
||||
return { |
return { |
||||
user: {}, |
user: {}, |
||||
searchParam: {pageSize: 5, currentPage: 1,total: 10}, |
searchParam: { pageSize: 5, currentPage: 1, total: 0 }, |
||||
dialogVisible: false, |
dialogVisible: false, |
||||
addresses: [ |
dialogType: "add", |
||||
{ |
dialogData: {}, |
||||
id: 1, |
addresses: [], |
||||
receiver: '张三', |
}; |
||||
region: '北京', |
|
||||
detailAddress: '北京市朝阳区xx街道xx小区xx号楼xx单元', |
|
||||
phone: '13800138000', |
|
||||
fixedPhone: '010-12345678', |
|
||||
alias: '家' |
|
||||
}, |
|
||||
{ |
|
||||
id: 2, |
|
||||
receiver: '李四', |
|
||||
region: '上海', |
|
||||
detailAddress: '上海市浦东新区xx街道xx小区xx号楼xx单元', |
|
||||
phone: '13900139000', |
|
||||
fixedPhone: '021-12345678', |
|
||||
alias: '公司' |
|
||||
}, |
|
||||
{ |
|
||||
id: 3, |
|
||||
receiver: '王五', |
|
||||
region: '广州', |
|
||||
detailAddress: '广州市天河区xx街道xx小区xx号楼xx单元', |
|
||||
phone: '13700137000', |
|
||||
fixedPhone: '020-12345678', |
|
||||
alias: '朋友家' |
|
||||
} |
|
||||
], |
|
||||
address: { |
|
||||
type: 'add', |
|
||||
id: '', |
|
||||
receiver: '', |
|
||||
region: '', |
|
||||
detailAddress: '', |
|
||||
phone: '', |
|
||||
fixedPhone: '', |
|
||||
alias: '' |
|
||||
} |
|
||||
} |
|
||||
}, |
}, |
||||
methods:{ |
mounted() { |
||||
// 分页大小改变 |
this.getAddress(); |
||||
|
}, |
||||
|
methods: { |
||||
|
// 获取收货地址 |
||||
|
getAddress() { |
||||
|
this.post( |
||||
|
{ |
||||
|
contactType: "CONSIGNEE", |
||||
|
offset: "0", |
||||
|
limit: "100", |
||||
|
}, |
||||
|
"/api/uservice/user/getContactOrConsignee" |
||||
|
).then((res) => { |
||||
|
if (res) { |
||||
|
this.addresses = res.data || []; |
||||
|
this.searchParam.total = this.addresses.length; |
||||
|
} |
||||
|
}); |
||||
|
}, |
||||
|
|
||||
|
// 分页相关方法 |
||||
handleSizeChange(val) { |
handleSizeChange(val) { |
||||
this.searchParam.pageSize = val; |
this.searchParam.pageSize = val; |
||||
|
this.searchParam.currentPage = 1; |
||||
}, |
}, |
||||
|
|
||||
// 当前页改变 |
|
||||
handleCurrentChange(val) { |
handleCurrentChange(val) { |
||||
this.searchParam.currentPage = val; |
this.searchParam.currentPage = val; |
||||
}, |
}, |
||||
openDialog (type, item) { |
|
||||
this.address = { |
// 打开对话框 |
||||
type: type, |
openDialog(type, item) { |
||||
id: item.id || "", |
this.dialogType = type; |
||||
receiver: item.receiver || "", |
this.dialogData = { ...item }; |
||||
region: item.region || "", |
|
||||
detailAddress: item.detailAddress || "", |
|
||||
phone: item.phone || "", |
|
||||
fixedPhone: item.fixedPhone || "", |
|
||||
alias: item.alias || "" |
|
||||
} |
|
||||
this.dialogVisible = true; |
this.dialogVisible = true; |
||||
}, |
}, |
||||
|
|
||||
saveAddress() { |
// 处理保存地址 |
||||
if (this.address.id) { |
handleSaveAddress(formData) { |
||||
// 编辑地址 |
formData.is_default = 0; |
||||
const index = this.addresses.findIndex(item => item.id === this.address.id); |
if (this.dialogType === "add") { |
||||
if (index !== -1) { |
this.post(formData, "/api/uservice/user/addNewConsignee").then( |
||||
this.addresses[index] = { ...this.address }; |
(res) => { |
||||
|
if (res.code == 1) { |
||||
|
this.$message.success("保存成功"); |
||||
|
this.getAddress(); |
||||
|
this.dialogVisible = false; |
||||
} |
} |
||||
} else { |
|
||||
// 新增地址 |
|
||||
this.address.id = Date.now(); |
|
||||
this.addresses.push({ ...this.address }); |
|
||||
} |
} |
||||
this.$message({ |
); |
||||
message: '保存成功', |
} else { |
||||
type: 'success' |
this.post(formData, "/api/uservice/user/editConsignee").then((res) => { |
||||
}); |
if (res.code == 1) { |
||||
this.dialogVisible = false; |
this.$message.success("保存成功"); |
||||
}, |
this.getAddress(); |
||||
handleEdit(row) { |
this.dialogVisible = false; |
||||
this.address = { ...row }; |
} |
||||
this.dialogVisible = true; |
}); |
||||
}, |
} |
||||
handleDelete(row) { |
}, |
||||
this.$confirm('此操作将永久删除该地址, 是否继续?', '提示', { |
|
||||
confirmButtonText: '确定', |
// 编辑地址 |
||||
cancelButtonText: '取消', |
handleEdit(row) { |
||||
type: 'warning' |
console.log(row); |
||||
}).then(() => { |
row.username = row.name; |
||||
const index = this.addresses.findIndex(item => item.id === row.id); |
row.mobile = row.tel; |
||||
if (index !== -1) { |
this.openDialog("edit", row); |
||||
this.addresses.splice(index, 1); |
}, |
||||
|
|
||||
|
// 删除地址 |
||||
|
handleDelete(row) { |
||||
|
this.$confirm("此操作将永久删除该地址, 是否继续?", "提示", { |
||||
|
confirmButtonText: "确定", |
||||
|
cancelButtonText: "取消", |
||||
|
type: "warning", |
||||
|
}) |
||||
|
.then(() => { |
||||
|
this.post( |
||||
|
{ |
||||
|
id: row.id, |
||||
|
}, |
||||
|
"/api/uservice/user/delConsignee" |
||||
|
).then((res) => { |
||||
|
if (res.code == 1) { |
||||
|
this.getAddress(); |
||||
|
this.$message.success("删除成功!"); |
||||
} |
} |
||||
this.$message({ |
|
||||
type: 'success', |
|
||||
message: '删除成功!' |
|
||||
}); |
|
||||
}).catch(() => { |
|
||||
this.$message({ |
|
||||
type: 'info', |
|
||||
message: '已取消删除' |
|
||||
}); |
|
||||
}); |
}); |
||||
} |
}) |
||||
} |
.catch(() => { |
||||
|
this.$message.info("已取消删除"); |
||||
} |
}); |
||||
|
}, |
||||
|
}, |
||||
|
}; |
||||
</script> |
</script> |
||||
<style lang="scss" scoped> |
|
||||
|
|
||||
|
<style lang="scss" scoped> |
||||
|
.flex-between { |
||||
|
display: flex; |
||||
|
justify-content: space-between; |
||||
|
align-items: center; |
||||
|
} |
||||
</style> |
</style> |
Loading…
Reference in new issue