jiangchengfeiyi-Web/src/views/Coupons/CouponCenter.vue

248 lines
8.5 KiB
Vue
Raw Normal View History

2024-11-03 10:59:41 +00:00
<template>
<!-- 搜索-->
<div>
2024-11-04 10:30:18 +00:00
<el-input style="width: 200px; height: 30px; margin-right: 10px;" suffix-icon="Search" placeholder="请输入优惠券名称"
2025-02-18 06:06:06 +00:00
v-model="name"></el-input>
<el-button class="ml-5" type="primary" @click="load(name)" style="height: 25px;">搜索</el-button>
2024-11-03 10:59:41 +00:00
<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="{ '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="name" label="优惠券名称"></el-table-column>
2025-03-03 12:52:10 +00:00
<el-table-column prop="content" label="简介"></el-table-column>
<el-table-column prop="standardAmount" label="满减价格"></el-table-column>
<el-table-column prop="conditionAmount" label="优惠价格"></el-table-column>
2024-11-03 10:59:41 +00:00
<el-table-column prop="requirePoints" label="兑换积分"></el-table-column>
<el-table-column prop="endTime" label="截止时间"></el-table-column>
2025-03-03 12:52:10 +00:00
<el-table-column prop="status" label="状态"></el-table-column>
2025-02-18 06:06:06 +00:00
<el-table-column label="操作" width="200px" >
2024-11-03 10:59:41 +00:00
<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-popconfirm class="ml-5" confirm-button-text='确定' cancel-button-text='取消' icon="InfoFilled" icon-color="red"
title="是否确认删除" @confirm="deleteCoupons(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>
</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">
2025-03-03 12:52:10 +00:00
<el-form label-width="100px" :disabled="disabled" size="large">
<el-form-item label="优惠券名称" style="width: 400px">
2024-11-03 10:59:41 +00:00
<el-input v-model="editForm.name"></el-input>
</el-form-item>
2025-03-03 12:52:10 +00:00
<el-form-item label="简介" style="width: 400px">
<el-input v-model="editForm.content" type="textarea" maxlength="20" :rows="2"></el-input>
</el-form-item>
<el-form-item label="满减价格">
<el-input-number v-model="editForm.standardAmount" min="0.01" :precision="2" :step="1" />
<el-text class="mx-1" size="large"></el-text>
2024-11-03 10:59:41 +00:00
</el-form-item>
2025-03-03 12:52:10 +00:00
<el-form-item label="优惠价格">
<el-input-number v-model="editForm.conditionAmount" min="0.01" :precision="2" :step="1" />
<el-text class="mx-1" size="large"></el-text>
2024-11-03 10:59:41 +00:00
</el-form-item>
2025-03-03 12:52:10 +00:00
<el-form-item label="兑换积分">
<el-input-number v-model="editForm.requirePoints" min="0" :step="1" />
<el-text class="mx-1" size="large">积分</el-text>
2024-11-03 10:59:41 +00:00
</el-form-item>
2025-03-03 12:52:10 +00:00
2025-02-05 11:31:00 +00:00
<el-form-item label="截至日期">
2025-03-03 12:52:10 +00:00
<el-date-picker
v-model="editForm.endTime"
type="datetime"
placeholder="Pick a Date"
format="YYYY-MM-DD hh:mm:ss"
value-format="YYYY-MM-DD hh:mm:ss"
/>
2024-11-03 10:59:41 +00:00
</el-form-item>
2025-03-03 12:52:10 +00:00
<el-form-item label="使用说明" style="width: 600px">
<el-input v-model="editForm.description" type="textarea" maxlength="100" :rows="4"></el-input>
2024-11-03 10:59:41 +00:00
</el-form-item>
2025-02-05 11:31:00 +00:00
2024-11-03 10:59:41 +00:00
</el-form>
<template #footer >
<span class="dialog-footer">
<el-button @click="DialogVisible = false" :disabled="disabled">取消</el-button>
<el-button type="primary" @click="saveEdit" :disabled="disabled">确认</el-button>
</span>
</template>
</el-dialog>
</template>
<script lang="ts" setup>
2025-02-18 06:06:06 +00:00
import {inject, onMounted, ref} from "vue";
2024-11-03 10:59:41 +00:00
import myAxios from "@/api/myAxios";
import {ElMessage, type UploadProps} from "element-plus";
onMounted(() => {
getCouponsList()
})
2025-02-18 06:06:06 +00:00
const name=ref('')
2024-11-03 10:59:41 +00:00
const DialogVisible = ref(false)
2024-12-02 01:49:09 +00:00
const idList = ref([])
2024-11-03 10:59:41 +00:00
const total = ref(0)
const tableData : any= ref([])
const Couponsname = ref('')
const title = ref('')
const editForm : any = ref({})
const fileSimple = ref()
const disabled = ref(true)
const searchParams: any = ref({ //分页
current: 1,
pageSize: 5,
sortField: "id", //根据ID分类
sortOrder: "descend" //降序
2024-11-03 10:59:41 +00:00
})
2025-02-18 06:06:06 +00:00
2024-11-03 10:59:41 +00:00
//处理行数大小变化
const handleSizeChange = (newSize: any) => {
searchParams.value.pageSize = newSize //新的页面数
getCouponsList()
}
//处理当前表格变化
const handleCurrentChange = (Current: any) => {
searchParams.value.current = Current
getCouponsList()
}
2024-12-02 01:49:09 +00:00
const handleSelectionChange = (row: any) => {
idList.value = row.map((item : any)=>item.id)
}
//批量删除
const delBatch = async ()=>{
const res = await myAxios.post('/coupon/delete', {
id:idList.value
})
if (res.data.code === 1) {
ElMessage({
type:'success',
message:"批量删除成功"
})
getCouponsList()
}else {
ElMessage.error('删除失败')
}
2024-11-03 10:59:41 +00:00
}
//重置搜索
2025-02-18 06:06:06 +00:00
const reload : any = inject("reload")
const reset = ()=>{
reload()
2024-11-03 10:59:41 +00:00
}
//搜索
2024-12-02 01:49:09 +00:00
const load =(data:String)=>{
searchParams.value.name = data
searchParams.value.content = 1
getCouponsList()
2024-11-03 10:59:41 +00:00
}
2025-02-05 11:31:00 +00:00
//获取
2024-11-03 10:59:41 +00:00
const saveEdit = async () => { //编辑商品
const res = await myAxios.post('/coupon/update',{...editForm.value})
if( res.data.code === 1 ) {
ElMessage({
type: 'success',
message: '更新成功'
})
DialogVisible.value = false
} else {
ElMessage.error('更新失败,请检查字段')
}
}
const ReviseOrView = (index: number, row: any , flag : number) => {
flag ? (title.value = "编辑商品" , disabled.value = false) : (title.value = "商品详情" , disabled.value = true)
DialogVisible.value = true;
editForm.value = row;
};
const getCouponsList = async ()=> {
try {
const res = await myAxios.post('/coupon/list/page', {...searchParams.value})
console.log(res)
if (res.data.code === 1) {
tableData.value = res.data.data.records;
total.value = parseInt(res.data.data.total)
}else {
ElMessage({
type: 'error',
message: '获取数据失败'
})
}
}catch (error){
ElMessage({
type: 'error',
message: '发生错误'
})
}
}
const handleChange = async (file: any, flag: number) => {
2024-12-08 14:39:32 +00:00
fileSimple.value = file
2024-11-03 10:59:41 +00:00
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") // 取出formData对象中的file
}
})
if (res.data.code === 1) {
editForm.value.image = res.data.data
}
}
const deleteCoupons = async (index: number) => {
console.log(typeof index)
const res = await myAxios.post('/coupon/delete', { id: index })
console.log(res)
if (res.data.code === 1) {
ElMessage({
type: 'success',
message: '删除成功',
})
getCouponsList()
}
}
</script>
<style>
</style>