抵扣金管理

This commit is contained in:
zhonghua.li
2026-05-21 11:46:01 +08:00
parent d7180a5334
commit f1ce746af0
4 changed files with 466 additions and 88 deletions

View File

@@ -0,0 +1,32 @@
import request from '@/utils/request'
export function getLbDeductionAmountList(params) {
return request({
url: '/lbDeductionAmount/list',
method: 'get',
params
})
}
export function addLbDeductionAmount(data) {
return request({
url: '/lbDeductionAmount/add',
method: 'post',
data
})
}
export function updateLbDeductionAmount(data) {
return request({
url: '/lbDeductionAmount/update',
method: 'put',
data
})
}
export function deleteLbDeductionAmount(id) {
return request({
url: `/lbDeductionAmount/delete/${id}`,
method: 'delete'
})
}

View File

@@ -421,6 +421,12 @@ export const constantRoutes = [
name: 'LbUserManage', name: 'LbUserManage',
component: () => import('@/views/lb-business/user-manage/index'), component: () => import('@/views/lb-business/user-manage/index'),
meta: { title: '用户管理', icon: 'el-icon-user' } meta: { title: '用户管理', icon: 'el-icon-user' }
},
{
path: 'deduction-manage',
name: 'LbDeductionManage',
component: () => import('@/views/lb-business/deduction-manage/index'),
meta: { title: '抵扣金管理', icon: 'el-icon-wallet' }
} }
] ]
}, },

View File

@@ -0,0 +1,340 @@
<template>
<div class="app-container">
<el-card class="filter-container" shadow="never">
<el-form :model="queryParams" :inline="true" label-width="90px">
<el-form-item label="用户姓名">
<el-input v-model="queryParams.userName" clearable placeholder="请输入用户姓名" style="width: 160px" />
</el-form-item>
<el-form-item label="用户电话">
<el-input v-model="queryParams.userPhone" clearable placeholder="请输入用户电话" style="width: 160px" />
</el-form-item>
<el-form-item label="创建时间">
<el-date-picker
v-model="createTimeRange"
type="datetimerange"
range-separator=""
start-placeholder="开始"
end-placeholder="结束"
value-format="yyyy-MM-dd HH:mm:ss"
:default-time="['00:00:00', '23:59:59']"
style="width: 360px"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" @click="handleQuery">查询</el-button>
<el-button icon="el-icon-delete" @click="resetQuery">清空</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card class="action-container" shadow="never">
<el-button type="primary" icon="el-icon-plus" @click="handleAdd">新增</el-button>
</el-card>
<el-card class="table-container" shadow="never">
<el-table v-loading="loading" :data="list" style="width: 100%">
<el-table-column label="用户姓名" prop="userName" min-width="100" show-overflow-tooltip />
<el-table-column label="用户电话" prop="userPhone" min-width="120" show-overflow-tooltip />
<el-table-column label="抵扣金额" prop="dikouAmt" min-width="100" align="right">
<template slot-scope="scope">
{{ formatAmount(scope.row.dikouAmt) }}
</template>
</el-table-column>
<el-table-column label="原始文本" prop="originalText" min-width="200" show-overflow-tooltip />
<el-table-column label="创建时间" prop="createTime" min-width="160">
<template slot-scope="scope">
{{ formatDateTime(scope.row.createTime) }}
</template>
</el-table-column>
<el-table-column label="修改时间" prop="updateTime" min-width="160">
<template slot-scope="scope">
{{ formatDateTime(scope.row.updateTime) }}
</template>
</el-table-column>
<el-table-column label="操作" fixed="right" width="140">
<template slot-scope="scope">
<el-button type="text" @click="handleEdit(scope.row)">编辑</el-button>
<el-button type="text" style="color:#F56C6C;" @click="handleDelete(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
:current-page="queryParams.current"
:page-size="queryParams.size"
:page-sizes="[10, 20, 50, 100]"
:total="total"
layout="total, sizes, prev, pager, next, jumper"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
/>
</el-card>
<el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="640px" @close="resetForm">
<el-form ref="dataForm" :model="form" :rules="formRules" label-width="100px">
<el-form-item label="用户姓名" prop="userName">
<el-input v-model="form.userName" placeholder="请输入用户姓名" />
</el-form-item>
<el-form-item label="用户电话" prop="userPhone">
<el-input v-model="form.userPhone" placeholder="请输入用户电话" />
</el-form-item>
<el-form-item label="抵扣金额" prop="dikouAmt">
<el-input-number
v-model="form.dikouAmt"
:min="0"
:precision="2"
:step="0.01"
controls-position="right"
style="width: 100%"
placeholder="请输入抵扣金额"
/>
</el-form-item>
<el-form-item label="原始文本">
<el-input
v-model="form.originalText"
type="textarea"
:rows="4"
placeholder="请输入原始文本信息"
/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" :loading="submitLoading" @click="handleSubmit">确定</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import {
addLbDeductionAmount,
deleteLbDeductionAmount,
getLbDeductionAmountList,
updateLbDeductionAmount
} from '@/api/lb-deduction-amount'
import { getBusinessHeaders } from '@/utils/business-headers'
export default {
name: 'LbDeductionManage',
data() {
return {
loading: false,
submitLoading: false,
list: [],
total: 0,
createTimeRange: [],
dialogVisible: false,
dialogTitle: '',
isEdit: false,
queryParams: {
current: 1,
size: 10,
userName: '',
userPhone: ''
},
form: {
id: '',
userName: '',
userPhone: '',
dikouAmt: undefined,
originalText: ''
},
formRules: {
userName: [{ required: true, message: '请输入用户姓名', trigger: 'blur' }],
userPhone: [{ required: true, message: '请输入用户电话', trigger: 'blur' }],
dikouAmt: [{ required: true, message: '请输入抵扣金额', trigger: 'change' }]
}
}
},
created() {
this.fetchList()
},
methods: {
getTenantIdFromBusinessHeaders() {
const headers = getBusinessHeaders()
const value = headers && headers['X-Tenant-Id']
return value ? String(value).trim() : ''
},
fetchList() {
this.loading = true
getLbDeductionAmountList(this.buildListParams())
.then((res) => {
if (res && (res.code === 20000 || res.code === 200 || res.success === true)) {
this.list = Array.isArray(res.data) ? res.data : []
this.total = typeof res.total === 'number'
? res.total
: (res.page && typeof res.page.total === 'number' ? res.page.total : this.list.length)
} else {
this.list = []
this.total = 0
}
})
.catch(() => {
this.list = []
this.total = 0
})
.finally(() => {
this.loading = false
})
},
buildListParams() {
const params = {
current: this.queryParams.current,
size: this.queryParams.size,
userName: this.queryParams.userName || undefined,
userPhone: this.queryParams.userPhone || undefined
}
const tenantId = this.getTenantIdFromBusinessHeaders()
if (tenantId) params.tenantId = tenantId
const range = this.createTimeRange || []
if (range[0]) params.createTimeStart = range[0]
if (range[1]) params.createTimeEnd = range[1]
Object.keys(params).forEach((key) => {
if (params[key] === undefined || params[key] === '') delete params[key]
})
return params
},
handleQuery() {
this.queryParams.current = 1
this.fetchList()
},
resetQuery() {
this.queryParams = {
current: 1,
size: 10,
userName: '',
userPhone: ''
}
this.createTimeRange = []
this.fetchList()
},
handleSizeChange(size) {
this.queryParams.size = size
this.fetchList()
},
handleCurrentChange(current) {
this.queryParams.current = current
this.fetchList()
},
handleAdd() {
this.dialogTitle = '新增抵扣金'
this.isEdit = false
this.resetFormData()
this.dialogVisible = true
this.$nextTick(() => {
this.$refs.dataForm && this.$refs.dataForm.clearValidate()
})
},
handleEdit(row) {
this.dialogTitle = '编辑抵扣金'
this.isEdit = true
this.form = {
id: row.id || '',
userName: row.userName || '',
userPhone: row.userPhone || '',
dikouAmt: row.dikouAmt === null || row.dikouAmt === undefined ? undefined : Number(row.dikouAmt),
originalText: row.originalText || ''
}
this.dialogVisible = true
this.$nextTick(() => {
this.$refs.dataForm && this.$refs.dataForm.clearValidate()
})
},
handleDelete(row) {
this.$confirm('确定删除这条抵扣金记录吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => deleteLbDeductionAmount(row.id))
.then((res) => {
this.$message.success((res && res.message) || '删除成功')
this.fetchList()
})
.catch(() => {})
},
handleSubmit() {
this.$refs.dataForm.validate((valid) => {
if (!valid) return
const tenantId = this.getTenantIdFromBusinessHeaders()
if (!tenantId) {
this.$message.error('未获取到租户ID请先登录或配置业务请求头中的租户')
return
}
const payload = { ...this.buildPayload(), tenantId }
this.submitLoading = true
const req = this.isEdit ? updateLbDeductionAmount(payload) : addLbDeductionAmount(payload)
req.then((res) => {
this.$message.success((res && res.message) || (this.isEdit ? '更新成功' : '新增成功'))
this.dialogVisible = false
this.fetchList()
}).finally(() => {
this.submitLoading = false
})
})
},
buildPayload() {
const payload = {
userName: this.form.userName,
userPhone: this.form.userPhone,
dikouAmt: this.form.dikouAmt,
originalText: this.form.originalText || undefined
}
if (this.isEdit) payload.id = this.form.id
Object.keys(payload).forEach((key) => {
if (payload[key] === undefined || payload[key] === '') delete payload[key]
})
return payload
},
resetForm() {
this.$refs.dataForm && this.$refs.dataForm.resetFields()
this.resetFormData()
},
resetFormData() {
this.form = {
id: '',
userName: '',
userPhone: '',
dikouAmt: undefined,
originalText: ''
}
},
formatAmount(val) {
if (val === null || val === undefined || val === '') return '-'
const n = Number(val)
return Number.isNaN(n) ? String(val) : n.toFixed(2)
},
formatDateTime(dateTime) {
if (!dateTime) return '-'
const date = new Date(String(dateTime).replace('T', ' '))
if (Number.isNaN(date.getTime())) return String(dateTime)
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
const hours = String(date.getHours()).padStart(2, '0')
const minutes = String(date.getMinutes()).padStart(2, '0')
const seconds = String(date.getSeconds()).padStart(2, '0')
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
}
}
}
</script>
<style lang="scss" scoped>
.app-container {
.filter-container {
margin-bottom: 20px;
}
.action-container {
margin-bottom: 20px;
}
.table-container {
.el-pagination {
margin-top: 20px;
text-align: right;
}
}
}
</style>