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({ const myAxios = axios.create({
withCredentials:true, withCredentials:true,
baseURL: 'http://localhost:8888/api'//测试服务器 baseURL: 'http://localhost:9092/api'//测试服务器
}); });
// 添加请求拦截器 // 添加请求拦截器
axios.interceptors.request.use(function (config) { axios.interceptors.request.use(function (config) {

View File

@ -53,6 +53,16 @@
<span slot="title">类别管理</span> <span slot="title">类别管理</span>
</el-menu-item> </el-menu-item>
</el-sub-menu> </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-menu>
</el-aside> </el-aside>

View File

@ -37,6 +37,11 @@ export const routes = [
path: '/TypeManagement', path: '/TypeManagement',
name: '类别管理', name: '类别管理',
component: ()=> import("../views/Commodity/TypeManagement.vue") 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-input v-model="form.desc" type="textarea" placeholder="产品尺寸,服务等"/>
</el-form-item> </el-form-item>
<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-item>
</el-form> </el-form>
</div> </div>
@ -138,8 +138,8 @@ const form = reactive({
desc:'',// desc:'',//
}) })
onMounted(()=>{ onMounted(()=>{
addProduct()
upload() upload()
addProduct()
}) })
const addProduct = async () => { const addProduct = async () => {
const res = await myAxios.post('goods/add',{ const res = await myAxios.post('goods/add',{
@ -151,17 +151,18 @@ const addProduct = async () => {
intro : form.desc, intro : form.desc,
festivalOrder : form.festivalName festivalOrder : form.festivalName
}) })
if(res.data.code == 1){
ElMessage({ // if(res.data.code == 1){
message: '上架成功', // ElMessage({
type: 'success' // message: '',
}) // type: 'success'
}else{ // })
ElMessage({ // }else{
message: '上架失败', // ElMessage({
type: 'error' // message: '',
}) // type: 'error'
} // })
// }
} }
const upload = async () => { const upload = async () => {
const res = await myAxios.post('file/upload/server',{ 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> <template>
<div> <el-form :model="form" label-width="auto" style="max-width: 600px">
<div> <el-form-item label="优惠券名称">
<el-input style="width: 200px; height: 30px; margin-right: 10px;" suffix-icon="Search" placeholder="请输入商品名称" v-model="username"></el-input> <el-input v-model="form.name" />
<el-form-item label="商品类型" style="width: 200px; margin-right: 10px;display: inline-block"> </el-form-item>
<el-select v-model="resources" placeholder="请选择"> <el-form-item label="兑换积分">
<el-option label="材料包" value="材料包" /> <el-input v-model="form.requirePoints" />
<el-option label="手持物" value="手持物" /> </el-form-item>
<el-option label="头饰" value="头饰" /> <el-form-item label="满减金额">
<el-option label="定制" value="定制" /> <el-input v-model="form.conditionAmount" />
<el-option label="积分兑换" value="积分兑换" /> <!-- <el-select v-model="form.conditionAmount" placeholder="">-->
</el-select> <!-- <el-option label="Zone one" value="shanghai" />-->
</el-form-item> <!-- <el-option label="Zone two" value="beijing" />-->
<el-form-item label="商品状态" style="width: 200px;margin-right: 10px;display: inline-block"> <!-- </el-select>-->
<el-select v-model="Region" placeholder="请选择"> </el-form-item>
<el-option label="已上架" value="上架" /> <el-form-item label="发放数量">
<el-option label="已下架" value="下架" /> <el-input v-model="form.totalNum" />
</el-select> </el-form-item>
</el-form-item> <el-form-item label="限量领取">
<el-button class="ml-5" type="primary" @click="load" style="height: 25px;">搜索</el-button> <el-input v-model="form.limitNum" />
<el-button type="warning" @click="reset" style="height:25px">重置</el-button> </el-form-item>
</div> <el-form-item label="使用范围">
<div style="margin: 15px 0"> <el-input v-model="form.useScope" />
<el-popconfirm </el-form-item>
class="ml-5" <el-form-item label="开始日期">
confirm-button-text='确定' <el-col :span="11">
cancel-button-text='取消' <el-date-picker
icon="InfoFilled" v-model="form.startTime"
icon-color="red" type="date"
title="您确定批量删除这些数据吗?" placeholder="Pick a date"
@confirm="delBatch" style="width: 100%"
width=180 />
> </el-col>
<template #reference> <el-col :span="2" class="text-center">
<el-button style="height: 25px" class="ml-5" type="danger">批量删除 <el-icon style="margin-left: 5px;"><Remove /></el-icon></el-button> <span class="text-gray-500">--------</span>
</template> </el-col>
</el-popconfirm> <el-col :span="11">
</div> <el-time-picker
<el-table :data="tableData" border stripe header-cell-class-name="headerBg" :cell-style="{textAlign: 'center'}" v-model="form.date1"
@selection-change="handleSelectionChange" :header-cell-style="{'text-align': 'center'}" placeholder="Pick a time"
> style="width: 100%"
<el-table-column type="selection" width="55"></el-table-column> />
<el-table-column label="商品编号" width="80"> </el-col>
<template #default="scope"> </el-form-item>
<div> <el-form-item label="截至日期">
<span style="align-items: center">{{ scope.row.selectedItems }}</span> <el-col :span="11">
</div> <el-date-picker
</template> v-model="form.endTime"
</el-table-column> type="date"
<el-table-column label="商品图片"> placeholder="Pick a date"
<template #default="scope"> style="width: 100%"
<div> />
<img :src="scope.row.img" alt="" style="height: 50px;"> </el-col>
</div> <el-col :span="2" class="text-center">
</template> <span class="text-gray-500">--------</span>
</el-table-column> </el-col>
<el-table-column label="商品名称"> <el-col :span="11">
<template #default="scope"> <el-time-picker
<div> v-model="form.date2"
<span style="margin-left: 10px">{{ scope.row.name }}</span> placeholder="Pick a time"
</div> style="width: 100%"
</template> />
</el-table-column> </el-col>
<el-table-column label="商品价格" width="180"> </el-form-item>
<template #default="scope"> <el-form-item label="使用说明">
<div> <el-input v-model="form.description" type="textarea" />
<span style="margin-left: 10px">{{ scope.row.price }}</span> </el-form-item>
</div> <!-- <el-form-item label="Instant delivery">-->
</template> <!-- <el-switch v-model="form.delivery" />-->
</el-table-column> <!-- </el-form-item>-->
<el-table-column label="商品类型"> <!-- <el-form-item label="Activity type">-->
<template #default="scope"> <!-- <el-checkbox-group v-model="form.type">-->
<div> <!-- <el-checkbox value="Online activities" name="type">-->
<span style="margin-left: 10px">{{ scope.row.resource }}</span> <!-- Online activities-->
</div> <!-- </el-checkbox>-->
</template> <!-- <el-checkbox value="Promotion activities" name="type">-->
</el-table-column> <!-- Promotion activities-->
<el-table-column label="商品数量"> <!-- </el-checkbox>-->
<template #default="scope"> <!-- <el-checkbox value="Offline activities" name="type">-->
<div> <!-- Offline activities-->
<span style="margin-left: 10px">{{ scope.row.quantity }}</span> <!-- </el-checkbox>-->
</div> <!-- <el-checkbox value="Simple brand exposure" name="type">-->
</template> <!-- Simple brand exposure-->
</el-table-column> <!-- </el-checkbox>-->
<el-table-column label="商品状态"> <!-- </el-checkbox-group>-->
<template #default="scope"> <!-- </el-form-item>-->
<div> <!-- <el-form-item label="Resources">-->
<span style="margin-left: 10px">{{ scope.row.state }}</span> <!-- <el-radio-group v-model="form.resource">-->
</div> <!-- <el-radio value="Sponsor">Sponsor</el-radio>-->
</template> <!-- <el-radio value="Venue">Venue</el-radio>-->
</el-table-column> <!-- </el-radio-group>-->
<el-table-column label="操作" width="250px"> <!-- </el-form-item>-->
<template #default="scope"> <!-- <el-form-item label="Activity form">-->
<el-button size="small" @click="handleView(scope.$index, scope.row)"> <!-- <el-input v-model="form.desc" type="textarea" />-->
详情 <!-- </el-form-item>-->
</el-button> <!-- <el-form-item>-->
<el-button size="small" @click="handleRevise(scope.$index, scope.row)"> <!-- <el-button type="primary" @click="onSubmit">Create</el-button>-->
编辑 <!-- <el-button>Cancel</el-button>-->
</el-button> <!-- </el-form-item>-->
<el-button size="small" @click="handleOff(scope.$index, scope.row)"> </el-form>
{{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"
/>
</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-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>
<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>
</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> </template>
<script setup lang="ts"> <script lang="ts" setup>
import instance from '@/utils/request'; import { reactive } from 'vue'
import { ElMessage } from 'element-plus';
import { ref, onMounted } from 'vue'; // do not use same name with ref
const pageNum = ref(0); const form = reactive({
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: '',
name: '', name: '',
price: '', conditionAmount:'',//
resource: '', totalNum:'',
quantity: '', requirePoints:'',//
state: '', limitNum:'',//
attribute:'', useScope:'',//使
region: '', startTime:'',
label: '', endTime:'',
desc: '', date1: '',
}); date2: '',
const handleView = (index: number, row: any) => { description:'',//使
selectedProduct = row; })
detailDialogVisible.value = true; const AddCoupon = async () => {
};
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',
});
}
};
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',
});
}
});
};
</script>
<style scoped>
.headerBg {
background-color: #eee!important;
} }
</style> const onSubmit = () => {
console.log('submit!')
}
</script>