重构: 管理后台不支持管理员创建和编辑用户的地址数据
This commit is contained in:
@@ -78,53 +78,4 @@ public class AdminAddressController {
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
public Object create(@LoginAdmin Integer adminId, @RequestBody LitemallAddress address){
|
||||
if(adminId == null){
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
String mobile = address.getMobile();
|
||||
if(!RegexUtil.isMobileExact(mobile)){
|
||||
return ResponseUtil.fail(403, "手机号格式不正确");
|
||||
}
|
||||
|
||||
address.setAddTime(LocalDateTime.now());
|
||||
addressService.add(address);
|
||||
|
||||
Map<String, Object> addressVo = toVo(address);
|
||||
return ResponseUtil.ok(addressVo);
|
||||
}
|
||||
|
||||
@GetMapping("/read")
|
||||
public Object read(@LoginAdmin Integer adminId, @NotNull Integer id){
|
||||
if(adminId == null){
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
LitemallAddress address = addressService.findById(id);
|
||||
Map<String, Object> addressVo = toVo(address);
|
||||
return ResponseUtil.ok(addressVo);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public Object update(@LoginAdmin Integer adminId, @RequestBody LitemallAddress address){
|
||||
if(adminId == null){
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
addressService.updateById(address);
|
||||
Map<String, Object> addressVo = toVo(address);
|
||||
return ResponseUtil.ok(addressVo);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@LoginAdmin Integer adminId, @RequestBody LitemallAddress address){
|
||||
if(adminId == null){
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
addressService.delete(address.getId());
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,35 +7,3 @@ export function listAddress(query) {
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
export function createAddress(data) {
|
||||
return request({
|
||||
url: '/address/create',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
export function readAddress(data) {
|
||||
return request({
|
||||
url: '/address/read',
|
||||
method: 'get',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
export function updateAddress(data) {
|
||||
return request({
|
||||
url: '/address/update',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
export function deleteAddress(data) {
|
||||
return request({
|
||||
url: '/address/delete',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
<el-input clearable class="filter-item" style="width: 200px;" placeholder="请输入收货人名称" v-model="listQuery.name">
|
||||
</el-input>
|
||||
<el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">查找</el-button>
|
||||
<el-button class="filter-item" type="primary" @click="handleCreate" icon="el-icon-edit">添加</el-button>
|
||||
<el-button class="filter-item" type="primary" :loading="downloadLoading" icon="el-icon-download" @click="handleDownload">导出</el-button>
|
||||
</div>
|
||||
|
||||
@@ -38,12 +37,6 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column align="center" label="操作" width="250" class-name="small-padding fixed-width">
|
||||
<template slot-scope="scope">
|
||||
<el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
|
||||
<el-button type="danger" size="mini" @click="handleDelete(scope.row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 分页 -->
|
||||
@@ -53,57 +46,11 @@
|
||||
</el-pagination>
|
||||
</div>
|
||||
|
||||
<!-- 添加或修改对话框 -->
|
||||
<el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
|
||||
<el-form :rules="rules" ref="dataForm" :model="dataForm" status-icon label-position="left" label-width="100px" style='width: 400px; margin-left:50px;'>
|
||||
<el-form-item label="用户ID" prop="userId">
|
||||
<el-input v-model="dataForm.userId"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="收货人名称" prop="name">
|
||||
<el-input v-model="dataForm.name"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="收获人手机" prop="mobile">
|
||||
<el-input v-model="dataForm.mobile"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="区域地址">
|
||||
<el-select v-model="dataForm.provinceId" placeholder="省" @change="provinceChange">
|
||||
<el-option v-for="item in provinces" :key="item.id" :label="item.name" :value="item.id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
<el-select v-model="dataForm.cityId" placeholder="市" @change="cityChange">
|
||||
<el-option v-for="item in cities" :key="item.id" :label="item.name" :value="item.id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
<el-select v-model="dataForm.areaId" placeholder="区" @change="areaChange">
|
||||
<el-option v-for="item in areas" :key="item.id" :label="item.name" :value="item.id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="详细地址" prop="address">
|
||||
<el-input v-model="dataForm.address"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="是否默认地址" prop="isDefault">
|
||||
<el-select v-model="dataForm.isDefault" placeholder="请选择">
|
||||
<el-option label="否" :value="false">
|
||||
</el-option>
|
||||
<el-option label="是" :value="true">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button @click="dialogFormVisible = false">取消</el-button>
|
||||
<el-button v-if="dialogStatus=='create'" type="primary" @click="createData">确定</el-button>
|
||||
<el-button v-else type="primary" @click="updateData">确定</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listAddress, createAddress, updateAddress, deleteAddress } from '@/api/address'
|
||||
import { listSubRegion } from '@/api/region'
|
||||
import { listAddress } from '@/api/address'
|
||||
|
||||
export default {
|
||||
name: 'UserAddress',
|
||||
@@ -120,41 +67,11 @@ export default {
|
||||
sort: 'add_time',
|
||||
order: 'desc'
|
||||
},
|
||||
provinces: {},
|
||||
cities: {},
|
||||
areas: {},
|
||||
dataForm: {
|
||||
id: undefined,
|
||||
userId: undefined,
|
||||
name: undefined,
|
||||
mobile: undefined,
|
||||
address: undefined,
|
||||
isDefault: undefined,
|
||||
provinceId: undefined,
|
||||
cityId: undefined,
|
||||
areaId: undefined
|
||||
},
|
||||
dialogFormVisible: false,
|
||||
dialogStatus: '',
|
||||
textMap: {
|
||||
update: '编辑',
|
||||
create: '创建'
|
||||
},
|
||||
rules: {
|
||||
userId: [{ required: true, message: '用户ID不能为空', trigger: 'blur' }],
|
||||
name: [{ required: true, message: '收货人名称不能为空', trigger: 'blur' }],
|
||||
mobile: [{ required: true, message: '收货人手机号码不能为空', trigger: 'blur' }],
|
||||
provinceId: [{ required: true, message: '收货人所在省不能为空', trigger: 'blur' }],
|
||||
cityId: [{ required: true, message: '收货人所在市不能为空', trigger: 'blur' }],
|
||||
areaId: [{ required: true, message: '收货人所在区不能为空', trigger: 'blur' }],
|
||||
address: [{ required: true, message: '收货人地址不能为空', trigger: 'blur' }]
|
||||
},
|
||||
downloadLoading: false
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.getList()
|
||||
this.getProvinces()
|
||||
},
|
||||
methods: {
|
||||
getList() {
|
||||
@@ -168,36 +85,6 @@ export default {
|
||||
this.total = 0
|
||||
this.listLoading = false
|
||||
})
|
||||
},
|
||||
getProvinces() {
|
||||
listSubRegion({ id: 0 }).then(response => {
|
||||
this.provinces = response.data.data
|
||||
})
|
||||
},
|
||||
provinceChange(val) {
|
||||
if (val === undefined) {
|
||||
return
|
||||
}
|
||||
this.cities = {}
|
||||
this.dataForm.cityId = undefined
|
||||
this.areas = {}
|
||||
this.dataForm.areaId = undefined
|
||||
listSubRegion({ id: val }).then(response => {
|
||||
this.cities = response.data.data
|
||||
})
|
||||
},
|
||||
cityChange(val) {
|
||||
if (val === undefined) {
|
||||
return
|
||||
}
|
||||
this.areas = {}
|
||||
this.dataForm.areaId = undefined
|
||||
listSubRegion({ id: val }).then(response => {
|
||||
this.areas = response.data.data
|
||||
})
|
||||
},
|
||||
areaChange(val) {
|
||||
|
||||
},
|
||||
handleFilter() {
|
||||
this.listQuery.page = 1
|
||||
@@ -211,96 +98,6 @@ export default {
|
||||
this.listQuery.page = val
|
||||
this.getList()
|
||||
},
|
||||
resetForm() {
|
||||
this.dataForm = {
|
||||
id: undefined,
|
||||
userId: undefined,
|
||||
name: undefined,
|
||||
mobile: undefined,
|
||||
address: undefined,
|
||||
isDefault: undefined,
|
||||
provinceId: undefined,
|
||||
cityId: undefined,
|
||||
areaId: undefined
|
||||
}
|
||||
},
|
||||
handleCreate() {
|
||||
this.resetForm()
|
||||
this.cities = {}
|
||||
this.areas = {}
|
||||
this.dialogStatus = 'create'
|
||||
this.dialogFormVisible = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs['dataForm'].clearValidate()
|
||||
})
|
||||
},
|
||||
createData() {
|
||||
this.$refs['dataForm'].validate((valid) => {
|
||||
if (valid) {
|
||||
createAddress(this.dataForm).then(response => {
|
||||
this.list.unshift(response.data.data)
|
||||
this.dialogFormVisible = false
|
||||
this.$notify({
|
||||
title: '成功',
|
||||
message: '创建成功',
|
||||
type: 'success',
|
||||
duration: 2000
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
handleUpdate(row) {
|
||||
this.dataForm = Object.assign({}, row)
|
||||
this.cities = {}
|
||||
this.areas = {}
|
||||
listSubRegion({ id: this.dataForm.provinceId }).then(response => {
|
||||
this.cities = response.data.data
|
||||
})
|
||||
listSubRegion({ id: this.dataForm.cityId }).then(response => {
|
||||
this.areas = response.data.data
|
||||
})
|
||||
this.dialogStatus = 'update'
|
||||
this.dialogFormVisible = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs['dataForm'].clearValidate()
|
||||
})
|
||||
},
|
||||
updateData() {
|
||||
this.$refs['dataForm'].validate((valid) => {
|
||||
if (valid) {
|
||||
updateAddress(this.dataForm).then(response => {
|
||||
const updatedAddress = response.data.data
|
||||
for (const v of this.list) {
|
||||
if (v.id === updatedAddress.id) {
|
||||
const index = this.list.indexOf(v)
|
||||
this.list.splice(index, 1, updatedAddress)
|
||||
break
|
||||
}
|
||||
}
|
||||
this.dialogFormVisible = false
|
||||
this.$notify({
|
||||
title: '成功',
|
||||
message: '更新成功',
|
||||
type: 'success',
|
||||
duration: 2000
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
handleDelete(row) {
|
||||
deleteAddress(row).then(response => {
|
||||
this.$notify({
|
||||
title: '成功',
|
||||
message: '删除成功',
|
||||
type: 'success',
|
||||
duration: 2000
|
||||
})
|
||||
const index = this.list.indexOf(row)
|
||||
this.list.splice(index, 1)
|
||||
})
|
||||
},
|
||||
handleDownload() {
|
||||
this.downloadLoading = true
|
||||
import('@/vendor/Export2Excel').then(excel => {
|
||||
|
||||
@@ -30,7 +30,7 @@ public class LitemallAddressService {
|
||||
}
|
||||
|
||||
public int update(LitemallAddress address) {
|
||||
return addressMapper.updateByPrimaryKeySelective(address);
|
||||
return addressMapper.updateWithVersionByPrimaryKeySelective(address.getVersion(), address);
|
||||
}
|
||||
|
||||
public void delete(Integer id) {
|
||||
@@ -85,8 +85,4 @@ public class LitemallAddressService {
|
||||
|
||||
return (int)addressMapper.countByExample(example);
|
||||
}
|
||||
|
||||
public void updateById(LitemallAddress address) {
|
||||
addressMapper.updateByPrimaryKeySelective(address);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user