This commit is contained in:
sa_10_0 2024-11-03 13:34:38 +08:00
parent b0615ba36d
commit cd07761392
6 changed files with 161 additions and 392 deletions

View File

@ -4,7 +4,7 @@ import router from '../router'
const myAxios = axios.create({
withCredentials:true,
baseURL: 'http://localhost:8888/api'//测试服务器
baseURL: 'http://localhost:9092/api'//测试服务器
});
// 添加请求拦截器
axios.interceptors.request.use(function (config) {

View File

@ -53,6 +53,16 @@
<span slot="title">类别管理</span>
</el-menu-item>
</el-sub-menu>
<el-sub-menu index="3">
<template #title>
<el-icon><HomeFilled /></el-icon>
<span>优惠券管理</span>
</template>
<el-menu-item index="/AddCoupons">
<el-icon><Menu /></el-icon>
<span slot="title">添加优惠券</span>
</el-menu-item>
</el-sub-menu>
</el-menu>
</el-aside>

View File

@ -37,6 +37,11 @@ export const routes = [
path: '/TypeManagement',
name: '类别管理',
component: ()=> import("../views/Commodity/TypeManagement.vue")
},
{
path:'/AddCoupons',
name:'添加优惠券',
component:()=>import("../views/Coupons/AddCoupons.vue")
}
]
}

View File

@ -100,7 +100,7 @@
<el-input v-model="form.desc" type="textarea" placeholder="产品尺寸,服务等"/>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="onSubmit">上架</el-button>
<el-button type="primary" @click="addProduct">上架</el-button>
</el-form-item>
</el-form>
</div>
@ -138,8 +138,8 @@ const form = reactive({
desc:'',//
})
onMounted(()=>{
addProduct()
upload()
addProduct()
})
const addProduct = async () => {
const res = await myAxios.post('goods/add',{
@ -151,17 +151,18 @@ const addProduct = async () => {
intro : form.desc,
festivalOrder : form.festivalName
})
if(res.data.code == 1){
ElMessage({
message: '上架成功',
type: 'success'
})
}else{
ElMessage({
message: '上架失败',
type: 'error'
})
}
// if(res.data.code == 1){
// ElMessage({
// message: '',
// type: 'success'
// })
// }else{
// ElMessage({
// message: '',
// type: 'error'
// })
// }
}
const upload = async () => {
const res = await myAxios.post('file/upload/server',{

View File

@ -0,0 +1,11 @@
<script setup lang="ts">
</script>
<template>
</template>
<style scoped>
</style>

View File

@ -1,384 +1,126 @@
<template>
<div>
<div>
<el-input style="width: 200px; height: 30px; margin-right: 10px;" suffix-icon="Search" placeholder="请输入商品名称" v-model="username"></el-input>
<el-form-item label="商品类型" style="width: 200px; margin-right: 10px;display: inline-block">
<el-select v-model="resources" placeholder="请选择">
<el-option label="材料包" value="材料包" />
<el-option label="手持物" value="手持物" />
<el-option label="头饰" value="头饰" />
<el-option label="定制" value="定制" />
<el-option label="积分兑换" value="积分兑换" />
</el-select>
<el-form :model="form" label-width="auto" style="max-width: 600px">
<el-form-item label="优惠券名称">
<el-input v-model="form.name" />
</el-form-item>
<el-form-item label="商品状态" style="width: 200px;margin-right: 10px;display: inline-block">
<el-select v-model="Region" placeholder="请选择">
<el-option label="已上架" value="上架" />
<el-option label="已下架" value="下架" />
</el-select>
<el-form-item label="兑换积分">
<el-input v-model="form.requirePoints" />
</el-form-item>
<el-button class="ml-5" type="primary" @click="load" style="height: 25px;">搜索</el-button>
<el-button type="warning" @click="reset" style="height:25px">重置</el-button>
</div>
<div style="margin: 15px 0">
<el-popconfirm
class="ml-5"
confirm-button-text='确定'
cancel-button-text='取消'
icon="InfoFilled"
icon-color="red"
title="您确定批量删除这些数据吗?"
@confirm="delBatch"
width=180
>
<template #reference>
<el-button style="height: 25px" class="ml-5" type="danger">批量删除 <el-icon style="margin-left: 5px;"><Remove /></el-icon></el-button>
</template>
</el-popconfirm>
</div>
<el-table :data="tableData" border stripe header-cell-class-name="headerBg" :cell-style="{textAlign: 'center'}"
@selection-change="handleSelectionChange" :header-cell-style="{'text-align': 'center'}"
>
<el-table-column type="selection" width="55"></el-table-column>
<el-table-column label="商品编号" width="80">
<template #default="scope">
<div>
<span style="align-items: center">{{ scope.row.selectedItems }}</span>
</div>
</template>
</el-table-column>
<el-table-column label="商品图片">
<template #default="scope">
<div>
<img :src="scope.row.img" alt="" style="height: 50px;">
</div>
</template>
</el-table-column>
<el-table-column label="商品名称">
<template #default="scope">
<div>
<span style="margin-left: 10px">{{ scope.row.name }}</span>
</div>
</template>
</el-table-column>
<el-table-column label="商品价格" width="180">
<template #default="scope">
<div>
<span style="margin-left: 10px">{{ scope.row.price }}</span>
</div>
</template>
</el-table-column>
<el-table-column label="商品类型">
<template #default="scope">
<div>
<span style="margin-left: 10px">{{ scope.row.resource }}</span>
</div>
</template>
</el-table-column>
<el-table-column label="商品数量">
<template #default="scope">
<div>
<span style="margin-left: 10px">{{ scope.row.quantity }}</span>
</div>
</template>
</el-table-column>
<el-table-column label="商品状态">
<template #default="scope">
<div>
<span style="margin-left: 10px">{{ scope.row.state }}</span>
</div>
</template>
</el-table-column>
<el-table-column label="操作" width="250px">
<template #default="scope">
<el-button size="small" @click="handleView(scope.$index, scope.row)">
详情
</el-button>
<el-button size="small" @click="handleRevise(scope.$index, scope.row)">
编辑
</el-button>
<el-button size="small" @click="handleOff(scope.$index, scope.row)">
{{scope.row.attribute}}
</el-button>
<el-button
size="small"
type="danger"
@click="handleDelete(scope.$index, scope.row)"
>
删除
</el-button>
<el-popconfirm
confirm-button-text='确定'
cancel-button-text='取消'
icon="el-icon-info"
icon-color="red"
title="您确定删除吗?"
>
</el-popconfirm>
</template>
</el-table-column>
</el-table>
<div style="padding: 10px 0">
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="pageNum"
:page-size="pageSize"
:page-sizes="[2, 5, 10, 20]"
:small="null"
:disabled="null"
:background="null"
layout="total, sizes, prev, pager, next, jumper"
:total="total"
<el-form-item label="满减金额">
<el-input v-model="form.conditionAmount" />
<!-- <el-select v-model="form.conditionAmount" placeholder="">-->
<!-- <el-option label="Zone one" value="shanghai" />-->
<!-- <el-option label="Zone two" value="beijing" />-->
<!-- </el-select>-->
</el-form-item>
<el-form-item label="发放数量">
<el-input v-model="form.totalNum" />
</el-form-item>
<el-form-item label="限量领取">
<el-input v-model="form.limitNum" />
</el-form-item>
<el-form-item label="使用范围">
<el-input v-model="form.useScope" />
</el-form-item>
<el-form-item label="开始日期">
<el-col :span="11">
<el-date-picker
v-model="form.startTime"
type="date"
placeholder="Pick a date"
style="width: 100%"
/>
</div>
</div>
<el-dialog v-model="detailDialogVisible" title="商品详情">
<el-form label-width="100px">
<el-form-item label="商品编号">
<el-input v-model="selectedProduct.selectedItems" disabled></el-input>
</el-col>
<el-col :span="2" class="text-center">
<span class="text-gray-500">--------</span>
</el-col>
<el-col :span="11">
<el-time-picker
v-model="form.date1"
placeholder="Pick a time"
style="width: 100%"
/>
</el-col>
</el-form-item>
<el-form-item label="商品图片">
<div v-if="selectedProduct.img">
<img :src="selectedProduct.img" alt="类别图标" class="thumbnail" style="width: 100px; height: 100px;"/>
</div>
<el-form-item label="截至日期">
<el-col :span="11">
<el-date-picker
v-model="form.endTime"
type="date"
placeholder="Pick a date"
style="width: 100%"
/>
</el-col>
<el-col :span="2" class="text-center">
<span class="text-gray-500">--------</span>
</el-col>
<el-col :span="11">
<el-time-picker
v-model="form.date2"
placeholder="Pick a time"
style="width: 100%"
/>
</el-col>
</el-form-item>
<el-form-item label="商品名称">
<el-input v-model="selectedProduct.name" disabled></el-input>
</el-form-item>
<el-form-item label="商品价格">
<el-input v-model="selectedProduct.price" disabled></el-input>
</el-form-item>
<el-form-item label="商品类型">
<el-select v-model="selectedProduct.resource" placeholder="请选择" disabled>
<el-option label="材料包" value="材料包" />
<el-option label="手持物" value="手持物" />
<el-option label="头饰" value="头饰" />
<el-option label="定制" value="定制" />
<el-option label="积分兑换" value="积分兑换" />
</el-select>
</el-form-item>
<el-form-item label="商品数量">
<el-input v-model="selectedProduct.quantity" disabled></el-input>
</el-form-item>
<el-form-item label="商品状态">
<el-select v-model="selectedProduct.state" placeholder="请选择" disabled>
<el-option label="上架" value="上架" />
<el-option label="下架" value="下架" />
</el-select>
</el-form-item>
<el-form-item label="是否为限定产品">
<el-select v-model="selectedProduct.region" placeholder="请选择" disabled>
<el-option label="是" value="是" />
<el-option label="否" value="否" />
</el-select>
</el-form-item>
<el-form-item label="商品标签">
<el-input v-model="selectedProduct.label" disabled></el-input>
</el-form-item>
<el-form-item label="商品描述">
<el-input type="textarea" v-model="selectedProduct.desc" disabled></el-input>
<el-form-item label="使用说明">
<el-input v-model="form.description" type="textarea" />
</el-form-item>
<!-- <el-form-item label="Instant delivery">-->
<!-- <el-switch v-model="form.delivery" />-->
<!-- </el-form-item>-->
<!-- <el-form-item label="Activity type">-->
<!-- <el-checkbox-group v-model="form.type">-->
<!-- <el-checkbox value="Online activities" name="type">-->
<!-- Online activities-->
<!-- </el-checkbox>-->
<!-- <el-checkbox value="Promotion activities" name="type">-->
<!-- Promotion activities-->
<!-- </el-checkbox>-->
<!-- <el-checkbox value="Offline activities" name="type">-->
<!-- Offline activities-->
<!-- </el-checkbox>-->
<!-- <el-checkbox value="Simple brand exposure" name="type">-->
<!-- Simple brand exposure-->
<!-- </el-checkbox>-->
<!-- </el-checkbox-group>-->
<!-- </el-form-item>-->
<!-- <el-form-item label="Resources">-->
<!-- <el-radio-group v-model="form.resource">-->
<!-- <el-radio value="Sponsor">Sponsor</el-radio>-->
<!-- <el-radio value="Venue">Venue</el-radio>-->
<!-- </el-radio-group>-->
<!-- </el-form-item>-->
<!-- <el-form-item label="Activity form">-->
<!-- <el-input v-model="form.desc" type="textarea" />-->
<!-- </el-form-item>-->
<!-- <el-form-item>-->
<!-- <el-button type="primary" @click="onSubmit">Create</el-button>-->
<!-- <el-button>Cancel</el-button>-->
<!-- </el-form-item>-->
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="detailDialogVisible = false">取消</el-button>
</span>
</template>
</el-dialog>
<el-dialog v-model="editDialogVisible" title="商品编辑">
<el-form label-width="100px">
<el-form-item label="商品编号">
<el-input v-model="editForm.selectedItems"></el-input>
</el-form-item>
<el-form-item label="商品图片">
<el-upload action="#" list-type="picture" :auto-upload="false">
<el-icon><Plus /></el-icon>
<template #file="{ file }">
<img class="el-upload-list__item-thumbnail" :src="file.url" alt="" />
</template>
</el-upload>
</el-form-item>
<el-form-item label="商品名称">
<el-input v-model="editForm.name"></el-input>
</el-form-item>
<el-form-item label="商品价格">
<el-input v-model="editForm.price"></el-input>
</el-form-item>
<el-form-item label="商品类型">
<el-select v-model="editForm.resource" placeholder="请选择">
<el-option label="材料包" value="材料包" />
<el-option label="手持物" value="手持物" />
<el-option label="头饰" value="头饰" />
<el-option label="定制" value="定制" />
<el-option label="积分兑换" value="定制" />
</el-select>
</el-form-item>
<el-form-item label="商品数量">
<el-input v-model="editForm.quantity"></el-input>
</el-form-item>
<el-form-item label="商品状态">
<el-select v-model="editForm.state" disabled>
<el-option label="上架" value="上架" />
<el-option label="下架" value="下架" />
</el-select>
</el-form-item>
<el-form-item label="是否为限定产品">
<el-select v-model="editForm.region" placeholder="请选择">
<el-option label="是" value="是" />
<el-option label="否" value="否" />
</el-select>
</el-form-item>
<el-form-item label="商品标签">
<el-input v-model="editForm.label"></el-input>
</el-form-item>
<el-form-item label="商品描述">
<el-input type="textarea" v-model="editForm.desc"></el-input>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="editDialogVisible = false">取消</el-button>
<el-button type="primary" @click="saveEdit">保存</el-button>
</span>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import instance from '@/utils/request';
import { ElMessage } from 'element-plus';
import { ref, onMounted } from 'vue';
const pageNum = ref(0);
const pageSize = ref(0);
const total = ref(0);
const selectedItems = ref([]);
onMounted(() => {
load();
});
const handleSelectionChange = (row: any) => {
selectedItems.value = JSON.parse(JSON.stringify(row));
};
const username = ref('');
const detailDialogVisible = ref(false);
const editDialogVisible = ref(false);
const resources = ref('');
const Region = ref('');
let selectedProduct = ref('');
let editForm = ref({
selectedItems: '',
img: '',
<script lang="ts" setup>
import { reactive } from 'vue'
// do not use same name with ref
const form = reactive({
name: '',
price: '',
resource: '',
quantity: '',
state: '',
attribute:'',
region: '',
label: '',
desc: '',
});
const handleView = (index: number, row: any) => {
selectedProduct = row;
detailDialogVisible.value = true;
};
const handleRevise = (index: number, row: any) => {
selectedProduct = row;
editDialogVisible.value = true;
editForm.value = row;
};
const handleOff = (index: number, row: any) => {
if (row.attribute === '上架') {
row.state = '上架';
row.attribute = '下架';
} else if (row.attribute === '下架') {
row.state = '下架';
row.attribute = '上架';
}
};
const handleDelete = (index: number, row: any) => {
const confirmDelete = window.confirm('您确定要删除该商品吗?');
if (confirmDelete) {
tableData.value = tableData.value.filter((item, i) => i!== index);
ElMessage({
message: '删除成功',
type: 'success',
});
}
};
conditionAmount:'',//
totalNum:'',
requirePoints:'',//
limitNum:'',//
useScope:'',//使
startTime:'',
endTime:'',
date1: '',
date2: '',
description:'',//使
})
const AddCoupon = async () => {
const tableData = [
{
selectedItems: '001',
img: 'https://s21.ax1x.com/2024/10/24/pAdzjZ6.png',
name: '随便起的',
price: '300rmb',
resource: '头饰',
quantity: '10',
state: '上架',
region: '是',
label: '送礼好物',
desc: '描述',
attribute:'下架',
},
];
const list = {
region: '',
label: [],
desc: '',
};
const reset = () => {
username.value = '';
resources.value = '';
Region.value = '';
};
const saveEdit = () => {
const indexToUpdate = tableData.findIndex(item => item.selectedItems === editForm.value.selectedItems);
if (indexToUpdate!== -1) {
tableData[indexToUpdate] = {
...tableData[indexToUpdate],
...editForm.value,
};
ElMessage({
message: '编辑成功',
type: 'success',
});
editDialogVisible.value = false;
};
};
const load = async () => {
await instance.get('/admin/findAllUsers').then(res => {
console.log(res.data.data);
res.data.data.forEach(item => {
console.log(item);
});
tableData.value = res.data.data;
});
};
const delBatchSuccess = () => {
ElMessage({
message: '批量删除成功',
type: 'success',
});
};
const delBatch = async () => {
await instance.post('').then(res => {
if (res.data.code === '200') {
load();
} else {
ElMessage({
message: '批量删除失败',
type: 'error',
});
}
});
};
const onSubmit = () => {
console.log('submit!')
}
</script>
<style scoped>
.headerBg {
background-color: #eee!important;
}
</style>