sql数据流,amdin业务逻辑接入
This commit is contained in:
@@ -73,17 +73,63 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { reactive } from 'vue'
|
||||
import { reactive, onMounted, ref } from 'vue'
|
||||
import { fetchRechargeConfig, saveRechargeConfig, RechargeConfig } from '@/services/admin/marketingService.uts'
|
||||
|
||||
const isLoading = ref(false)
|
||||
const isSaving = ref(false)
|
||||
|
||||
const config = reactive({
|
||||
balance_enabled: true,
|
||||
notice: '充值后账户的金额不能提现,可用于商城消费使用\n佣金导入账户之后不能再次导出、不可提现\n账户充值出现问题可联系商城客服',
|
||||
notice: '',
|
||||
mp_recharge: false,
|
||||
min_amount: 0.01
|
||||
})
|
||||
|
||||
const handleSave = () => {
|
||||
uni.showToast({ title: '保存成功', icon: 'success' })
|
||||
onMounted(() => {
|
||||
loadConfig()
|
||||
})
|
||||
|
||||
async function loadConfig() {
|
||||
isLoading.value = true
|
||||
try {
|
||||
const res = await fetchRechargeConfig()
|
||||
if (res != null) {
|
||||
config.balance_enabled = res.balance_enabled
|
||||
config.notice = res.recharge_notice ?? ''
|
||||
config.mp_recharge = res.mp_recharge_enabled
|
||||
config.min_amount = res.min_recharge_amount
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载配置失败', icon: 'none' })
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSave() {
|
||||
if (isSaving.value) return
|
||||
|
||||
isSaving.value = true
|
||||
const payload : RechargeConfig = {
|
||||
balance_enabled: config.balance_enabled,
|
||||
recharge_notice: config.notice,
|
||||
mp_recharge_enabled: config.mp_recharge,
|
||||
min_recharge_amount: config.min_amount
|
||||
}
|
||||
|
||||
try {
|
||||
const success = await saveRechargeConfig(payload)
|
||||
if (success) {
|
||||
uni.showToast({ title: '保存成功', icon: 'success' })
|
||||
} else {
|
||||
uni.showToast({ title: '保存失败', icon: 'none' })
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '保存异常', icon: 'none' })
|
||||
} finally {
|
||||
isSaving.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -120,74 +120,120 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref, reactive } from 'vue'
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { fetchRechargeQuotas, saveRechargeQuota, deleteRechargeQuota, RechargeQuota } from '@/services/admin/marketingService.uts'
|
||||
|
||||
const showAddModal = ref(false)
|
||||
const isLoading = ref(false)
|
||||
const isSaving = ref(false)
|
||||
const list = ref<RechargeQuota[]>([])
|
||||
|
||||
const formData = reactive({
|
||||
id: null as string | null,
|
||||
price: '',
|
||||
bonus: '',
|
||||
sort: 1,
|
||||
is_open: true
|
||||
})
|
||||
|
||||
const list = ref([
|
||||
{ id: 640, price: 10, bonus: 2, is_open: true, sort: 6 },
|
||||
{ id: 641, price: 20, bonus: 8, is_open: true, sort: 5 },
|
||||
{ id: 642, price: 50, bonus: 20, is_open: true, sort: 4 },
|
||||
{ id: 643, price: 100, bonus: 50, is_open: true, sort: 3 },
|
||||
{ id: 644, price: 200, bonus: 110, is_open: true, sort: 2 },
|
||||
{ id: 645, price: 300, bonus: 200, is_open: true, sort: 1 }
|
||||
])
|
||||
onMounted(() => {
|
||||
loadData()
|
||||
})
|
||||
|
||||
const toggleStatus = (item: any) => {
|
||||
item.is_open = !item.is_open
|
||||
uni.showToast({ title: '操作成功', icon: 'success' })
|
||||
async function loadData() {
|
||||
isLoading.value = true
|
||||
try {
|
||||
const res = await fetchRechargeQuotas()
|
||||
list.value = res
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleEdit = (item: any) => {
|
||||
uni.showToast({ title: '编辑功能', icon: 'none' })
|
||||
async function toggleStatus(item : RechargeQuota) {
|
||||
if (item.id == null) return
|
||||
const nextStatus = !item.is_open
|
||||
isLoading.value = true
|
||||
try {
|
||||
const success = await saveRechargeQuota({ ...item, is_open: nextStatus } as RechargeQuota)
|
||||
if (success) {
|
||||
item.is_open = nextStatus
|
||||
uni.showToast({ title: '操作成功', icon: 'success' })
|
||||
}
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleDelete = (item: any) => {
|
||||
function handleEdit(item : RechargeQuota) {
|
||||
formData.id = item.id ?? null
|
||||
formData.price = String(item.price)
|
||||
formData.bonus = String(item.bonus_price)
|
||||
formData.sort = item.sort_order
|
||||
formData.is_open = item.is_open
|
||||
showAddModal.value = true
|
||||
}
|
||||
|
||||
async function handleDelete(item : RechargeQuota) {
|
||||
if (item.id == null) return
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确认删除该项吗?',
|
||||
success: (res) => {
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
const index = list.value.findIndex(i => i.id === item.id)
|
||||
if (index > -1) {
|
||||
list.value.splice(index, 1)
|
||||
uni.showToast({ title: '已删除', icon: 'success' })
|
||||
isLoading.value = true
|
||||
try {
|
||||
const success = await deleteRechargeQuota(item.id!)
|
||||
if (success) {
|
||||
uni.showToast({ title: '已删除', icon: 'success' })
|
||||
loadData()
|
||||
}
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const handleSubmit = () => {
|
||||
async function handleSubmit() {
|
||||
if (!formData.price) {
|
||||
uni.showToast({ title: '请输入售价', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
const newItem = {
|
||||
id: Math.floor(Math.random() * 1000) + 700,
|
||||
isSaving.value = true
|
||||
const payload : RechargeQuota = {
|
||||
id: formData.id ?? undefined,
|
||||
price: parseFloat(formData.price),
|
||||
bonus: parseFloat(formData.bonus || '0'),
|
||||
sort: parseInt(formData.sort.toString()),
|
||||
bonus_price: parseFloat(formData.bonus || '0'),
|
||||
sort_order: parseInt(formData.sort.toString()),
|
||||
is_open: formData.is_open
|
||||
}
|
||||
|
||||
list.value.push(newItem)
|
||||
|
||||
// 重置表单
|
||||
try {
|
||||
const success = await saveRechargeQuota(payload)
|
||||
if (success) {
|
||||
uni.showToast({ title: formData.id ? '修改成功' : '添加成功', icon: 'success' })
|
||||
showAddModal.value = false
|
||||
resetForm()
|
||||
loadData()
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '操作异常', icon: 'none' })
|
||||
} finally {
|
||||
isSaving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function resetForm() {
|
||||
formData.id = null
|
||||
formData.price = ''
|
||||
formData.bonus = ''
|
||||
formData.sort = 1
|
||||
formData.is_open = true
|
||||
|
||||
showAddModal.value = false
|
||||
uni.showToast({ title: '添加成功', icon: 'success' })
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user