码迷,mamicode.com
首页 > 编程语言 > 详细

java微服务框架之Product

时间:2020-07-10 00:38:19      阅读:74      评论:0      收藏:0      [点我收藏+]

标签:微服务   type   var   model   fir   layout   tar   hid   编辑   

<template>
<div class="product">
<el-col :span="2">
<el-button type="success" @click="openInsertDialog">添加</el-button>
</el-col>
<el-col :span="2">
<el-button type="danger" @click="delecteObjects">批量删除</el-button>
</el-col>
<el-col :span="18">
<el-form :inline="true" :model="formInline">
<el-form-item label="产品名">
<el-input v-model="formInline.name" placeholder="产品名"></el-input>
</el-form-item>
<el-form-item label="价格查询">
<el-input v-model="formInline.start" placeholder="¥" style="width: 6.25rem;"></el-input>
-<el-input v-model="formInline.end" placeholder="¥" style="width: 6.25rem;"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="onSubmit">查询</el-button>
</el-form-item>
</el-form>
</el-col>
<el-table :data="tableData" style="width: 100%" ref="row" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55">
</el-table-column>
<el-table-column prop="id" label="编号" width="180">
</el-table-column>
<el-table-column prop="name" label="商品名称" width="180">
</el-table-column>
<el-table-column prop="pic" label="商品图片" width="180">
<template slot-scope="scope">
<el-image style="width: 100px; height: 100px" :src="scope.row.pic"></el-image>
</template>
</el-table-column>
<el-table-column prop="price" label="商品价格" width="180">
</el-table-column>
<el-table-column prop="createTime" label="商品上架时间" width="180">
</el-table-column>
<el-table-column prop="price" label="促销类型" width="180">
<template slot-scope="scope">
<span v-for="item in scope.row.salesList">{{item.name}}/</span>
</template>
</el-table-column>
<el-table-column label="产地" width="180">
<template slot-scope="scope">
<span>{{scope.row.province.cityName}}/{{scope.row.city.cityName}}/{{scope.row.xian.cityName}}</span>
</template>
</el-table-column>

<el-table-column label="操作">
<template slot-scope="scope">
<el-button type="primary" @click="editOpen(scope.row)">编辑</el-button>
<el-button type="success">详情</el-button>
</template>
</el-table-column>
</el-table>
<el-row>
<el-col>
<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page"
:page-sizes="sizes" :page-size="size" layout="total, sizes, prev, pager, next, jumper" :total="total">
</el-pagination>
</el-col>
</el-row>


<el-dialog title="添加对话框" :visible.sync="dialogVisibleInsert" width="50%">

<el-form ref="insertForm" :model="insertForm" label-width="80px">
<el-form-item label="商品名称">
<el-input v-model="insertForm.name"></el-input>
</el-form-item>
<el-form-item label="商品图片">
<el-upload class="avatar-uploader" action="http://localhost:8800/api/product/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="进货时间">
<el-date-picker v-model="insertForm.createTime" type="date" placeholder="选择日期" value-format="yyyy-MM-dd">
</el-date-picker>
</el-form-item>
<el-form-item label="商品价格">
<el-input v-model="insertForm.price"></el-input>
</el-form-item>
<el-form-item label="产地">
<el-cascader v-model="values" :options="options" :props="props" @change="handleChange"></el-cascader>
</el-form-item>
<el-form-item label="促销">
<el-checkbox-group v-model="checkedSales" @change="handlechangeChecked">
<el-checkbox v-for="sale in sales" :label="sale">{{sale.name}}</el-checkbox>
</el-checkbox-group>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="insertData(‘insertForm‘)">确定</el-button>
<el-button @click="dialogVisibleInsert = false">取 消</el-button>
</el-form-item>
</el-form>
</el-dialog>

<el-dialog title="修改对话框" :visible.sync="dialogVisibleUpdate" width="50%">

<el-form ref="updateForm" :model="updateForm" label-width="80px">
<el-form-item label="商品名称">
<el-input v-model="updateForm.name"></el-input>
</el-form-item>
<el-form-item label="商品图片">
<el-upload class="avatar-uploader" action="http://localhost:8800/api/product/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="进货时间">
<el-date-picker v-model="updateForm.createTime" type="date" placeholder="选择日期" value-format="yyyy-MM-dd">
</el-date-picker>
</el-form-item>
<el-form-item label="商品价格">
<el-input v-model="updateForm.price"></el-input>
</el-form-item>
<el-form-item label="产地">
<el-cascader v-model="values" :options="options" :props="props" @change="handleChange"></el-cascader>
</el-form-item>
<el-form-item label="促销">
<el-checkbox-group v-model="checkedSales" @change="handlechangeChecked">
<el-checkbox v-for="sale in sales" :label="sale.id">{{sale.name}}</el-checkbox>
</el-checkbox-group>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="updateData(‘updateForm‘)">确定</el-button>
<el-button @click="dialogVisibleUpdate = false">取 消</el-button>
</el-form-item>
</el-form>
</el-dialog>

</div>
</template>

<script>
export default {
data() {
return {

dialogVisibleUpdate: false,
checkedSales: [],
sales: [],
options: [],
values: [],
props: {
value: ‘id‘,
label: ‘cityName‘,
children: ‘cityList‘
},
imageUrl: ‘‘,
updateForm: {
id: ‘‘,
createTime: ‘‘,
name: ‘‘,
pic: ‘‘,
price: ‘‘,
pid: 0,
cid: 0,
xid: 0,
salesList: []
},
insertForm: {
createTime: ‘‘,
name: ‘‘,
pic: ‘‘,
price: ‘‘,
pid: 0,
cid: 0,
xid: 0,
salesList: []
},
dialogVisibleInsert: false,
row: [],
tableData: [],
total: 0,
page: 1,
size: 3,
sizes: [2, 3, 5],
formInline: {
name: ‘‘,
start: ‘‘,
end: ‘‘
}
}
},
created: function() {
this.initData();
this.initCity();
this.initSales();
},
methods: {

editOpen(row) {
this.values[0] = row.pid;
this.values[1] = row.cid;
this.values[2] = row.xid;
this.dialogVisibleUpdate = true;
Object.assign(this.updateForm, row);
this.imageUrl = row.pic;

//促销回显
this.checkedSales = [];


for (var i = 0; i < row.salesList.length; i++) {
this.checkedSales[i] = row.salesList[i].id;
}

},
handlechangeChecked() {
if (this.dialogVisibleInsert) {
this.insertForm.salesList = [];
this.insertForm.salesList = this.checkedSales;
} else if (this.dialogVisibleUpdate) {
this.updateForm.salesList = [];
this.updateForm.salesList = this.checkedSales;
}
},
initSales() {
this.axios.get(‘http://localhost:8800/api/product/sales‘).then((response) => {
this.sales = response.data.result;
})
},
handleChange(value) {
console.log(value);
if (this.dialogVisibleInsert) {
this.insertForm.pid = value[0];
this.insertForm.cid = value[1];
this.insertForm.xid = value[2];
} else if (this.dialogVisibleUpdate) {
this.updateForm.pid = value[0];
this.updateForm.cid = value[1];
this.updateForm.xid = value[2];
}

},
initCity() {
this.axios.get(‘http://localhost:8800/api/product/city‘).then((response) => {
this.options = response.data.result;
})
},
handleAvatarSuccess(res, file) {
this.imageUrl = URL.createObjectURL(file.raw);
if (this.dialogVisibleInsert) {
this.insertForm.pic = res.result;
} else if (this.dialogVisibleUpdate) {
this.updateForm.pic = res.result;
}
},
updateData() {
for (var n = 0; n < this.sales.length; n++) {

for (var j = 0; j < this.checkedSales.length; j++) {

if (this.sales[n].id == this.checkedSales[j]) {

this.updateForm.salesList[j] = this.sales[n];

}
}
}
this.axios.post(‘http://localhost:8800/api/product/insert‘, this.updateForm).then((response) => {

if (response.data.result) {
this.$message({
type: ‘success‘,
message: ‘修改成功!‘
});
this.dialogVisibleUpdate = false;
this.initData();
} else {
this.$message({
message: ‘警告哦,修改失败‘,
type: ‘warning‘
});
}
});
},
insertData() {
console.log(this.insertForm);
this.axios.post(‘http://localhost:8800/api/product/insert‘, this.insertForm).then((response) => {

if (response.data.result) {
this.$message({
type: ‘success‘,
message: ‘添加成功!‘
});
this.dialogVisibleInsert = false;
this.initData();
} else {
this.$message({
message: ‘警告哦,添加失败‘,
type: ‘warning‘
});
}
});
},
openInsertDialog() {
this.dialogVisibleInsert = true;
},
// 批量删除
delecteObjects() {
this.$confirm(‘此操作将永久删除该文件, 是否继续?‘, ‘提示‘, {
confirmButtonText: ‘确定‘,
cancelButtonText: ‘取消‘,
type: ‘warning‘
}).then(() => {
this.axios.post(‘http://localhost:8800/api/product/delete‘, this.row).then((response) => {
if (response.data.result) {
this.$message({
type: ‘success‘,
message: ‘删除成功!‘
});
this.initData();
}
})

}).catch(() => {
this.$message({
type: ‘info‘,
message: ‘已取消删除‘
});
});
},
onSubmit() {
this.initData();
},
handleSelectionChange(val) {
console.log(val);
this.row = val;
},
handleSizeChange(val) {
this.size = val;
this.initData();
},
handleCurrentChange(val) {
this.page = val;
this.initData();
},
initData() {
this.axios.get(‘http://localhost:8800/api/product/list‘, {
params: {
page: this.page,
size: this.size,
name: this.formInline.name,
start: this.formInline.start,
end: this.formInline.end
}
}).then((res) => {
console.log(res);
this.tableData = res.data.result.content;
this.total = res.data.result.totalElements;
});
}
}
}
</script>

<style>
.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>

java微服务框架之Product

标签:微服务   type   var   model   fir   layout   tar   hid   编辑   

原文地址:https://www.cnblogs.com/whyuan/p/13276822.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!