sc
This commit is contained in:
@@ -40,14 +40,7 @@
|
||||
<view class="quota-item">
|
||||
<view class="quota-label">月度赠会员总额度</view>
|
||||
<view class="quota-control">
|
||||
<input
|
||||
v-model="totalQuota"
|
||||
type="number"
|
||||
class="quota-input"
|
||||
placeholder="请输入总额度"
|
||||
min="0"
|
||||
max="1000"
|
||||
/>
|
||||
<view class="quota-value">{{ totalQuota }}</view>
|
||||
<view class="quota-unit">个</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -68,17 +61,17 @@
|
||||
class="quota-item"
|
||||
>
|
||||
<view class="distributor-info">
|
||||
<view class="distributor-name">{{ distributor.name }}</view>
|
||||
<view class="distributor-id">ID: {{ distributor.id }}</view>
|
||||
<view class="distributor-name">{{ distributor.distributorName }}</view>
|
||||
<view class="distributor-id">ID: {{ distributor.distributorId }}</view>
|
||||
</view>
|
||||
<view class="quota-control">
|
||||
<input
|
||||
v-model="distributor.quota"
|
||||
v-model="distributor.num"
|
||||
type="number"
|
||||
class="quota-input"
|
||||
placeholder="0"
|
||||
min="0"
|
||||
:max="maxDistributorQuota"
|
||||
:max="maxDistributorQuota(distributor.num)"
|
||||
/>
|
||||
<view class="quota-unit">个</view>
|
||||
</view>
|
||||
@@ -104,10 +97,11 @@
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, onMounted } from "vue"
|
||||
import { getQuotaInfoWithUser, saveQuotaInfo, getQuotaList } from "@/api/member/quota"
|
||||
|
||||
// 当前月份
|
||||
const currentMonth = ref('2026-01')
|
||||
const currentMonthDisplay = ref('2026年01月')
|
||||
const currentMonth = ref(new Date().toISOString().substring(0, 7))
|
||||
const currentMonthDisplay = ref(new Date().toISOString().substring(0, 7))
|
||||
|
||||
// 总额度
|
||||
const totalQuota = ref(100)
|
||||
@@ -135,16 +129,27 @@
|
||||
quota: 15
|
||||
}
|
||||
])
|
||||
|
||||
// 计算单个分销员最大可分配额度
|
||||
const maxDistributorQuota = computed(() => {
|
||||
return Math.floor(totalQuota.value * 0.5)
|
||||
})
|
||||
|
||||
|
||||
const loadCurrentMonthQuota = () => {
|
||||
getQuotaInfoWithUser({
|
||||
year: currentMonth.value.split('-')[0],
|
||||
month: currentMonth.value.split('-')[1]
|
||||
}).then(res => {
|
||||
totalQuota.value = res.data.num || 0
|
||||
})
|
||||
|
||||
getQuotaList({
|
||||
year: currentMonth.value.split('-')[0],
|
||||
month: currentMonth.value.split('-')[1]
|
||||
}).then(res => {
|
||||
distributors.value = res.data || []
|
||||
})
|
||||
}
|
||||
|
||||
// 计算已分配额度
|
||||
const allocatedQuota = computed(() => {
|
||||
return distributors.value.reduce((sum, distributor) => {
|
||||
return sum + parseInt(distributor.quota || 0)
|
||||
return sum + parseInt(distributor.num || 0)
|
||||
}, 0)
|
||||
})
|
||||
|
||||
@@ -153,6 +158,10 @@
|
||||
return totalQuota.value - allocatedQuota.value
|
||||
})
|
||||
|
||||
const maxDistributorQuota = (count) => {
|
||||
return remainingQuota.value ? count + remainingQuota.value : count
|
||||
}
|
||||
|
||||
// 返回上一页
|
||||
function goBack() {
|
||||
uni.navigateBack({ delta: 1 })
|
||||
@@ -162,9 +171,8 @@
|
||||
function onMonthChange(e) {
|
||||
currentMonth.value = e.detail.value
|
||||
const date = new Date(e.detail.value)
|
||||
currentMonthDisplay.value = `${date.getFullYear()}年${String(date.getMonth() + 1).padStart(2, '0')}月`
|
||||
// 实际项目中应根据选择的月份加载对应的额度配置
|
||||
// loadQuotaByMonth(currentMonth.value)
|
||||
currentMonthDisplay.value = new Date(date).toISOString().substring(0, 7)
|
||||
loadCurrentMonthQuota()
|
||||
}
|
||||
|
||||
// 保存配额
|
||||
@@ -186,23 +194,27 @@
|
||||
}
|
||||
|
||||
uni.showLoading({ title: '保存中...' })
|
||||
|
||||
setTimeout(() => {
|
||||
|
||||
saveQuotaInfo({
|
||||
year: currentMonth.value.split('-')[0],
|
||||
month: currentMonth.value.split('-')[1],
|
||||
nums: distributors.value.map(distributor => {
|
||||
return {
|
||||
distributorId: distributor.distributorId,
|
||||
num: distributor.num
|
||||
}
|
||||
})
|
||||
}).then(() => {
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: '保存成功',
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
// 实际项目中应调用接口保存配额配置
|
||||
// saveQuotaConfig()
|
||||
}, 1500)
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
// 实际项目中应从接口获取分销员列表和当前月份的配额配置
|
||||
// loadDistributors()
|
||||
// loadCurrentMonthQuota()
|
||||
loadCurrentMonthQuota()
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user