@@ -14,6 +14,15 @@
< el-form-item label = "上级昵称" >
< el-input v-model = "queryParams.parentNickname" clearable placeholder="请输入上级昵称" style="width: 160px" / >
< / el-form-item >
< el-form-item label = "数据类型" >
< el-select v-model = "queryParams.dataType" clearable placeholder="请选择数据类型" style="width: 160px" >
< el -option label = "明细数据" value = "data_detail" / >
< el-option label = "月度统计" value = "data_month_static" / >
< / el-select >
< / el-form-item >
< el-form-item label = "优惠金额大于" >
< el-input-number v-model = "queryParams.couponAmount" :min="0" :precision="2" :controls-position="'right'" placeholder="请输入金额" style="width: 160px" / >
< / el-form-item >
< el-form-item label = "优惠日期" >
< el-date-picker
v-model = "couponDateRange"
@@ -35,6 +44,8 @@
< el-card class = "action-container" shadow = "never" >
< el-button type = "primary" icon = "el-icon-plus" @click ="handleAdd" > 新增 < / el -button >
< el-button type = "success" icon = "el-icon-refresh" :loading = "syncLoading" style = "margin-left: 10px" @click ="openSyncDialog" > 同步优惠券 < / el -button >
< el-button type = "info" icon = "el-icon-data-line" :loading = "statLoading" style = "margin-left: 10px" @click ="openStatDialog" > 按月统计 < / el -button >
< el-button type = "warning" icon = "el-icon-download" :loading = "exportLoading" style = "margin-left: 10px" @click ="handleExport" > 导出 < / el -button >
< / el-card >
< el-card class = "table-container" shadow = "never" >
@@ -44,6 +55,11 @@
< el-table-column label = "用户昵称" prop = "userNickname" min -width = " 120 " show -overflow -tooltip / >
< el-table-column label = "上级手机号" prop = "parentPhone" min -width = " 120 " show -overflow -tooltip / >
< el-table-column label = "上级昵称" prop = "parentNickname" min -width = " 120 " show -overflow -tooltip / >
< el-table-column label = "数据类型" prop = "dataType" min -width = " 100 " align = "center" >
< template slot -scope = " scope " >
{ { scope . row . dataType === 'data_detail' ? '明细数据' : scope . row . dataType === 'data_month_static' ? '月度统计' : '-' } }
< / template >
< / el-table-column >
< el-table-column label = "优惠券金额" prop = "couponAmount" min -width = " 100 " align = "center" >
< template slot -scope = " scope " >
{ { scope . row . couponAmount != null ? scope . row . couponAmount : '-' } }
@@ -141,6 +157,46 @@
< el-button type = "primary" :loading = "syncLoading" @click ="handleSync" > 确定 < / el -button >
< / div >
< / el-dialog >
< el-dialog title = "按月统计" :visible.sync = "statDialogVisible" width = "600px" @close ="resetStatForm" >
< el -form ref = "statFormRef" :model = "statForm" label -width = " 100px " >
< el-form-item label = "租户ID" >
< el-input :value = "tenantIdDisplay" disabled placeholder = "未获取到租户ID" / >
< / el-form-item >
< el-form-item label = "优惠日期范围" >
< el-date-picker
v-model = "statDateRange"
type = "daterange"
range -separator = " 至 "
start -placeholder = " 开始日期 "
end -placeholder = " 结束日期 "
value -format = " yyyy -MM -dd "
style = "width: 100%"
/ >
< / el-form-item >
< / el-form >
< div v-if = "statResult && statResult.length" style="margin-top: 20px;" >
< el -divider content -position = " left " > 统计结果 < / el-divider >
< el-table :data = "statResult" style = "width: 100%" size = "small" >
< el-table-column prop = "month" label = "月份" min -width = " 100 " / >
< el-table-column prop = "totalAmount" label = "总金额" min -width = " 120 " align = "right" >
< template slot -scope = " scope " >
{ { scope . row . totalAmount != null ? scope . row . totalAmount . toFixed ( 2 ) : '-' } }
< / template >
< / el-table-column >
< el-table-column prop = "count" label = "数量" min -width = " 100 " align = "right" / >
< / el-table >
< div v-if = "statTotal" style="margin-top: 10px; text-align: right; font-weight: bold;" >
合计金额 : {{ statTotal.toFixed ( 2 ) }}
< / div >
< / div >
< div slot = "footer" class = "dialog-footer" >
< el-button @click ="statDialogVisible = false" > 关闭 < / el -button >
< el-button type = "primary" :loading = "statLoading" @click ="handleStat" > 统计 < / el -button >
< / div >
< / el-dialog >
< / div >
< / template >
@@ -148,7 +204,9 @@
import {
addLbUserCoupon ,
deleteLbUserCoupon ,
exportLbUserCoupon ,
getLbUserCouponList ,
monthlyStatistic ,
syncCoupons ,
updateLbUserCoupon
} from '@/api/lb-user-coupon'
@@ -161,6 +219,7 @@ export default {
loading : false ,
submitLoading : false ,
syncLoading : false ,
exportLoading : false ,
list : [ ] ,
total : 0 ,
couponDateRange : [ ] ,
@@ -174,13 +233,20 @@ export default {
syncFormRules : {
recentDays : [ { required : true , message : '请输入最近天数' , trigger : 'blur' } ]
} ,
statDialogVisible : false ,
statLoading : false ,
statDateRange : [ ] ,
statResult : [ ] ,
statTotal : null ,
queryParams : {
current : 1 ,
size : 10 ,
userPhone : '' ,
userNickname : '' ,
parentPhone : '' ,
parentNickname : ''
parentNickname : '' ,
dataType : '' ,
couponAmount : 3044
} ,
form : {
id : '' ,
@@ -197,14 +263,14 @@ export default {
}
}
} ,
created ( ) {
this . fetchList ( )
} ,
computed : {
tenantIdDisplay ( ) {
return this . getTenantIdFromBusinessHeaders ( )
}
} ,
created ( ) {
this . fetchList ( )
} ,
methods : {
getTenantIdFromBusinessHeaders ( ) {
const headers = getBusinessHeaders ( )
@@ -240,7 +306,9 @@ export default {
userPhone : this . queryParams . userPhone || undefined ,
userNickname : this . queryParams . userNickname || undefined ,
parentPhone : this . queryParams . parentPhone || undefined ,
parentNickname : this . queryParams . parentNickname || undefined
parentNickname : this . queryParams . parentNickname || undefined ,
dataType : this . queryParams . dataType || undefined ,
couponAmountMin : this . queryParams . couponAmount
}
const range = this . couponDateRange || [ ]
if ( range [ 0 ] ) params . couponDateStart = range [ 0 ]
@@ -261,7 +329,9 @@ export default {
userPhone : '' ,
userNickname : '' ,
parentPhone : '' ,
parentNickname : ''
parentNickname : '' ,
dataType : '' ,
couponAmount : undefined
}
this . couponDateRange = [ ]
this . fetchList ( )
@@ -408,6 +478,89 @@ export default {
} )
} )
} ,
openStatDialog ( ) {
this . statDialogVisible = true
} ,
resetStatForm ( ) {
this . statDateRange = [ ]
this . statResult = [ ]
this . statTotal = null
} ,
handleStat ( ) {
const tenantId = this . getTenantIdFromBusinessHeaders ( )
if ( ! tenantId ) {
this . $message . error ( '未获取到租户ID, 请先登录或配置业务请求头中的租户' )
return
}
this . statLoading = true
const params = { tenantId }
const range = this . statDateRange || [ ]
if ( range [ 0 ] ) params . couponDateStart = range [ 0 ]
if ( range [ 1 ] ) params . couponDateEnd = range [ 1 ]
monthlyStatistic ( params )
. then ( ( res ) => {
if ( res && ( res . success === true || res . code === 200 || res . code === 20000 ) ) {
this . statResult = Array . isArray ( res . data ) ? res . data : [ ]
this . statTotal = this . statResult . reduce ( ( sum , item ) => {
const amount = typeof item . totalAmount === 'number' ? item . totalAmount : 0
return sum + amount
} , 0 )
if ( ! this . statResult . length ) {
this . $message . info ( '该时间段内暂无统计数据' )
}
} else {
this . $message . error ( ( res && ( res . message || res . msg ) ) || '统计失败' )
}
} )
. catch ( ( ) => {
this . $message . error ( '统计失败' )
} )
. finally ( ( ) => {
this . statLoading = false
} )
} ,
handleExport ( ) {
const tenantId = this . getTenantIdFromBusinessHeaders ( )
if ( ! tenantId ) {
this . $message . error ( '未获取到租户ID, 请先登录或配置业务请求头中的租户' )
return
}
this . exportLoading = true
const params = {
tenantId ,
userPhone : this . queryParams . userPhone || undefined ,
userNickname : this . queryParams . userNickname || undefined ,
parentPhone : this . queryParams . parentPhone || undefined ,
parentNickname : this . queryParams . parentNickname || undefined ,
dataType : this . queryParams . dataType || undefined ,
couponAmountMin : this . queryParams . couponAmount
}
const range = this . couponDateRange || [ ]
if ( range [ 0 ] ) params . couponDateStart = range [ 0 ]
if ( range [ 1 ] ) params . couponDateEnd = range [ 1 ]
Object . keys ( params ) . forEach ( ( key ) => {
if ( params [ key ] === undefined || params [ key ] === '' ) delete params [ key ]
} )
exportLbUserCoupon ( params )
. then ( ( res ) => {
const blob = new Blob ( [ res ] , { type : 'application/vnd.ms-excel' } )
const url = window . URL . createObjectURL ( blob )
const link = document . createElement ( 'a' )
link . href = url
link . download = '用户优惠券.xlsx'
document . body . appendChild ( link )
link . click ( )
document . body . removeChild ( link )
window . URL . revokeObjectURL ( url )
this . $message . success ( '导出成功' )
} )
. catch ( ( ) => {
this . $message . error ( '导出失败' )
} )
. finally ( ( ) => {
this . exportLoading = false
} )
} ,
formatDateTime ( dateTime ) {
if ( ! dateTime ) return '-'
const dateStr = String ( dateTime ) . replace ( 'T' , ' ' )