<template>
<div id="app" class="bg">
<h1>規(guī)格管理</h1>
<el-divider class="margin"></el-divider>
<el-input
size="small"
class="input"
placeholder="請輸入分類名稱"
v-model="stan_name"
maxlength="30"
clearable
>
</el-input>
<el-button
type="primary"
icon="el-icon-search"
size="small"
@click="query()"
>查詢
</el-button>
<div>
<el-button
type="primary"
icon="el-icon-plus"
class="margin"
size="small"
@click="dialogTableVisible = true"
>新增
</el-button>
</div>
<div>
<el-dialog
title="商品分類"
:visible.sync="dialogTableVisible"
width="60%"
append-to-body
>
<el-row>
<el-col :span="14">
<div class="grid-content bg-purple">
<el-form-item label="上級分類:" style="width: 300px">
<template>
<el-select
v-model="val"
style="width: 300px"
clearable
placeholder="上級分類名稱"
>
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value"
>
</el-option>
</el-select>
</template>
</el-form-item>
<div>
<el-form-item label="分類名稱:" style="width: 200px">
<el-input
placeholder="分類名稱"
style="width: 300px"
v-model="comc_name"
clearable
class="width"
></el-input>
</el-form-item>
</div>
<div class="center">
<el-form-item label="分類描述:" style="width: 200px">
<textarea
name="maosu"
id=""
cols="40"
rows="15"
v-model="comc_desc"
placeholder="分類描述"
></textarea>
</el-form-item>
</div>
</div>
</el-col>
<el-col :span="10">
<el-form-item label="商品圖片" style="width: 200px">
<el-upload
action="https://jsonplaceholder.typicode.com/posts/"
list-type="picture-card"
:on-preview="handlePictureCardPreview"
:on-remove="handleRemove"
>
<i class="el-icon-plus"></i>
</el-upload>
<el-dialog :visible.sync="dialogVisible">
<img width="100%" :src="dialogImageUrl" alt="" />
</el-dialog>
</el-form-item>
</el-col>
</el-row>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogTableVisible = false">取 消</el-button>
<el-button type="primary" @click="determine">確 定 </el-button>
</div>
</el-dialog>
</div>
<template>
<el-table
ref="multipleTable"
:data="tableData"
tooltip-effect="dark"
style="width: 100%; "
:header-cell-style="tableHeaderColor"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="55"></el-table-column>
<el-table-column prop="comc_pno" label="商品分類名稱" width="">
</el-table-column>
<el-table-column prop="comc_name" label="商品名稱" width="">
</el-table-column>
<el-table-column prop="comc_desc" label="商品分類描述" width="">
</el-table-column>
<el-table-column prop="comc_img" label="商品分類圖片" width="150">
<template slot-scope="scope">
<el-image
style="width: 100px;height: 100px"
:src="scope.row.comc_img"
></el-image>
</template>
</el-table-column>
<el-table-column prop="comc_lower" label="下架商品數(shù)量" width="">
</el-table-column>
<el-table-column prop="comc_upper" label="上架商品數(shù)量" width="">
</el-table-column>
<el-table-column fixed="right" label="操作" width="150">
<template slot-scope="scope">
<el-button
@click="Modify(scope.row)"
size="mini"
type="primary"
icon="el-icon-edit"
></el-button>
<el-button
@click="Delete(scope.row)"
size="mini"
type="danger"
icon="el-icon-delete"
></el-button>
</template>
</el-table-column>
</el-table>
</template>
<div class="block">
<el-pagination
v-show="show"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage"
:page-size="pageSize"
background
:page-sizes="[3, 6, 10, 15, 20]"
layout="total, sizes, prev, pager, next, jumper"
:total="count"
>
</el-pagination>
</div>
</div>
</template>
<script>
export default {
name: "specifications",
data() {
return {
show: true,
// 總條數(shù)
count: 1,
// 當前頁
currentPage: 1,
// 顯示條數(shù)
pageSize: 5,
//查詢名稱
stan_name: "",
//添加分類名稱
text: "",
//添加分類描述
maosu: "",
// 圖片上傳
imageUrl: "",
// 彈出框,
value: [],
options: [
{
value: 1,
label: "黃金糕"
},
{
value: 2,
label: "雙皮奶"
},
{
value: 3,
label: "蚵仔煎"
},
{
value: 4,
label: "龍須面"
},
{
value: 5,
label: "北京烤鴨"
}
],
val: "",
dialogTableVisible: false,
// 批量刪除
disabled: true,
// 表格假數(shù)據
tableData: [
{
comc_no: 2, // 商品分類編號
comc_name: "香蕉", //商品分類名稱
comc_pno: "1", //商品分類上級編號
comc_desc: "122324@qq.com", //商品分類描述
comc_img: "../../assets/logo.png", //商品分類圖片
comc_lower: 10, //下架商品數(shù)量
comc_upper: 20 //上架商品數(shù)量
}
],
multipleSelection: []
};
},
methods: {
//提交信息
submit() {
this.dialogTableVisible = false;
console.log(this.val);
},
// 圖片上傳
handleAvatarSuccess(res, file) {
console.log("mfoiejfoelfm");
this.imageUrl = URL.createObjectURL(file.raw);
},
beforeAvatarUpload(file) {
const isJPG = file.type === "image/jpeg";
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isJPG) {
this.message.error("上傳頭像圖片大小不能超過 2MB!");
}
return isJPG && isLt2M;
}, //彈出框數(shù)據
handleChange(value) {
console.log(value);
},
// 分頁獲取數(shù)據
shuju() {
this.message("沒有數(shù)據");
}
}
},
// 修改table header的背景色
tableHeaderColor({ rowIndex }) {
if (rowIndex === 0) {
return "background-color: #90ADE5;color: #fff;font-weight:500;height:60px";
}
},
// 批量刪除
batchBelete() {
for (var i = 0; this.multipleSelection.length; i++) {
console.log(12334566);
console.log(this.multipleSelection[i]);
this.tableData.splice(this.multipleSelection[i], 1);
this.$message("刪除成功");
this.disabled = true;
}
},
// 表格復選框
handleSelectionChange(val) {
this.disabled = false;
this.multipleSelection = val;
console.log(val);
},
// 修改
Modify(val) {
console.log(val);
this.dialogTableVisible = true;
// this.options=val
this.val = val.comc_pno;
this.text = val.comc_name;
this.maosu = val.comc_desc;
this.imageUrl = val.comc_img;
console.log(this.val);
},
// 刪除
Delete(val) {
this.tableData.splice(val, 1);
if (this.tableData.length == 0) {
this.count = 0;
}
}
},
mounted: function() {
// 請求數(shù)據
this.$axios
.post(
"/api/sale/queryComc.do",
{
page: this.currentPage,
pageSize: this.pageSize
},
{
// 設置請求頭
headers: {
"Content-Type": "application/json"
}
}
)
.then(response => {
console.log(response.data.data.list);
this.tableData = response.data.data;
this.count = response.data.data.count;
})
.catch(err => {
console.log(err);
});
}
};
</script>
<style scoped>
.block {
margin-top: 20px;
margin-bottom: 20px;
text-align: center;
}
/圖片/
.el-upload {
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
}
.avatar-uploader .el-upload {
border: 1px dashed #d92651;
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;
}
/**/
.center {
height: 200px;
width: 300px;
}
.center input {
margin-top: 20px;
}
.width {
width: 150px;
margin-top: 20px;
margin-bottom: 20px;
}
.bg {
background-color: ghostwhite;
margin: 0;
padding: 10px;
height: 1200px;
}
.input {
width: 200px;
margin-right: 50px;
}
.margin {
margin-top: 20px;
margin-bottom: 20px;
}
</style>