mall:code review 商品模块的代码

This commit is contained in:
YunaiV 2022-09-05 00:14:17 +08:00
parent 37e948cc1b
commit 1bd1c79ff3
3 changed files with 77 additions and 213 deletions

View File

@ -42,13 +42,3 @@ export function getSpuPage(query) {
params: query params: query
}) })
} }
// 导出商品spu Excel
export function exportSpuExcel(query) {
return request({
url: '/product/spu/export-excel',
method: 'get',
params: query,
responseType: 'blob'
})
}

View File

@ -1,57 +1,30 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<!-- 搜索工作栏 --> <!-- 搜索工作栏 -->
<el-form <!-- TODO @Luowenfeng参考界面https://v5.niuteam.cn/shop/goods/lists.html
:model="queryParams" 商品名称商品编码商品分类商品品牌
ref="queryForm" 商品销量商品价格
size="small" -->
:inline="true" <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
v-show="showSearch"
label-width="68px"
>
<el-form-item label="商品名称" prop="name"> <el-form-item label="商品名称" prop="name">
<el-input <el-input v-model="queryParams.name" placeholder="请输入商品名称" clearable @keyup.enter.native="handleQuery"/>
v-model="queryParams.name"
placeholder="请输入商品名称"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item> </el-form-item>
<el-form-item label="分类id" prop="categoryId"> <el-form-item label="分类id" prop="categoryId">
<el-input <el-input v-model="queryParams.categoryId" placeholder="请输入分类id" clearable @keyup.enter.native="handleQuery"/>
v-model="queryParams.categoryId"
placeholder="请输入分类id"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item> </el-form-item>
<el-form-item label="状态" prop="status"> <el-form-item label="状态" prop="status">
<el-select <el-select v-model="queryParams.status" placeholder="请选择上下架状态" clearable size="small">
v-model="queryParams.status"
placeholder="请选择上下架状态"
clearable
size="small"
>
<el-option label="请选择字典生成" value="" /> <el-option label="请选择字典生成" value="" />
<el-option label="上架" value="0" /> <el-option label="上架" value="0" />
<el-option label="下架" value="1" /> <el-option label="下架" value="1" />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="创建时间"> <el-form-item label="创建时间">
<el-date-picker <el-date-picker v-model="dateRangeCreateTime" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
v-model="dateRangeCreateTime" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"/>
style="width: 240px"
value-format="yyyy-MM-dd"
type="daterange"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
/>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" icon="el-icon-search" @click="handleQuery" <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
>搜索</el-button
>
<el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button> <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
@ -59,36 +32,20 @@
<!-- 操作工具栏 --> <!-- 操作工具栏 -->
<el-row :gutter="10" class="mb8"> <el-row :gutter="10" class="mb8">
<el-col :span="1.5"> <el-col :span="1.5">
<el-button <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
type="primary" v-hasPermi="['product:spu:create']">新增</el-button>
plain
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['product:spu:create']"
>新增
</el-button>
</el-col> </el-col>
<el-col :span="1.5"> <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" />
<el-button
type="warning"
plain
icon="el-icon-download"
size="mini"
@click="handleExport"
:loading="exportLoading"
v-hasPermi="['product:spu:export']"
>导出
</el-button>
</el-col>
<right-toolbar
:showSearch.sync="showSearch"
@queryTable="getList"
></right-toolbar>
</el-row> </el-row>
<!-- 列表 --> <!-- 列表 -->
<el-table v-loading="loading" :data="list"> <el-table v-loading="loading" :data="list">
<!--
TODO @Luowenfeng参考界面
https://v5.niuteam.cn/shop/goods/lists.html
1. 字段商品信息价格库存销量排序创建时间状态操作
2. tab 分成全部销售中仓库中预警中
-->
<el-table-column label="主键" align="center" prop="id" /> <el-table-column label="主键" align="center" prop="id" />
<el-table-column label="商品名称" align="center" prop="name" /> <el-table-column label="商品名称" align="center" prop="name" />
<el-table-column label="分类id" align="center" prop="categoryId" /> <el-table-column label="分类id" align="center" prop="categoryId" />
@ -111,50 +68,23 @@
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/> <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column label="创建时间" align="center" prop="createTime" width="180">
label="创建时间"
align="center"
prop="createTime"
width="180"
>
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span> <span>{{ parseTime(scope.row.createTime) }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
label="操作"
align="center"
class-name="small-padding fixed-width"
>
<template slot-scope="scope"> <template slot-scope="scope">
<el-button <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
size="mini" v-hasPermi="['product:spu:update']">修改</el-button>
type="text" <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
icon="el-icon-edit" v-hasPermi="['product:spu:delete']">删除</el-button>
@click="handleUpdate(scope.row)"
v-hasPermi="['product:spu:update']"
>修改
</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['product:spu:delete']"
>删除
</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<!-- 分页组件 --> <!-- 分页组件 -->
<pagination <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
v-show="total > 0" @pagination="getList"/>
:total="total"
:page.sync="queryParams.pageNo"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<el-dialog :title="title" :visible.sync="open" width="900px" append-to-body destroy-on-close :close-on-click-modal="false" > <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body destroy-on-close :close-on-click-modal="false" >
<save @closeDialog="closeDialog" :type="dialogType" :obj="dialogObj" v-if="open" /> <save @closeDialog="closeDialog" :type="dialogType" :obj="dialogObj" v-if="open" />
@ -166,13 +96,15 @@
import { import {
deleteSpu, deleteSpu,
getSpuPage, getSpuPage,
exportSpuExcel,
} from "@/api/mall/product/spu"; } from "@/api/mall/product/spu";
import Editor from "@/components/Editor"; import Editor from "@/components/Editor";
import ImageUpload from "@/components/ImageUpload"; import ImageUpload from "@/components/ImageUpload";
import save from "./save"; import save from "./save";
// 1. TODO @Luowenfenghttps://v5.niuteam.cn/shop/goods/addgoods.html
// 2. TODO
export default { export default {
name: "Spu", name: "Spu",
components: { components: {
@ -306,27 +238,7 @@ export default {
this.$modal.msgSuccess("删除成功"); this.$modal.msgSuccess("删除成功");
}) })
.catch(() => {}); .catch(() => {});
}, }
/** 导出按钮操作 */
handleExport() {
//
let params = { ...this.queryParams };
params.pageNo = undefined;
params.pageSize = undefined;
this.addBeginAndEndTime(params, this.dateRangeCreateTime, "createTime");
//
this.$modal
.confirm("是否确认导出所有商品spu数据项?")
.then(() => {
this.exportLoading = true;
return exportSpuExcel(params);
})
.then((response) => {
this.$download.excel(response, "商品spu.xls");
this.exportLoading = false;
})
.catch(() => {});
},
}, },
}; };
</script> </script>

View File

@ -7,24 +7,28 @@
<el-form-item label="商品名称" prop="name"> <el-form-item label="商品名称" prop="name">
<el-input v-model="baseForm.name" placeholder="请输入商品名称"/> <el-input v-model="baseForm.name" placeholder="请输入商品名称"/>
</el-form-item> </el-form-item>
<el-form-item label="卖点"> <el-form-item label="商品卖点">
<el-input v-model="baseForm.sellPoint" placeholder="请输入卖点"/> <el-input type="textarea" v-model="baseForm.sellPoint" placeholder="请输入商品卖点"/>
</el-form-item> </el-form-item>
<el-form-item label="分类id" prop="categoryIds"> <!-- TODO @Luowenfeng商品主图80 x 80 即可 -->
<el-cascader <el-form-item label="商品主图" prop="picUrls">
v-model="baseForm.categoryIds"
placeholder="请输入分类id"
style="width: 100%"
:options="categoryList"
:props="propName"
clearable
></el-cascader>
</el-form-item>
<el-form-item label="商品轮播图" prop="picUrls">
<ImageUpload v-model="baseForm.picUrls" :value="baseForm.picUrls" :limit="10"/> <ImageUpload v-model="baseForm.picUrls" :value="baseForm.picUrls" :limit="10"/>
</el-form-item> </el-form-item>
<el-form-item label="排序字段"> <!-- TODO @Luowenfeng商品视频 -->
<el-input v-model="baseForm.sort" placeholder="请输入排序字段" oninput="value=value.replace(/^(0+)|[^\d]+/g,'')"/> <el-form-item label="商品品牌" prop="brandId">
<el-select v-model="baseForm.brandId" placeholder="请选择商品品牌">
<el-option v-for="item in brandList" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
</el-form-item>
<el-form-item label="商品分类" prop="categoryIds">
<el-cascader v-model="baseForm.categoryIds" placeholder="商品分类" style="width: 100%"
:options="categoryList" :props="propName" clearable />
</el-form-item>
<el-form-item label="是否上架" prop="status">
<el-radio-group v-model="baseForm.status">
<el-radio :label="0">立即上架</el-radio>
<el-radio :label="1">放入仓库</el-radio>
</el-radio-group>
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-tab-pane> </el-tab-pane>
@ -32,7 +36,8 @@
<!-- 价格库存 --> <!-- 价格库存 -->
<el-tab-pane label="价格库存" name="rates" class="rates"> <el-tab-pane label="价格库存" name="rates" class="rates">
<el-form ref="rates" :model="ratesForm" :rules="rules"> <el-form ref="rates" :model="ratesForm" :rules="rules">
<el-form-item label="商品规格"> <el-form-item label="启用多规格">
<!-- TODO @Luowenfeng改成开关的按钮关闭单规格开启多规格 -->
<el-radio-group v-model="ratesForm.spec" @change="changeRadio"> <el-radio-group v-model="ratesForm.spec" @change="changeRadio">
<el-radio :label="1">单规格</el-radio> <el-radio :label="1">单规格</el-radio>
<el-radio :label="2">多规格</el-radio> <el-radio :label="2">多规格</el-radio>
@ -41,28 +46,13 @@
<!-- 动态添加规格属性 --> <!-- 动态添加规格属性 -->
<div v-show="ratesForm.spec === 2"> <div v-show="ratesForm.spec === 2">
<div <div v-for="(specs, index) in dynamicSpec" :key="index" class="dynamic-spec">
v-for="(specs, index) in dynamicSpec"
:key="index"
class="dynamic-spec"
>
<!-- 删除按钮 --> <!-- 删除按钮 -->
<el-button <el-button type="danger" icon="el-icon-delete" circle class="spec-delete" @click="removeSpec(index)" />
type="danger"
icon="el-icon-delete"
circle
class="spec-delete"
@click="removeSpec(index)"
></el-button>
<div class="spec-header"> <div class="spec-header">
规格项 规格项
<el-select v-model="specs.specId" filterable placeholder="请选择" @change="changeSpec"> <el-select v-model="specs.specId" filterable placeholder="请选择" @change="changeSpec">
<el-option <el-option v-for="item in propertyPageList" :key="item.id" :label="item.name" :value="item.id" />
v-for="item in propertyPageList"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select> </el-select>
</div> </div>
<div class="spec-values"> <div class="spec-values">
@ -71,24 +61,17 @@
</template> </template>
</div> </div>
</div> </div>
<el-button type="primary" @click="dynamicSpec.push({specValue: []}); ratesForm.rates = []" <el-button type="primary" @click="dynamicSpec.push({specValue: []}); ratesForm.rates = []">添加规格项目</el-button>
>添加规格项目
</el-button
>
</div> </div>
<!-- 规格明细 --> <!-- 规格明细 -->
<el-form-item label="规格明细"> <el-form-item label="规格明细">
<el-table :data="ratesForm.rates" border style="width: 100%" ref="ratesTable"> <el-table :data="ratesForm.rates" border style="width: 100%" ref="ratesTable">
<template v-if="ratesForm.spec == 2"> <template v-if="ratesForm.spec == 2">
<el-table-column :key="index" v-for="(item, index) in dynamicSpec.filter(v=>v.specName != undefined)" <el-table-column :key="index" v-for="(item, index) in dynamicSpec.filter(v => v.specName !== undefined)"
:label="item.specName"> :label="item.specName">
<template slot-scope="scope"> <template slot-scope="scope">
<el-input <el-input v-if="scope.row.spec" v-model="scope.row.spec[index]" disabled />
v-if="scope.row.spec"
v-model="scope.row.spec[index]"
disabled
></el-input>
</template> </template>
</el-table-column> </el-table-column>
</template> </template>
@ -98,25 +81,20 @@
style="width: 100px; height: 50px"/> style="width: 100px; height: 50px"/>
</template> </template>
</el-table-column> </el-table-column>
<template v-if="ratesForm.spec == 2"> <template v-if="ratesForm.spec === 2">
<el-table-column label="sku名称" :render-header="addRedStar" key="91"> <el-table-column label="sku名称" :render-header="addRedStar" key="91">
<template slot-scope="scope"> <template slot-scope="scope">
<el-form-item :prop="'rates.'+ scope.$index + '.name'" :rules="[{required: true, trigger: 'change'}]"> <el-form-item :prop="'rates.'+ scope.$index + '.name'" :rules="[{required: true, trigger: 'change'}]">
<el-input <el-input v-model="scope.row.name" />
v-model="scope.row.name"
></el-input>
</el-form-item> </el-form-item>
</template> </template>
</el-table-column> </el-table-column>
</template> </template>
<el-table-column label="市场价(元)" :render-header="addRedStar" key="92"> <el-table-column label="市场价(元)" :render-header="addRedStar" key="92">
<template slot-scope="scope"> <template slot-scope="scope">
<el-form-item :prop="'rates.'+ scope.$index + '.marketPrice'" :rules="[{required: true, trigger: 'change'}]"> <el-form-item :prop="'rates.'+ scope.$index + '.marketPrice'" :rules="[{required: true, trigger: 'change'}]">
<el-input <el-input v-model="scope.row.marketPrice"
v-model="scope.row.marketPrice" oninput="value= value.match(/\d+(\.\d{0,2})?/) ? value.match(/\d+(\.\d{0,2})?/)[0] : ''"/>
oninput="value= value.match(/\d+(\.\d{0,2})?/) ? value.match(/\d+(\.\d{0,2})?/)[0] : ''"
></el-input>
</el-form-item> </el-form-item>
</template> </template>
</el-table-column> </el-table-column>
@ -164,12 +142,8 @@
<el-input v-model="scope.row.barCode"></el-input> <el-input v-model="scope.row.barCode"></el-input>
</template> </template>
</el-table-column> </el-table-column>
<template v-if="ratesForm.spec == 2"> <template v-if="ratesForm.spec === 2">
<el-table-column <el-table-column fixed="right" label="操作" width="50" key="100">
fixed="right"
label="操作"
width="50"
key="100">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button @click="scope.row.status = 1" type="text" size="small" v-show="scope.row.status == undefined || scope.row.status == 0 ">禁用</el-button> <el-button @click="scope.row.status = 1" type="text" size="small" v-show="scope.row.status == undefined || scope.row.status == 0 ">禁用</el-button>
<el-button @click="scope.row.status = 0" type="text" size="small" v-show="scope.row.status == 1">启用</el-button> <el-button @click="scope.row.status = 0" type="text" size="small" v-show="scope.row.status == 1">启用</el-button>
@ -178,11 +152,15 @@
</template> </template>
</el-table> </el-table>
</el-form-item> </el-form-item>
<el-form-item label="虚拟销量" prop="virtualSalesCount">
<!-- TODO @Luowenfeng使用 input 类型即可 -->
<el-input v-model="baseForm.virtualSalesCount" placeholder="请输入虚拟销量" oninput="value=value.replace(/^(0+)|[^\d]+/g,'')"/>
</el-form-item>
</el-form> </el-form>
</el-tab-pane> </el-tab-pane>
<!-- 商品详情 --> <!-- 商品详情 -->
<el-tab-pane label="商品描述" name="third"> <el-tab-pane label="商品详情" name="third">
<el-form ref="third" :model="baseForm" :rules="rules"> <el-form ref="third" :model="baseForm" :rules="rules">
<el-form-item prop="description"> <el-form-item prop="description">
<editor v-model="baseForm.description" :min-height="380"/> <editor v-model="baseForm.description" :min-height="380"/>
@ -191,20 +169,10 @@
</el-tab-pane> </el-tab-pane>
<!-- 销售设置 --> <!-- 销售设置 -->
<el-tab-pane label="销售设置" name="fourth"> <el-tab-pane label="高级设置" name="fourth">
<el-form ref="fourth" :model="baseForm" :rules="rules" label-width="100px" style="width: 95%"> <el-form ref="fourth" :model="baseForm" :rules="rules" label-width="100px" style="width: 95%">
<el-form-item label="所属品牌" prop="brandId"> <el-form-item label="排序字段">
<el-select v-model="baseForm.brandId" placeholder="请选择"> <el-input v-model="baseForm.sort" placeholder="请输入排序字段" oninput="value=value.replace(/^(0+)|[^\d]+/g,'')"/>
<el-option
v-for="item in brandList"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="虚拟销量" prop="virtualSalesCount">
<el-input v-model="baseForm.virtualSalesCount" placeholder="请输入虚拟销量" oninput="value=value.replace(/^(0+)|[^\d]+/g,'')"/>
</el-form-item> </el-form-item>
<el-form-item label="是否展示库存" prop="showStock"> <el-form-item label="是否展示库存" prop="showStock">
<el-radio-group v-model="baseForm.showStock"> <el-radio-group v-model="baseForm.showStock">
@ -212,12 +180,6 @@
<el-radio :label="false"></el-radio> <el-radio :label="false"></el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
<el-form-item label="商品状态" prop="status">
<el-radio-group v-model="baseForm.status">
<el-radio :label="0">上架</el-radio>
<el-radio :label="1">下架</el-radio>
</el-radio-group>
</el-form-item>
</el-form> </el-form>
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
@ -253,7 +215,7 @@ export default {
}, },
data() { data() {
return { return {
activeName: "base", activeName: "base", // TODO @Luowenfeng
propName: { propName: {
checkStrictly: true, checkStrictly: true,
label: "name", label: "name",