|
@@ -26,7 +26,7 @@
|
|
|
/>
|
|
|
</el-form-item>
|
|
|
<el-form-item>
|
|
|
- <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
|
|
+ <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
|
|
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
|
|
</el-form-item>
|
|
|
</el-form>
|
|
@@ -44,44 +44,27 @@
|
|
|
</el-col>
|
|
|
<el-col :span="1.5">
|
|
|
<el-button
|
|
|
- type="success"
|
|
|
+ type="info"
|
|
|
plain
|
|
|
- icon="el-icon-edit"
|
|
|
+ icon="el-icon-sort"
|
|
|
size="mini"
|
|
|
- :disabled="single"
|
|
|
- @click="handleUpdate"
|
|
|
- v-hasPermi="['manage:product:edit']"
|
|
|
- >修改</el-button>
|
|
|
- </el-col>
|
|
|
- <el-col :span="1.5">
|
|
|
- <el-button
|
|
|
- type="danger"
|
|
|
- plain
|
|
|
- icon="el-icon-delete"
|
|
|
- size="mini"
|
|
|
- :disabled="multiple"
|
|
|
- @click="handleDelete"
|
|
|
- v-hasPermi="['manage:product:remove']"
|
|
|
- >删除</el-button>
|
|
|
- </el-col>
|
|
|
- <el-col :span="1.5">
|
|
|
- <el-button
|
|
|
- type="warning"
|
|
|
- plain
|
|
|
- icon="el-icon-download"
|
|
|
- size="mini"
|
|
|
- @click="handleExport"
|
|
|
- v-hasPermi="['manage:product:export']"
|
|
|
- >导出</el-button>
|
|
|
+ @click="toggleExpandAll"
|
|
|
+ >展开/折叠</el-button>
|
|
|
</el-col>
|
|
|
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
|
|
</el-row>
|
|
|
|
|
|
- <el-table v-loading="loading" :data="productList" @selection-change="handleSelectionChange">
|
|
|
- <el-table-column type="selection" width="55" align="center" />
|
|
|
+ <el-table
|
|
|
+ v-if="refreshTable"
|
|
|
+ v-loading="loading"
|
|
|
+ :data="productList"
|
|
|
+ row-key="id"
|
|
|
+ :default-expand-all="isExpandAll"
|
|
|
+ :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
|
|
|
+ >
|
|
|
+ <el-table-column label="归属" align="center" prop="parentName" />
|
|
|
<el-table-column label="名称" align="center" prop="name" />
|
|
|
<el-table-column label="SNS编号" align="center" prop="snsId" />
|
|
|
- <el-table-column label="归属" align="center" prop="parentName" />
|
|
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
|
|
<template slot-scope="scope">
|
|
|
<el-button
|
|
@@ -91,6 +74,13 @@
|
|
|
@click="handleUpdate(scope.row)"
|
|
|
v-hasPermi="['manage:product:edit']"
|
|
|
>修改</el-button>
|
|
|
+ <el-button
|
|
|
+ size="mini"
|
|
|
+ type="text"
|
|
|
+ icon="el-icon-plus"
|
|
|
+ @click="handleAdd(scope.row)"
|
|
|
+ v-hasPermi="['manage:product:add']"
|
|
|
+ >新增</el-button>
|
|
|
<el-button
|
|
|
size="mini"
|
|
|
type="text"
|
|
@@ -101,24 +91,22 @@
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
</el-table>
|
|
|
-
|
|
|
- <pagination
|
|
|
- v-show="total>0"
|
|
|
- :total="total"
|
|
|
- :page.sync="queryParams.pageNum"
|
|
|
- :limit.sync="queryParams.pageSize"
|
|
|
- @pagination="getList"
|
|
|
- />
|
|
|
|
|
|
<!-- 添加或修改产品树信息对话框 -->
|
|
|
<el-dialog :title="title" :visible.sync="open" :close-on-click-modal="false" width="500px" append-to-body>
|
|
|
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
|
|
+ <el-form-item label="父ID" prop="parentId">
|
|
|
+ <treeselect v-model="form.parentId" :options="productOptions" :normalizer="normalizer" placeholder="请选择父ID" />
|
|
|
+ </el-form-item>
|
|
|
<el-form-item label="名称" prop="name">
|
|
|
<el-input v-model="form.name" placeholder="请输入名称" />
|
|
|
</el-form-item>
|
|
|
<el-form-item label="SNS编号" prop="snsId">
|
|
|
<el-input v-model="form.snsId" placeholder="请输入SNS编号" />
|
|
|
</el-form-item>
|
|
|
+ <el-form-item label="数据是否删除" prop="isDelete">
|
|
|
+ <el-input v-model="form.isDelete" placeholder="请输入数据是否删除" />
|
|
|
+ </el-form-item>
|
|
|
</el-form>
|
|
|
<div slot="footer" class="dialog-footer">
|
|
|
<el-button type="primary" @click="submitForm">确 定</el-button>
|
|
@@ -130,33 +118,34 @@
|
|
|
|
|
|
<script>
|
|
|
import { listProduct, getProduct, delProduct, addProduct, updateProduct } from "@/api/manage/product";
|
|
|
+import Treeselect from "@riophae/vue-treeselect";
|
|
|
+import "@riophae/vue-treeselect/dist/vue-treeselect.css";
|
|
|
|
|
|
export default {
|
|
|
name: "Product",
|
|
|
+ components: {
|
|
|
+ Treeselect
|
|
|
+ },
|
|
|
data() {
|
|
|
return {
|
|
|
// 遮罩层
|
|
|
loading: true,
|
|
|
- // 选中数组
|
|
|
- ids: [],
|
|
|
- // 非单个禁用
|
|
|
- single: true,
|
|
|
- // 非多个禁用
|
|
|
- multiple: true,
|
|
|
// 显示搜索条件
|
|
|
showSearch: true,
|
|
|
- // 总条数
|
|
|
- total: 0,
|
|
|
// 产品树信息表格数据
|
|
|
productList: [],
|
|
|
+ // 产品树信息树选项
|
|
|
+ productOptions: [],
|
|
|
// 弹出层标题
|
|
|
title: "",
|
|
|
// 是否显示弹出层
|
|
|
open: false,
|
|
|
+ // 是否展开,默认全部展开
|
|
|
+ isExpandAll: true,
|
|
|
+ // 重新渲染表格状态
|
|
|
+ refreshTable: true,
|
|
|
// 查询参数
|
|
|
queryParams: {
|
|
|
- pageNum: 1,
|
|
|
- pageSize: 10,
|
|
|
parentName: null,
|
|
|
name: null,
|
|
|
snsId: null,
|
|
@@ -165,6 +154,12 @@ export default {
|
|
|
form: {},
|
|
|
// 表单校验
|
|
|
rules: {
|
|
|
+ parentId: [
|
|
|
+ { required: true, message: "父ID不能为空", trigger: "blur" }
|
|
|
+ ],
|
|
|
+ isDelete: [
|
|
|
+ { required: true, message: "数据是否删除不能为空", trigger: "blur" }
|
|
|
+ ],
|
|
|
}
|
|
|
};
|
|
|
},
|
|
@@ -176,11 +171,30 @@ export default {
|
|
|
getList() {
|
|
|
this.loading = true;
|
|
|
listProduct(this.queryParams).then(response => {
|
|
|
- this.productList = response.rows;
|
|
|
- this.total = response.total;
|
|
|
+ this.productList = this.handleTree(response.data, "id", "parentId");
|
|
|
this.loading = false;
|
|
|
});
|
|
|
},
|
|
|
+ /** 转换产品树信息数据结构 */
|
|
|
+ normalizer(node) {
|
|
|
+ if (node.children && !node.children.length) {
|
|
|
+ delete node.children;
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ id: node.id,
|
|
|
+ label: node.name,
|
|
|
+ children: node.children
|
|
|
+ };
|
|
|
+ },
|
|
|
+ /** 查询产品树信息下拉树结构 */
|
|
|
+ getTreeselect() {
|
|
|
+ listProduct().then(response => {
|
|
|
+ this.productOptions = [];
|
|
|
+ const data = { id: 0, name: '顶级节点', children: [] };
|
|
|
+ data.children = this.handleTree(response.data, "id", "parentId");
|
|
|
+ this.productOptions.push(data);
|
|
|
+ });
|
|
|
+ },
|
|
|
// 取消按钮
|
|
|
cancel() {
|
|
|
this.open = false;
|
|
@@ -204,7 +218,6 @@ export default {
|
|
|
},
|
|
|
/** 搜索按钮操作 */
|
|
|
handleQuery() {
|
|
|
- this.queryParams.pageNum = 1;
|
|
|
this.getList();
|
|
|
},
|
|
|
/** 重置按钮操作 */
|
|
@@ -212,23 +225,34 @@ export default {
|
|
|
this.resetForm("queryForm");
|
|
|
this.handleQuery();
|
|
|
},
|
|
|
- // 多选框选中数据
|
|
|
- handleSelectionChange(selection) {
|
|
|
- this.ids = selection.map(item => item.id)
|
|
|
- this.single = selection.length!==1
|
|
|
- this.multiple = !selection.length
|
|
|
- },
|
|
|
/** 新增按钮操作 */
|
|
|
- handleAdd() {
|
|
|
+ handleAdd(row) {
|
|
|
this.reset();
|
|
|
+ this.getTreeselect();
|
|
|
+ if (row != null && row.id) {
|
|
|
+ this.form.parentId = row.id;
|
|
|
+ } else {
|
|
|
+ this.form.parentId = 0;
|
|
|
+ }
|
|
|
this.open = true;
|
|
|
this.title = "添加产品树信息";
|
|
|
},
|
|
|
+ /** 展开/折叠操作 */
|
|
|
+ toggleExpandAll() {
|
|
|
+ this.refreshTable = false;
|
|
|
+ this.isExpandAll = !this.isExpandAll;
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.refreshTable = true;
|
|
|
+ });
|
|
|
+ },
|
|
|
/** 修改按钮操作 */
|
|
|
handleUpdate(row) {
|
|
|
this.reset();
|
|
|
- const id = row.id || this.ids
|
|
|
- getProduct(id).then(response => {
|
|
|
+ this.getTreeselect();
|
|
|
+ if (row != null) {
|
|
|
+ this.form.parentId = row.id;
|
|
|
+ }
|
|
|
+ getProduct(row.id).then(response => {
|
|
|
this.form = response.data;
|
|
|
this.open = true;
|
|
|
this.title = "修改产品树信息";
|
|
@@ -256,19 +280,12 @@ export default {
|
|
|
},
|
|
|
/** 删除按钮操作 */
|
|
|
handleDelete(row) {
|
|
|
- const ids = row.id || this.ids;
|
|
|
- this.$modal.confirm('是否确认删除产品树信息编号为"' + ids + '"的数据项?').then(function() {
|
|
|
- return delProduct(ids);
|
|
|
+ this.$modal.confirm('是否确认删除产品树信息编号为"' + row.id + '"的数据项?').then(function() {
|
|
|
+ return delProduct(row.id);
|
|
|
}).then(() => {
|
|
|
this.getList();
|
|
|
this.$modal.msgSuccess("删除成功");
|
|
|
}).catch(() => {});
|
|
|
- },
|
|
|
- /** 导出按钮操作 */
|
|
|
- handleExport() {
|
|
|
- this.download('manage/product/export', {
|
|
|
- ...this.queryParams
|
|
|
- }, `product_${new Date().getTime()}.xlsx`)
|
|
|
}
|
|
|
}
|
|
|
};
|