取消会员

This commit is contained in:
Flow 2025-06-24 10:44:18 +08:00
parent e71b032180
commit dfc8bf8575
3 changed files with 121 additions and 38 deletions

View File

@ -108,5 +108,10 @@ export const PersonApi = {
// 开通会员
becomeVip: async (data: any) => {
return await request.put({ url: `/system/person/become-vip`, data })
}
},
//取消会员
cancelVip: async (userid: number) => {
return await request.put({ url: `/system/person/cancel-vip?userid=` + userid })
},
}

View File

@ -52,8 +52,40 @@
value-format="YYYY-MM-DD"
:disabled-date="disabledDate"
class="expire-picker"
@change="calculateDuration"
/>
<!-- 快捷选项 -->
<div class="quick-options">
<div class="quick-title">快捷选择</div>
<div class="quick-buttons">
<el-button
size="small"
type="primary"
plain
@click="setQuickDate(1)"
class="quick-btn"
>
一个月
</el-button>
<el-button
size="small"
type="primary"
plain
@click="setQuickDate(3)"
class="quick-btn"
>
三个月
</el-button>
<el-button
size="small"
type="primary"
plain
@click="setQuickDate(12)"
class="quick-btn"
>
一年
</el-button>
</div>
</div>
</div>
</div>
@ -61,10 +93,10 @@
<div class="duration-card" v-if="newExpireDate">
<div class="duration-header">
<Icon icon="ep:timer" class="duration-icon" />
<span>开通时长</span>
<span>剩余时长</span>
</div>
<div class="duration-value">{{ calculatedDuration }}</div>
<div class="duration-tip">从当前到期时间开始计算</div>
<div class="duration-tip">当前会员剩余时长</div>
</div>
</div>
</div>
@ -138,6 +170,8 @@ watch(() => props.visible, (val) => {
if (val) {
//
setDefaultExpireDate()
//
calculateDuration()
}
})
@ -172,51 +206,55 @@ const setDefaultExpireDate = () => {
calculateDuration()
}
//
const setQuickDate = (months) => {
let baseDate
if (props.member.vipendtime) {
//
baseDate = new Date(props.member.vipendtime)
} else {
//
baseDate = new Date()
}
//
const targetDate = new Date(baseDate)
targetDate.setMonth(targetDate.getMonth() + months)
//
const year = targetDate.getFullYear()
const month = String(targetDate.getMonth() + 1).padStart(2, '0')
const day = String(targetDate.getDate()).padStart(2, '0')
newExpireDate.value = `${year}-${month}-${day}`
}
//
const calculateDuration = () => {
if (!newExpireDate.value) {
calculatedDuration.value = ''
if (!props.member.vipendtime) {
calculatedDuration.value = '未开通会员'
return
}
let startDate
if (props.member.vipendtime) {
//
startDate = new Date(props.member.vipendtime)
} else {
//
startDate = new Date()
}
//
const startDate = new Date()
// 23:59:59
const endDate = new Date(newExpireDate.value + ' 23:59:59')
//
const endDate = new Date(props.member.vipendtime)
//
const timeDiff = endDate.getTime() - startDate.getTime()
if (timeDiff <= 0) {
calculatedDuration.value = '无效时长'
calculatedDuration.value = '已过期'
return
}
//
const days = Math.floor(timeDiff / (1000 * 60 * 60 * 24))
const hours = Math.floor((timeDiff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
const minutes = Math.floor((timeDiff % (1000 * 60 * 60)) / (1000 * 60))
//
const days = Math.ceil(timeDiff / (1000 * 60 * 60 * 24))
//
let durationText = ''
if (days > 0) {
durationText += `${days}`
}
if (hours > 0) {
durationText += `${hours}小时`
}
if (minutes > 0) {
durationText += `${minutes}分钟`
}
calculatedDuration.value = durationText || '0分钟'
//
calculatedDuration.value = `${days}`
}
//
@ -381,6 +419,9 @@ const handleSubmit = async () => {
border: 1px solid #e2e8f0;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
transition: all 0.3s ease;
display: flex;
flex-direction: column;
height: 100%;
}
.time-card:hover {
@ -416,10 +457,14 @@ const handleSubmit = async () => {
font-weight: 600;
color: #1e293b;
font-family: 'Courier New', monospace;
margin-bottom: 8px;
padding: 8px 12px;
margin-bottom: 12px;
padding: 12px;
background: #f1f5f9;
border-radius: 6px;
flex: 1;
display: flex;
align-items: center;
min-height: 40px;
}
.time-status {
@ -428,6 +473,7 @@ const handleSubmit = async () => {
border-radius: 12px;
text-align: center;
font-weight: 500;
margin-top: 8px;
}
.time-status:not(.expired) {
@ -453,6 +499,38 @@ const handleSubmit = async () => {
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
/* 快捷选项样式 */
.quick-options {
margin-top: 12px;
padding-top: 12px;
border-top: 1px solid #e2e8f0;
}
.quick-title {
font-size: 12px;
color: #64748b;
margin-bottom: 8px;
font-weight: 500;
}
.quick-buttons {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
.quick-btn {
font-size: 12px;
padding: 4px 8px;
border-radius: 6px;
transition: all 0.2s ease;
}
.quick-btn:hover {
transform: translateY(-1px);
box-shadow: 0 2px 8px rgba(59, 130, 246, 0.2);
}
/* 开通时长卡片 */
.duration-card {
background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);

View File

@ -264,8 +264,8 @@ const handleCancel = (member) => {
//
const handlePasswordVerifySuccess = async (password) => {
try {
// TODO: API
//
// API
await PersonApi.cancelVip(currentMember.value.id)
ElMessage.success('已取消会员资格')
//
passwordVerifyVisible.value = false