This commit is contained in:
yuanteng 2024-12-04 09:38:32 +08:00
parent d1cdb9df2b
commit 8b40389be5

View File

@ -1,14 +1,9 @@
<template>
<!-- 修改前请注释以前的 -->
<!-- 搜索 -->
<div>
<el-input style="width: 200px; height: 30px; margin-right: 10px;" suffix-icon="Search" placeholder="请输入商品名称"
<!-- 修改前请注释以前的 -->
<!-- 搜索 -->
<div>
<el-input style="width: 200px; height: 30px; margin-right: 10px;" suffix-icon="Search" placeholder="请输入课程名称"
v-model="productName"></el-input>
<el-form-item label="商品类型" style="width: 200px; margin-right: 10px;display: inline-block">
<el-select v-model="editForm.type" @change="(event: any) => searchByType(event)" placeholder="请选择">
<el-option v-for="item in typeList" :key="item.value" :label="item.label" :value="item.value1" />
</el-select>
</el-form-item>
<el-form-item label="商品状态" style="width: 200px;margin-right: 10px;display: inline-block">
<el-select v-model="state" placeholder="请选择" @change="(event: any) => searchByState(event)">
<el-option label="已上架" value="1" />
@ -17,8 +12,8 @@
</el-form-item>
<el-button class="ml-5" type="primary" @click="onSearch(productName)" style="height: 25px;">搜索</el-button>
<el-button type="warning" @click="reset" style="height:25px">重置</el-button>
</div>
<div style="margin: 15px 0">
</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>
@ -27,71 +22,86 @@
</el-icon></el-button>
</template>
</el-popconfirm>
</div>
<!-- 数据展示 -->
<el-table :data="tableData" border stripe header-cell-class-name="headerBg"
:cell-style="{ 'text-align': 'center', 'font-size': '16px' }" @selection-change="handleSelectionChange"
:header-cell-style="{ 'text-align': 'center' }">
<el-table-column type="selection" width="55"></el-table-column>
<el-table-column prop="id" label="商品编号" width="80">
<template #default="{ $index }">
{{ $index + 1 }}
</div>
<!-- 数据展示 -->
<el-table :data="tableData" border stripe header-cell-class-name="headerBg"
:cell-style="{ 'text-align': 'center', 'font-size': '16px' }" @selection-change="handleSelectionChange"
:header-cell-style="{ 'text-align': 'center' }">
<el-table-column type="selection" width="55"></el-table-column>
<el-table-column prop="id" label="课程编号" width="80">
<template #default="{ $index }">
{{ $index + 1 }}
</template>
</el-table-column>
<el-table-column prop="goodImg" label="课程图片">
<template #default="scope">
<div>
<img :src="scope.row.goodImg" alt="" style="height: 50px;">
</div>
</template>
</el-table-column>
<el-table-column prop="name" label="课程名称"></el-table-column>
<el-table-column prop="price" label="单次价格" width="100"></el-table-column>
<el-table-column label="展开时间段" type="expand" width="80">
<template #default="props">
<!-- 放后端传来的预约时间 -->
<el-table :data="props.row.appointmentDateVOS" :header-cell-style="{ 'text-align': 'center' }" :cell-style="{ 'text-align': 'center' }">
<el-table-column label="日期" prop="specificDate" />
<el-table-column label="人数范围" prop="numberRange" />
<el-table-column label="时间段" prop="timeSlot"/>
<el-table-column label="此段课程人数" prop=""/>
<el-table-column label="操作">
<el-button size="small" @click="">
编辑
</el-button>
<el-button size="small" @click="" type="danger">
删除
</el-button>
</el-table-column>
</el-table>
</template>
</el-table-column>
<el-table-column label="商品状态" width="80">
<template #default="scope">
<div>
<span style="margin-left: 10px" v-if="scope.row.isShelves == 1">上架</span>
<span style="margin-left: 10px" v-if="scope.row.isShelves == 0">下架</span>
</div>
</template>
</el-table-column>
<el-table-column label="操作" width="250px">
<template #default="scope">
<el-button size="small" @click="ReviseOrView(scope.$index, scope.row , 0)">
详情
</el-button>
<el-button size="small" @click="ReviseOrView(scope.$index, scope.row, 1)">
编辑
</el-button>
<el-button size="small" @click="handleOff(scope.$index, scope.row)">
<div v-if="scope.row.isShelves == 1">下架 </div>
<div v-if="scope.row.isShelves == 0">上架 </div>
</el-button>
<el-popconfirm class="ml-5" confirm-button-text='确定' cancel-button-text='取消' icon="InfoFilled" icon-color="red"
title="是否确认删除" @confirm="deleteProduct(scope.row.id)" width=180>
<template #reference>
<el-button class="ml-5" type="danger">删除</el-button>
</template>
</el-table-column>
<el-table-column prop="goodImg" label="商品图片">
<template #default="scope">
<div>
<img :src="scope.row.goodImg" alt="" style="height: 50px;">
</div>
</template>
</el-table-column>
<el-table-column prop="name" label="商品名称"></el-table-column>
<el-table-column prop="price" label="商品价格" width="180"></el-table-column>
<el-table-column prop="type" label="商品类型"></el-table-column>
<el-table-column prop="inventory" label="商品数量"></el-table-column>
<el-table-column prop="createTime" label="创建时间"></el-table-column>
<el-table-column prop="updateTime" label="更新时间"></el-table-column>
<el-table-column label="商品状态">
<template #default="scope">
<div>
<span style="margin-left: 10px" v-if="scope.row.isShelves == 1">上架</span>
<span style="margin-left: 10px" v-if="scope.row.isShelves == 0">下架</span>
</div>
</template>
</el-table-column>
<el-table-column label="操作" width="250px">
<template #default="scope">
<el-button size="small" @click="ReviseOrView(scope.$index, scope.row , 0)">
详情
</el-button>
<el-button size="small" @click="ReviseOrView(scope.$index, scope.row, 1)">
编辑
</el-button>
<el-button size="small" @click="handleOff(scope.$index, scope.row)">
<div v-if="scope.row.isShelves == 1">下架 </div>
<div v-if="scope.row.isShelves == 0">上架 </div>
</el-button>
<el-popconfirm class="ml-5" confirm-button-text='确定' cancel-button-text='取消' icon="InfoFilled" icon-color="red"
title="是否确认删除" @confirm="deleteProduct(scope.row.id)" width=180>
<template #reference>
<el-button class="ml-5" type="danger">删除</el-button>
</template>
</el-popconfirm>
<el-popconfirm confirm-button-text='确定' cancel-button-text='取消' icon="el-icon-info" icon-color="red"
title="您确定删除吗?">
</el-popconfirm>
<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">
</template>
</el-table-column>
</el-table>
<!-- 分页器 -->
<div style="padding: 10px 0">
<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
:current-page="searchParams.current" :page-size="searchParams.pageSize" :page-sizes="[5, 10, 15, 20]"
:small="null" :disabled="null" :background="null" layout="total, sizes, prev, pager, next, jumper"
:total="total" />
</div>
<!-- 编辑/详情表单 -->
<el-dialog v-model="DialogVisible" :title="title">
</div>
<!-- 编辑/详情表单 -->
<el-dialog v-model="DialogVisible" :title="title">
<el-form label-width="100px" :disabled="disabled">
<el-form-item label="商品编号">
<el-input v-model="editForm.id" disabled></el-input>
@ -173,208 +183,184 @@
<el-button type="primary" @click="saveEdit" :disabled="disabled">确认</el-button>
</span>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import { ElMessage , type UploadProps , genFileId ,type UploadRawFile } from 'element-plus';
import { ref, onMounted, inject } from 'vue';
import myAxios from "@/api/myAxios";
const total = ref(0); //
const idList = ref([]);
const searchParams: any = ref({ //
current: 1, //
pageSize: 5, //
sortField: "id", //ID
sortOrder: "descend" //
})
const fileSimple = ref()
const disabled = ref(true)
const title = ref('') //
const productName = ref('');
const DialogVisible = ref(false);
const state = ref(''); //select
const tableData : any= ref([]);
const editForm : any = ref({});
const reload : any = inject("reload") //
const uploadProductImg : any = ref() //ref
const uploadProductDetail : any = ref() //ref
const typeList: any = ref([
{
value1: '',
label: ''
}
])
onMounted(() => { //
getProductList()
getTypeList()
})
const getProductList = async () => {
try {
const res = await myAxios.post('/goods/list/page', { ...searchParams.value });
// console.log(res.data)
if (res.data.code === 1) {
tableData.value = res.data.data.records;
total.value = parseInt(res.data.data.total) //
} else {
ElMessage({
message: '获取数据失败',
});
return;
}
} catch (error) {
</el-dialog>
</template>
<script setup lang="ts">
import { ElMessage , type UploadProps , genFileId ,type UploadRawFile } from 'element-plus';
import { ref, onMounted, inject } from 'vue';
import myAxios from "@/api/myAxios";
const total = ref(0); //
const idList = ref([]);
const searchParams: any = ref({ //
current: 1, //
pageSize: 5, //
sortField: "id", //ID
sortOrder: "descend" //
})
const fileSimple = ref()
const disabled = ref(true)
const title = ref('') //
const productName = ref('');
const DialogVisible = ref(false);
const state = ref(''); //select
const tableData : any= ref([]);
const editForm : any = ref({});
const reload : any = inject("reload") //
const uploadProductImg : any = ref() //ref
const uploadProductDetail : any = ref() //ref
const typeList: any = ref([
{
value1: '',
label: ''
}
])
onMounted(() => { //
getProductList()
})
const getProductList = async () => {
try {
const res = await myAxios.post('/goods/service/list/page', { ...searchParams.value });
// console.log(res.data)
if (res.data.code === 1) {
tableData.value = res.data.data.records;
total.value = parseInt(res.data.data.total) //
console.log(tableData.value);
} else {
ElMessage({
message: '发生错误',
message: '获取数据失败',
});
return;
}
} catch (error) {
ElMessage({
message: '发生错误',
});
}
const getTypeList = async () => {
const res = await myAxios.post('/category/list', {}) //
for (let key in res.data.data) { //
typeList.value[key] = {
value1: res.data.data[key].typeName,
label: res.data.data[key].typeName
}
}
}
const saveEdit = async () => { //
const res = await myAxios.post('/goods/update',{...editForm.value})
if( res.data.code === 1 ) {
ElMessage({
type: 'success',
message: '更新成功'
})
DialogVisible.value = false
} else {
ElMessage.error('更新失败,请检查字段')
}
}
const searchByType =(event : any)=>{ //
searchParams.value.type = event
searchParams.value.current = 1
getProductList()
}
const searchByState = (event : any) => { ///
searchParams.value.isShelves = event
searchParams.value.current = 1
getProductList()
}
//
const deleteProduct = async (index: number) => {
console.log(typeof index)
const res = await myAxios.post('/goods/delete', { id: index })
console.log(res)
if (res.data.code === 1) {
ElMessage({
type: 'success',
message: '删除成功',
})
getProductList()
}
getTypeList()
}
//--->
//
const ReviseOrView = (index: number, row: any , flag : number) => {
//flag disabled
flag ? (title.value = "编辑商品" , disabled.value = false) : (title.value = "商品详情" , disabled.value = true)
DialogVisible.value = true;
editForm.value = row;
};
//()
const handleOff = async (index: number, row: any) => {
row.isShelves ? row.isShelves = 0 : row.isShelves = 1 //
editForm.value = row;
const res = await myAxios.post('/goods/update',{...editForm.value})
if(res.data.code === 1) {
ElMessage({
type:'success',
message:'更新成功'
})
}
}
//
const handleSizeChange = (newSize: any) => {
searchParams.value.pageSize = newSize //
getProductList()
}
//
const handleCurrentChange = (Current: any) => {
searchParams.value.current = Current
getProductList()
}
//
const reset = () => {
reload()
};
// --
const handleRemove: UploadProps['onRemove'] = (uploadFile, uploadFiles) => {
console.log(uploadFile, uploadFiles)
}
const Exceed_ProductImg: UploadProps['onExceed'] = (files , flag) => { //
uploadProductImg.value!.clearFiles()
const file = files[0] as UploadRawFile
file.uid = genFileId()
uploadProductImg.value!.handleStart(file)
}
const Exceed_ProductDetail: UploadProps['onExceed'] = (files) => { //
uploadProductDetail.value!.clearFiles()
const file = files[0] as UploadRawFile
file.uid = genFileId()
uploadProductDetail.value!.handleStart(file)
}
//
const loadForm = (value: any, flag: number) => {
flag ? editForm.value.type = value : editForm.value.festivalOrder = value // flag=1 "" flag=0
}
//
const handleChange = async (file: any, flag: number) => {
fileSimple.value = file
let formData = new FormData() // FormData
formData.append("file", fileSimple.value.raw) //fileSimple.value.raw formData
const res = await myAxios({ //
url: '/file/upload/server/not_login',
method: 'post',
headers: {
'content-Type': 'multipart/form-data'
},
data: {
biz: "test",
file: formData.get("file") // formDatafile
}
}
const saveEdit = async () => { //
}
const searchByState = (event : any) => { ///
searchParams.value.isShelves = event
searchParams.value.current = 1
getProductList()
}
//
const deleteProduct = async (index: number) => {
console.log(typeof index)
const res = await myAxios.post('/goods/delete', { id: index })
console.log(res)
if (res.data.code === 1) {
ElMessage({
type: 'success',
message: '删除成功',
})
if (res.data.code === 1) {
// flag0 flag1
flag ? editForm.value.detailImg = res.data.data : editForm.value.goodImg = res.data.data
}
}
const onSearch = (data : String)=>{ //
searchParams.value.name = data
searchParams.value.current = 1
getProductList()
}
//
const delBatch = async ()=>{
console.log(idList.value);
const res = await myAxios.post('/goods/delBatch',{
idList: idList.value
}
//--->
//
const ReviseOrView = (index: number, row: any , flag : number) => {
//flag disabled
flag ? (title.value = "编辑商品" , disabled.value = false) : (title.value = "商品详情" , disabled.value = true)
DialogVisible.value = true;
editForm.value = row;
};
//()
const handleOff = async (index: number, row: any) => {
row.isShelves ? row.isShelves = 0 : row.isShelves = 1 //
editForm.value = row;
const res = await myAxios.post('/goods/update',{...editForm.value})
if(res.data.code === 1) {
ElMessage({
type:'success',
message:'更新成功'
})
console.log(res.data);
if(res.data.code === 1) {
ElMessage({
type: 'success',
message: '批量删除成功'
})
getProductList()
} else {
ElMessage.error('删除失败')
}
}
//
const handleSizeChange = (newSize: any) => {
searchParams.value.pageSize = newSize //
getProductList()
}
//
const handleCurrentChange = (Current: any) => {
searchParams.value.current = Current
getProductList()
}
//
const reset = () => {
reload()
};
// --
const handleRemove: UploadProps['onRemove'] = (uploadFile, uploadFiles) => {
console.log(uploadFile, uploadFiles)
}
const Exceed_ProductImg: UploadProps['onExceed'] = (files , flag) => { //
uploadProductImg.value!.clearFiles()
const file = files[0] as UploadRawFile
file.uid = genFileId()
uploadProductImg.value!.handleStart(file)
}
const Exceed_ProductDetail: UploadProps['onExceed'] = (files) => { //
uploadProductDetail.value!.clearFiles()
const file = files[0] as UploadRawFile
file.uid = genFileId()
uploadProductDetail.value!.handleStart(file)
}
//
const loadForm = (value: any, flag: number) => {
flag ? editForm.value.type = value : editForm.value.festivalOrder = value // flag=1 "" flag=0
}
//
const handleChange = async (file: any, flag: number) => {
fileSimple.value = file
let formData = new FormData() // FormData
formData.append("file", fileSimple.value.raw) //fileSimple.value.raw formData
const res = await myAxios({ //
url: '/file/upload/server/not_login',
method: 'post',
headers: {
'content-Type': 'multipart/form-data'
},
data: {
biz: "test",
file: formData.get("file") // formDatafile
}
})
if (res.data.code === 1) {
// flag0 flag1
flag ? editForm.value.detailImg = res.data.data : editForm.value.goodImg = res.data.data
}
const handleSelectionChange =()=>{}
</script>
<style scoped>
.headerBg {
background-color: #eee !important;
}
const onSearch = (data : String)=>{ //
searchParams.value.name = data
searchParams.value.current = 1
getProductList()
}
//
const delBatch = async ()=>{
console.log(idList.value);
const res = await myAxios.post('/goods/delBatch',{
idList: idList.value
})
console.log(res.data);
if(res.data.code === 1) {
ElMessage({
type: 'success',
message: '批量删除成功'
})
getProductList()
} else {
ElMessage.error('删除失败')
}
</style>
}
const handleSelectionChange =()=>{}
</script>
<style scoped>
.headerBg {
background-color: #eee !important;
}
</style>