ADD file via upload

main
pjhmizn49 1 year ago
parent c6fbded130
commit 41c5069f05

@ -0,0 +1,396 @@
<template>
<div>
<div class="tableTop">
<div>
<el-button @click="handleAdd"></el-button>
<el-button @click="handleDeleteMul" type="danger">批量删除</el-button>
</div>
<!-- 表单 -->
<el-dialog title="地址信息" :visible.sync="dialogVisible" :before-close="handleClose">
<el-form align="left" ref="dialogForm" :rules="rules" :model="dialogForm" label-width="130px" style="margin-right: 150px">
<el-form-item label="收件人" prop="address_name">
<el-input v-model="dialogForm.address_name" placeholder="请输入收件人"></el-input>
</el-form-item>
<el-form-item label="联系电话" prop="address_phone">
<el-input v-model="dialogForm.address_phone" placeholder="请输入联系电话"></el-input>
</el-form-item>
<el-form-item label="省" prop="address_sheng">
<el-input v-model="dialogForm.address_sheng" placeholder="请输入省"></el-input>
</el-form-item>
<el-form-item label="市" prop="address_shi">
<el-input v-model="dialogForm.address_shi" placeholder="请输入市"></el-input>
</el-form-item>
<el-form-item label="区" prop="address_qu">
<el-input v-model="dialogForm.address_qu" placeholder="请输入区"></el-input>
</el-form-item>
<el-form-item label="详细地址" prop="address_detail">
<el-input v-model="dialogForm.address_detail" placeholder="请输入详细地址"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="handleClose"> </el-button>
<el-button type="primary" @click="submitForm"> </el-button>
</div>
</el-dialog>
</div>
<el-table
ref="multipleTable"
:data="tableData"
style="width: 100%; padding: 0 10px"
@selection-change="handleSelectionChange">
<el-table-column type="selection" width="55"></el-table-column>
<el-table-column prop="address_name" label="收件人" width="120"></el-table-column>
<el-table-column prop="address_phone" label="联系电话" width="150"></el-table-column>
<el-table-column label="地址">
<el-table-column prop="address_sheng" label="省" width="100"></el-table-column>
<el-table-column prop="address_shi" label="市" width="100"></el-table-column>
<el-table-column prop="address_qu" label="区" width="100"></el-table-column>
<el-table-column prop="address_detail" label="详细地址" width="240"></el-table-column>
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button @click="handleModify(scope.row)" type="primary" size="small" plain>修改</el-button>
<el-button @click="handleDelete(scope.row)" type="danger" size="small" plain>删除</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
background
:current-page="currentPage"
:page-size="pageSize"
layout="total, prev, pager, next, jumper"
:total="total"
:page-count="page_number"
style="margin-top: 30px"
@current-change="handleCurrentChange">
</el-pagination>
</div>
</template>
<script>
import Cookie from "js-cookie";
export default {
data(){
return{
tableData:[{
address_id:1,
address_name:'',
address_sheng:'',
address_shi:'',
address_qu:'',
address_detail:'',
address_phone:''
}],
dialogForm:[{
address_id:1,
address_name:'',
address_sheng:'',
address_shi:'',
address_qu:'',
address_detail:'',
address_phone:''
}],
//
rules:{
address_name:[
{ required:true, trigger:'blur', message:'请输入名称'}
],
address_phone:[
{ required:true, trigger:'blur', message:'请输入联系电话'}
],
address_detail:[
{ required:true, trigger:'blur', message:'请输入详细地址'}
],
},
//
multipleSelection: [],
dialogVisible:false,
modelType:0, //01
//
currentPage:1,
pageSize:5,
page_number:1,//
total:10,//
}
},
created() {
this.fetchData();
},
methods:{
fetchData(){
const _this=this;
try {
axios({
method: 'post',
url: 'http://localhost:8181/address/list',
headers: {
Authorization: Cookie.get('token'),
'Content-Type': 'application/json'
},
data:{
page:_this.currentPage,
page_size:_this.pageSize
}
}).then(function (response){
if (response.data.code===200){
//
_this.tableData=response.data.data.addresses;
_this.page_number=response.data.data.page_number;
_this.total=response.data.data.total;
}
if (response.data.code===401){
_this.$message.warning('身份验证失败,请重新登录!')
}
if (response.data.code===403){
const message = response.data.msg;
this.$alert("页面加载出错,具体原因如下:\n"+message, '页面加载失败', {
confirmButtonText: '确定'
})
}
});
}catch (error){
this.$message.warning('页面加载出错,请重试!')
}
},
//
handleCurrentChange(page) {
this.currentPage = page;
this.fetchData();
},
//
handleSelectionChange(val) {
this.multipleSelection = val;
},
//
//
handleAdd(){
this.modelType = 0
this.dialogVisible = true
},
//
handleModify(row){
const _this = this
this.modelType = 1
axios({
method: 'post',
url: 'http://localhost:8181/address/info',
headers: {
Authorization: Cookie.get('token'),
'Content-Type': 'application/json'
},
data:{
address_id: row.address_id
}
}).then(function (response){
if (response.data.code===200) {
//
_this.dialogForm = response.data.data
}
if (response.data.code===401){
_this.$message.warning('身份验证失败,请重新登录!')
}
if (response.data.code===403){
const message = response.data.msg;
this.$alert("任务出错,具体原因如下:\n"+message, '页面加载失败', {
confirmButtonText: '确定'
})
}
});
this.dialogVisible = true
},
//
submitForm(){ //
const _this=this;
this.$refs.dialogForm.validate((valid) =>{
if(valid){
if(_this.modelType===0){
//
axios({
method: 'post',
url: 'http://localhost:8181/address/add',
headers: {
Authorization: Cookie.get('token'),
'Content-Type': 'application/json'
},
data:{
address_id:_this.dialogForm.address_id,
address_name:_this.dialogForm.address_name,
address_phone:_this.dialogForm.address_phone,
address_sheng:_this.dialogForm.address_sheng,
address_shi:_this.dialogForm.address_shi,
address_qu:_this.dialogForm.address_qu,
address_detail:_this.dialogForm.address_detail
}
}).then(function (response){
if (response.data.code===200) {
//
_this.$message.success('添加成功!')
//
_this.fetchData()
}
if (response.data.code===401){
_this.$message.warning('身份验证失败,请重新登录!')
}
if (response.data.code===403){
const message = response.data.msg;
this.$alert("任务出错,具体原因如下:\n"+message, '页面加载失败', {
confirmButtonText: '确定'
})
}
});
}
else if(_this.modelType===1){
//
axios({
method: 'post',
url: 'http://localhost:8181/address/modify',
headers: {
Authorization: Cookie.get('token'),
'Content-Type': 'application/json'
},
data:{
address_id:_this.dialogForm.address_id,
address_name:_this.dialogForm.address_name,
address_phone:_this.dialogForm.address_phone,
address_sheng:_this.dialogForm.address_sheng,
address_shi:_this.dialogForm.address_shi,
address_qu:_this.dialogForm.address_qu,
address_detail:_this.dialogForm.detail
}
}).then(function (response){
if (response.data.code===200) {
//
_this.$message.success('修改成功!')
//
_this.fetchData()
}
if (response.data.code===401){
_this.$message.warning('身份验证失败,请重新登录!')
}
if (response.data.code===403){
const message = response.data.msg;
this.$alert("任务出错,具体原因如下:\n"+message, '页面加载失败', {
confirmButtonText: '确定'
})
}
});
}
//
this.handleClose();
}
})
},
//
handleDelete(row){
const _this = this;
this.$confirm('此操作将永久删除该地址信息, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
//
axios({
method: 'post',
url: 'http://localhost:8181/address/deletePer',
headers: {
Authorization: Cookie.get('token'),
'Content-Type': 'application/json'
},
data:{
address_id:row.address_id
}
}).then(function (response){
if (response.data.code===200) {
//
_this.fetchData()
}
if (response.data.code===401){
_this.$message.warning('身份验证失败,请重新登录!')
}
if (response.data.code===403){
const message = response.data.msg;
this.$alert("页面加载出错,具体原因如下:\n"+message, '页面加载失败', {
confirmButtonText: '确定'
})
}
});
this.$message({type: 'success', message: '删除成功!'});
}).catch(() => {
this.$message({type: 'info', message: '已取消删除'});
});
},
handleDeleteMul(){
const _this = this
if(_this.multipleSelection.length===0)
this.$message({type: 'warning', message: '请选择地址'});
else{
let ids = []
for (let i=0; i<_this.multipleSelection.length; i++){
ids[i] = _this.multipleSelection[i].address_id
}
this.$confirm('此操作将永久删除地址信息, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
//
axios({
method: 'post',
url: 'http://localhost:8181/address/deleteMul',
headers: {
Authorization: Cookie.get('token'),
'Content-Type': 'application/json'
},
data:{
address_ids:ids
}
}).then(function (response){
if (response.data.code===200) {
//
_this.fetchData()
}
if (response.data.code===401){
_this.$message.warning('身份验证失败,请重新登录!')
}
if (response.data.code===403){
const message = response.data.msg;
this.$alert("任务出错,具体原因如下:\n"+message, '页面加载失败', {
confirmButtonText: '确定'
})
}
});
this.$message({type: 'success', message: '批量删除成功!'});
}).catch(() => {
this.$message({type: 'info', message: '已取消删除'});
});
}
},
//dialog
handleClose(){
this.$refs.dialogForm.resetFields()
//
this.dialogForm.address_id = 1;
this.dialogForm.address_name='';
this.dialogForm.address_sheng='';
this.dialogForm.address_shi='';
this.dialogForm.address_qu='';
this.dialogForm.address_detail='';
this.dialogForm.address_phone='';
this.dialogVisible = false;
},
}
}
</script>
<style>
.tableTop{
width: 1000px;
display: flex;
justify-content: space-between;
align-items: center;
margin: 50px 0 30px 50px;
}
</style>
Loading…
Cancel
Save