Commit bd944c4a8b6374eb84cac580f412a89ad02b5ae0
1 parent
0b087c84
商品规格和spu前端代码生成
Showing
5 changed files
with
640 additions
and
2 deletions
sql/mall.sql
| @@ -129,7 +129,7 @@ CREATE TABLE `market_activity` | @@ -129,7 +129,7 @@ CREATE TABLE `market_activity` | ||
| 129 | 129 | ||
| 130 | -- 规格菜单 SQL | 130 | -- 规格菜单 SQL |
| 131 | INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) | 131 | INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) |
| 132 | -VALUES ('规格管理', '', 2, 3, 2001, 'property', '', 'product/property/index', 0); | 132 | +VALUES ('规格管理', '', 2, 3, 2001, 'property', '', 'mall/product/property/index', 0); |
| 133 | 133 | ||
| 134 | -- 按钮父菜单ID | 134 | -- 按钮父菜单ID |
| 135 | SELECT @parentId := LAST_INSERT_ID(); | 135 | SELECT @parentId := LAST_INSERT_ID(); |
| @@ -149,7 +149,7 @@ VALUES ('规格导出', 'product:property:export', 3, 5, @parentId, '', '', '', | @@ -149,7 +149,7 @@ VALUES ('规格导出', 'product:property:export', 3, 5, @parentId, '', '', '', | ||
| 149 | 149 | ||
| 150 | -- 商品菜单 SQL | 150 | -- 商品菜单 SQL |
| 151 | INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) | 151 | INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) |
| 152 | -VALUES ('商品管理', '', 2, 2, 2001, 'spu', '', 'product/spu/index', 0); | 152 | +VALUES ('商品管理', '', 2, 2, 2001, 'spu', '', 'mall/product/spu/index', 0); |
| 153 | 153 | ||
| 154 | -- 按钮父菜单ID | 154 | -- 按钮父菜单ID |
| 155 | SELECT @parentId := LAST_INSERT_ID(); | 155 | SELECT @parentId := LAST_INSERT_ID(); |
yudao-ui-admin/src/api/mall/product/property.js
0 → 100644
| 1 | +import request from '@/utils/request' | ||
| 2 | + | ||
| 3 | +// 创建规格名称 | ||
| 4 | +export function createProperty(data) { | ||
| 5 | + return request({ | ||
| 6 | + url: '/product/property/create', | ||
| 7 | + method: 'post', | ||
| 8 | + data: data | ||
| 9 | + }) | ||
| 10 | +} | ||
| 11 | + | ||
| 12 | +// 更新规格名称 | ||
| 13 | +export function updateProperty(data) { | ||
| 14 | + return request({ | ||
| 15 | + url: '/product/property/update', | ||
| 16 | + method: 'put', | ||
| 17 | + data: data | ||
| 18 | + }) | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +// 删除规格名称 | ||
| 22 | +export function deleteProperty(id) { | ||
| 23 | + return request({ | ||
| 24 | + url: '/product/property/delete?id=' + id, | ||
| 25 | + method: 'delete' | ||
| 26 | + }) | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +// 获得规格名称 | ||
| 30 | +export function getProperty(id) { | ||
| 31 | + return request({ | ||
| 32 | + url: '/product/property/get?id=' + id, | ||
| 33 | + method: 'get' | ||
| 34 | + }) | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +// 获得规格名称分页 | ||
| 38 | +export function getPropertyPage(query) { | ||
| 39 | + return request({ | ||
| 40 | + url: '/product/property/page', | ||
| 41 | + method: 'get', | ||
| 42 | + params: query | ||
| 43 | + }) | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +// 导出规格名称 Excel | ||
| 47 | +export function exportPropertyExcel(query) { | ||
| 48 | + return request({ | ||
| 49 | + url: '/product/property/export-excel', | ||
| 50 | + method: 'get', | ||
| 51 | + params: query, | ||
| 52 | + responseType: 'blob' | ||
| 53 | + }) | ||
| 54 | +} |
yudao-ui-admin/src/api/mall/product/spu.js
0 → 100644
| 1 | +import request from '@/utils/request' | ||
| 2 | + | ||
| 3 | +// 创建商品spu | ||
| 4 | +export function createSpu(data) { | ||
| 5 | + return request({ | ||
| 6 | + url: '/product/spu/create', | ||
| 7 | + method: 'post', | ||
| 8 | + data: data | ||
| 9 | + }) | ||
| 10 | +} | ||
| 11 | + | ||
| 12 | +// 更新商品spu | ||
| 13 | +export function updateSpu(data) { | ||
| 14 | + return request({ | ||
| 15 | + url: '/product/spu/update', | ||
| 16 | + method: 'put', | ||
| 17 | + data: data | ||
| 18 | + }) | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +// 删除商品spu | ||
| 22 | +export function deleteSpu(id) { | ||
| 23 | + return request({ | ||
| 24 | + url: '/product/spu/delete?id=' + id, | ||
| 25 | + method: 'delete' | ||
| 26 | + }) | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +// 获得商品spu | ||
| 30 | +export function getSpu(id) { | ||
| 31 | + return request({ | ||
| 32 | + url: '/product/spu/get?id=' + id, | ||
| 33 | + method: 'get' | ||
| 34 | + }) | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +// 获得商品spu分页 | ||
| 38 | +export function getSpuPage(query) { | ||
| 39 | + return request({ | ||
| 40 | + url: '/product/spu/page', | ||
| 41 | + method: 'get', | ||
| 42 | + params: query | ||
| 43 | + }) | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +// 导出商品spu Excel | ||
| 47 | +export function exportSpuExcel(query) { | ||
| 48 | + return request({ | ||
| 49 | + url: '/product/spu/export-excel', | ||
| 50 | + method: 'get', | ||
| 51 | + params: query, | ||
| 52 | + responseType: 'blob' | ||
| 53 | + }) | ||
| 54 | +} |
yudao-ui-admin/src/views/mall/product/property/index.vue
0 → 100644
| 1 | +<template> | ||
| 2 | + <div class="app-container"> | ||
| 3 | + | ||
| 4 | + <!-- 搜索工作栏 --> | ||
| 5 | + <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"> | ||
| 6 | + <el-form-item label="规格名称" prop="name"> | ||
| 7 | + <el-input v-model="queryParams.name" placeholder="请输入规格名称" clearable @keyup.enter.native="handleQuery"/> | ||
| 8 | + </el-form-item> | ||
| 9 | + <el-form-item label="状态: 0 开启 ,1 禁用" prop="status"> | ||
| 10 | + <el-select v-model="queryParams.status" placeholder="请选择状态: 0 开启 ,1 禁用" clearable size="small"> | ||
| 11 | + <el-option label="请选择字典生成" value="" /> | ||
| 12 | + </el-select> | ||
| 13 | + </el-form-item> | ||
| 14 | + <el-form-item label="创建时间"> | ||
| 15 | + <el-date-picker v-model="dateRangeCreateTime" style="width: 240px" value-format="yyyy-MM-dd" | ||
| 16 | + type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" /> | ||
| 17 | + </el-form-item> | ||
| 18 | + <el-form-item> | ||
| 19 | + <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button> | ||
| 20 | + <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button> | ||
| 21 | + </el-form-item> | ||
| 22 | + </el-form> | ||
| 23 | + | ||
| 24 | + <!-- 操作工具栏 --> | ||
| 25 | + <el-row :gutter="10" class="mb8"> | ||
| 26 | + <el-col :span="1.5"> | ||
| 27 | + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" | ||
| 28 | + v-hasPermi="['product:property:create']">新增</el-button> | ||
| 29 | + </el-col> | ||
| 30 | + <el-col :span="1.5"> | ||
| 31 | + <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading" | ||
| 32 | + v-hasPermi="['product:property:export']">导出</el-button> | ||
| 33 | + </el-col> | ||
| 34 | + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> | ||
| 35 | + </el-row> | ||
| 36 | + | ||
| 37 | + <!-- 列表 --> | ||
| 38 | + <el-table v-loading="loading" :data="list"> | ||
| 39 | + <el-table-column label="主键" align="center" prop="id" /> | ||
| 40 | + <el-table-column label="规格名称" align="center" prop="name" /> | ||
| 41 | + <el-table-column label="状态: 0 开启 ,1 禁用" align="center" prop="status" /> | ||
| 42 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | ||
| 43 | + <template slot-scope="scope"> | ||
| 44 | + <span>{{ parseTime(scope.row.createTime) }}</span> | ||
| 45 | + </template> | ||
| 46 | + </el-table-column> | ||
| 47 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | ||
| 48 | + <template slot-scope="scope"> | ||
| 49 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" | ||
| 50 | + v-hasPermi="['product:property:update']">修改</el-button> | ||
| 51 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | ||
| 52 | + v-hasPermi="['product:property:delete']">删除</el-button> | ||
| 53 | + </template> | ||
| 54 | + </el-table-column> | ||
| 55 | + </el-table> | ||
| 56 | + <!-- 分页组件 --> | ||
| 57 | + <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" | ||
| 58 | + @pagination="getList"/> | ||
| 59 | + | ||
| 60 | + <!-- 对话框(添加 / 修改) --> | ||
| 61 | + <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> | ||
| 62 | + <el-form ref="form" :model="form" :rules="rules" label-width="80px"> | ||
| 63 | + <el-form-item label="规格名称" prop="name"> | ||
| 64 | + <el-input v-model="form.name" placeholder="请输入规格名称" /> | ||
| 65 | + </el-form-item> | ||
| 66 | + <el-form-item label="状态: 0 开启 ,1 禁用" prop="status"> | ||
| 67 | + <el-radio-group v-model="form.status"> | ||
| 68 | + <el-radio label="1">请选择字典生成</el-radio> | ||
| 69 | + </el-radio-group> | ||
| 70 | + </el-form-item> | ||
| 71 | + </el-form> | ||
| 72 | + <div slot="footer" class="dialog-footer"> | ||
| 73 | + <el-button type="primary" @click="submitForm">确 定</el-button> | ||
| 74 | + <el-button @click="cancel">取 消</el-button> | ||
| 75 | + </div> | ||
| 76 | + </el-dialog> | ||
| 77 | + </div> | ||
| 78 | +</template> | ||
| 79 | + | ||
| 80 | +<script> | ||
| 81 | +import { createProperty, updateProperty, deleteProperty, getProperty, getPropertyPage, exportPropertyExcel } from "@/api/mall/product/property"; | ||
| 82 | + | ||
| 83 | +export default { | ||
| 84 | + name: "Property", | ||
| 85 | + components: { | ||
| 86 | + }, | ||
| 87 | + data() { | ||
| 88 | + return { | ||
| 89 | + // 遮罩层 | ||
| 90 | + loading: true, | ||
| 91 | + // 导出遮罩层 | ||
| 92 | + exportLoading: false, | ||
| 93 | + // 显示搜索条件 | ||
| 94 | + showSearch: true, | ||
| 95 | + // 总条数 | ||
| 96 | + total: 0, | ||
| 97 | + // 规格名称列表 | ||
| 98 | + list: [], | ||
| 99 | + // 弹出层标题 | ||
| 100 | + title: "", | ||
| 101 | + // 是否显示弹出层 | ||
| 102 | + open: false, | ||
| 103 | + dateRangeCreateTime: [], | ||
| 104 | + // 查询参数 | ||
| 105 | + queryParams: { | ||
| 106 | + pageNo: 1, | ||
| 107 | + pageSize: 10, | ||
| 108 | + name: null, | ||
| 109 | + status: null, | ||
| 110 | + }, | ||
| 111 | + // 表单参数 | ||
| 112 | + form: {}, | ||
| 113 | + // 表单校验 | ||
| 114 | + rules: { | ||
| 115 | + } | ||
| 116 | + }; | ||
| 117 | + }, | ||
| 118 | + created() { | ||
| 119 | + this.getList(); | ||
| 120 | + }, | ||
| 121 | + methods: { | ||
| 122 | + /** 查询列表 */ | ||
| 123 | + getList() { | ||
| 124 | + this.loading = true; | ||
| 125 | + // 处理查询参数 | ||
| 126 | + let params = {...this.queryParams}; | ||
| 127 | + this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime'); | ||
| 128 | + // 执行查询 | ||
| 129 | + getPropertyPage(params).then(response => { | ||
| 130 | + this.list = response.data.list; | ||
| 131 | + this.total = response.data.total; | ||
| 132 | + this.loading = false; | ||
| 133 | + }); | ||
| 134 | + }, | ||
| 135 | + /** 取消按钮 */ | ||
| 136 | + cancel() { | ||
| 137 | + this.open = false; | ||
| 138 | + this.reset(); | ||
| 139 | + }, | ||
| 140 | + /** 表单重置 */ | ||
| 141 | + reset() { | ||
| 142 | + this.form = { | ||
| 143 | + id: undefined, | ||
| 144 | + name: undefined, | ||
| 145 | + status: undefined, | ||
| 146 | + }; | ||
| 147 | + this.resetForm("form"); | ||
| 148 | + }, | ||
| 149 | + /** 搜索按钮操作 */ | ||
| 150 | + handleQuery() { | ||
| 151 | + this.queryParams.pageNo = 1; | ||
| 152 | + this.getList(); | ||
| 153 | + }, | ||
| 154 | + /** 重置按钮操作 */ | ||
| 155 | + resetQuery() { | ||
| 156 | + this.dateRangeCreateTime = []; | ||
| 157 | + this.resetForm("queryForm"); | ||
| 158 | + this.handleQuery(); | ||
| 159 | + }, | ||
| 160 | + /** 新增按钮操作 */ | ||
| 161 | + handleAdd() { | ||
| 162 | + this.reset(); | ||
| 163 | + this.open = true; | ||
| 164 | + this.title = "添加规格名称"; | ||
| 165 | + }, | ||
| 166 | + /** 修改按钮操作 */ | ||
| 167 | + handleUpdate(row) { | ||
| 168 | + this.reset(); | ||
| 169 | + const id = row.id; | ||
| 170 | + getProperty(id).then(response => { | ||
| 171 | + this.form = response.data; | ||
| 172 | + this.open = true; | ||
| 173 | + this.title = "修改规格名称"; | ||
| 174 | + }); | ||
| 175 | + }, | ||
| 176 | + /** 提交按钮 */ | ||
| 177 | + submitForm() { | ||
| 178 | + this.$refs["form"].validate(valid => { | ||
| 179 | + if (!valid) { | ||
| 180 | + return; | ||
| 181 | + } | ||
| 182 | + // 修改的提交 | ||
| 183 | + if (this.form.id != null) { | ||
| 184 | + updateProperty(this.form).then(response => { | ||
| 185 | + this.$modal.msgSuccess("修改成功"); | ||
| 186 | + this.open = false; | ||
| 187 | + this.getList(); | ||
| 188 | + }); | ||
| 189 | + return; | ||
| 190 | + } | ||
| 191 | + // 添加的提交 | ||
| 192 | + createProperty(this.form).then(response => { | ||
| 193 | + this.$modal.msgSuccess("新增成功"); | ||
| 194 | + this.open = false; | ||
| 195 | + this.getList(); | ||
| 196 | + }); | ||
| 197 | + }); | ||
| 198 | + }, | ||
| 199 | + /** 删除按钮操作 */ | ||
| 200 | + handleDelete(row) { | ||
| 201 | + const id = row.id; | ||
| 202 | + this.$modal.confirm('是否确认删除规格名称编号为"' + id + '"的数据项?').then(function() { | ||
| 203 | + return deleteProperty(id); | ||
| 204 | + }).then(() => { | ||
| 205 | + this.getList(); | ||
| 206 | + this.$modal.msgSuccess("删除成功"); | ||
| 207 | + }).catch(() => {}); | ||
| 208 | + }, | ||
| 209 | + /** 导出按钮操作 */ | ||
| 210 | + handleExport() { | ||
| 211 | + // 处理查询参数 | ||
| 212 | + let params = {...this.queryParams}; | ||
| 213 | + params.pageNo = undefined; | ||
| 214 | + params.pageSize = undefined; | ||
| 215 | + this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime'); | ||
| 216 | + // 执行导出 | ||
| 217 | + this.$modal.confirm('是否确认导出所有规格名称数据项?').then(() => { | ||
| 218 | + this.exportLoading = true; | ||
| 219 | + return exportPropertyExcel(params); | ||
| 220 | + }).then(response => { | ||
| 221 | + this.$download.excel(response, '规格名称.xls'); | ||
| 222 | + this.exportLoading = false; | ||
| 223 | + }).catch(() => {}); | ||
| 224 | + } | ||
| 225 | + } | ||
| 226 | +}; | ||
| 227 | +</script> |
yudao-ui-admin/src/views/mall/product/spu/index.vue
0 → 100644
| 1 | +<template> | ||
| 2 | + <div class="app-container"> | ||
| 3 | + | ||
| 4 | + <!-- 搜索工作栏 --> | ||
| 5 | + <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"> | ||
| 6 | + <el-form-item label="商品名称" prop="name"> | ||
| 7 | + <el-input v-model="queryParams.name" placeholder="请输入商品名称" clearable @keyup.enter.native="handleQuery"/> | ||
| 8 | + </el-form-item> | ||
| 9 | + <el-form-item label="卖点" prop="sellPoint"> | ||
| 10 | + <el-input v-model="queryParams.sellPoint" placeholder="请输入卖点" clearable @keyup.enter.native="handleQuery"/> | ||
| 11 | + </el-form-item> | ||
| 12 | + <el-form-item label="分类id" prop="categoryId"> | ||
| 13 | + <el-input v-model="queryParams.categoryId" placeholder="请输入分类id" clearable @keyup.enter.native="handleQuery"/> | ||
| 14 | + </el-form-item> | ||
| 15 | + <el-form-item label="商品主图地址" prop="picUrls"> | ||
| 16 | + <el-input v-model="queryParams.picUrls" placeholder="请输入商品主图地址" clearable @keyup.enter.native="handleQuery"/> | ||
| 17 | + </el-form-item> | ||
| 18 | + <el-form-item label="排序字段" prop="sort"> | ||
| 19 | + <el-input v-model="queryParams.sort" placeholder="请输入排序字段" clearable @keyup.enter.native="handleQuery"/> | ||
| 20 | + </el-form-item> | ||
| 21 | + <el-form-item label="点赞初始人数" prop="likeCount"> | ||
| 22 | + <el-input v-model="queryParams.likeCount" placeholder="请输入点赞初始人数" clearable @keyup.enter.native="handleQuery"/> | ||
| 23 | + </el-form-item> | ||
| 24 | + <el-form-item label="价格 单位使用:分" prop="price"> | ||
| 25 | + <el-input v-model="queryParams.price" placeholder="请输入价格 单位使用:分" clearable @keyup.enter.native="handleQuery"/> | ||
| 26 | + </el-form-item> | ||
| 27 | + <el-form-item label="库存数量" prop="quantity"> | ||
| 28 | + <el-input v-model="queryParams.quantity" placeholder="请输入库存数量" clearable @keyup.enter.native="handleQuery"/> | ||
| 29 | + </el-form-item> | ||
| 30 | + <el-form-item label="上下架状态: 0 上架(开启) 1 下架(禁用)" prop="status"> | ||
| 31 | + <el-select v-model="queryParams.status" placeholder="请选择上下架状态: 0 上架(开启) 1 下架(禁用)" clearable size="small"> | ||
| 32 | + <el-option label="请选择字典生成" value="" /> | ||
| 33 | + </el-select> | ||
| 34 | + </el-form-item> | ||
| 35 | + <el-form-item label="创建时间"> | ||
| 36 | + <el-date-picker v-model="dateRangeCreateTime" style="width: 240px" value-format="yyyy-MM-dd" | ||
| 37 | + type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" /> | ||
| 38 | + </el-form-item> | ||
| 39 | + <el-form-item> | ||
| 40 | + <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button> | ||
| 41 | + <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button> | ||
| 42 | + </el-form-item> | ||
| 43 | + </el-form> | ||
| 44 | + | ||
| 45 | + <!-- 操作工具栏 --> | ||
| 46 | + <el-row :gutter="10" class="mb8"> | ||
| 47 | + <el-col :span="1.5"> | ||
| 48 | + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" | ||
| 49 | + v-hasPermi="['product:spu:create']">新增</el-button> | ||
| 50 | + </el-col> | ||
| 51 | + <el-col :span="1.5"> | ||
| 52 | + <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading" | ||
| 53 | + v-hasPermi="['product:spu:export']">导出</el-button> | ||
| 54 | + </el-col> | ||
| 55 | + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> | ||
| 56 | + </el-row> | ||
| 57 | + | ||
| 58 | + <!-- 列表 --> | ||
| 59 | + <el-table v-loading="loading" :data="list"> | ||
| 60 | + <el-table-column label="主键" align="center" prop="id" /> | ||
| 61 | + <el-table-column label="商品名称" align="center" prop="name" /> | ||
| 62 | + <el-table-column label="卖点" align="center" prop="sellPoint" /> | ||
| 63 | + <el-table-column label="描述" align="center" prop="description" /> | ||
| 64 | + <el-table-column label="分类id" align="center" prop="categoryId" /> | ||
| 65 | + <el-table-column label="商品主图地址" align="center" prop="picUrls" /> | ||
| 66 | + <el-table-column label="排序字段" align="center" prop="sort" /> | ||
| 67 | + <el-table-column label="点赞初始人数" align="center" prop="likeCount" /> | ||
| 68 | + <el-table-column label="价格 单位使用:分" align="center" prop="price" /> | ||
| 69 | + <el-table-column label="库存数量" align="center" prop="quantity" /> | ||
| 70 | + <el-table-column label="上下架状态: 0 上架(开启) 1 下架(禁用)" align="center" prop="status" /> | ||
| 71 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | ||
| 72 | + <template slot-scope="scope"> | ||
| 73 | + <span>{{ parseTime(scope.row.createTime) }}</span> | ||
| 74 | + </template> | ||
| 75 | + </el-table-column> | ||
| 76 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | ||
| 77 | + <template slot-scope="scope"> | ||
| 78 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" | ||
| 79 | + v-hasPermi="['product:spu:update']">修改</el-button> | ||
| 80 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | ||
| 81 | + v-hasPermi="['product:spu:delete']">删除</el-button> | ||
| 82 | + </template> | ||
| 83 | + </el-table-column> | ||
| 84 | + </el-table> | ||
| 85 | + <!-- 分页组件 --> | ||
| 86 | + <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" | ||
| 87 | + @pagination="getList"/> | ||
| 88 | + | ||
| 89 | + <!-- 对话框(添加 / 修改) --> | ||
| 90 | + <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> | ||
| 91 | + <el-form ref="form" :model="form" :rules="rules" label-width="80px"> | ||
| 92 | + <el-form-item label="商品名称" prop="name"> | ||
| 93 | + <el-input v-model="form.name" placeholder="请输入商品名称" /> | ||
| 94 | + </el-form-item> | ||
| 95 | + <el-form-item label="卖点" prop="sellPoint"> | ||
| 96 | + <el-input v-model="form.sellPoint" placeholder="请输入卖点" /> | ||
| 97 | + </el-form-item> | ||
| 98 | + <el-form-item label="描述"> | ||
| 99 | + <editor v-model="form.description" :min-height="192"/> | ||
| 100 | + </el-form-item> | ||
| 101 | + <el-form-item label="分类id" prop="categoryId"> | ||
| 102 | + <el-input v-model="form.categoryId" placeholder="请输入分类id" /> | ||
| 103 | + </el-form-item> | ||
| 104 | + <el-form-item label="商品主图地址" prop="picUrls"> | ||
| 105 | + <el-input v-model="form.picUrls" placeholder="请输入商品主图地址" /> | ||
| 106 | + </el-form-item> | ||
| 107 | + <el-form-item label="排序字段" prop="sort"> | ||
| 108 | + <el-input v-model="form.sort" placeholder="请输入排序字段" /> | ||
| 109 | + </el-form-item> | ||
| 110 | + <el-form-item label="点赞初始人数" prop="likeCount"> | ||
| 111 | + <el-input v-model="form.likeCount" placeholder="请输入点赞初始人数" /> | ||
| 112 | + </el-form-item> | ||
| 113 | + <el-form-item label="价格 单位使用:分" prop="price"> | ||
| 114 | + <el-input v-model="form.price" placeholder="请输入价格 单位使用:分" /> | ||
| 115 | + </el-form-item> | ||
| 116 | + <el-form-item label="库存数量" prop="quantity"> | ||
| 117 | + <el-input v-model="form.quantity" placeholder="请输入库存数量" /> | ||
| 118 | + </el-form-item> | ||
| 119 | + <el-form-item label="上下架状态: 0 上架(开启) 1 下架(禁用)" prop="status"> | ||
| 120 | + <el-radio-group v-model="form.status"> | ||
| 121 | + <el-radio label="1">请选择字典生成</el-radio> | ||
| 122 | + </el-radio-group> | ||
| 123 | + </el-form-item> | ||
| 124 | + </el-form> | ||
| 125 | + <div slot="footer" class="dialog-footer"> | ||
| 126 | + <el-button type="primary" @click="submitForm">确 定</el-button> | ||
| 127 | + <el-button @click="cancel">取 消</el-button> | ||
| 128 | + </div> | ||
| 129 | + </el-dialog> | ||
| 130 | + </div> | ||
| 131 | +</template> | ||
| 132 | + | ||
| 133 | +<script> | ||
| 134 | +import { createSpu, updateSpu, deleteSpu, getSpu, getSpuPage, exportSpuExcel } from "@/api/mall/product/spu"; | ||
| 135 | +import Editor from '@/components/Editor'; | ||
| 136 | + | ||
| 137 | +export default { | ||
| 138 | + name: "Spu", | ||
| 139 | + components: { | ||
| 140 | + Editor, | ||
| 141 | + }, | ||
| 142 | + data() { | ||
| 143 | + return { | ||
| 144 | + // 遮罩层 | ||
| 145 | + loading: true, | ||
| 146 | + // 导出遮罩层 | ||
| 147 | + exportLoading: false, | ||
| 148 | + // 显示搜索条件 | ||
| 149 | + showSearch: true, | ||
| 150 | + // 总条数 | ||
| 151 | + total: 0, | ||
| 152 | + // 商品spu列表 | ||
| 153 | + list: [], | ||
| 154 | + // 弹出层标题 | ||
| 155 | + title: "", | ||
| 156 | + // 是否显示弹出层 | ||
| 157 | + open: false, | ||
| 158 | + dateRangeCreateTime: [], | ||
| 159 | + // 查询参数 | ||
| 160 | + queryParams: { | ||
| 161 | + pageNo: 1, | ||
| 162 | + pageSize: 10, | ||
| 163 | + name: null, | ||
| 164 | + sellPoint: null, | ||
| 165 | + description: null, | ||
| 166 | + categoryId: null, | ||
| 167 | + picUrls: null, | ||
| 168 | + sort: null, | ||
| 169 | + likeCount: null, | ||
| 170 | + price: null, | ||
| 171 | + quantity: null, | ||
| 172 | + status: null, | ||
| 173 | + }, | ||
| 174 | + // 表单参数 | ||
| 175 | + form: {}, | ||
| 176 | + // 表单校验 | ||
| 177 | + rules: { | ||
| 178 | + sellPoint: [{ required: true, message: "卖点不能为空", trigger: "blur" }], | ||
| 179 | + description: [{ required: true, message: "描述不能为空", trigger: "blur" }], | ||
| 180 | + categoryId: [{ required: true, message: "分类id不能为空", trigger: "blur" }], | ||
| 181 | + picUrls: [{ required: true, message: "商品主图地址", trigger: "blur" }], | ||
| 182 | + sort: [{ required: true, message: "排序字段不能为空", trigger: "blur" }], | ||
| 183 | + } | ||
| 184 | + }; | ||
| 185 | + }, | ||
| 186 | + created() { | ||
| 187 | + this.getList(); | ||
| 188 | + }, | ||
| 189 | + methods: { | ||
| 190 | + /** 查询列表 */ | ||
| 191 | + getList() { | ||
| 192 | + this.loading = true; | ||
| 193 | + // 处理查询参数 | ||
| 194 | + let params = {...this.queryParams}; | ||
| 195 | + this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime'); | ||
| 196 | + // 执行查询 | ||
| 197 | + getSpuPage(params).then(response => { | ||
| 198 | + this.list = response.data.list; | ||
| 199 | + this.total = response.data.total; | ||
| 200 | + this.loading = false; | ||
| 201 | + }); | ||
| 202 | + }, | ||
| 203 | + /** 取消按钮 */ | ||
| 204 | + cancel() { | ||
| 205 | + this.open = false; | ||
| 206 | + this.reset(); | ||
| 207 | + }, | ||
| 208 | + /** 表单重置 */ | ||
| 209 | + reset() { | ||
| 210 | + this.form = { | ||
| 211 | + id: undefined, | ||
| 212 | + name: undefined, | ||
| 213 | + sellPoint: undefined, | ||
| 214 | + description: undefined, | ||
| 215 | + categoryId: undefined, | ||
| 216 | + picUrls: undefined, | ||
| 217 | + sort: undefined, | ||
| 218 | + likeCount: undefined, | ||
| 219 | + price: undefined, | ||
| 220 | + quantity: undefined, | ||
| 221 | + status: undefined, | ||
| 222 | + }; | ||
| 223 | + this.resetForm("form"); | ||
| 224 | + }, | ||
| 225 | + /** 搜索按钮操作 */ | ||
| 226 | + handleQuery() { | ||
| 227 | + this.queryParams.pageNo = 1; | ||
| 228 | + this.getList(); | ||
| 229 | + }, | ||
| 230 | + /** 重置按钮操作 */ | ||
| 231 | + resetQuery() { | ||
| 232 | + this.dateRangeCreateTime = []; | ||
| 233 | + this.resetForm("queryForm"); | ||
| 234 | + this.handleQuery(); | ||
| 235 | + }, | ||
| 236 | + /** 新增按钮操作 */ | ||
| 237 | + handleAdd() { | ||
| 238 | + this.reset(); | ||
| 239 | + this.open = true; | ||
| 240 | + this.title = "添加商品spu"; | ||
| 241 | + }, | ||
| 242 | + /** 修改按钮操作 */ | ||
| 243 | + handleUpdate(row) { | ||
| 244 | + this.reset(); | ||
| 245 | + const id = row.id; | ||
| 246 | + getSpu(id).then(response => { | ||
| 247 | + this.form = response.data; | ||
| 248 | + this.open = true; | ||
| 249 | + this.title = "修改商品spu"; | ||
| 250 | + }); | ||
| 251 | + }, | ||
| 252 | + /** 提交按钮 */ | ||
| 253 | + submitForm() { | ||
| 254 | + this.$refs["form"].validate(valid => { | ||
| 255 | + if (!valid) { | ||
| 256 | + return; | ||
| 257 | + } | ||
| 258 | + // 修改的提交 | ||
| 259 | + if (this.form.id != null) { | ||
| 260 | + updateSpu(this.form).then(response => { | ||
| 261 | + this.$modal.msgSuccess("修改成功"); | ||
| 262 | + this.open = false; | ||
| 263 | + this.getList(); | ||
| 264 | + }); | ||
| 265 | + return; | ||
| 266 | + } | ||
| 267 | + // 添加的提交 | ||
| 268 | + createSpu(this.form).then(response => { | ||
| 269 | + this.$modal.msgSuccess("新增成功"); | ||
| 270 | + this.open = false; | ||
| 271 | + this.getList(); | ||
| 272 | + }); | ||
| 273 | + }); | ||
| 274 | + }, | ||
| 275 | + /** 删除按钮操作 */ | ||
| 276 | + handleDelete(row) { | ||
| 277 | + const id = row.id; | ||
| 278 | + this.$modal.confirm('是否确认删除商品spu编号为"' + id + '"的数据项?').then(function() { | ||
| 279 | + return deleteSpu(id); | ||
| 280 | + }).then(() => { | ||
| 281 | + this.getList(); | ||
| 282 | + this.$modal.msgSuccess("删除成功"); | ||
| 283 | + }).catch(() => {}); | ||
| 284 | + }, | ||
| 285 | + /** 导出按钮操作 */ | ||
| 286 | + handleExport() { | ||
| 287 | + // 处理查询参数 | ||
| 288 | + let params = {...this.queryParams}; | ||
| 289 | + params.pageNo = undefined; | ||
| 290 | + params.pageSize = undefined; | ||
| 291 | + this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime'); | ||
| 292 | + // 执行导出 | ||
| 293 | + this.$modal.confirm('是否确认导出所有商品spu数据项?').then(() => { | ||
| 294 | + this.exportLoading = true; | ||
| 295 | + return exportSpuExcel(params); | ||
| 296 | + }).then(response => { | ||
| 297 | + this.$download.excel(response, '商品spu.xls'); | ||
| 298 | + this.exportLoading = false; | ||
| 299 | + }).catch(() => {}); | ||
| 300 | + } | ||
| 301 | + } | ||
| 302 | +}; | ||
| 303 | +</script> |