<template>
|
<div>
|
<Card>
|
<Form
|
ref="searchForm"
|
@keydown.enter.native="handleSearch"
|
:model="searchForm"
|
inline
|
:label-width="70"
|
class="search-form"
|
>
|
<Form-item label="套餐名称" prop="comboName">
|
<Input
|
type="text"
|
v-model="searchForm.comboName"
|
clearable
|
@on-clear="handleSearch"
|
@on-change="handleSearch"
|
style="width: 160px"
|
/>
|
</Form-item>
|
<Form-item label="分类" prop="tagId">
|
<Select
|
v-model="searchForm.tagId"
|
placeholder="请选择分类"
|
clearable
|
style="width: 160px"
|
filterable
|
>
|
<Option
|
v-for="tag in tagList"
|
:key="tag.id"
|
:label="tag.tagName"
|
:value="tag.id"
|
>
|
{{ tag.tagName }}
|
</Option>
|
</Select>
|
</Form-item>
|
<Form-item label="启用状态" prop="status">
|
<Select
|
v-model="searchForm.status"
|
placeholder="全部状态"
|
clearable
|
style="width: 160px"
|
>
|
<Option value="ENABLE">启用</Option>
|
<Option value="DISABLE">禁用</Option>
|
</Select>
|
</Form-item>
|
<Button
|
@click="handleSearch"
|
type="primary"
|
icon="ios-search"
|
class="search-btn"
|
>搜索
|
</Button
|
>
|
</Form>
|
|
<Row class="operation padding-row">
|
<Button @click="openAdd" type="info">添加</Button>
|
<Button @click="delBatch" type="error">批量删除</Button>
|
</Row>
|
|
<Modal
|
v-model="modelShow"
|
:title="modelTitle"
|
width="800"
|
>
|
<Form ref="form" :model="form" :label-width="70" :rules="rules">
|
<Row :gutter="24">
|
<Col span="12">
|
<FormItem label="套餐名字" prop="comboName">
|
<Input v-model="form.comboName" autocomplete="off"/>
|
</FormItem>
|
</Col>
|
<Col span="12">
|
<FormItem label="备注" prop="remark">
|
<Input v-model="form.remark" autocomplete="off"/>
|
</FormItem>
|
</Col>
|
</Row>
|
<Row :gutter="24">
|
<Col span="12">
|
<FormItem label="人数" prop="num">
|
<Input v-model="form.num" autocomplete="off"/>
|
</FormItem>
|
</Col>
|
<Col span="12">
|
<FormItem label="套餐封面" prop="coverImg">
|
<Upload
|
v-if="!coverTempUrl"
|
:before-upload="(file) => handleBeforeUpload(file, 'cover')"
|
:format="['jpg','jpeg','png','gif']"
|
:max-size="20480"
|
action=""
|
accept="image/*"
|
>
|
<Button icon="ios-cloud-upload-outline">上传封面图片</Button>
|
</Upload>
|
<div v-else class="upload-file-info">
|
<img :src="coverTempUrl" alt="封面图片" class="preview-image-limit">
|
<Button type="text" @click="handleRemove('cover')">删除</Button>
|
</div>
|
</FormItem>
|
</Col>
|
</Row>
|
<Row :gutter="24">
|
<Col span="12">
|
<FormItem label="原价" prop="orginPrice">
|
<Input v-model="form.orginPrice" autocomplete="off"/>
|
</FormItem>
|
</Col>
|
<Col span="12">
|
<FormItem label="私厨分类" prop="tagId">
|
<Select
|
v-model="form.tagId"
|
placeholder="请选择分类"
|
clearable
|
style="width: 100%"
|
filterable
|
>
|
<Option
|
v-for="tag in tagList"
|
:key="tag.id"
|
:label="tag.tagName"
|
:value="tag.id"
|
>
|
{{ tag.tagName }}
|
</Option>
|
</Select>
|
</FormItem>
|
</Col>
|
</Row>
|
<Row :gutter="24">
|
<Col span="12">
|
<FormItem label="启用状态" prop="status">
|
<Select v-model="form.status" placeholder="请选择状态">
|
<Option value="ENABLE">启用</Option>
|
<Option value="DISABLE">禁用</Option>
|
</Select>
|
</FormItem>
|
</Col>
|
<Col span="12">
|
<FormItem label="排序" prop="sort">
|
<Input v-model="form.sort" autocomplete="off"/>
|
</FormItem>
|
</Col>
|
</Row>
|
<Row :gutter="24">
|
<Col span="24">
|
<FormItem label="已选商品" :label-width="70">
|
<div style="height: 100px;overflow: auto;" v-if="form.goods">
|
<div style="display: flex;
|
align-items: center;justify-content: flex-start;border: 1px solid gray;margin-top: 10px;
|
padding: 10px;border-radius: 20px">
|
<div>
|
<img :src="getThumbnailUrl(form.goods.thumbnail)"
|
style="width: 80px;height: 80px">
|
</div>
|
<div style="display: flex;flex-direction: column;margin-left: 20px">
|
<div style="font-size: 1.5em;font-weight: bold">{{ form.goods.goodsName }}</div>
|
<div style="color: #ff6f6f">
|
¥{{ form.goods.price }}
|
</div>
|
</div>
|
<div style="margin-left: 10px">
|
<Button type="error" size="small" @click="removeGoods">移除</Button>
|
</div>
|
</div>
|
</div>
|
<div v-else style="color: #999; padding: 10px;">
|
暂无已选商品
|
</div>
|
</FormItem>
|
</Col>
|
</Row>
|
<Row :gutter="24">
|
<Col span="24">
|
<FormItem label="绑定商品" :label-width="70">
|
<Input v-model="searchGoodsForm.keyword" style="width:200px" @on-change="searchGoodsList"></Input>
|
<div style="height: 300px;overflow: auto;">
|
<div v-for="item in goodsData" :key="item.id" style="display: flex;
|
align-items: center;justify-content: flex-start;border: 1px solid gray;margin-top: 10px;
|
padding: 10px;border-radius: 20px" @click="chooseGoods(item.id)">
|
<div>
|
<img :src="getThumbnailUrl(item.thumbnail)" style="width: 80px;height: 80px">
|
</div>
|
<div style="display: flex;flex-direction: column;margin-left: 20px">
|
<div style="font-size: 1.5em;font-weight: bold">{{ item.goodsName }}</div>
|
<div style="color: #ff6f6f">
|
¥{{ item.price }}
|
</div>
|
</div>
|
</div>
|
</div>
|
<Page
|
:current="searchGoodsForm.pageNumber"
|
:total="goodsTotal"
|
:page-size="searchGoodsForm.pageSize"
|
@on-change="goodsChangePage"
|
@on-page-size-change="goodsChangePageSize"
|
:page-size-opts="[10, 20, 50]"
|
size="small"
|
show-total
|
></Page>
|
</FormItem>
|
</Col>
|
</Row>
|
</Form>
|
<div slot="footer">
|
<Button type="text" @click="modelClose">取消</Button>
|
<Button type="primary" :loading="submitLoading" @click="saveOrUpdate">提交</Button>
|
</div>
|
</Modal>
|
|
<Table
|
:loading="loading"
|
border
|
:columns="columns"
|
:data="data"
|
ref="table"
|
sortable="custom"
|
@on-sort-change="changeSort"
|
@on-selection-change="showSelect"
|
>
|
<template slot-scope="{ row, index }" slot="action">
|
<Button type="info" size="small" style="margin-right: 5px" @click="openEdit(row)">编辑</Button>
|
<Button
|
v-if="row.status === 'DISABLE'"
|
type="success"
|
size="small"
|
style="margin-right: 5px"
|
@click="enableGoods(row)"
|
>启用</Button>
|
<Button
|
v-if="row.status === 'ENABLE'"
|
type="warning"
|
size="small"
|
style="margin-right: 5px"
|
@click="disableGoods(row)"
|
>禁用</Button>
|
<Button type="error" size="small" @click="delById(row)">删除</Button>
|
</template>
|
</Table>
|
|
<Row type="flex" justify="end" class="mt_10">
|
<Page
|
:current="searchForm.pageNumber"
|
:total="total"
|
:page-size="searchForm.pageSize"
|
@on-change="changePage"
|
@on-page-size-change="changePageSize"
|
:page-size-opts="[10, 20, 50]"
|
size="small"
|
show-total
|
show-elevator
|
show-sizer
|
></Page>
|
</Row>
|
</Card>
|
</div>
|
</template>
|
|
<script>
|
import JsonExcel from "vue-json-excel";
|
import {deleteVideoTagById, getVideoTags, editVideoTag, addVideoTag, deleteVideoTagByIds} from "@/api/videoTag";
|
import {addKitchenType, deleteBatch, delKitchenType, editKitchenType, getKitchenGoodsPage, addKitchenGoods, editKitchenGoods, delKitchenGoods, deleteGoodsBatch, getKitchenTagList, editKitchenGoodsStaus} from "@/api/kitchen";
|
import {videoGoodsEsPage, recommend} from "@/api/videoTag";
|
import {getSts} from "@/api/file";
|
import {uploadFileByLmk} from "@/api/common";
|
|
export default {
|
name: "KitchenCustomize",
|
components: {
|
"download-excel": JsonExcel,
|
uploadPicInput: () => import('@/components/lili/upload-pic-input.vue'),
|
},
|
data() {
|
return {
|
// 保存加载
|
submitLoading: false,
|
// 新增修改表单
|
form: {
|
id: '',
|
goodsId: '', // 商品id - 选择商品后自动填充
|
skuId: '', // skuId - 选择商品后自动填充
|
comboName: '', // 套餐名字
|
remark: '', // 备注
|
num: '', // 人数
|
coverImg: '', // 封面图片
|
orginPrice: '', // 原价
|
tagId: '', // 标签id
|
status: '', // 启用状态
|
sort: '', // 排序
|
goods: null, // 绑定商品
|
},
|
rules: {
|
comboName: [
|
{
|
required: true, message: "套餐名字不能为空", trigger: "blur",
|
validator: (rule, value, callback) => {
|
if (value === null || value === '') {
|
callback(new Error('套餐名字不能为空'));
|
} else {
|
callback();
|
}
|
}
|
}
|
],
|
remark: [
|
{
|
required: true, message: "备注不能为空", trigger: "blur",
|
validator: (rule, value, callback) => {
|
if (value === null || value === '') {
|
callback(new Error('备注不能为空'));
|
} else {
|
callback();
|
}
|
}
|
}
|
],
|
num: [
|
{
|
required: true, message: "人数不能为空", trigger: "blur",
|
validator: (rule, value, callback) => {
|
if (value === null || value === '') {
|
callback(new Error('人数不能为空'));
|
} else {
|
callback();
|
}
|
}
|
}
|
],
|
coverImg: [
|
{
|
required: true, message: "封面图片不能为空", trigger: "change",
|
validator: (rule, value, callback) => {
|
// 只在新增时验证,编辑时如果已有图片则不需要上传新图片
|
if (!this.form.id && !value && !this.coverFile) {
|
callback(new Error('请上传封面图片'));
|
} else {
|
callback();
|
}
|
}
|
}
|
],
|
orginPrice: [
|
{
|
required: true, message: "原价必须是数字", trigger: "blur",
|
validator: (rule, value, callback) => {
|
if (value === null || value === '') {
|
callback(new Error('原价必须是数字'));
|
} else {
|
// 检查是否为数字
|
const numValue = Number(value);
|
if (isNaN(numValue)) {
|
callback(new Error('原价必须是数字'));
|
} else if (numValue < 0.01 || numValue > 9999999.99) {
|
callback(new Error('原价必须在0.01到9999999.99之间'));
|
} else {
|
callback();
|
}
|
}
|
}
|
}
|
],
|
tagId: [
|
{
|
required: true, message: "标签id不能为空", trigger: "change",
|
validator: (rule, value, callback) => {
|
if (value === null || value === '') {
|
callback(new Error('标签id不能为空'));
|
} else {
|
callback();
|
}
|
}
|
}
|
],
|
status: [
|
{
|
required: true, message: "启用状态不能为空", trigger: "change",
|
validator: (rule, value, callback) => {
|
if (value === null || value === '') {
|
callback(new Error('启用状态不能为空'));
|
} else {
|
callback();
|
}
|
}
|
}
|
],
|
sort: [
|
{
|
required: true, message: "排序不能为空", trigger: "blur",
|
validator: (rule, value, callback) => {
|
if (value === null || value === '') {
|
callback(new Error('排序不能为空'));
|
} else {
|
callback();
|
}
|
}
|
}
|
],
|
},
|
modelShow: false, // 弹窗显隐
|
modelTitle: '', // 弹窗title
|
// 表格的表头以及内容
|
fields: {
|
商品ID: "goodsId",
|
套餐名字: "comboName",
|
人数: "num",
|
原价: "orginPrice",
|
启用状态: "status",
|
排序: "sort",
|
操作: "action"
|
},
|
loading: true, // 表单加载状态
|
searchForm: {
|
// 搜索框初始化对象
|
pageNumber: 1, // 当前页数
|
pageSize: 10, // 页面大小
|
comboName: '', // 套餐名称
|
tagId: '', // 标签ID
|
status: '', // 启用状态
|
},
|
selectDate: null,
|
tagList: [], // 标签列表
|
columns: [
|
{
|
type: 'selection',
|
width: 60,
|
align: 'center'
|
},
|
{
|
title: "商品名称",
|
key: "goodsName",
|
minWidth: 150,
|
tooltip: true,
|
},
|
{
|
title: "商品图片",
|
key: "thumbnail",
|
width: 120,
|
align: 'center',
|
render: (h, params) => {
|
const thumbnail = params.row.thumbnail;
|
if (thumbnail) {
|
// 如果是数字类型,拼接endpoint
|
let imgUrl = thumbnail;
|
if (typeof thumbnail === 'number') {
|
imgUrl = this.endpoint + '/' + thumbnail;
|
} else if (typeof thumbnail === 'string' && !thumbnail.startsWith('http')) {
|
// 如果是字符串但不包含http,可能是ID,拼接endpoint
|
imgUrl = this.endpoint + '/' + thumbnail;
|
}
|
return h('img', {
|
attrs: {
|
src: imgUrl,
|
alt: '商品图片',
|
style: 'width: 50px; height: 50px; object-fit: cover; border-radius: 4px'
|
},
|
style: {
|
width: '50px',
|
height: '50px',
|
objectFit: 'cover',
|
borderRadius: '4px',
|
cursor: 'pointer'
|
},
|
on: {
|
click: () => {
|
// 点击图片可以预览大图
|
window.open(imgUrl, '_blank');
|
}
|
}
|
});
|
} else {
|
return h('span', '暂无图片');
|
}
|
}
|
},
|
{
|
title: "套餐名字",
|
key: "comboName",
|
minWidth: 70,
|
tooltip: true,
|
},
|
{
|
title: "套餐封面",
|
key: "coverImg",
|
width: 120,
|
align: 'center',
|
render: (h, params) => {
|
const coverImg = params.row.coverImg;
|
if (coverImg) {
|
// 如果是数字类型,拼接endpoint
|
let imgUrl = coverImg;
|
if (typeof coverImg === 'number') {
|
imgUrl = this.endpoint + '/' + coverImg;
|
} else if (typeof coverImg === 'string' && !coverImg.startsWith('http')) {
|
// 如果是字符串但不包含http,可能是ID,拼接endpoint
|
imgUrl = this.endpoint + '/' + coverImg;
|
}
|
return h('img', {
|
attrs: {
|
src: imgUrl,
|
alt: '套餐封面',
|
style: 'width: 50px; height: 50px; object-fit: cover; border-radius: 4px'
|
},
|
style: {
|
width: '50px',
|
height: '50px',
|
objectFit: 'cover',
|
borderRadius: '4px',
|
cursor: 'pointer'
|
},
|
on: {
|
click: () => {
|
// 点击图片可以预览大图
|
window.open(imgUrl, '_blank');
|
}
|
}
|
});
|
} else {
|
return h('span', '暂无图片');
|
}
|
}
|
},
|
|
{
|
title: "人数",
|
key: "num",
|
width: 100
|
},
|
{
|
title: "原价",
|
key: "orginPrice",
|
width: 100
|
},
|
{
|
title: "现价",
|
key: "price",
|
width: 100
|
},
|
{
|
title: "启用状态",
|
key: "status",
|
width: 100,
|
align: 'center',
|
render: (h, params) => {
|
const status = params.row.status;
|
const color = status === 'ENABLE' ? 'success' : status === 'DISABLE' ? 'default' : 'warning';
|
const text = status === 'ENABLE' ? '启用' : status === 'DISABLE' ? '禁用' : '未知';
|
return h('Tag', {
|
props: {
|
color: color
|
}
|
}, text);
|
}
|
},
|
{
|
title: "排序",
|
key: "sort",
|
width: 100
|
},
|
{
|
title: "备注",
|
key: "remark",
|
width: 100
|
},
|
{
|
title: "操作",
|
key: "action",
|
slot: "action",
|
align: "center",
|
fixed: "right",
|
width: 300,
|
},
|
],
|
data: [], // 表单数据
|
total: 0, // 表单数据总数
|
selectCount: 0, // 已选数量
|
selectList: [], // 已选数据列表
|
// 商品选择相关数据
|
goodsData: [], // 商品列表
|
goodsTotal: 0, // 商品总数
|
endpoint: '', // 文件访问端点
|
searchGoodsForm: {
|
// 商品搜索框初始化对象
|
pageNumber: 1, // 当前页数
|
pageSize: 10, // 页面大小
|
keyword: '',
|
searchFromSelfStore: false
|
},
|
// 图片上传相关
|
coverFile: null,
|
coverTempUrl: null,
|
};
|
},
|
methods: {
|
showSelect(e) {
|
this.selectList = e.map(d => d.id);
|
this.selectCount = e.length;
|
},
|
// 排序
|
changeSort(e) {
|
this.searchForm.sort = e.key;
|
this.searchForm.order = e.order;
|
if (e.order == "normal") {
|
this.searchForm.order = "";
|
}
|
this.getDataList();
|
},
|
// 批量删除
|
delBatch() {
|
if (this.selectCount <= 0) {
|
this.$Message.warning("您还未选择要删除的数据");
|
return;
|
}
|
this.$Modal.confirm({
|
title: "确认删除",
|
content: "您确认要删除所选的 " + this.selectCount + " 条数据?",
|
loading: true,
|
onOk: () => {
|
deleteGoodsBatch(this.selectList).then(res => {
|
this.$Modal.remove();
|
if (res.code == 200) {
|
this.$Message.success("删除成功");
|
this.selectList = [];
|
this.selectCount = 0;
|
this.getDataList();
|
}
|
});
|
}
|
});
|
},
|
// id删除
|
delById(row) {
|
this.$Modal.confirm({
|
title: "确认删除",
|
content: "您确认要删除: " + row.comboName + " ?",
|
loading: true,
|
onOk: () => {
|
delKitchenGoods(row.id).then(res => {
|
this.$Modal.remove();
|
if (res.code == 200) {
|
this.$Message.success("删除成功");
|
this.getDataList();
|
}
|
});
|
}
|
});
|
},
|
// 打开新增
|
openAdd() {
|
this.modelTitle = "新增标签"
|
this.modelShow = true
|
this.form = {
|
id: '',
|
goodsId: '', // 商品id
|
skuId: '', // skuId
|
comboName: '', // 套餐名字
|
remark: '', // 备注
|
num: '', // 人数
|
coverImg: '', // 封面图片
|
orginPrice: '', // 原价
|
tagId: '', // 标签id
|
status: '', // 启用状态
|
sort: '', // 排序
|
goods: null, // 绑定商品
|
}
|
// 清空图片上传状态
|
this.coverFile = null;
|
this.coverTempUrl = null;
|
this.searchGoodsList(); // 加载商品列表
|
},
|
// 打开修改
|
openEdit(row) {
|
this.modelTitle = "修改标签"
|
// 初始化表单
|
this.form = {
|
id: '',
|
goodsId: '',
|
skuId: '',
|
comboName: '',
|
remark: '',
|
num: '',
|
coverImg: '',
|
orginPrice: '',
|
tagId: '',
|
status: '',
|
sort: '',
|
goods: null,
|
};
|
// 使用Object.assign合并数据,保留row中的goods信息
|
this.form = Object.assign(this.form, row);
|
this.modelShow = true
|
// 如果有封面图片URL,则设置预览
|
if (row.coverImg) {
|
this.coverTempUrl = row.coverImg;
|
}
|
// 如果row中包含商品信息,直接使用
|
if (this.form.goodsId && this.form.skuId) {
|
// 直接使用row中的商品信息创建goods对象用于显示
|
this.form.goods = {
|
goodsId: this.form.goodsId,
|
goodsSkuId: this.form.skuId,
|
goodsName: this.form.goodsName || this.form.comboName || '',
|
thumbnail: this.form.thumbnail || this.form.goodsThumbnail || this.form.coverImg || '',
|
price: this.form.price || this.form.orginPrice || '',
|
};
|
// 如果封面图片为空,且商品有缩略图,则使用商品缩略图
|
if (!this.form.coverImg && this.form.goods.thumbnail) {
|
// 如果thumbnail是数字ID,需要拼接成URL
|
if (typeof this.form.goods.thumbnail === 'number') {
|
this.form.coverImg = this.endpoint + '/' + this.form.goods.thumbnail;
|
} else {
|
this.form.coverImg = this.form.goods.thumbnail;
|
}
|
}
|
}
|
// 加载商品列表
|
this.searchGoodsList();
|
console.log(this.form)
|
},
|
// 新增或修改
|
async saveOrUpdate() {
|
this.$refs.form.validate(valid => {
|
try {
|
if (valid) {
|
this.submitLoading = true
|
// 先上传封面图片,但不阻塞后续操作
|
this.uploadFileByLmk().then(() => {
|
// 处理商品绑定数据
|
let formData = { ...this.form };
|
// 如果没有选择商品,则设置为null
|
if (!formData.goods) {
|
delete formData.goods;
|
}
|
if (this.form.id) {
|
// 修改
|
editKitchenGoods(formData).then(res => {
|
if (res.code == 200) {
|
this.$Message.success("修改成功");
|
this.modelClose()
|
this.getDataList()
|
}
|
})
|
} else {
|
// 新增
|
addKitchenGoods(formData).then(res => {
|
if (res.code == 200) {
|
this.$Message.success("添加成功");
|
this.modelClose()
|
this.getDataList()
|
}
|
})
|
}
|
}).catch(() => {
|
// 即使上传失败,也要继续执行保存逻辑
|
let formData = { ...this.form };
|
// 如果没有选择商品,则设置为null
|
if (!formData.goods) {
|
delete formData.goods;
|
}
|
if (this.form.id) {
|
// 修改
|
editKitchenGoods(formData).then(res => {
|
if (res.code == 200) {
|
this.$Message.success("修改成功");
|
this.modelClose()
|
this.getDataList()
|
}
|
})
|
} else {
|
// 新增
|
addKitchenGoods(formData).then(res => {
|
if (res.code == 200) {
|
this.$Message.success("添加成功");
|
this.modelClose()
|
this.getDataList()
|
}
|
})
|
}
|
});
|
}
|
} finally {
|
this.submitLoading = false
|
}
|
});
|
},
|
// 关闭弹窗
|
modelClose() {
|
this.submitLoading = false
|
this.modelShow = false
|
// 重置图片上传状态
|
this.coverFile = null;
|
this.coverTempUrl = null;
|
this.form.coverImg = '';
|
},
|
// 初始化数据
|
init() {
|
this.getDataList();
|
},
|
// 分页 改变页码
|
changePage(v) {
|
this.searchForm.pageNumber = v;
|
this.getDataList();
|
},
|
// 分页 改变页数
|
changePageSize(v) {
|
this.searchForm.pageNumber = 1;
|
this.searchForm.pageSize = v;
|
this.getDataList();
|
},
|
// 搜索
|
handleSearch() {
|
this.searchForm.pageNumber = 1;
|
this.searchForm.pageSize = 10;
|
this.getDataList();
|
},
|
// 起止时间从新赋值
|
selectDateRange(v) {
|
if (v) {
|
this.searchForm.startDate = v[0];
|
this.searchForm.endDate = v[1];
|
}
|
},
|
// 商品选择相关方法
|
chooseGoods(id) {
|
const goods = this.goodsData.find(item => {
|
return item.id === id;
|
})
|
if (goods) {
|
// 只选择一个商品,直接替换当前商品
|
this.form.goods = {
|
goodsId: goods.goodsId,
|
goodsSkuId: goods.id,
|
goodsName: goods.goodsName,
|
thumbnail: goods.thumbnail,
|
price: goods.price,
|
}
|
// 自动填充商品ID和SKU ID
|
this.form.goodsId = goods.goodsId;
|
this.form.skuId = goods.id;
|
// 如果封面图片为空,自动使用商品缩略图
|
if (!this.form.coverImg) {
|
// 如果thumbnail是数字ID,需要拼接成URL
|
if (typeof goods.thumbnail === 'number') {
|
this.form.coverImg = this.endpoint + '/' + goods.thumbnail;
|
} else {
|
this.form.coverImg = goods.thumbnail;
|
}
|
}
|
}
|
},
|
removeGoods() {
|
this.form.goods = null;
|
this.form.goodsId = '';
|
this.form.skuId = '';
|
},
|
// 获取缩略图URL
|
getThumbnailUrl(thumbnail) {
|
if (!thumbnail) {
|
return '';
|
}
|
// 如果是数字类型,拼接endpoint
|
if (typeof thumbnail === 'number') {
|
return this.endpoint + '/' + thumbnail;
|
}
|
// 如果是字符串且包含http,直接返回
|
if (typeof thumbnail === 'string') {
|
if (thumbnail.startsWith('http')) {
|
return thumbnail;
|
} else {
|
// 如果是字符串但不包含http,可能是ID,拼接endpoint
|
return this.endpoint + '/' + thumbnail;
|
}
|
}
|
return thumbnail;
|
},
|
searchGoodsList() {
|
this.searchGoodsForm.pageNumber = 1;
|
return this.getGoodsDataList();
|
},
|
// 获取商品列表数据
|
getGoodsDataList() {
|
let search = this.searchGoodsForm;
|
if (search.pageNumber > 0) {
|
search.pageNumber = search.pageNumber - 1;
|
}
|
return new Promise((resolve, reject) => {
|
videoGoodsEsPage(search).then((res) => {
|
if (res.code == 200) {
|
this.goodsData = res.data;
|
getSts().then(res => {
|
this.endpoint = res.data.endpoint
|
})
|
this.goodsTotal = res.total;
|
resolve(res);
|
} else {
|
reject(res);
|
}
|
}).catch(error => {
|
reject(error);
|
});
|
});
|
},
|
// 分页 改变页码
|
goodsChangePage(v) {
|
this.searchGoodsForm.pageNumber = v;
|
this.getGoodsDataList();
|
},
|
// 分页 改变页数
|
goodsChangePageSize(v) {
|
this.searchGoodsForm.pageNumber = 1;
|
this.searchGoodsForm.pageSize = v;
|
this.getGoodsDataList();
|
},
|
// 上传文件
|
async uploadFileByLmk() {
|
if (this.coverFile) {
|
this.submitLoading = true;
|
const formData = new FormData();
|
formData.append('file', this.coverFile);
|
|
await uploadFileByLmk(formData).then(res => {
|
this.submitLoading = false;
|
if (res.code === 200) {
|
this.form.coverImg = res.data.fileKey;
|
} else {
|
this.$Message.error(res.msg || '上传失败');
|
}
|
}).catch(() => {
|
this.submitLoading = false;
|
this.$Message.error('上传失败');
|
});
|
}
|
},
|
// 处理图片上传前
|
handleBeforeUpload(file, type) {
|
if ("cover" === type) {
|
this.coverFile = file;
|
this.coverTempUrl = URL.createObjectURL(file);
|
return false;
|
}
|
},
|
// 删除图片
|
handleRemove(type) {
|
if ('cover' === type) {
|
this.coverFile = null;
|
this.coverTempUrl = null;
|
this.form.coverImg = '';
|
}
|
},
|
// 启用厨房商品
|
enableGoods(row) {
|
this.$Modal.confirm({
|
title: "确认启用",
|
content: "您确认要启用厨房商品: " + row.comboName + " ?",
|
loading: true,
|
onOk: () => {
|
const params = {
|
id: row.id,
|
status: 'ENABLE'
|
};
|
editKitchenGoodsStaus(params.id, params.status).then(res => {
|
this.$Modal.remove();
|
if (res.code == 200) {
|
this.$Message.success("启用成功");
|
this.getDataList();
|
}
|
});
|
}
|
});
|
},
|
// 禁用厨房商品
|
disableGoods(row) {
|
this.$Modal.confirm({
|
title: "确认禁用",
|
content: "您确认要禁用厨房商品: " + row.comboName + " ?",
|
loading: true,
|
onOk: () => {
|
const params = {
|
id: row.id,
|
status: 'DISABLE'
|
};
|
editKitchenGoodsStaus(params.id, params.status).then(res => {
|
this.$Modal.remove();
|
if (res.code == 200) {
|
this.$Message.success("禁用成功");
|
this.getDataList();
|
}
|
});
|
}
|
});
|
},
|
// 获取列表数据
|
getDataList() {
|
this.loading = true;
|
getKitchenGoodsPage(this.searchForm).then((res) => {
|
console.log(res)
|
this.loading = false;
|
if (res.code == 200) {
|
this.data = res.data;
|
this.total = res.total;
|
}
|
});
|
this.total = this.data.length;
|
this.loading = false;
|
},
|
// 获取标签列表
|
getTagList() {
|
getKitchenTagList().then(res => {
|
if (res.code === 200) {
|
this.tagList = res.data;
|
}
|
});
|
},
|
},
|
mounted() {
|
this.init();
|
// 初始化商品列表
|
this.getGoodsDataList();
|
// 初始化标签列表
|
this.getTagList();
|
},
|
};
|
</script>
|
<style lang="scss" scoped>
|
.export {
|
margin: 10px 20px 10px 0;
|
}
|
|
.export-excel-wrapper {
|
display: inline;
|
}
|
|
.order-tab {
|
width: 950px;
|
height: 36px;
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
background-color: #f0f0f0;
|
padding: 0 10px;
|
margin-bottom: 10px;
|
|
div {
|
text-align: center;
|
padding: 4px 12px;
|
border-radius: 4px;
|
cursor: pointer;
|
}
|
|
.current {
|
background-color: #ffffff;
|
}
|
}
|
|
.upload-file-info {
|
display: flex;
|
align-items: center;
|
margin-top: 10px;
|
}
|
|
.upload-file-info img {
|
max-width: 200px;
|
max-height: 200px;
|
margin-right: 10px;
|
border-radius: 4px;
|
}
|
|
.preview-image-limit{
|
max-width: 100%;
|
max-height: 200px;
|
object-fit: contain;
|
border-radius: 4px;
|
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
display: block;
|
}</style>
|