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
})
}
// 导出商品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>
<div class="app-container">
<!-- 搜索工作栏 -->
<el-form
:model="queryParams"
ref="queryForm"
size="small"
:inline="true"
v-show="showSearch"
label-width="68px"
>
<!-- TODO @Luowenfeng参考界面https://v5.niuteam.cn/shop/goods/lists.html
商品名称商品编码商品分类商品品牌
商品销量商品价格
-->
<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-input v-model="queryParams.name" placeholder="请输入商品名称" clearable @keyup.enter.native="handleQuery"/>
</el-form-item>
<el-form-item label="分类id" prop="categoryId">
<el-input
v-model="queryParams.categoryId"
placeholder="请输入分类id"
clearable
@keyup.enter.native="handleQuery"
/>
<el-input v-model="queryParams.categoryId" placeholder="请输入分类id" clearable @keyup.enter.native="handleQuery"/>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-select
v-model="queryParams.status"
placeholder="请选择上下架状态"
clearable
size="small"
>
<el-select v-model="queryParams.status" placeholder="请选择上下架状态" clearable size="small">
<el-option label="请选择字典生成" value="" />
<el-option label="上架" value="0" />
<el-option label="下架" value="1" />
</el-select>
</el-form-item>
<el-form-item label="创建时间">
<el-date-picker
v-model="dateRangeCreateTime"
style="width: 240px"
value-format="yyyy-MM-dd"
type="daterange"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
/>
<el-date-picker v-model="dateRangeCreateTime" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" @click="handleQuery"
>搜索</el-button
>
<el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
@ -59,36 +32,20 @@
<!-- 操作工具栏 -->
<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="['product:spu:create']"
>新增
</el-button>
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
v-hasPermi="['product:spu:create']">新增</el-button>
</el-col>
<el-col :span="1.5">
<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>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList" />
</el-row>
<!-- 列表 -->
<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="name" />
<el-table-column label="分类id" align="center" prop="categoryId" />
@ -111,50 +68,23 @@
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/>
</template>
</el-table-column>
<el-table-column
label="创建时间"
align="center"
prop="createTime"
width="180"
>
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column
label="操作"
align="center"
class-name="small-padding fixed-width"
>
<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="['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>
<el-button size="mini" type="text" icon="el-icon-edit" @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>
</el-table-column>
</el-table>
<!-- 分页组件 -->
<pagination
v-show="total > 0"
:total="total"
:page.sync="queryParams.pageNo"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<pagination v-show="total > 0" :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" >
<save @closeDialog="closeDialog" :type="dialogType" :obj="dialogObj" v-if="open" />
@ -166,13 +96,15 @@
import {
deleteSpu,
getSpuPage,
exportSpuExcel,
} from "@/api/mall/product/spu";
import Editor from "@/components/Editor";
import ImageUpload from "@/components/ImageUpload";
import save from "./save";
// 1. TODO @Luowenfenghttps://v5.niuteam.cn/shop/goods/addgoods.html
// 2. TODO
export default {
name: "Spu",
components: {
@ -306,27 +238,7 @@ export default {
this.$modal.msgSuccess("删除成功");
})
.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>

View File

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