You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

236 lines
7.0 KiB

<template>
<data-list-panel modern-table>
<template #header>
<div class="adjust-heading">
<div class="adjust-heading__title">手动调整积分 · 补发 / 扣减</div>
<div class="adjust-heading__description">
正数为补发、负数为扣减。操作会生成积分流水(MANUAL_ADD / MANUAL_DEDUCT)并写入审计日志,请谨慎操作。
</div>
</div>
</template>
<el-form
ref="adjustForm"
:model="form"
:rules="rules"
label-width="96px"
size="small"
class="adjust-form"
>
<el-form-item label="目标用户" prop="userId">
<el-cascader
v-model="form.userId"
:options="orgOptions"
:props="cascaderProps"
:loading="orgLoading"
filterable
clearable
placeholder="按部门选择用户"
style="width: 100%; max-width: 420px"
@change="handleUserChange"
/>
</el-form-item>
<el-form-item label="当前积分">
<span class="adjust-balance">{{ balanceText }}</span>
</el-form-item>
<el-form-item label="调整积分" prop="points">
<el-input-number
v-model="form.points"
:min="-100000"
:max="100000"
:precision="0"
:step="10"
style="width: 200px"
/>
<span class="adjust-hint">正数补发,负数扣减,不能为 0</span>
</el-form-item>
<el-form-item label="调整原因" prop="reason">
<el-input
v-model.trim="form.reason"
type="textarea"
:rows="3"
maxlength="200"
show-word-limit
placeholder="请填写调整原因(会写入审计日志)"
style="max-width: 560px"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" :loading="submitting" @click="handleSubmit">提交调整</el-button>
<el-button @click="resetForm">重置</el-button>
</el-form-item>
</el-form>
</data-list-panel>
</template>
<script>
import { adjustPoints, getBalanceByUserId } from '@/api/points/balance'
import { getOrgUsers } from '@/api/system/user'
export default {
name: 'AdjustBalancePanel',
data() {
const pointsValidator = (rule, value, callback) => {
if (value === undefined || value === null || value === '') {
callback(new Error('请输入调整积分'))
} else if (Number(value) === 0) {
callback(new Error('调整积分不能为 0'))
} else {
callback()
}
}
return {
orgLoading: false,
orgOptions: [],
balanceLoading: false,
balance: null,
submitting: false,
// emitPath: false → v-model 直接是选中的用户 ID(只允许选叶子节点)
cascaderProps: { value: 'id', label: 'label', children: 'children', emitPath: false },
form: { userId: undefined, points: undefined, reason: '' },
rules: {
userId: [{ required: true, message: '请选择目标用户', trigger: 'change' }],
points: [{ validator: pointsValidator, trigger: 'change' }],
reason: [{ required: true, message: '请填写调整原因', trigger: 'blur' }]
}
}
},
computed: {
balanceText() {
if (this.balanceLoading) return '加载中...'
if (!this.balance) return '—'
const available = this.balance.availableBalance
const frozen = this.balance.frozenBalance
const frozenText =
frozen === undefined || frozen === null ? '' : `(冻结 ${frozen})`
return `可用 ${available === undefined || available === null ? '—' : available}${frozenText}`
},
selectedUserLabel() {
const target = this.form.userId === undefined || this.form.userId === null ? '' : String(this.form.userId)
if (!target) return ''
let label = ''
const walk = nodes => {
(nodes || []).forEach(node => {
if (label) return
if (String(node.id) === target) {
label = node.label || node.name || ''
return
}
if (node.children) walk(node.children)
})
}
walk(this.orgOptions)
return label
}
},
created() {
this.loadOrgUsers()
},
methods: {
loadOrgUsers() {
this.orgLoading = true
getOrgUsers()
.then(response => {
const payload = response && response.data !== undefined ? response.data : response
this.orgOptions = Array.isArray(payload)
? payload
: payload.list || payload.rows || []
})
.catch(() => {
this.orgOptions = []
this.$modal.msgError('组织架构加载失败,请稍后重试')
})
.finally(() => {
this.orgLoading = false
})
},
handleUserChange(userId) {
this.form.points = undefined
this.loadBalance(userId)
},
loadBalance(userId) {
if (userId === undefined || userId === null || userId === '') {
this.balance = null
return
}
this.balanceLoading = true
getBalanceByUserId(userId)
.then(response => {
this.balance = response && response.data !== undefined ? response.data : response
})
.catch(() => {
this.balance = null
})
.finally(() => {
this.balanceLoading = false
})
},
handleSubmit() {
this.$refs.adjustForm.validate(valid => {
if (!valid) return
const points = Number(this.form.points)
const action = points > 0 ? '补发' : '扣减'
const userLabel = this.selectedUserLabel || `用户ID ${this.form.userId}`
this.$confirm(
`确认对「${userLabel}」${action} ${Math.abs(points)} 积分?操作将生成积分流水与审计日志,且不可撤销。`,
'手动调整积分',
{ type: 'warning' }
)
.then(() => {
this.submitting = true
return adjustPoints({
userId: this.form.userId,
points,
reason: this.form.reason
})
})
.then(() => {
this.$modal.msgSuccess('积分调整成功')
this.loadBalance(this.form.userId)
})
.catch(error => {
// 取消确认;接口失败已由请求拦截器统一提示,无需重复弹错
if (error === 'cancel') return
})
.finally(() => {
this.submitting = false
})
})
},
resetForm() {
this.$refs.adjustForm.resetFields()
this.form.points = undefined
this.balance = null
}
}
}
</script>
<style lang="scss" scoped>
.adjust-heading__title {
color: #1a1a2e;
font-size: 14px;
font-weight: 600;
line-height: 20px;
}
.adjust-heading__description {
margin-top: 6px;
color: #9898ae;
font-size: 11px;
font-weight: 400;
line-height: 18px;
}
.adjust-form {
max-width: 720px;
padding-top: 4px;
}
.adjust-balance {
color: #1a1a2e;
font-size: 13px;
}
.adjust-hint {
margin-left: 10px;
color: #9898ae;
font-size: 12px;
}
</style>