sql数据流,amdin业务逻辑接入
This commit is contained in:
@@ -45,13 +45,13 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<button class="btn-select-action" @click="showCouponModal = true">选择优惠券</button>
|
||||
<button class="btn-select-action" @click="openCouponModal">选择优惠券</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 确认按钮 -->
|
||||
<view class="form-submit-bar">
|
||||
<button class="btn-primary-confirm" @click="handleSubmit">确认</button>
|
||||
<button class="btn-primary-confirm" @click="handleSubmit" :disabled="isLoading">确认</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -65,8 +65,13 @@
|
||||
</view>
|
||||
|
||||
<view class="modal-body">
|
||||
<!-- 编辑/设置模式:当用户由于点击“修改设置”时触发 -->
|
||||
<view v-if="isEditing" class="setting-form">
|
||||
<!-- 加载中 -->
|
||||
<view v-if="isLoading" class="modal-loading">
|
||||
<text>加载中...</text>
|
||||
</view>
|
||||
|
||||
<!-- 编辑/设置模式 -->
|
||||
<view v-else-if="isEditing" class="setting-form">
|
||||
<view class="setting-row">
|
||||
<text class="setting-label">显示名称:</text>
|
||||
<input class="setting-input" v-model="editingCoupon.name" placeholder="请输入页面显示的名称" />
|
||||
@@ -75,13 +80,13 @@
|
||||
<text class="setting-label">发放描述:</text>
|
||||
<input class="setting-input" v-model="editingCoupon.desc" placeholder="请输入发放时的描述" />
|
||||
</view>
|
||||
<view class="setting-tip">
|
||||
<text class="tip-text">* 此处的修改仅影响“新人礼”活动中的展示,不影响优惠券自身配置</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 选择模式 -->
|
||||
<view v-else class="selection-list">
|
||||
<view v-if="couponOptions.length === 0" class="empty-tip">
|
||||
<text>暂无可用优惠券</text>
|
||||
</view>
|
||||
<view v-for="(item, index) in couponOptions" :key="index"
|
||||
class="selection-card" :class="{'selected-card': isSelected(item)}"
|
||||
@click="toggleCoupon(item)">
|
||||
@@ -108,36 +113,73 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref, reactive } from 'vue'
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { fetchNewcomerConfig, saveNewcomerConfig, fetchAdminCoupons, NewcomerConfig, CouponTemplate } from '@/services/admin/marketingService.uts'
|
||||
|
||||
interface Coupon {
|
||||
id: number;
|
||||
name: string;
|
||||
desc: string;
|
||||
interface NewcomerCoupon {
|
||||
id : string;
|
||||
name : string;
|
||||
desc : string;
|
||||
}
|
||||
|
||||
const formData = reactive({
|
||||
balance: '88888',
|
||||
integral: '88888',
|
||||
coupons: [] as Coupon[]
|
||||
balance: '0',
|
||||
integral: '0',
|
||||
coupons: [] as NewcomerCoupon[]
|
||||
})
|
||||
|
||||
const isLoading = ref(false)
|
||||
const showCouponModal = ref(false)
|
||||
const isEditing = ref(false)
|
||||
const editingIndex = ref(-1)
|
||||
const editingCoupon = reactive<Coupon>({ id: 0, name: '', desc: '' })
|
||||
const editingCoupon = reactive<NewcomerCoupon>({ id: '', name: '', desc: '' })
|
||||
|
||||
const couponOptions = reactive<Coupon[]>([
|
||||
{ id: 1, name: '满100减10元券', desc: '全场通用' },
|
||||
{ id: 2, name: '新人5元无门槛', desc: '仅限新人使用' },
|
||||
{ id: 3, name: '满200减50元券', desc: '限特定商品' }
|
||||
])
|
||||
const couponOptions = ref<NewcomerCoupon[]>([])
|
||||
|
||||
function isSelected(item: Coupon): boolean {
|
||||
onMounted(() => {
|
||||
loadConfig()
|
||||
})
|
||||
|
||||
async function loadConfig() {
|
||||
isLoading.value = true
|
||||
try {
|
||||
const res = await fetchNewcomerConfig()
|
||||
if (res != null) {
|
||||
formData.balance = String(res.balance_reward)
|
||||
formData.integral = String(res.integral_reward)
|
||||
formData.coupons = res.coupons_json.map((c : any) : NewcomerCoupon => ({
|
||||
id: String(c.id),
|
||||
name: String(c.name),
|
||||
desc: String(c.desc)
|
||||
} as NewcomerCoupon))
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('加载配置失败:', e)
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function openCouponModal() {
|
||||
showCouponModal.value = true
|
||||
isLoading.value = true
|
||||
try {
|
||||
const res = await fetchAdminCoupons({ page: 1, pageSize: 100, status: 1 })
|
||||
couponOptions.value = res.items.map((item : CouponTemplate) : NewcomerCoupon => ({
|
||||
id: item.id!,
|
||||
name: item.name,
|
||||
desc: item.description ?? ''
|
||||
} as NewcomerCoupon))
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function isSelected(item : NewcomerCoupon) : boolean {
|
||||
return formData.coupons.some(c => c.id === item.id)
|
||||
}
|
||||
|
||||
function toggleCoupon(item: Coupon) {
|
||||
function toggleCoupon(item : NewcomerCoupon) {
|
||||
const index = formData.coupons.findIndex(c => c.id === item.id)
|
||||
if (index > -1) {
|
||||
formData.coupons.splice(index, 1)
|
||||
@@ -146,11 +188,11 @@ function toggleCoupon(item: Coupon) {
|
||||
}
|
||||
}
|
||||
|
||||
function removeCoupon(index: number) {
|
||||
function removeCoupon(index : number) {
|
||||
formData.coupons.splice(index, 1)
|
||||
}
|
||||
|
||||
function editCoupon(index: number) {
|
||||
function editCoupon(index : number) {
|
||||
editingIndex.value = index
|
||||
const coupon = formData.coupons[index]
|
||||
editingCoupon.id = coupon.id
|
||||
@@ -173,15 +215,25 @@ function confirmModal() {
|
||||
closeModal()
|
||||
}
|
||||
|
||||
function handleSubmit() {
|
||||
async function handleSubmit() {
|
||||
uni.showLoading({ title: '保存中...' })
|
||||
setTimeout(() => {
|
||||
try {
|
||||
const payload : NewcomerConfig = {
|
||||
balance_reward: parseFloat(formData.balance),
|
||||
integral_reward: parseInt(formData.integral),
|
||||
coupons_json: formData.coupons as any[]
|
||||
}
|
||||
const success = await saveNewcomerConfig(payload)
|
||||
if (success) {
|
||||
uni.showToast({ title: '设置已生效', icon: 'success' })
|
||||
} else {
|
||||
uni.showToast({ title: '保存失败', icon: 'none' })
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '系统异常', icon: 'none' })
|
||||
} finally {
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: '设置已生效',
|
||||
icon: 'success'
|
||||
})
|
||||
}, 500)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -516,6 +568,22 @@ function handleSubmit() {
|
||||
color: #fff;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.modal-loading {
|
||||
padding: 40px 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #1890ff;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.empty-tip {
|
||||
padding: 40px 0;
|
||||
text-align: center;
|
||||
color: #999;
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user