<template>
|
<section>
|
<!--工具条-->
|
<toolbar :buttonList="buttonList" @callFunction="callFunction"></toolbar>
|
|
<!--列表-->
|
<el-table
|
:data="WMProductClass"
|
highlight-current-row
|
v-loading="listLoading"
|
@selection-change="selsChange"
|
@current-change="selectCurrentRow"
|
@select="selsChangeOne"
|
row-key="Id"
|
lazy
|
:load="load"
|
:tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
|
style="width: 100%"
|
ref="multipleTable"
|
>
|
<el-table-column type="selection" width="50"></el-table-column>
|
<el-table-column type="index" width="200"></el-table-column>
|
<el-table-column label="分类名称">
|
<template slot-scope="scope">{{ scope.row.ClassName }}</template>
|
</el-table-column>
|
<el-table-column label="分类编号">
|
<template slot-scope="scope">{{ scope.row.ClassCode }}</template>
|
</el-table-column>
|
<el-table-column prop="Sort" label="排序" width="400"></el-table-column>
|
<el-table-column
|
prop="LevelId"
|
label="分类级别(数字代表相应的级别)"
|
width="400"
|
></el-table-column>
|
<!-- <el-table-column label="操作">
|
<template scope="scope">
|
<el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
|
<el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
|
</template>
|
</el-table-column> -->
|
</el-table>
|
|
<!--工具条-->
|
<el-col :span="24" class="toolbar">
|
<el-pagination
|
layout="prev, pager, next"
|
@current-change="handleCurrentChange"
|
:page-size="20"
|
:total="total"
|
style="float: right"
|
></el-pagination>
|
</el-col>
|
|
<!--编辑界面-->
|
<el-dialog
|
title="编辑"
|
:visible.sync="editFormVisible"
|
v-model="editFormVisible"
|
:close-on-click-modal="false"
|
>
|
<el-form
|
:model="editForm"
|
label-width="80px"
|
:rules="editFormRules"
|
ref="editForm"
|
>
|
<el-form-item prop="ParentIdArr" label="父级分类" width sortable>
|
<el-cascader
|
placeholder="请选择分类,支持搜索功能"
|
style="width: 400px"
|
v-model="editForm.ParentIdArr"
|
:options="options"
|
filterable
|
change-on-select
|
></el-cascader>
|
</el-form-item>
|
<el-form-item label="分类名称" prop="ClassName">
|
<el-input
|
v-model="editForm.ClassName"
|
placeholder="请输入分类名称"
|
></el-input>
|
</el-form-item>
|
<el-form-item label="排序" prop="Sort">
|
<el-input
|
type="number"
|
v-model="editForm.Sort"
|
placeholder="请输入排序"
|
></el-input>
|
</el-form-item>
|
</el-form>
|
<div slot="footer" class="dialog-footer">
|
<el-button @click.native="editFormVisible = false">取消</el-button>
|
<el-button
|
type="primary"
|
@click.native="editSubmit"
|
:loading="editLoading"
|
>提交</el-button
|
>
|
</div>
|
</el-dialog>
|
|
<!--新增界面-->
|
<el-dialog
|
title="新增"
|
:visible.sync="addFormVisible"
|
v-model="addFormVisible"
|
:close-on-click-modal="false"
|
>
|
<el-form
|
:model="addForm"
|
label-width="80px"
|
:rules="addFormRules"
|
ref="addForm"
|
>
|
<el-form-item prop="ParentIdArr" label="父级分类" width sortable>
|
<el-cascader
|
placeholder="请选择分类,支持搜索功能"
|
style="width: 400px"
|
v-model="addForm.ParentIdArr"
|
:options="options"
|
filterable
|
change-on-select
|
></el-cascader>
|
</el-form-item>
|
<el-form-item label="分类名称" prop="ClassName">
|
<el-input
|
v-model="addForm.ClassName"
|
placeholder="请输入分类名称"
|
></el-input>
|
</el-form-item>
|
<el-form-item label="排序" prop="Sort">
|
<el-input v-model="addForm.Sort" placeholder="请输入排序"></el-input>
|
</el-form-item>
|
</el-form>
|
<div slot="footer" class="dialog-footer">
|
<el-button @click.native="addFormVisible = false">取消</el-button>
|
<el-button
|
type="primary"
|
@click.native="addSubmit"
|
:loading="addLoading"
|
>提交</el-button
|
>
|
</div>
|
</el-dialog>
|
|
<!--导入界面-->
|
<!-- <el-dialog
|
title="导入"
|
:visible.sync="importFormVisible"
|
v-model="importFormVisible"
|
:close-on-click-modal="false"
|
>
|
<el-upload
|
class="upload-demo"
|
ref="upload"
|
action="/api/WMProductClass/ImportProductClass"
|
:on-preview="handlePreview"
|
:on-remove="handleRemove"
|
:on-change="handleChange"
|
:file-list="fileList"
|
:auto-upload="false"
|
>
|
<el-button slot="trigger" size="small" type="primary">选取商品分类表格</el-button>
|
<el-button
|
style="margin-left: 10px;"
|
size="small"
|
type="success"
|
@click="submitUpload"
|
>批量导入表格</el-button>
|
</el-upload>
|
</el-dialog> -->
|
|
<el-dialog
|
title="导入"
|
:visible.sync="importFormVisible"
|
v-model="importFormVisible"
|
:close-on-click-modal="false"
|
>
|
<form id="upFileBox" style="display: inline-block">
|
<input
|
class="upload-demo"
|
id="inputId"
|
type="file"
|
ref="files"
|
style="width: 268px"
|
/>
|
</form>
|
|
<el-button
|
class="el-icon-upload"
|
type="primary"
|
@click="submitForm($event)"
|
v-loading.fullscreen.lock="uploading"
|
element-loading-text="拼命导入中....."
|
element-loading-spinner="el-icon-loading"
|
element-loading-background="rgba(0, 0, 0, 0.8)"
|
>导入表格</el-button
|
>
|
</el-dialog>
|
</section>
|
</template>
|
|
<script>
|
import util from "../../../../util/date";
|
import {
|
getWMProductClassListPage,
|
getWMProductClassTreeTable,
|
// removeWMProductClass,
|
editWMProductClass,
|
addWMProductClass,
|
getWMProductClassTree,
|
ExportWMProductClass,
|
uploadProductClass,
|
} from "../../../api/api";
|
import { getButtonList } from "../../../promissionRouter";
|
import Toolbar from "../../../components/Toolbar";
|
|
export default {
|
components: { Toolbar },
|
data() {
|
return {
|
buttonList: [],
|
currentRow: null,
|
options: [],
|
filters: {
|
ClassName: "",
|
},
|
WMProductClass: [],
|
total: 0,
|
page: 1,
|
listLoading: false,
|
sels: [], //列表选中列
|
//编辑
|
editFormVisible: false, //编辑界面是否显示
|
editLoading: false,
|
//验证是否必填
|
editFormRules: {
|
ParentIdArr: [
|
{ required: true, message: "请选择分类下拉", trigger: "blur" },
|
],
|
ClassName: [
|
{ required: true, message: "请输入分类名称", trigger: "blur" },
|
],
|
},
|
//编辑界面数据
|
editForm: {},
|
//新增
|
addDialogFormVisible: false,
|
addFormVisible: false, //新增界面是否显示
|
addLoading: false,
|
//验证是否必填
|
addFormRules: {
|
ParentIdArr: [
|
{ required: true, message: "请选择分类下拉", trigger: "blur" },
|
],
|
ClassName: [
|
{ required: true, message: "请输入分类名称", trigger: "blur" },
|
],
|
},
|
//新增界面数据
|
addForm: {},
|
//导入
|
importFormVisible: false, //导入界面是否显示
|
uploading: false, //导入加载显示
|
fileList: [],
|
};
|
},
|
methods: {
|
//选中行时勾选框
|
selsChangeOne(selection, row) {
|
this.currentRow = row;
|
this.$refs.multipleTable.toggleRowSelection(row); //选中当前选择
|
this.selectCurrentRow(row);
|
},
|
selectCurrentRow(val) {
|
this.currentRow = val;
|
this.$refs.multipleTable.toggleRowSelection(val); //选中当前选择
|
},
|
callFunction(item) {
|
this.filters = {
|
ClassName: item.search,
|
};
|
this[item.Func].apply(this, item);
|
},
|
handleCurrentChange(val) {
|
this.page = val;
|
this.getWMProductClass();
|
},
|
load(tree, treeNode, resolve) {
|
let para = {
|
page: this.page,
|
parent: tree.Id,
|
key: this.filters.ClassName,
|
};
|
getWMProductClassTreeTable(para).then((res) => {
|
resolve(res.data.response);
|
});
|
},
|
//获取用户列表
|
getWMProductClass() {
|
let para = {
|
page: this.page,
|
key: this.filters.ClassName,
|
};
|
this.listLoading = true;
|
|
getWMProductClassTreeTable(para).then((res) => {
|
this.WMProductClass = res.data.response;
|
this.listLoading = false;
|
});
|
},
|
//删除
|
// handleDel: function (index, row) {
|
// if (!row) {
|
// row = this.currentRow;
|
// }
|
// if (!row) {
|
// this.$message({
|
// message: "请选择要删除的一行数据!",
|
// type: "error",
|
// });
|
|
// return;
|
// }
|
// this.$confirm("确认删除该记录吗?", "提示", {
|
// type: "warning",
|
// })
|
// .then(() => {
|
// this.listLoading = true;
|
// //NProgress.start();
|
// let para = { id: row.Id };
|
// removeWMProductClass(para).then((res) => {
|
// if (util.isEmt.format(res)) {
|
// this.listLoading = false;
|
// return;
|
// }
|
// this.listLoading = false;
|
// //NProgress.done();
|
// if (res.data.success) {
|
// this.$message({
|
// message: "删除成功",
|
// type: "success",
|
// });
|
// this.getWMProductClass();
|
// } else {
|
// this.$message({
|
// message: res.data.msg,
|
// type: "error",
|
// });
|
// }
|
// });
|
// })
|
// .catch(() => {});
|
// },
|
//显示编辑界面
|
handleEdit: function (index, row) {
|
if (!row) {
|
row = this.currentRow;
|
}
|
if (!row) {
|
this.$message({
|
message: "请选择要编辑的一行数据!",
|
type: "error",
|
});
|
|
return;
|
}
|
|
this.editFormVisible = true;
|
this.options = [];
|
// this.editForm = {};
|
|
let para = { parentId: row.Id };
|
getWMProductClassTree(para).then((res) => {
|
this.editForm = Object.assign({}, row);
|
this.options.push(res.data.response);
|
});
|
},
|
//显示新增界面
|
handleAdd() {
|
this.options = [];
|
this.addFormVisible = true;
|
this.addForm = {
|
ClassName: "",
|
Sort: 0,
|
ParentIdArr: [],
|
};
|
|
let para = { parentId: 0 };
|
getWMProductClassTree(para).then((res) => {
|
this.options.push(res.data.response);
|
});
|
},
|
//编辑
|
editSubmit: function () {
|
this.$refs.editForm.validate((valid) => {
|
if (valid) {
|
this.$confirm("确认提交吗?", "提示", {}).then(() => {
|
this.editLoading = true;
|
//NProgress.start();
|
let para = Object.assign({}, this.editForm);
|
para.ParentId = para.ParentIdArr.pop();
|
|
if (para.Id == para.ParentId) {
|
this.$message({
|
message: "警告,父节点不能是自己!",
|
type: "error",
|
});
|
|
this.editLoading = false;
|
return;
|
}
|
|
editWMProductClass(para).then((res) => {
|
if (util.isEmt.format(res)) {
|
this.editLoading = false;
|
return;
|
}
|
this.editLoading = false;
|
if (res.data.success) {
|
this.editLoading = false;
|
//NProgress.done();
|
this.$message({
|
message: res.data.msg,
|
type: "success",
|
});
|
this.$refs["editForm"].resetFields();
|
this.editFormVisible = false;
|
this.getWMProductClass();
|
} else {
|
this.$message({
|
message: res.data.msg,
|
type: "error",
|
});
|
}
|
});
|
});
|
}
|
});
|
},
|
//新增
|
addSubmit: function () {
|
this.$refs.addForm.validate((valid) => {
|
if (valid) {
|
this.$confirm("确认提交吗?", "提示", {}).then(() => {
|
this.addLoading = true;
|
//NProgress.start();
|
let para = Object.assign({}, this.addForm);
|
para.ParentId = para.ParentIdArr.pop();
|
|
addWMProductClass(para).then((res) => {
|
if (util.isEmt.format(res)) {
|
this.addLoading = false;
|
return;
|
}
|
this.addLoading = false;
|
if (res.data.success) {
|
this.addLoading = false;
|
//NProgress.done();
|
this.$message({
|
message: res.data.msg,
|
type: "success",
|
});
|
this.$refs["addForm"].resetFields();
|
this.addFormVisible = false;
|
this.getWMProductClass();
|
} else {
|
this.$message({
|
message: res.data.msg,
|
type: "error",
|
});
|
}
|
});
|
});
|
}
|
});
|
},
|
selsChange: function (sels) {
|
this.sels = sels;
|
},
|
//导出
|
handleExport() {
|
ExportWMProductClass()
|
.then((res) => {
|
const blob = new Blob([res.data], {
|
type: "application/x-xls",
|
});
|
const url = window.URL.createObjectURL(blob);
|
const aLink = document.createElement("a");
|
aLink.style.display = "none";
|
aLink.href = url;
|
aLink.setAttribute(
|
"download",
|
"商品分类" + new Date().getTime() + ".xlsx"
|
);
|
document.body.appendChild(aLink);
|
aLink.click();
|
document.body.removeChild(aLink); // 下载完成移除元素
|
window.URL.revokeObjectURL(url); // 释放掉blob对象
|
})
|
.catch((err) => {
|
console.log(err);
|
});
|
},
|
//显示导入界面
|
// handleImport() {
|
// this.importFormVisible = true;
|
// },
|
//导入表格
|
// submitUpload() {
|
// if (this.fileList.length == 0) {
|
// this.$message({
|
// message: "请先选取要上传的商品分类表格!",
|
// type: "error",
|
// });
|
// return;
|
// }
|
// this.$refs.upload.submit();
|
// },
|
// //移除表格
|
// handleRemove(file, fileList) {
|
// console.log(file, fileList);
|
// },
|
// //预览表格
|
// handlePreview(file) {
|
// console.log(file);
|
// },
|
// handleChange(file, fileList) {
|
// this.fileList = fileList;
|
// },
|
//显示导入界面
|
handleImport() {
|
//上传成功清除文件
|
document.getElementById("upFileBox") &&
|
document.getElementById("upFileBox").reset();
|
this.importFormVisible = true;
|
},
|
submitForm() {
|
let fileVal = this.$refs.files.value;
|
if (fileVal == "" || fileVal == null || !fileVal) {
|
this.$message.error("请选择您要上传的文件");
|
return false;
|
}
|
this.uploading = true;
|
let file = this.$refs.files.files[0];
|
let dataFile = new FormData();
|
dataFile.append("file_upload", file);
|
uploadProductClass(dataFile)
|
.then((res) => {
|
this.uploading = false;
|
const data = res.data;
|
if (data.success) {
|
fileVal = ""; // 清空表单
|
this.$message.success("上传成功");
|
this.importFormVisible = false;
|
this.uploading = false;
|
|
return false;
|
} else {
|
this.$message.error(data.msg);
|
this.importFormVisible = false;
|
this.uploading = false;
|
return false;
|
}
|
})
|
.catch((err) => {
|
this.$message.error("服务异常,请重试");
|
this.importFormVisible = false;
|
this.uploading = false;
|
return false;
|
});
|
},
|
},
|
mounted() {
|
this.getWMProductClass();
|
|
let routers = window.localStorage.router
|
? JSON.parse(window.localStorage.router)
|
: [];
|
this.buttonList = getButtonList(this.$route.path, routers);
|
},
|
};
|
</script>
|
|
<style scoped>
|
</style>
|