重构商品模块,支持多规格
This commit is contained in:
@@ -38,6 +38,11 @@ export interface PageParam {
|
||||
companyId?: number;
|
||||
// 商户ID
|
||||
merchantId?: number;
|
||||
merchantName?: string;
|
||||
categoryIds?: any;
|
||||
// 商品分类
|
||||
categoryId?: number;
|
||||
categoryName?: string;
|
||||
// 搜素关键词
|
||||
keywords?: string;
|
||||
// 起始时间
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { PageParam } from '@/api';
|
||||
import { GoodsSpec } from '@/api/shop/goodsSpec/model';
|
||||
import { GoodsSku } from '@/api/shop/goodsSku/model';
|
||||
import { GoodsSpec } from "@/api/shop/goodsSpec/model";
|
||||
import { GoodsSku } from "@/api/shop/goodsSku/model";
|
||||
|
||||
export interface GoodsCount {
|
||||
totalNum: number;
|
||||
@@ -18,59 +18,64 @@ export interface Goods {
|
||||
type?: number;
|
||||
// 商品编码
|
||||
code?: string;
|
||||
// 商品名称
|
||||
// 商品标题
|
||||
goodsName?: string;
|
||||
// 商品封面图
|
||||
image?: string;
|
||||
// 商品详情
|
||||
content?: string;
|
||||
// 商品附件
|
||||
files?: string;
|
||||
// 分类ID
|
||||
// 商品分类ID
|
||||
categoryId?: number;
|
||||
// 一级分类
|
||||
categoryParent?: string;
|
||||
// 二级分类
|
||||
categoryChildren?: string;
|
||||
// 分类名称
|
||||
categoryName?: string;
|
||||
// 规格
|
||||
// 商品规格 0单规格 1多规格
|
||||
specs?: number;
|
||||
// 货架
|
||||
position?: string;
|
||||
// 进货价格
|
||||
price?: number;
|
||||
price?: string;
|
||||
// 销售价格
|
||||
salePrice?: string;
|
||||
// 库存计算方式(10下单减库存 20付款减库存)
|
||||
deductStockType?: number;
|
||||
// 封面图
|
||||
files?: string;
|
||||
// 销量
|
||||
sales?: number;
|
||||
// 库存
|
||||
stock?: number;
|
||||
// 商品重量
|
||||
goodsWeight?: number;
|
||||
// 库存计算方式
|
||||
deductStockType?: number;
|
||||
// 消费赚取积分
|
||||
gainIntegral?: number;
|
||||
// 推荐
|
||||
recommend?: number;
|
||||
// 状态, 0正常, 1待修,2异常已修,3异常未修
|
||||
// 商户ID
|
||||
merchantId?: number;
|
||||
// 商户名称
|
||||
merchantName?: string;
|
||||
// 状态(0:未上架,1:上架)
|
||||
isShow?: number;
|
||||
// 状态, 0上架 1待上架 2待审核 3审核不通过
|
||||
status?: number;
|
||||
// 备注
|
||||
comments?: string;
|
||||
// 排序号
|
||||
sortNumber?: number;
|
||||
// 所有人
|
||||
// 用户ID
|
||||
userId?: number;
|
||||
// 是否删除, 0否, 1是
|
||||
deleted?: number;
|
||||
// 租户id
|
||||
tenantId?: number;
|
||||
// 商户ID
|
||||
merchantId?: number;
|
||||
// 店铺名称
|
||||
merchantName?: string;
|
||||
// 创建时间
|
||||
createTime?: string;
|
||||
// 修改时间
|
||||
updateTime?: string;
|
||||
// 显示规格名
|
||||
specName?: string;
|
||||
// 商品规格
|
||||
goodsSpecs?: GoodsSpec[];
|
||||
// 商品sku列表
|
||||
@@ -89,7 +94,6 @@ export interface BathSet {
|
||||
*/
|
||||
export interface GoodsParam extends PageParam {
|
||||
goodsId?: number;
|
||||
status?: number;
|
||||
isShow?: number;
|
||||
stock?: number;
|
||||
keywords?: string;
|
||||
|
||||
@@ -36,6 +36,7 @@ export interface GoodsSku {
|
||||
tenantId?: number;
|
||||
// 创建时间
|
||||
createTime?: string;
|
||||
images?: any;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,7 +14,7 @@ export interface GoodsSpec {
|
||||
specName?: string;
|
||||
// 规格值
|
||||
valueList?: any[];
|
||||
specValues?: string;
|
||||
specValue?: string;
|
||||
// 活动类型 0=商品,1=秒杀,2=砍价,3=拼团
|
||||
type?: string;
|
||||
// 租户id
|
||||
@@ -26,5 +26,6 @@ export interface GoodsSpec {
|
||||
*/
|
||||
export interface GoodsSpecParam extends PageParam {
|
||||
id?: number;
|
||||
goodsId: number;
|
||||
keywords?: string;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ export interface SpecValue {
|
||||
label?: string;
|
||||
value?: string;
|
||||
detail?: [string];
|
||||
specName?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,6 +35,8 @@ export interface FileRecord {
|
||||
createNickname?: string;
|
||||
// 是否编辑状态
|
||||
isUpdate?: boolean;
|
||||
// 商品SKU索引
|
||||
index?: any;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
};
|
||||
|
||||
const onChange = (item: any, value: ValueType) => {
|
||||
console.log(item,value);
|
||||
emit('done', item, value);
|
||||
};
|
||||
|
||||
|
||||
169
src/components/SelectSpec/components/select-data.vue
Normal file
169
src/components/SelectSpec/components/select-data.vue
Normal file
@@ -0,0 +1,169 @@
|
||||
<template>
|
||||
<ele-modal
|
||||
:width="750"
|
||||
:visible="visible"
|
||||
:maskClosable="false"
|
||||
:title="title"
|
||||
:footer="null"
|
||||
:body-style="{ paddingBottom: '28px' }"
|
||||
@update:visible="updateVisible"
|
||||
>
|
||||
<ele-pro-table
|
||||
ref="tableRef"
|
||||
row-key="specId"
|
||||
:datasource="datasource"
|
||||
:columns="columns"
|
||||
:customRow="customRow"
|
||||
:pagination="false"
|
||||
>
|
||||
<template #toolbar>
|
||||
<a-input-search
|
||||
allow-clear
|
||||
v-model:value="searchText"
|
||||
placeholder="请输入搜索关键词"
|
||||
style="width: 200px"
|
||||
@search="reload"
|
||||
@pressEnter="reload"
|
||||
/>
|
||||
</template>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'image'">
|
||||
<a-image
|
||||
v-if="record.image"
|
||||
:src="record.image"
|
||||
:preview="false"
|
||||
:width="45"
|
||||
/>
|
||||
</template>
|
||||
<template v-if="column.key === 'specValue'">
|
||||
<a-space direction="vertical">
|
||||
<template
|
||||
v-for="(item, index) in JSON.parse(record.specValue)"
|
||||
:key="index"
|
||||
>
|
||||
<div class="text-left">
|
||||
<span class="text-gray-400 mr-2">{{ item.value }} :</span>
|
||||
<ele-tag
|
||||
shape="round"
|
||||
size="small"
|
||||
v-for="(sub, subIndex) in item.detail"
|
||||
:key="subIndex"
|
||||
>
|
||||
{{ sub }}
|
||||
</ele-tag>
|
||||
</div>
|
||||
</template>
|
||||
</a-space>
|
||||
</template>
|
||||
<template v-if="column.key === 'action'">
|
||||
<a-radio @click="onRadio(record)" />
|
||||
</template>
|
||||
</template>
|
||||
</ele-pro-table>
|
||||
</ele-modal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
import {
|
||||
ColumnItem,
|
||||
DatasourceFunction
|
||||
} from 'ele-admin-pro/es/ele-pro-table/types';
|
||||
import { pageSpec } from '@/api/shop/spec';
|
||||
import { EleProTable } from 'ele-admin-pro';
|
||||
import { Spec, SpecParam } from '@/api/shop/spec/model';
|
||||
|
||||
const props = defineProps<{
|
||||
// 弹窗是否打开
|
||||
visible: boolean;
|
||||
// 标题
|
||||
title?: string;
|
||||
// 商户类型
|
||||
shopType?: string;
|
||||
// 修改回显的数据
|
||||
data?: Spec | null;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'done', data: Spec): void;
|
||||
(e: 'update:visible', visible: boolean): void;
|
||||
}>();
|
||||
|
||||
/* 更新visible */
|
||||
const updateVisible = (value: boolean) => {
|
||||
emit('update:visible', value);
|
||||
};
|
||||
|
||||
// 搜索内容
|
||||
const searchText = ref(null);
|
||||
|
||||
// 表格实例
|
||||
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
|
||||
|
||||
// 表格配置
|
||||
const columns = ref<ColumnItem[]>([
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
title: '规格',
|
||||
dataIndex: 'specName',
|
||||
key: 'specName',
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
title: '规格值',
|
||||
dataIndex: 'specValue',
|
||||
key: 'specValue'
|
||||
}
|
||||
]);
|
||||
|
||||
// 表格数据源
|
||||
const datasource: DatasourceFunction = ({ page, limit, where, orders }) => {
|
||||
where = {};
|
||||
// 搜索条件
|
||||
if (searchText.value) {
|
||||
where.keywords = searchText.value;
|
||||
}
|
||||
if (props.shopType == 'empty') {
|
||||
where.emptyType = true;
|
||||
} else {
|
||||
where.shopType = props.shopType;
|
||||
}
|
||||
return pageSpec({
|
||||
...where,
|
||||
...orders,
|
||||
page,
|
||||
limit
|
||||
});
|
||||
};
|
||||
|
||||
/* 搜索 */
|
||||
const reload = (where?: SpecParam) => {
|
||||
tableRef?.value?.reload({ page: 1, where });
|
||||
};
|
||||
|
||||
const onRadio = (record: Spec) => {
|
||||
updateVisible(false);
|
||||
emit('done', record);
|
||||
};
|
||||
|
||||
/* 自定义行属性 */
|
||||
const customRow = (record: Spec) => {
|
||||
return {
|
||||
// 行点击事件
|
||||
// onClick: () => {
|
||||
// updateVisible(false);
|
||||
// emit('done', record);
|
||||
// },
|
||||
// 行双击事件
|
||||
onDblclick: () => {
|
||||
updateVisible(false);
|
||||
emit('done', record);
|
||||
}
|
||||
};
|
||||
};
|
||||
</script>
|
||||
<style lang="less"></style>
|
||||
@@ -1,58 +1,61 @@
|
||||
<!-- 选择下拉框 -->
|
||||
<template>
|
||||
<a-select
|
||||
:allow-clear="allowClear"
|
||||
:show-search="showSearch"
|
||||
optionFilterProp="label"
|
||||
:options="specDict"
|
||||
:value="value"
|
||||
:placeholder="placeholder"
|
||||
@update:value="updateValue"
|
||||
:style="`width: ${width}px`"
|
||||
@blur="onBlur"
|
||||
@change="onChange"
|
||||
/>
|
||||
<div>
|
||||
<a-input-group compact>
|
||||
<a-input
|
||||
disabled
|
||||
style="width: calc(100% - 32px)"
|
||||
v-model:value="value"
|
||||
:placeholder="placeholder"
|
||||
/>
|
||||
<a-button @click="openEdit">
|
||||
<template #icon><BulbOutlined class="ele-text-warning" /></template>
|
||||
</a-button>
|
||||
</a-input-group>
|
||||
<!-- 选择弹窗 -->
|
||||
<SelectData
|
||||
v-model:visible="showEdit"
|
||||
:data="current"
|
||||
:title="placeholder"
|
||||
:customer-type="customerType"
|
||||
@done="onChange"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { BulbOutlined } from '@ant-design/icons-vue';
|
||||
import { ref } from 'vue';
|
||||
import SelectData from './components/select-data.vue';
|
||||
import { Spec } from '@/api/shop/spec/model';
|
||||
|
||||
const props = withDefaults(
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
value?: string;
|
||||
value?: any;
|
||||
customerType?: string;
|
||||
placeholder?: string;
|
||||
showSearch?: string;
|
||||
allowClear?: boolean;
|
||||
width?: number;
|
||||
specDict?: Spec[];
|
||||
index?: number;
|
||||
}>(),
|
||||
{
|
||||
placeholder: '请选择服务器厂商'
|
||||
placeholder: '请选择商户'
|
||||
}
|
||||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:value', value: string): void;
|
||||
(e: 'blur'): void;
|
||||
(e: 'done', value: Spec, index: number): void;
|
||||
(e: 'done', Merchant): void;
|
||||
(e: 'clear'): void;
|
||||
}>();
|
||||
|
||||
/* 更新选中数据 */
|
||||
const updateValue = (value: string) => {
|
||||
emit('update:value', value);
|
||||
// 是否显示编辑弹窗
|
||||
const showEdit = ref(false);
|
||||
// 当前编辑数据
|
||||
const current = ref<Spec | null>(null);
|
||||
|
||||
/* 打开编辑弹窗 */
|
||||
const openEdit = (row?: Spec) => {
|
||||
current.value = row ?? null;
|
||||
showEdit.value = true;
|
||||
};
|
||||
|
||||
/* 失去焦点 */
|
||||
const onBlur = () => {
|
||||
emit('blur');
|
||||
};
|
||||
|
||||
const onChange = (value: string) => {
|
||||
props.specDict?.map((d) => {
|
||||
if (d.value == value) {
|
||||
emit('done', d, Number(props.index));
|
||||
}
|
||||
});
|
||||
const onChange = (row) => {
|
||||
emit('done', row);
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -792,7 +792,7 @@
|
||||
specId: d.specId,
|
||||
name: d.specName,
|
||||
value: d.specName,
|
||||
list: d.specValues?.map(v => {
|
||||
list: d.specValue?.map(v => {
|
||||
return {
|
||||
specId: v.specId,
|
||||
specValueId: v.specValueId,
|
||||
|
||||
1046
src/views/shop/goods/add/index.vue
Normal file
1046
src/views/shop/goods/add/index.vue
Normal file
File diff suppressed because it is too large
Load Diff
765
src/views/shop/goods/components/goodsEdit.vue
Normal file
765
src/views/shop/goods/components/goodsEdit.vue
Normal file
@@ -0,0 +1,765 @@
|
||||
<!-- 编辑弹窗 -->
|
||||
<template>
|
||||
<ele-modal
|
||||
:width="900"
|
||||
:visible="visible"
|
||||
:maskClosable="false"
|
||||
:maxable="maxable"
|
||||
:title="isUpdate ? '编辑商品' : '添加商品'"
|
||||
:body-style="{ paddingBottom: '28px' }"
|
||||
@update:visible="updateVisible"
|
||||
@ok="save"
|
||||
>
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="form"
|
||||
:rules="rules"
|
||||
:label-col="styleResponsive ? { md: 3, sm: 5, xs: 24 } : { flex: '90px' }"
|
||||
:wrapper-col="
|
||||
styleResponsive ? { md: 24, sm: 24, xs: 24 } : { flex: '1' }
|
||||
"
|
||||
>
|
||||
<a-tabs type="card" v-model:active-key="active" @change="onChange">
|
||||
<a-tab-pane tab="基本信息" key="base">
|
||||
<a-form-item label="商品类型" name="type">
|
||||
<a-space>
|
||||
<a-button
|
||||
:type="form.type == 1 ? 'primary' : ''"
|
||||
@click="onType(1)"
|
||||
:ghost="form.type == 1"
|
||||
>实物商品</a-button
|
||||
>
|
||||
<a-button
|
||||
:type="form.type == 2 ? 'primary' : ''"
|
||||
@click="onType(2)"
|
||||
:ghost="form.type == 2"
|
||||
>虚拟商品</a-button
|
||||
>
|
||||
</a-space>
|
||||
<div class="ele-text-placeholder">
|
||||
{{
|
||||
form.type == 1
|
||||
? `支持快递邮寄、同城配送或到店自提方式发货`
|
||||
: '电子券码等,线下到店核销,无需备货'
|
||||
}}
|
||||
</div>
|
||||
</a-form-item>
|
||||
<a-form-item
|
||||
label="选择店铺"
|
||||
name="merchantId"
|
||||
>
|
||||
<SelectMerchant
|
||||
:placeholder="`选择商户`"
|
||||
class="input-item"
|
||||
style="width: 558px"
|
||||
v-model:value="form.merchantName"
|
||||
@done="chooseMerchantId"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="商品名称" name="goodsName">
|
||||
<a-input
|
||||
allow-clear
|
||||
style="width: 558px"
|
||||
placeholder="请输入商品名称"
|
||||
v-model:value="form.goodsName"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="商品分类" name="categoryId">
|
||||
<SelectGoodsCategory
|
||||
:data="data"
|
||||
placeholder="请选择商品分类"
|
||||
style="width: 558px"
|
||||
v-model:value="category"
|
||||
@done="chooseGoodsCategory"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="商品卖点" name="comments">
|
||||
<a-input
|
||||
allow-clear
|
||||
:maxlength="60"
|
||||
style="width: 558px"
|
||||
placeholder="此款商品美观大方 性价比较高 不容错过"
|
||||
v-model:value="form.comments"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="单位名称" name="unitName">
|
||||
<a-input
|
||||
allow-clear
|
||||
style="width: 558px"
|
||||
placeholder="单位名称,如(个)"
|
||||
v-model:value="form.unitName"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="商品价格" name="price">
|
||||
<a-input-number
|
||||
:placeholder="`商品价格`"
|
||||
style="width: 240px"
|
||||
v-model:value="form.price"
|
||||
/>
|
||||
<div class="ele-text-placeholder">商品的实际购买金额,最低0.01</div>
|
||||
</a-form-item>
|
||||
<a-form-item label="市场价" name="salePrice">
|
||||
<a-input-number
|
||||
:placeholder="`市场价`"
|
||||
style="width: 240px"
|
||||
v-model:value="form.salePrice"
|
||||
/>
|
||||
<div class="ele-text-placeholder">划线价仅用于商品页展示</div>
|
||||
</a-form-item>
|
||||
<a-form-item label="当前库存" name="stock">
|
||||
<a-input-number
|
||||
:placeholder="`商品库存`"
|
||||
style="width: 240px"
|
||||
v-model:value="form.stock"
|
||||
/>
|
||||
<div class="ele-text-placeholder">划线价仅用于商品页展示</div>
|
||||
</a-form-item>
|
||||
<a-form-item label="商品图片" name="image">
|
||||
<SelectFile
|
||||
:placeholder="`请选择视频文件`"
|
||||
:limit="1"
|
||||
:data="images"
|
||||
@done="chooseImage"
|
||||
@del="onDeleteItem"
|
||||
/>
|
||||
<div class="ele-text-placeholder"
|
||||
>支持上传视频(mp4格式),视频时长不超过60秒,视频大小不超过200M。</div
|
||||
>
|
||||
</a-form-item>
|
||||
<a-form-item label="轮播图" name="files">
|
||||
<SelectFile
|
||||
:placeholder="`请选择视频文件`"
|
||||
:limit="9"
|
||||
:data="files"
|
||||
@done="chooseFile"
|
||||
@del="onDeleteFile"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="状态" name="isShow">
|
||||
<a-radio-group v-model:value="form.isShow">
|
||||
<a-radio :value="1">上架</a-radio>
|
||||
<a-radio :value="0">下架</a-radio>
|
||||
</a-radio-group>
|
||||
</a-form-item>
|
||||
</a-tab-pane>
|
||||
<a-tab-pane tab="商品规格" key="spec">
|
||||
<a-form-item label="规格类型" name="specs">
|
||||
<a-radio-group v-model:value="form.specs">
|
||||
<a-radio :value="0">单规格</a-radio>
|
||||
<a-radio :value="1">多规格</a-radio>
|
||||
</a-radio-group>
|
||||
|
||||
</a-form-item>
|
||||
<a-form-item name="multipleSpec" v-if="form.specs == 1">
|
||||
<div class="w-[300px] ml-10">
|
||||
<SelectSpec
|
||||
placeholder="选择规格"
|
||||
:width="130"
|
||||
v-model:value="form.specName"
|
||||
@done="onSpec"
|
||||
/>
|
||||
</div>
|
||||
</a-form-item>
|
||||
<a-form-item name="specValue" v-if="form.specs == 1">
|
||||
<a-space direction="vertical" class="ml-[40px]">
|
||||
<template v-for="(item, index) in spec" :key="index">
|
||||
<div class="text-left flex items-center leading-10 text-gray-400">
|
||||
<div class="mr-2">{{ item.value }} :</div>
|
||||
<CloseCircleOutlined
|
||||
class="cursor-pointer"
|
||||
@click="onClose(index)"
|
||||
/>
|
||||
</div>
|
||||
<ele-edit-tag
|
||||
v-model:data="item.detail"
|
||||
size="middle"
|
||||
shape="round"
|
||||
/>
|
||||
</template>
|
||||
<a-card class="ml-[40px]" v-if="showSpecForm">
|
||||
<a-form-item name="name">
|
||||
<a-input
|
||||
allow-clear
|
||||
placeholder="请输入规格"
|
||||
v-model:value="name"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item name="value">
|
||||
<a-input
|
||||
allow-clear
|
||||
placeholder="请输入规格值"
|
||||
v-model:value="value"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-space>
|
||||
<a-button type="primary" @click="addSpecValue">确定</a-button>
|
||||
<a-button @click="openSpecForm">取消</a-button>
|
||||
</a-space>
|
||||
</a-card>
|
||||
<a-space v-if="spec.length > 0">
|
||||
<a-button type="primary" class="mt-5" @click="openSpecForm"
|
||||
>添加新规格</a-button
|
||||
>
|
||||
<a-button type="primary" class="mt-5" @click="generateSku"
|
||||
>生成SKU</a-button
|
||||
>
|
||||
</a-space>
|
||||
</a-space>
|
||||
</a-form-item>
|
||||
<a-form-item name="oneSpec">
|
||||
<div class="w-full">
|
||||
<div class="sku-table">
|
||||
<a-table
|
||||
:pagination="false"
|
||||
:dataSource="skuList"
|
||||
:columns="columns"
|
||||
:scroll="{ y: 500 }"
|
||||
>
|
||||
<template #bodyCell="{ record, column, index }">
|
||||
<template v-if="column.key === 'line'">
|
||||
{{ index + 1 }}
|
||||
</template>
|
||||
<template v-if="column.key === 'image'">
|
||||
<SelectFile
|
||||
:placeholder="`请选择商品图片`"
|
||||
:limit="1"
|
||||
:data="record.images || []"
|
||||
:index="index"
|
||||
@done="chooseSkuImage"
|
||||
@del="onDeleteSkuItem"
|
||||
/>
|
||||
</template>
|
||||
<template v-if="column.key === 'price'">
|
||||
<a-input :placeholder="`成本价`" v-model:value="skuList[index].price" />
|
||||
</template>
|
||||
<template v-if="column.key === 'salePrice'">
|
||||
<a-input :placeholder="`售价`" v-model:value="record.salePrice" />
|
||||
</template>
|
||||
<template v-if="column.key === 'stock'">
|
||||
<a-input :placeholder="`库存`" v-model:value="record.stock" />
|
||||
</template>
|
||||
<template v-if="column.key === 'skuNo'">
|
||||
<a-input :placeholder="`编码`" v-model:value="record.skuNo" />
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
</div>
|
||||
</div>
|
||||
</a-form-item>
|
||||
</a-tab-pane>
|
||||
<a-tab-pane tab="商品详情" key="content">
|
||||
<a-form-item name="content">
|
||||
<!-- 编辑器 -->
|
||||
<tinymce-editor
|
||||
ref="editorRef"
|
||||
class="content"
|
||||
v-model:value="content"
|
||||
:disabled="disabled"
|
||||
:init="config"
|
||||
placeholder="图片直接粘贴自动上传"
|
||||
@paste="onPaste"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-tab-pane>
|
||||
<a-tab-pane tab="营销设置" key="coupon">
|
||||
<a-form-item label="货架" name="position">
|
||||
<a-input
|
||||
allow-clear
|
||||
style="width: 250px"
|
||||
placeholder="请输入货架"
|
||||
v-model:value="form.position"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="商品重量" name="goodsWeight">
|
||||
<a-input
|
||||
allow-clear
|
||||
style="width: 250px"
|
||||
placeholder="请输入商品重量"
|
||||
v-model:value="form.goodsWeight"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="销量" name="sales">
|
||||
<a-input-number
|
||||
allow-clear
|
||||
style="width: 250px"
|
||||
placeholder="请输入销量"
|
||||
v-model:value="form.sales"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="获取积分" name="gainIntegral">
|
||||
<a-input-number
|
||||
:placeholder="`消费获取的积分`"
|
||||
style="width: 250px"
|
||||
v-model:value="form.gainIntegral"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="库存计算方式" name="deductStockType">
|
||||
<a-radio-group v-model:value="form.deductStockType">
|
||||
<a-radio :value="20">付款减库存</a-radio>
|
||||
<a-radio :value="10">下单减库存</a-radio>
|
||||
</a-radio-group>
|
||||
</a-form-item>
|
||||
<a-form-item label="排序号" name="sortNumber">
|
||||
<a-input-number
|
||||
:min="0"
|
||||
:max="9999"
|
||||
style="width: 250px"
|
||||
placeholder="请输入排序号"
|
||||
v-model:value="form.sortNumber"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-tab-pane>
|
||||
</a-tabs>
|
||||
</a-form>
|
||||
</ele-modal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { CloseCircleOutlined } from '@ant-design/icons-vue';
|
||||
import { ref, reactive, watch } from 'vue';
|
||||
import { Form, message } from 'ant-design-vue';
|
||||
import { assignObject, uuid } from 'ele-admin-pro';
|
||||
import { addGoods, getGoods, updateGoods } from "@/api/shop/goods";
|
||||
import { Goods } from '@/api/shop/goods/model';
|
||||
import { useThemeStore } from '@/store/modules/theme';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { ItemType } from 'ele-admin-pro/es/ele-image-upload/types';
|
||||
import { FormInstance, RuleObject } from 'ant-design-vue/es/form';
|
||||
import { FileRecord } from '@/api/system/file/model';
|
||||
import { Merchant } from '@/api/shop/merchant/model';
|
||||
import TinymceEditor from '@/components/TinymceEditor/index.vue';
|
||||
import { uploadFile, uploadOss } from "@/api/system/file";
|
||||
import { SpecValue } from "@/api/shop/specValue/model";
|
||||
import { Spec } from "@/api/shop/spec/model";
|
||||
import {ColumnItem} from "ele-admin-pro/es/ele-pro-table/types";
|
||||
import { GoodsSku } from "@/api/shop/goodsSku/model";
|
||||
import { GoodsSpec } from "@/api/shop/goodsSpec/model";
|
||||
import { getGoodsSpec, pageGoodsSpec } from "@/api/shop/goodsSpec";
|
||||
import { openUrl } from "@/utils/common";
|
||||
|
||||
// 是否是修改
|
||||
const isUpdate = ref(false);
|
||||
const useForm = Form.useForm;
|
||||
// 是否开启响应式布局
|
||||
const themeStore = useThemeStore();
|
||||
const { styleResponsive } = storeToRefs(themeStore);
|
||||
|
||||
const props = defineProps<{
|
||||
// 弹窗是否打开
|
||||
visible: boolean;
|
||||
// 修改回显的数据
|
||||
data?: Goods | null;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'done'): void;
|
||||
(e: 'update:visible', visible: boolean): void;
|
||||
}>();
|
||||
|
||||
// 提交状态
|
||||
const loading = ref(false);
|
||||
// 是否显示最大化切换按钮
|
||||
const maxable = ref(true);
|
||||
// 表格选中数据
|
||||
const formRef = ref<FormInstance | null>(null);
|
||||
const images = ref<ItemType[]>([]);
|
||||
const content = ref('');
|
||||
const disabled = ref(false);
|
||||
// 当前选项卡
|
||||
const active = ref('spec');
|
||||
|
||||
const spec = ref<SpecValue[]>([]);
|
||||
const showSpecForm = ref(false);
|
||||
const name = ref();
|
||||
const value = ref();
|
||||
const skuList = ref<GoodsSku[]>([{images: []}]);
|
||||
const fileList = ref<any[]>([]);
|
||||
const files = ref<ItemType[]>([]);
|
||||
const goodsSpec = ref<GoodsSpec>();
|
||||
const category = ref<string[]>([]);
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: '图片',
|
||||
dataIndex: 'image',
|
||||
key: 'image',
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
title: '售价',
|
||||
dataIndex: 'salePrice',
|
||||
key: 'salePrice',
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: '成本价',
|
||||
dataIndex: 'price',
|
||||
key: 'price',
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: '库存',
|
||||
dataIndex: 'stock',
|
||||
key: 'stock',
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: '商品编号',
|
||||
dataIndex: 'skuNo',
|
||||
key: 'skuNo',
|
||||
align: 'center',
|
||||
},
|
||||
];
|
||||
|
||||
// 用户信息
|
||||
const form = reactive<Goods>({
|
||||
goodsId: undefined,
|
||||
type: 1,
|
||||
code: undefined,
|
||||
goodsName: undefined,
|
||||
image: undefined,
|
||||
content: undefined,
|
||||
categoryId: undefined,
|
||||
categoryParent: undefined,
|
||||
categoryChildren: undefined,
|
||||
specs: 0,
|
||||
position: undefined,
|
||||
price: undefined,
|
||||
salePrice: undefined,
|
||||
files: undefined,
|
||||
sales: 0,
|
||||
gainIntegral: 0,
|
||||
goodsWeight: undefined,
|
||||
recommend: undefined,
|
||||
merchantId: undefined,
|
||||
merchantName: undefined,
|
||||
stock: 1000,
|
||||
deductStockType: 20,
|
||||
isShow: 1,
|
||||
status: 0,
|
||||
comments: '',
|
||||
sortNumber: 100,
|
||||
specName: ''
|
||||
});
|
||||
|
||||
/* 更新visible */
|
||||
const updateVisible = (value: boolean) => {
|
||||
emit('update:visible', value);
|
||||
};
|
||||
|
||||
// 表单验证规则
|
||||
const rules = reactive({
|
||||
type: [
|
||||
{
|
||||
required: true,
|
||||
message: '请选择商品类型',
|
||||
type: 'number',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
image: [
|
||||
{
|
||||
required: true,
|
||||
message: '请上传图片',
|
||||
type: 'string',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
files: [
|
||||
{
|
||||
required: true,
|
||||
message: '请上传图片',
|
||||
type: 'string',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
specs: [
|
||||
{
|
||||
required: true,
|
||||
message: '请选择规格类型',
|
||||
type: 'number',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
price: [
|
||||
{
|
||||
required: true,
|
||||
message: '请填写商品价格',
|
||||
type: 'number',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
stock: [
|
||||
{
|
||||
required: true,
|
||||
message: '请填写商品库存',
|
||||
type: 'number',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
merchantId: [
|
||||
{
|
||||
required: true,
|
||||
message: '请选择店铺',
|
||||
type: 'number',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
categoryId: [
|
||||
{
|
||||
required: true,
|
||||
type: 'string',
|
||||
message: '选择商品分类',
|
||||
trigger: 'blur',
|
||||
validator: async (_rule: RuleObject, value: string) => {
|
||||
if (!form.categoryId) {
|
||||
return Promise.reject('选择商品分类');
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
],
|
||||
goodsName: [
|
||||
{
|
||||
required: true,
|
||||
message: '请选择商品名称',
|
||||
type: 'string',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
sortNumber: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入排序号',
|
||||
type: 'number',
|
||||
trigger: 'blur'
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
const onType = (index: number) => {
|
||||
form.type = index;
|
||||
};
|
||||
|
||||
/* 搜索 */
|
||||
const chooseMerchantId = (item: Merchant) => {
|
||||
form.merchantName = item.merchantName;
|
||||
form.merchantId = item.merchantId;
|
||||
};
|
||||
|
||||
const chooseGoodsCategory = (item,value) => {
|
||||
form.categoryId = value[1].value;
|
||||
form.categoryParent = value[0].label;
|
||||
form.categoryChildren = value[1].label;
|
||||
}
|
||||
|
||||
const chooseImage = (data: FileRecord) => {
|
||||
images.value.push({
|
||||
uid: data.id,
|
||||
url: data.path,
|
||||
status: 'done'
|
||||
});
|
||||
form.image = data.path;
|
||||
};
|
||||
|
||||
const chooseSkuImage = (data: FileRecord) => {
|
||||
const index = data?.index;
|
||||
skuList.value[index].images?.push({
|
||||
uid: uuid(),
|
||||
url: data.path,
|
||||
status: 'done'
|
||||
});
|
||||
skuList.value[index].image = data.path;
|
||||
}
|
||||
|
||||
const onDeleteSkuItem = (index: number) => {
|
||||
images.value.splice(index, 1);
|
||||
};
|
||||
|
||||
const onChange = () => {
|
||||
// reload();
|
||||
};
|
||||
|
||||
|
||||
const onDeleteItem = (index: number) => {
|
||||
images.value.splice(index, 1);
|
||||
form.image = '';
|
||||
};
|
||||
|
||||
const onClose = (index) => {
|
||||
spec.value.splice(index, 1);
|
||||
};
|
||||
|
||||
const openSpecForm = () => {
|
||||
showSpecForm.value = !showSpecForm.value;
|
||||
};
|
||||
|
||||
const onSpec = (row: Spec) => {
|
||||
form.specName = row.specName;
|
||||
goodsSpec.value = row;
|
||||
if(row.specValue){
|
||||
spec.value = JSON.parse(row?.specValue);
|
||||
}
|
||||
}
|
||||
|
||||
// 新增规格
|
||||
const addSpecValue = () => {
|
||||
if (!name.value || !value.value) {
|
||||
message.error(`请输入规格和规格值`);
|
||||
return false;
|
||||
}
|
||||
const findIndex = spec.value.findIndex((d) => d.value == name.value);
|
||||
if (findIndex == 0) {
|
||||
message.error(`${name.value}已存在)`);
|
||||
return false;
|
||||
}
|
||||
spec.value.push({
|
||||
value: name.value,
|
||||
detail: [value.value]
|
||||
});
|
||||
name.value = '';
|
||||
value.value = '';
|
||||
openSpecForm();
|
||||
};
|
||||
|
||||
const chooseFile = (data: FileRecord) => {
|
||||
files.value.push({
|
||||
uid: data.id,
|
||||
url: data.path,
|
||||
status: 'done'
|
||||
});
|
||||
};
|
||||
|
||||
const onDeleteFile = (index: number) => {
|
||||
files.value.splice(index, 1);
|
||||
};
|
||||
|
||||
|
||||
const editorRef = ref<InstanceType<typeof TinymceEditor> | null>(null);
|
||||
const config = ref({
|
||||
height: 240,
|
||||
plugins: 'code preview fullscreen searchreplace save autosave link autolink image media table codesample lists advlist charmap emoticons anchor directionality pagebreak quickbars nonbreaking visualblocks visualchars wordcount',
|
||||
toolbar: false,
|
||||
images_upload_handler: (blobInfo, success, error) => {
|
||||
const file = blobInfo.blob();
|
||||
const formData = new FormData();
|
||||
formData.append('file', file, file.name);
|
||||
uploadOss(file).then(res => {
|
||||
success(res.path)
|
||||
}).catch((msg) => {
|
||||
error(msg);
|
||||
})
|
||||
},
|
||||
});
|
||||
|
||||
/* 粘贴图片上传服务器并插入编辑器 */
|
||||
const onPaste = (e) => {
|
||||
const items = (e.clipboardData || e.originalEvent.clipboardData).items;
|
||||
let hasFile = false;
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
if (items[i].type.indexOf('image') !== -1) {
|
||||
let file = items[i].getAsFile();
|
||||
const item: ItemType = {
|
||||
file,
|
||||
uid: (file as any).lastModified,
|
||||
name: file.name
|
||||
};
|
||||
uploadFile(<File>item.file)
|
||||
.then((result) => {
|
||||
const addPath = `<p><img class="content-img" src="${result.url}"></p>`;
|
||||
content.value = content.value + addPath
|
||||
})
|
||||
.catch((e) => {
|
||||
message.error(e.message);
|
||||
});
|
||||
hasFile = true;
|
||||
}
|
||||
}
|
||||
if (hasFile) {
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
const { resetFields } = useForm(form, rules);
|
||||
|
||||
/* 保存编辑 */
|
||||
const save = () => {
|
||||
if (!formRef.value) {
|
||||
return;
|
||||
}
|
||||
formRef.value
|
||||
.validate()
|
||||
.then(() => {
|
||||
loading.value = true;
|
||||
files.value.map((d) => {
|
||||
fileList.value.push(d.url);
|
||||
});
|
||||
const formData = {
|
||||
...form,
|
||||
content: content.value,
|
||||
files: JSON.stringify(fileList.value),
|
||||
goodsSpecs: goodsSpec.value,
|
||||
goodsSkus: skuList.value
|
||||
};
|
||||
const saveOrUpdate = isUpdate.value ? updateGoods : addGoods;
|
||||
saveOrUpdate(formData)
|
||||
.then((msg) => {
|
||||
loading.value = false;
|
||||
message.success(msg);
|
||||
updateVisible(false);
|
||||
emit('done');
|
||||
})
|
||||
.catch((e) => {
|
||||
loading.value = false;
|
||||
message.error(e.message);
|
||||
});
|
||||
})
|
||||
.catch(() => {});
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.visible,
|
||||
(visible) => {
|
||||
if (visible) {
|
||||
images.value = [];
|
||||
if (props.data) {
|
||||
assignObject(form, props.data);
|
||||
if (props.data.image) {
|
||||
images.value.push({
|
||||
uid: uuid(),
|
||||
url: props.data.image,
|
||||
status: 'done'
|
||||
});
|
||||
}
|
||||
if(props.data.goodsSpecs){
|
||||
goodsSpec.value = props.data.goodsSpecs[0];
|
||||
if(props.data.specs == 1){
|
||||
form.specName = props.data.goodsSpecs[0].specName;
|
||||
}
|
||||
}
|
||||
if(props.data.goodsSkus){
|
||||
skuList.value = props.data.goodsSkus.map(d => {
|
||||
d.images = [];
|
||||
d.images.push({
|
||||
uid: uuid(),
|
||||
url: d.image,
|
||||
status: 'done'
|
||||
})
|
||||
return d;
|
||||
});
|
||||
}
|
||||
|
||||
isUpdate.value = true;
|
||||
} else {
|
||||
spec.value = [];
|
||||
goodsSpec.value = {};
|
||||
skuList.value = [];
|
||||
isUpdate.value = false;
|
||||
}
|
||||
} else {
|
||||
resetFields();
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
</script>
|
||||
145
src/views/shop/goods/components/search.vue
Normal file
145
src/views/shop/goods/components/search.vue
Normal file
@@ -0,0 +1,145 @@
|
||||
<!-- 搜索表单 -->
|
||||
<template>
|
||||
<a-space :size="10" style="flex-wrap: wrap">
|
||||
<a-button type="primary" class="ele-btn-icon" @click="add">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
<span>添加</span>
|
||||
</a-button>
|
||||
<a-radio-group v-model:value="type" @change="handleSearch">
|
||||
<a-radio-button value="出售中"
|
||||
>出售中({{ goodsCount?.totalNum }})</a-radio-button
|
||||
>
|
||||
<a-radio-button value="待上架"
|
||||
>待上架({{ goodsCount?.totalNum2 }})</a-radio-button
|
||||
>
|
||||
<a-radio-button value="已售罄"
|
||||
>已售罄({{ goodsCount?.totalNum3 }})</a-radio-button
|
||||
>
|
||||
</a-radio-group>
|
||||
<SelectMerchant
|
||||
:placeholder="`选择商户`"
|
||||
class="input-item"
|
||||
v-model:value="where.merchantName"
|
||||
@done="chooseMerchantId"
|
||||
/>
|
||||
<SelectGoodsCategory
|
||||
class="input-item"
|
||||
:placeholder="`请选择商品分类`"
|
||||
v-model:value="where.categoryId"
|
||||
@done="chooseGoodsCategory"
|
||||
/>
|
||||
<a-input-search
|
||||
allow-clear
|
||||
placeholder="请输入关键词"
|
||||
v-model:value="where.keywords"
|
||||
@pressEnter="reload"
|
||||
@search="reload"
|
||||
/>
|
||||
<a-button @click="reset">重置</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { PlusOutlined } from '@ant-design/icons-vue';
|
||||
import type { GradeParam } from '@/api/user/grade/model';
|
||||
import { ref, watch } from 'vue';
|
||||
import { getCount } from '@/api/shop/goods';
|
||||
import type { GoodsCount, GoodsParam } from '@/api/shop/goods/model';
|
||||
import useSearch from '@/utils/use-search';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { Merchant } from '@/api/shop/merchant/model';
|
||||
import { GoodsCategory } from '@/api/shop/goodsCategory/model';
|
||||
const { currentRoute } = useRouter();
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
// 选中的角色
|
||||
selection?: [];
|
||||
}>(),
|
||||
{}
|
||||
);
|
||||
|
||||
const type = ref<string>();
|
||||
// 统计数据
|
||||
const goodsCount = ref<GoodsCount>();
|
||||
|
||||
// 表单数据
|
||||
const { where, resetFields } = useSearch<GoodsParam>({
|
||||
goodsId: undefined,
|
||||
isShow: undefined,
|
||||
stock: undefined,
|
||||
categoryId: undefined,
|
||||
keywords: ''
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'search', where?: GradeParam): void;
|
||||
(e: 'add'): void;
|
||||
(e: 'remove'): void;
|
||||
(e: 'batchMove'): void;
|
||||
}>();
|
||||
|
||||
// 新增
|
||||
const add = () => {
|
||||
emit('add');
|
||||
};
|
||||
|
||||
const handleSearch = (e) => {
|
||||
const text = e.target.value;
|
||||
resetFields();
|
||||
if (text === '出售中') {
|
||||
where.isShow = 1;
|
||||
}
|
||||
if (text === '待上架') {
|
||||
where.isShow = 0;
|
||||
}
|
||||
if (text === '已售罄') {
|
||||
where.stock = 0;
|
||||
}
|
||||
emit('search', where);
|
||||
};
|
||||
|
||||
const reload = () => {
|
||||
getCount().then((data: any) => {
|
||||
goodsCount.value = data;
|
||||
});
|
||||
emit('search', where);
|
||||
};
|
||||
|
||||
/* 搜索 */
|
||||
const chooseMerchantId = (item: Merchant) => {
|
||||
where.merchantName = item.merchantName;
|
||||
where.merchantId = item.merchantId;
|
||||
reload();
|
||||
};
|
||||
|
||||
const chooseGoodsCategory = (
|
||||
category: GoodsCategory,
|
||||
data: GoodsCategory
|
||||
) => {
|
||||
where.categoryName = data[1].label;
|
||||
where.categoryId = data[1].value;
|
||||
reload();
|
||||
};
|
||||
|
||||
/* 重置 */
|
||||
const reset = () => {
|
||||
resetFields();
|
||||
type.value = '';
|
||||
reload();
|
||||
};
|
||||
|
||||
// watch(
|
||||
// () => props.selection,
|
||||
// () => {}
|
||||
// );
|
||||
watch(
|
||||
currentRoute,
|
||||
() => {
|
||||
reload();
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
</script>
|
||||
392
src/views/shop/goods/index.vue
Normal file
392
src/views/shop/goods/index.vue
Normal file
@@ -0,0 +1,392 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<div class="ele-body">
|
||||
<a-card :bordered="false" :body-style="{ padding: '16px' }">
|
||||
<ele-pro-table
|
||||
ref="tableRef"
|
||||
row-key="goodsId"
|
||||
:columns="columns"
|
||||
:datasource="datasource"
|
||||
:customRow="customRow"
|
||||
:scroll="{ x: 1200 }"
|
||||
tool-class="ele-toolbar-form"
|
||||
class="sys-org-table"
|
||||
>
|
||||
<template #toolbar>
|
||||
<search
|
||||
@search="reload"
|
||||
:selection="selection"
|
||||
@add="openEdit"
|
||||
@remove="removeBatch"
|
||||
@batchMove="openMove"
|
||||
/>
|
||||
</template>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'type'">
|
||||
<a-tag v-if="record.type === 0">虚拟商品</a-tag>
|
||||
<a-tag v-if="record.type === 1">实物商品</a-tag>
|
||||
</template>
|
||||
<template v-if="column.key === 'image'">
|
||||
<a-image :src="record.image" :width="80" />
|
||||
</template>
|
||||
<template v-if="column.key === 'salePrice'">
|
||||
¥{{ formatNumber(record.salePrice) }}
|
||||
</template>
|
||||
<template v-if="column.key === 'isShow'">
|
||||
<a-tag
|
||||
v-if="record.isShow === 1"
|
||||
color="green"
|
||||
class="cursor-pointer"
|
||||
@click="onUpdate(record)"
|
||||
>出售中</a-tag
|
||||
>
|
||||
<a-tag
|
||||
v-if="record.isShow === 0"
|
||||
color="red"
|
||||
class="cursor-pointer"
|
||||
@click="onUpdate(record)"
|
||||
>已下架</a-tag
|
||||
>
|
||||
</template>
|
||||
<template v-if="column.key === 'status'">
|
||||
<a-tag v-if="record.status === 0" color="green">显示</a-tag>
|
||||
<a-tag v-if="record.status === 1" color="red">隐藏</a-tag>
|
||||
</template>
|
||||
<template v-if="column.key === 'action'">
|
||||
<a-space>
|
||||
<a @click="openEdit(record)">修改</a>
|
||||
<a-divider type="vertical" />
|
||||
<a-popconfirm
|
||||
title="确定要删除此记录吗?"
|
||||
@confirm="remove(record)"
|
||||
>
|
||||
<a class="ele-text-danger">删除</a>
|
||||
</a-popconfirm>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</ele-pro-table>
|
||||
</a-card>
|
||||
|
||||
<!-- 编辑弹窗 -->
|
||||
<GoodsEdit v-model:visible="showEdit" :data="current" @done="reload" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { createVNode, ref } from 'vue';
|
||||
import { message, Modal } from 'ant-design-vue';
|
||||
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
|
||||
import type { EleProTable } from 'ele-admin-pro';
|
||||
import { toDateString } from 'ele-admin-pro';
|
||||
import type {
|
||||
DatasourceFunction,
|
||||
ColumnItem
|
||||
} from 'ele-admin-pro/es/ele-pro-table/types';
|
||||
import Search from './components/search.vue';
|
||||
import GoodsEdit from './components/goodsEdit.vue';
|
||||
import {
|
||||
pageGoods,
|
||||
removeGoods,
|
||||
removeBatchGoods,
|
||||
updateGoods
|
||||
} from '@/api/shop/goods';
|
||||
import type { Goods, GoodsParam } from '@/api/shop/goods/model';
|
||||
import { formatNumber } from 'ele-admin-pro/es';
|
||||
|
||||
// 表格实例
|
||||
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
|
||||
|
||||
// 表格选中数据
|
||||
const selection = ref<Goods[]>([]);
|
||||
// 当前编辑数据
|
||||
const current = ref<Goods | null>(null);
|
||||
// 是否显示编辑弹窗
|
||||
const showEdit = ref(false);
|
||||
// 是否显示批量移动弹窗
|
||||
const showMove = ref(false);
|
||||
// 加载状态
|
||||
const loading = ref(true);
|
||||
|
||||
// 表格数据源
|
||||
const datasource: DatasourceFunction = ({
|
||||
page,
|
||||
limit,
|
||||
where,
|
||||
orders,
|
||||
filters
|
||||
}) => {
|
||||
if (filters) {
|
||||
where.status = filters.status;
|
||||
}
|
||||
return pageGoods({
|
||||
...where,
|
||||
...orders,
|
||||
page,
|
||||
limit
|
||||
});
|
||||
};
|
||||
|
||||
// 表格列配置
|
||||
const columns = ref<ColumnItem[]>([
|
||||
{
|
||||
title: '商品ID',
|
||||
dataIndex: 'goodsId',
|
||||
key: 'goodsId',
|
||||
align: 'center',
|
||||
width: 90
|
||||
},
|
||||
{
|
||||
title: '商品图片',
|
||||
dataIndex: 'image',
|
||||
key: 'image',
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
title: '所属门店',
|
||||
dataIndex: 'merchantName',
|
||||
key: 'merchantName',
|
||||
ellipsis: true,
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
title: '商品名称',
|
||||
dataIndex: 'goodsName',
|
||||
key: 'goodsName',
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
title: '商品编码',
|
||||
dataIndex: 'code',
|
||||
key: 'code',
|
||||
align: 'center',
|
||||
hideInTable: true
|
||||
},
|
||||
{
|
||||
title: '类型',
|
||||
dataIndex: 'type',
|
||||
key: 'type',
|
||||
align: 'center',
|
||||
hideInTable: true
|
||||
},
|
||||
{
|
||||
title: '分类ID',
|
||||
dataIndex: 'categoryId',
|
||||
key: 'categoryId',
|
||||
align: 'center',
|
||||
hideInTable: true
|
||||
},
|
||||
{
|
||||
title: '一级分类',
|
||||
dataIndex: 'categoryParent',
|
||||
key: 'categoryParent',
|
||||
align: 'center',
|
||||
hideInTable: true
|
||||
},
|
||||
{
|
||||
title: '二级分类',
|
||||
dataIndex: 'categoryChildren',
|
||||
key: 'categoryChildren',
|
||||
align: 'center',
|
||||
hideInTable: true
|
||||
},
|
||||
{
|
||||
title: '多规格',
|
||||
dataIndex: 'specs',
|
||||
key: 'specs',
|
||||
align: 'center',
|
||||
hideInTable: true
|
||||
},
|
||||
{
|
||||
title: '货架',
|
||||
dataIndex: 'position',
|
||||
key: 'position',
|
||||
align: 'center',
|
||||
hideInTable: true
|
||||
},
|
||||
{
|
||||
title: '商品价格',
|
||||
dataIndex: 'salePrice',
|
||||
key: 'salePrice',
|
||||
sorter: true,
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
title: '进货价格',
|
||||
dataIndex: 'price',
|
||||
key: 'price',
|
||||
align: 'center',
|
||||
hideInTable: true
|
||||
},
|
||||
{
|
||||
title: '库存计算方式',
|
||||
dataIndex: 'deductStockType',
|
||||
key: 'deductStockType',
|
||||
align: 'center',
|
||||
hideInTable: true
|
||||
},
|
||||
{
|
||||
title: '销量',
|
||||
dataIndex: 'sales',
|
||||
key: 'sales',
|
||||
sorter: true,
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
title: '库存',
|
||||
dataIndex: 'stock',
|
||||
key: 'stock',
|
||||
sorter: true,
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
title: '商品重量',
|
||||
dataIndex: 'goodsWeight',
|
||||
key: 'goodsWeight',
|
||||
align: 'center',
|
||||
hideInTable: true
|
||||
},
|
||||
{
|
||||
title: '推荐',
|
||||
dataIndex: 'recommend',
|
||||
key: 'recommend',
|
||||
sorter: true,
|
||||
align: 'center',
|
||||
hideInTable: true
|
||||
},
|
||||
{
|
||||
title: '商户ID',
|
||||
dataIndex: 'merchantId',
|
||||
key: 'merchantId',
|
||||
align: 'center',
|
||||
hideInTable: true
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'isShow',
|
||||
key: 'isShow',
|
||||
sorter: true,
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
title: '排序号',
|
||||
dataIndex: 'sortNumber',
|
||||
key: 'sortNumber',
|
||||
sorter: true,
|
||||
align: 'center',
|
||||
hideInTable: true
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
key: 'createTime',
|
||||
align: 'center',
|
||||
width: 120,
|
||||
sorter: true
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 180,
|
||||
fixed: 'right',
|
||||
align: 'center',
|
||||
hideInSetting: true
|
||||
}
|
||||
]);
|
||||
|
||||
/* 搜索 */
|
||||
const reload = (where?: GoodsParam) => {
|
||||
selection.value = [];
|
||||
tableRef?.value?.reload({ where: where });
|
||||
};
|
||||
|
||||
/* 打开编辑弹窗 */
|
||||
const openEdit = (row?: Goods) => {
|
||||
current.value = row ?? null;
|
||||
showEdit.value = true;
|
||||
};
|
||||
|
||||
/* 打开批量移动弹窗 */
|
||||
const openMove = () => {
|
||||
showMove.value = true;
|
||||
};
|
||||
|
||||
const onUpdate = (row?: Goods) => {
|
||||
const isShow = row?.isShow == 0 ? 1 : 0;
|
||||
updateGoods({ ...row, isShow }).then((msg) => {
|
||||
message.success(msg);
|
||||
reload();
|
||||
});
|
||||
};
|
||||
|
||||
/* 删除单个 */
|
||||
const remove = (row: Goods) => {
|
||||
const hide = message.loading('请求中..', 0);
|
||||
removeGoods(row.goodsId)
|
||||
.then((msg) => {
|
||||
hide();
|
||||
message.success(msg);
|
||||
reload();
|
||||
})
|
||||
.catch((e) => {
|
||||
hide();
|
||||
message.error(e.message);
|
||||
});
|
||||
};
|
||||
|
||||
/* 批量删除 */
|
||||
const removeBatch = () => {
|
||||
if (!selection.value.length) {
|
||||
message.error('请至少选择一条数据');
|
||||
return;
|
||||
}
|
||||
Modal.confirm({
|
||||
title: '提示',
|
||||
content: '确定要删除选中的记录吗?',
|
||||
icon: createVNode(ExclamationCircleOutlined),
|
||||
maskClosable: true,
|
||||
onOk: () => {
|
||||
const hide = message.loading('请求中..', 0);
|
||||
removeBatchGoods(selection.value.map((d) => d.goodsId))
|
||||
.then((msg) => {
|
||||
hide();
|
||||
message.success(msg);
|
||||
reload();
|
||||
})
|
||||
.catch((e) => {
|
||||
hide();
|
||||
message.error(e.message);
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/* 查询 */
|
||||
const query = () => {
|
||||
loading.value = true;
|
||||
};
|
||||
|
||||
/* 自定义行属性 */
|
||||
const customRow = (record: Goods) => {
|
||||
return {
|
||||
// 行点击事件
|
||||
onClick: () => {
|
||||
// console.log(record);
|
||||
},
|
||||
// 行双击事件
|
||||
onDblclick: () => {
|
||||
openEdit(record);
|
||||
}
|
||||
};
|
||||
};
|
||||
query();
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default {
|
||||
name: 'Goods'
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped></style>
|
||||
Reference in New Issue
Block a user