同步优惠券
This commit is contained in:
40
src/api/lb-user-coupon.js
Normal file
40
src/api/lb-user-coupon.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
export function getLbUserCouponList(params) {
|
||||
return request({
|
||||
url: '/lbUserCoupon/list',
|
||||
method: 'get',
|
||||
params
|
||||
})
|
||||
}
|
||||
|
||||
export function addLbUserCoupon(data) {
|
||||
return request({
|
||||
url: '/lbUserCoupon/add',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
export function updateLbUserCoupon(data) {
|
||||
return request({
|
||||
url: '/lbUserCoupon/update',
|
||||
method: 'put',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
export function deleteLbUserCoupon(id) {
|
||||
return request({
|
||||
url: '/lbUserCoupon/delete/' + id,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
|
||||
export function syncCoupons(params) {
|
||||
return request({
|
||||
url: '/lbUserCoupon/syncCoupons',
|
||||
method: 'post',
|
||||
params
|
||||
})
|
||||
}
|
||||
@@ -186,6 +186,12 @@ export const constantRoutes = [
|
||||
name: 'LbShoppingManage',
|
||||
component: () => import('@/views/lb-business/shopping-manage/index'),
|
||||
meta: { title: '购物管理', icon: 'el-icon-shopping-cart-full' }
|
||||
},
|
||||
{
|
||||
path: 'coupon-manage',
|
||||
name: 'LbCouponManage',
|
||||
component: () => import('@/views/lb-business/coupon-manage/index'),
|
||||
meta: { title: '优惠券管理', icon: 'el-icon-discount' }
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
426
src/views/lb-business/coupon-manage/index.vue
Normal file
426
src/views/lb-business/coupon-manage/index.vue
Normal file
@@ -0,0 +1,426 @@
|
||||
<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.userPhone" clearable placeholder="请输入用户手机号" style="width: 160px" />
|
||||
</el-form-item>
|
||||
<el-form-item label="用户昵称">
|
||||
<el-input v-model="queryParams.userNickname" clearable placeholder="请输入用户昵称" style="width: 160px" />
|
||||
</el-form-item>
|
||||
<el-form-item label="上级手机号">
|
||||
<el-input v-model="queryParams.parentPhone" clearable placeholder="请输入上级手机号" style="width: 160px" />
|
||||
</el-form-item>
|
||||
<el-form-item label="上级昵称">
|
||||
<el-input v-model="queryParams.parentNickname" clearable placeholder="请输入上级昵称" style="width: 160px" />
|
||||
</el-form-item>
|
||||
<el-form-item label="优惠日期">
|
||||
<el-date-picker
|
||||
v-model="couponDateRange"
|
||||
type="daterange"
|
||||
range-separator="至"
|
||||
start-placeholder="开始"
|
||||
end-placeholder="结束"
|
||||
value-format="yyyy-MM-dd"
|
||||
style="width: 280px"
|
||||
/>
|
||||
</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-button type="success" icon="el-icon-refresh" :loading="syncLoading" style="margin-left: 10px" @click="openSyncDialog">同步优惠券</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="用户ID" prop="userId" min-width="120" show-overflow-tooltip />
|
||||
<el-table-column label="用户手机号" prop="userPhone" min-width="120" show-overflow-tooltip />
|
||||
<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="couponAmount" min-width="100" align="center">
|
||||
<template slot-scope="scope">
|
||||
{{ scope.row.couponAmount != null ? scope.row.couponAmount : '-' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="优惠日期" prop="couponDate" min-width="120">
|
||||
<template slot-scope="scope">
|
||||
{{ scope.row.couponDate || '-' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<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="操作" 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="560px" @close="resetForm">
|
||||
<el-form ref="dataForm" :model="form" :rules="formRules" label-width="100px">
|
||||
<el-form-item label="用户ID" prop="userId">
|
||||
<el-input v-model="form.userId" placeholder="请输入用户ID" />
|
||||
</el-form-item>
|
||||
<el-form-item label="用户手机号" prop="userPhone">
|
||||
<el-input v-model="form.userPhone" placeholder="请输入用户手机号" />
|
||||
</el-form-item>
|
||||
<el-form-item label="用户昵称" prop="userNickname">
|
||||
<el-input v-model="form.userNickname" placeholder="请输入用户昵称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="上级手机号" prop="parentPhone">
|
||||
<el-input v-model="form.parentPhone" placeholder="请输入上级手机号" />
|
||||
</el-form-item>
|
||||
<el-form-item label="上级昵称" prop="parentNickname">
|
||||
<el-input v-model="form.parentNickname" placeholder="请输入上级昵称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="优惠券金额" prop="couponAmount">
|
||||
<el-input-number
|
||||
v-model="form.couponAmount"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
:controls-position="right"
|
||||
style="width: 100%"
|
||||
placeholder="请输入优惠券金额"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="优惠日期" prop="couponDate">
|
||||
<el-date-picker
|
||||
v-model="form.couponDate"
|
||||
type="date"
|
||||
value-format="yyyy-MM-dd"
|
||||
placeholder="请选择优惠日期"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</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>
|
||||
|
||||
<el-dialog title="同步优惠券" :visible.sync="syncDialogVisible" width="460px" @close="resetSyncForm">
|
||||
<el-form ref="syncFormRef" :model="syncForm" :rules="syncFormRules" label-width="100px">
|
||||
<el-form-item label="租户ID">
|
||||
<el-input :value="tenantIdDisplay" disabled placeholder="未获取到租户ID" />
|
||||
</el-form-item>
|
||||
<el-form-item label="最近天数" prop="recentDays">
|
||||
<el-input-number
|
||||
v-model="syncForm.recentDays"
|
||||
:min="1"
|
||||
:max="365"
|
||||
style="width: 100%"
|
||||
placeholder="请输入最近天数"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button @click="syncDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="syncLoading" @click="handleSync">确定</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
addLbUserCoupon,
|
||||
deleteLbUserCoupon,
|
||||
getLbUserCouponList,
|
||||
syncCoupons,
|
||||
updateLbUserCoupon
|
||||
} from '@/api/lb-user-coupon'
|
||||
import { getBusinessHeaders } from '@/utils/business-headers'
|
||||
|
||||
export default {
|
||||
name: 'LbCouponManage',
|
||||
data() {
|
||||
return {
|
||||
loading: false,
|
||||
submitLoading: false,
|
||||
syncLoading: false,
|
||||
list: [],
|
||||
total: 0,
|
||||
couponDateRange: [],
|
||||
dialogVisible: false,
|
||||
dialogTitle: '',
|
||||
isEdit: false,
|
||||
syncDialogVisible: false,
|
||||
syncForm: {
|
||||
recentDays: 7
|
||||
},
|
||||
syncFormRules: {
|
||||
recentDays: [{ required: true, message: '请输入最近天数', trigger: 'blur' }]
|
||||
},
|
||||
queryParams: {
|
||||
current: 1,
|
||||
size: 10,
|
||||
userPhone: '',
|
||||
userNickname: '',
|
||||
parentPhone: '',
|
||||
parentNickname: ''
|
||||
},
|
||||
form: {
|
||||
id: '',
|
||||
userId: '',
|
||||
userPhone: '',
|
||||
userNickname: '',
|
||||
parentPhone: '',
|
||||
parentNickname: '',
|
||||
couponAmount: undefined,
|
||||
couponDate: ''
|
||||
},
|
||||
formRules: {
|
||||
userPhone: [{ required: true, message: '请输入用户手机号', trigger: 'blur' }]
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.fetchList()
|
||||
},
|
||||
computed: {
|
||||
tenantIdDisplay() {
|
||||
return this.getTenantIdFromBusinessHeaders()
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getTenantIdFromBusinessHeaders() {
|
||||
const headers = getBusinessHeaders()
|
||||
const value = headers && headers['X-Tenant-Id']
|
||||
return value ? String(value).trim() : ''
|
||||
},
|
||||
fetchList() {
|
||||
this.loading = true
|
||||
getLbUserCouponList(this.buildListParams())
|
||||
.then((res) => {
|
||||
if (res && (res.code === 20000 || res.code === 200 || res.success === true)) {
|
||||
this.list = Array.isArray(res.data) ? res.data : (res.data && Array.isArray(res.data.records) ? res.data.records : [])
|
||||
this.total = typeof res.total === 'number'
|
||||
? res.total
|
||||
: (res.data && typeof res.data.total === 'number' ? res.data.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,
|
||||
userPhone: this.queryParams.userPhone || undefined,
|
||||
userNickname: this.queryParams.userNickname || undefined,
|
||||
parentPhone: this.queryParams.parentPhone || undefined,
|
||||
parentNickname: this.queryParams.parentNickname || undefined
|
||||
}
|
||||
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]
|
||||
})
|
||||
return params
|
||||
},
|
||||
handleQuery() {
|
||||
this.queryParams.current = 1
|
||||
this.fetchList()
|
||||
},
|
||||
resetQuery() {
|
||||
this.queryParams = {
|
||||
current: 1,
|
||||
size: 10,
|
||||
userPhone: '',
|
||||
userNickname: '',
|
||||
parentPhone: '',
|
||||
parentNickname: ''
|
||||
}
|
||||
this.couponDateRange = []
|
||||
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 || '',
|
||||
userId: row.userId || '',
|
||||
userPhone: row.userPhone || '',
|
||||
userNickname: row.userNickname || '',
|
||||
parentPhone: row.parentPhone || '',
|
||||
parentNickname: row.parentNickname || '',
|
||||
couponAmount: row.couponAmount == null ? undefined : Number(row.couponAmount),
|
||||
couponDate: row.couponDate || ''
|
||||
}
|
||||
this.dialogVisible = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs.dataForm && this.$refs.dataForm.clearValidate()
|
||||
})
|
||||
},
|
||||
handleDelete(row) {
|
||||
if (!row.id) {
|
||||
this.$message.error('缺少ID,无法删除')
|
||||
return
|
||||
}
|
||||
this.$confirm('确定删除这条优惠券记录吗?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => deleteLbUserCoupon(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 ? updateLbUserCoupon(payload) : addLbUserCoupon(payload)
|
||||
req.then((res) => {
|
||||
this.$message.success((res && res.message) || (this.isEdit ? '更新成功' : '新增成功'))
|
||||
this.dialogVisible = false
|
||||
this.fetchList()
|
||||
}).finally(() => {
|
||||
this.submitLoading = false
|
||||
})
|
||||
})
|
||||
},
|
||||
buildPayload() {
|
||||
const payload = {
|
||||
id: this.form.id || undefined,
|
||||
userId: this.form.userId || undefined,
|
||||
userPhone: this.form.userPhone,
|
||||
userNickname: this.form.userNickname || undefined,
|
||||
parentPhone: this.form.parentPhone || undefined,
|
||||
parentNickname: this.form.parentNickname || undefined,
|
||||
couponAmount: this.form.couponAmount,
|
||||
couponDate: this.form.couponDate || undefined
|
||||
}
|
||||
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: '',
|
||||
userId: '',
|
||||
userPhone: '',
|
||||
userNickname: '',
|
||||
parentPhone: '',
|
||||
parentNickname: '',
|
||||
couponAmount: undefined,
|
||||
couponDate: ''
|
||||
}
|
||||
},
|
||||
openSyncDialog() {
|
||||
this.syncDialogVisible = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs.syncFormRef && this.$refs.syncFormRef.clearValidate()
|
||||
})
|
||||
},
|
||||
resetSyncForm() {
|
||||
this.syncForm = {
|
||||
recentDays: 7
|
||||
}
|
||||
this.$refs.syncFormRef && this.$refs.syncFormRef.resetFields()
|
||||
},
|
||||
handleSync() {
|
||||
this.$refs.syncFormRef.validate((valid) => {
|
||||
if (!valid) return
|
||||
const tenantId = this.getTenantIdFromBusinessHeaders()
|
||||
if (!tenantId) {
|
||||
this.$message.error('未获取到租户ID,请先登录或配置业务请求头中的租户')
|
||||
return
|
||||
}
|
||||
this.syncLoading = true
|
||||
syncCoupons({ tenantId, recentDays: this.syncForm.recentDays })
|
||||
.then((res) => {
|
||||
if (res && (res.success === true || res.code === 200 || res.code === 20000)) {
|
||||
this.$message.success((res && res.message) || '同步成功')
|
||||
this.syncDialogVisible = false
|
||||
this.fetchList()
|
||||
} else {
|
||||
this.$message.error((res && (res.message || res.msg)) || '同步失败')
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
this.$message.error('同步失败')
|
||||
})
|
||||
.finally(() => {
|
||||
this.syncLoading = false
|
||||
})
|
||||
})
|
||||
},
|
||||
formatDateTime(dateTime) {
|
||||
if (!dateTime) return '-'
|
||||
const dateStr = String(dateTime).replace('T', ' ')
|
||||
const date = new Date(dateStr)
|
||||
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>
|
||||
Reference in New Issue
Block a user