前后端分离之前端

<template>
<div class="custom">
<el-col :span="2">
<el-button type="primary" @click="opendialogVisible">添加</el-button>
</el-col>
<el-col :span="2">
<el-button type="danger" @click="deleteBatch">批量删除</el-button>
</el-col>
<el-col :span="20">
<el-form :model="searchForm" inline>
<el-form-item label="姓名">
<el-input v-model="searchForm.cname" placeholder="请输入查询内容"></el-input>
</el-form-item>
<el-form-item label="日期">
<el-input type="date" v-model="searchForm.bir1" style="width: 45%;"></el-input> --
<el-input type="date" v-model="searchForm.bir2" style="width: 45%;"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="searchData">查询</el-button>
</el-form-item>
</el-form>
</el-col>
<el-table ref="rows" :data="tableData" tooltip-effect="dark" style="width: 100%" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55">
</el-table-column>
<el-table-column prop="cid" label="序号" width="120">
</el-table-column>
<el-table-column prop="pic" label="头像" width="120">
<template slot-scope="scope">
<!--头像-->
<el-avatar shape="square" :size="100" :src="scope.row.pic"></el-avatar>
</template>
</el-table-column>
<el-table-column prop="cname" label="姓名" width="120">
</el-table-column>
<el-table-column prop="csex" label="性别" width="120">
</el-table-column>
<el-table-column prop="birthday" label="出生日期" width="120">
</el-table-column>
<el-table-column prop="bname" label="发卡银行" width="300">
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button size="mini" type="success" @click="editspan(scope.row)">查看</el-button>
<el-button size="mini" type="primary" @click="editVisible(scope.row)">修改</el-button>
<el-button size="mini" type="danger" @click="deleteCus(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="current"
:page-sizes="pageSizes" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"
prev-text="上一页" next-text="下一页">
</el-pagination>

<!-- 添加对话框 -->
<el-dialog title="添加列表" :visible.sync="dialogVisible" width="80%">
<el-form :model="insertForm" :rules="rulesForm" ref="insertForm" label-width="100px" class="demo-ruleForm">
<el-form-item label="客户姓名" prop="cname">
<el-input v-model="insertForm.cname"></el-input>
</el-form-item>
<el-form-item label="性别" prop="csex">
<el-radio v-model="insertForm.csex" label="男">男</el-radio>
<el-radio v-model="insertForm.csex" label="女">女</el-radio>
</el-form-item>
<el-form-item label="出生日期" prop="birthday">
<el-date-picker type="date" placeholder="选择日期" v-model="insertForm.birthday" style="width: 100%;"></el-date-picker>
</el-form-item>
<el-form-item label="头像" prop="pic">
<el-upload class="avatar-uploader" action="http://localhost:8090/upload" :show-file-list="false" :on-success="handleAvatarSuccess">
<img v-if="imageUrl" :src="imageUrl" class="avatar">
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
</el-form-item>
<el-form-item label="银行账号" prop="bname">
<el-checkbox-group v-model="checkedBanks" @change="handleCheckedBanksChange">
<el-checkbox v-for="bank in banks" :label="bank.bid">{{bank.bname}}</el-checkbox>
</el-checkbox-group>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitForm('insertForm')">添加</el-button>
<el-button @click="dialogVisible = false">取消</el-button>
</el-form-item>
</el-form>
</el-dialog>

<!-- 修改对话框 -->
<el-dialog title="修改列表" :visible.sync="editdialogVisible" width="80%">
<el-form :model="updateForm" ref="updateForm" label-width="100px">
<el-form-item label="客户姓名" prop="cname">
<el-input v-model="updateForm.cname"></el-input>
</el-form-item>
<el-form-item label="性别" prop="csex">
<el-radio v-model="updateForm.csex" label="男">男</el-radio>
<el-radio v-model="updateForm.csex" label="女">女</el-radio>
</el-form-item>
<el-form-item label="出生日期" prop="birthday">
<el-date-picker type="date" placeholder="选择日期" v-model="updateForm.birthday" style="width: 100%;"></el-date-picker>
</el-form-item>
<el-form-item label="银行账号" prop="bname">
<el-checkbox-group v-model="checkedBanks" @change="handleCheckedBanksChange">
<el-checkbox v-for="bank in banks" :label="bank.bid">{{bank.bname}}</el-checkbox>
</el-checkbox-group>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="updateData('updateForm')">更新</el-button>
<el-button @click="editdialogVisible = false">取消</el-button>
</el-form-item>
</el-form>
</el-dialog>

<!-- 详情对话框 -->
<el-dialog title="修改列表" :visible.sync="editSpanVisible" width="80%">
<el-form :model="editForm" ref="editForm" label-width="100px">
<el-form-item label="客户姓名" prop="cname">
<el-input v-model="editForm.cname"></el-input>
</el-form-item>
<el-form-item label="性别" prop="csex">
<el-radio v-model="editForm.csex" label="男">男</el-radio>
<el-radio v-model="editForm.csex" label="女">女</el-radio>
</el-form-item>
<el-form-item label="出生日期" prop="birthday">
<el-date-picker type="date" placeholder="选择日期" v-model="editForm.birthday" style="width: 100%;"></el-date-picker>
</el-form-item>
<el-form-item label="银行账号" prop="bname">
<el-checkbox-group v-model="checkedBanks" @change="handleCheckedBanksChange">
<el-checkbox v-for="bank in banks" :label="bank.bid">{{bank.bname}}</el-checkbox>
</el-checkbox-group>
</el-form-item>
<el-form-item>
<el-button @click="editSpanVisible = false">取消</el-button>
</el-form-item>
</el-form>
</el-dialog>
</div>
</template>

<script>
export default {
data() {
return {
rulesForm: {
cname: [{
required: true,
message: '请输入客户姓名',
trigger: 'blur'
}],
csex: [{
required: true,
message: '请选择客户性别',
trigger: 'blur'
}],
birthday: [{
type: 'date',
required: true,
message: '请选择出生日期',
trigger: 'blur'
}]
},
checkedBanks: [],
banks: [],
insertForm: {
cname: '',
csex: '',
birthday: '',
pic: '',
bname: '',
bids: ''
},
dialogVisible: false,
imageUrl: '',
updateForm: {
cid: 0,
cname: '',
csex: '男',
birthday: '',
bname: '',
bids: ''
},
editdialogVisible: false,
editForm: {
cid: 0,
cname: '',
csex: '男',
birthday: '',
bname: '',
bids: ''
},
editSpanVisible: false,
tableData: [],
rows: [],
current: 1,
pageSize: 3,
pageSizes: [2, 3, 5],
total: 0,
searchForm: {
cname: '',
bir1: '',
bir2: ''
}

}
},
created() {
this.initData();
this.initBank();
},
methods: {
//批量删除
deleteBatch() {
/* if (this.rows instanceof Array && this.rows.length > 0) { */
/* this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
//post请求
this.axios.post("http://localhost:8090/custom/delete",null, {

})
this.$message({
type: 'success',
message: '删除成功!'
});
}).catch(() => {
this.$message({
type: 'info',
message: '已取消删除'
});
}); */
this.$confirm('你确定要删除选中的数据吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
//post请求
this.axios.post('http://localhost:8090/custom/delete', null, {
params: {
ids: this.rows.map(row => row.cid).join(",")
}
}).then((response) => {
this.$message({
type: 'success',
message: '删除成功!'
});
//扩展操作
this.initData();
});
}).catch(() => {
this.$message({
type: 'info',
message: '已取消删除'
});
});
/* } else {
this.$message({
type: 'success',
message: '请选择要删除的数据!'
});
} */
},
//单删
deleteCus(row) {
this.$confirm('你确定要删除选中的数据吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
//post请求
this.axios.post('http://localhost:8090/custom/delete', null, {
params: {
ids: row.cid
}
}).then((response) => {
this.$message({
type: 'success',
message: '删除成功!'
});
//扩展操作
this.initData();
});
}).catch(() => {
this.$message({
type: 'info',
message: '已取消删除'
});
});
},
//添加
submitForm(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
//赋值过程
this.insertForm.bids = this.checkedBanks.map(bid => bid).join(",");
this.axios.post("http://localhost:8090/custom/insert", this.insertForm).then((response) => {
if (response.data.result) {
this.$message({
type: 'success',
message: '客户添加成功!'
});
//对话框关闭
this.dialogVisible = false;
//初始化列表数据
this.initData();
} else {
this.$message.error("客户添加失败");
}
});
} else {
return false;
}
});
},
//改变事件,绑定数值发生变化,更新数值
handleCheckedBanksChange(val) {
this.checkedBanks = val;
},
initBank() {
this.axios.get('http://localhost:8090/bank/findAll').then((response) => {
// 查询出所有的银行列表
this.banks = response.data;
});
},
opendialogVisible() {
//初始化空数组
this.checkedBanks = [];
//打开对话框钱,先查询所有的银行
this.initBank();
//打开对话框
this.dialogVisible = true;
},
//查看
editspan(row) {
//初始化空数组
this.checkedBanks = [];
//判断本身是否具有银行账号信息
if (row.bids != null && row.bids != '') {
//拆分银行
let bids = row.bids.split(",");
//遍历银行
for (let i = 0; i < bids.length; i++) {
//取出银行id值
let id = bids[i];
//判断是否为数字
if (!isNaN(id)) {
//存入到回显的数组中
this.checkedBanks.push(parseInt(id));
}
}
}
//打开对话框前,先查询所有银行
this.initBank();
Object.assign(this.editForm, row);
this.editSpanVisible = true;
},
//回显
editVisible(row) {
//初始化空数组
this.checkedBanks = [];
//判断本事是否具有银行账号信息
if (row.bids != null && row.bids != '') {
console.log("sadj")
//拆分银行
let bids = row.bids.split(",");
//遍历银行
for (let i = 0; i < bids.length; i++) {
console.log("skadj")
//取出银行id值
let bid = bids[i];
//判断是否为数字
if (!isNaN(bid)) {
//存入到回显的数组中
this.checkedBanks.push(parseInt(bid));
}
}
}
//打开对话框钱,先查询所有的银行
this.initBank();
Object.assign(this.updateForm, row);
this.editdialogVisible = true;
},
//修改
updateData(row) {
//赋值过程
this.updateForm.bids = this.checkedBanks.map((bid) => bid).join(",");
this.axios.post("http://localhost:8090/custom/update", this.updateForm).then((response) => {
if (response.data.result) {
this.$message({
type: 'success',
message: '客户更新成功!'
});
//对话框关闭
this.editdialogVisible = false;
//初始化列表数据
this.initData();
} else {
this.$message.error("客户更新失败!")
}
})
},
//图片上传
handleAvatarSuccess(res,file){
this.imageUrl = URL.createObjectURL(file.raw);
if(this.dialogVisible){
this.insertForm.pic = res.result;
}
},
//列表方法
initData() {
this.axios.get('http://localhost:8090/custom/list', {
params: {
cname: this.searchForm.cname,
bir1: this.searchForm.bir1,
bir2: this.searchForm.bir2,
current: this.current,
size: this.pageSize
}
}).then((response) => {
this.tableData = response.data.result.records;
this.total = response.data.result.total;
})
},
//查询方法
searchData() {
this.initData();
},
//改变每页显示的条数
handleSizeChange(val) {
this.pageSize = val;
this.initData();
},
//改变 上一页下一页
handleCurrentChange(val) {
this.current = val;
this.initData();
},
//全选,全不选
handleSelectionChange(val) {
this.rows = val;
},
}
}
</script>

<style scoped>
.avatar-uploader .el-upload {
border: 1px dashed #d9d9d9;
border-radius: 6px;
cursor: pointer;
position: relative;
overflow: hidden;
}

.avatar-uploader .el-upload:hover {
border-color: #409EFF;
}

.avatar-uploader-icon {
font-size: 28px;
color: #8c939d;
width: 178px;
height: 178px;
line-height: 178px;
text-align: center;
}

.avatar {
width: 178px;
height: 178px;
display: block;
}
</style>

上一篇:百度地图,设置起点终点,绘制路线,获取总路程和总时长,清除绘制路线


下一篇:JavaScript对接百度地图