dl-sale-platform/ruoyi-ui/src/views/system/goods/index.vue

434 lines
14 KiB
Vue

<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="设计名称" prop="name">
<el-input
v-model="queryParams.name"
placeholder="请输入设计名称"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="设计类型" prop="designName">
<el-input
v-model="queryParams.designName"
placeholder="请输入设计类型"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item>
<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>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['system:goods:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['system:goods: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="['system:goods: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="['system:goods:export']"
>导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="goodsList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="商品名称" align="center" prop="name" />
<el-table-column label="商品封面图片" align="center" prop="cover" width="100">
<template slot-scope="scope">
<image-preview :src="scope.row.cover" :width="50" :height="50"/>
</template>
</el-table-column>
<el-table-column label="技术类型" align="center" prop="technicalName" >
<!-- <template slot-scope="scope">-->
<!-- {{ technicalTypeMapping[scope.row.technicalTypeId] || scope.row.technicalTypeId }}-->
<!-- </template>-->
</el-table-column>
<el-table-column label="设计类型" align="center" prop="designName" >
<!-- <template slot-scope="scope">-->
<!-- {{ designTypeMapping[scope.row.designTypeId] || scope.row.designTypeId }}-->
<!-- </template>-->
</el-table-column>
<el-table-column label="商品价格" align="center" prop="price" />
<el-table-column label="商品简介" align="center" prop="introduction" >
<template slot-scope="scope">
<div class="introduction" :title="scope.row.introduction">
{{ scope.row.introduction }}
</div>
</template>
</el-table-column>
<el-table-column label="商品详情" align="center" prop="details" >
<template slot-scope="scope">
<div class="introduction" :title="scope.row.details">
{{ scope.row.details }}
</div>
</template>
</el-table-column>
<el-table-column label="商品视频" align="center" prop="video" >
<template slot-scope="scope">
<div class="introduction" :title="scope.row.video">
{{ scope.row.video }}
</div>
</template>
</el-table-column>
<el-table-column label="帮助" align="center" prop="help" >
<template slot-scope="scope">
<div class="introduction" :title="scope.row.help">
{{ scope.row.help }}
</div>
</template>
</el-table-column>
<el-table-column label="商品资源" align="center" prop="resource" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['system:goods:edit']"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['system:goods:remove']"
>删除</el-button>
</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" width="800px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="商品名称" prop="name">
<el-input v-model="form.name" placeholder="请输入商品名称" />
</el-form-item>
<el-form-item label="商品封面图片" prop="cover">
<image-upload v-model="form.cover"/>
</el-form-item>
<el-form-item label="商品价格" prop="price">
<el-input v-model="form.price" placeholder="请输入商品价格" />
</el-form-item>
<el-form-item label="技术类型" prop="technicalTypeId">
<el-select v-model="form.technicalTypeId" placeholder="请选择技术类型" clearable :style="{width: '100%'}">
<el-option v-for="(item, index) in technicalList" :key="item.number" :label="item.name"
:value="item.number" :disabled="item.disabled"></el-option>
</el-select>
</el-form-item>
<el-form-item label="设计类型" prop="designTypeId">
<el-select v-model="form.designTypeId" placeholder="请选择设计类型" clearable :style="{width: '100%'}">
<el-option v-for="(item, index) in designList" :key="item.type" :label="item.name"
:value="item.type" :disabled="item.disabled"></el-option>
</el-select>
</el-form-item>
<el-form-item label="商品简介" prop="introduction">
<el-input v-model="form.introduction" type="textarea" placeholder="请输入内容"/>
</el-form-item>
<el-form-item label="商品详情" prop="details">
<editor v-model="form.details" :min-height="192"/>
</el-form-item>
<el-form-item label="商品视频" prop="video">
<editor v-model="form.video" :min-height="192"/>
</el-form-item>
<el-form-item label="帮助" prop="help">
<editor v-model="form.help" :min-height="192"/>
</el-form-item>
<el-form-item label="商品资源" prop="resource">
<file-upload v-model="form.resource"/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import {listGoods, getGoods, delGoods, addGoods, updateGoods, listAllGoods} from "@/api/system/goods";
import {listDesignType} from "@/api/system/designType";
import {listType} from "@/api/system/type";
export default {
name: "Goods",
data() {
return {
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 商品表格数据
goodsList: [],
getAlllist: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 设计类型表格数据
designList: [],
// 技术类型表格数据
technicalList: [],
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
name: null,
cover: null,
technicalTypeId: null,
designTypeId: null,
price: null,
introduction: null,
details: null,
video: null,
help: null,
resource: null,
technicalName: null,
designName: null,
createTime: null,
},
queryParams2: {
pageNum: 1,
pageSize: 10,
name: null,
cover: null,
technicalTypeId: null,
designTypeId: null,
price: null,
introduction: null,
details: null,
video: null,
help: null,
resource: null,
technicalName: null,
designName: null,
createTime: null,
},
// 表单参数
form: {},
// 表单校验
rules: {
name: [{required: true, message: '请输入项目名称', trigger: 'blur'}],
cover: [{required: true, message: '请上传封面图片', trigger: 'blur'}],
price: [{required: true, message: '请输入价格', trigger: 'blur'}],
technicalTypeId: [{required: true, message: '请选择技术类型', trigger: 'blur'}],
designTypeId: [{required: true, message: '请选择设计类型', trigger: 'blur'}],
introduction: [{required: true, message: '请输入项目简介', trigger: 'blur'}],
details: [{required: true, message: '请输入项目详情', trigger: 'blur'}],
resource: [{required: true, message: '请上传项目资源', trigger: 'blur'}],
},
technicalTypeMapping: {},
designTypeMapping: {},
};
},
created() {
this.getList();
this.getDesignList();
this.getTechnicalList();
this.gitAllGoods();
},
methods: {
/** 查询商品列表 */
getList() {
this.loading = true;
listAllGoods(this.queryParams).then(response => {
this.goodsList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
id: null,
name: null,
cover: null,
technicalTypeId: null,
designTypeId: null,
price: null,
introduction: null,
details: null,
video: null,
help: null,
resource: null,
createId: null,
createTime: null
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length!==1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加商品";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const id = row.id || this.ids
getGoods(id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改商品";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.id != null) {
updateGoods(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addGoods(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const ids = row.id || this.ids;
this.$modal.confirm('是否确认删除商品编号为"' + ids + '"的数据项?').then(function() {
return delGoods(ids);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
},
/** 导出按钮操作 */
handleExport() {
this.download('system/goods/export', {
...this.queryParams
}, `goods_${new Date().getTime()}.xlsx`)
},
/** 查询设计类型列表 */
getDesignList() {
listDesignType(this.queryParams).then(response => {
this.designList = response.rows;
this.designTypeMapping = response.rows.reduce((acc, item) => {
acc[item.type] = item.name; // 这里假设 type 是唯一的
return acc;
}, {});
});
},
gitAllGoods(){
listAllGoods(this.queryParams).then(response => {
this.getAlllist = response.rows;
console.log('所有商品列表',this.getAlllist)
})
},
/** 查询技术类型列表 */
getTechnicalList() {
listType(this.queryParams).then(response => {
this.technicalList = response.rows;
this.technicalTypeMapping = response.rows.reduce((acc, item) => {
acc[item.number] = item.name;
return acc;
}, {});
});
},
}
};
</script>
<style scoped>
.introduction {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
text-overflow: ellipsis;
word-break: break-all;
}
</style>