支持固定分佣
This commit is contained in:
parent
76c0602564
commit
fd125f4f97
@ -72,13 +72,23 @@
|
|||||||
</template>
|
</template>
|
||||||
</a-space>
|
</a-space>
|
||||||
</template>
|
</template>
|
||||||
|
<template v-if="column.key === 'commission'">
|
||||||
|
<template v-if="record.delivery_commission_fixed > 0">
|
||||||
|
<a-tag color="blue">固定金额</a-tag>
|
||||||
|
<span>¥{{ record.delivery_commission_fixed }}</span>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<a-tag color="orange">按比例</a-tag>
|
||||||
|
<span>{{ record.delivery_commission_rate || 0 }}%</span>
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
<template v-if="column.key === 'action'">
|
<template v-if="column.key === 'action'">
|
||||||
<a-space>
|
<a-space>
|
||||||
<a-button type="link" @click="handleEditCommunity(record)">
|
<a-button type="link" @click="handleEditCommunity(record)">
|
||||||
{{ record.community_name ? '修改小区' : '设置小区' }}
|
{{ record.community_name ? '修改小区' : '设置小区' }}
|
||||||
</a-button>
|
</a-button>
|
||||||
<a-button type="link" @click="handleEditCommission(record)">
|
<a-button type="link" @click="showCommissionModal(record)">
|
||||||
设置分佣比例
|
设置分佣
|
||||||
</a-button>
|
</a-button>
|
||||||
</a-space>
|
</a-space>
|
||||||
</template>
|
</template>
|
||||||
@ -114,32 +124,68 @@
|
|||||||
</a-form>
|
</a-form>
|
||||||
</a-modal>
|
</a-modal>
|
||||||
|
|
||||||
<!-- 分佣比例设置模态框 -->
|
<!-- 设置分佣比例模态框 -->
|
||||||
<a-modal
|
<a-modal
|
||||||
v-model:visible="commissionModalVisible"
|
v-model:visible="commissionModalVisible"
|
||||||
title="设置分佣比例"
|
title="设置分佣"
|
||||||
:confirm-loading="commissionSaving"
|
:confirm-loading="commissionSubmitting"
|
||||||
@ok="handleCommissionSave"
|
@ok="handleCommissionSubmit"
|
||||||
@cancel="handleCommissionCancel"
|
@cancel="handleCommissionCancel"
|
||||||
>
|
>
|
||||||
<a-form layout="vertical">
|
<a-form
|
||||||
|
ref="commissionFormRef"
|
||||||
|
:model="commissionForm"
|
||||||
|
:rules="commissionRules"
|
||||||
|
layout="vertical"
|
||||||
|
>
|
||||||
<a-form-item
|
<a-form-item
|
||||||
label="分佣比例(%)"
|
label="分佣类型"
|
||||||
required
|
name="commission_type"
|
||||||
:rules="[
|
:rules="[{ required: true, message: '请选择分佣类型' }]"
|
||||||
{ required: true, message: '请输入分佣比例' },
|
>
|
||||||
{ type: 'number', min: 0, max: 100, message: '分佣比例必须在0-100之间' }
|
<a-radio-group v-model:value="commissionForm.commission_type" @change="handleCommissionTypeChange">
|
||||||
]"
|
<a-radio value="rate">按比例分佣</a-radio>
|
||||||
|
<a-radio value="fixed">固定金额分佣</a-radio>
|
||||||
|
</a-radio-group>
|
||||||
|
</a-form-item>
|
||||||
|
|
||||||
|
<a-form-item
|
||||||
|
v-if="commissionForm.commission_type === 'rate'"
|
||||||
|
label="分佣比例"
|
||||||
|
name="delivery_commission_rate"
|
||||||
|
:rules="[{ required: commissionForm.commission_type === 'rate', message: '请输入分佣比例' }]"
|
||||||
>
|
>
|
||||||
<a-input-number
|
<a-input-number
|
||||||
v-model:value="commissionRate"
|
v-model:value="commissionForm.delivery_commission_rate"
|
||||||
:min="0"
|
:min="0"
|
||||||
:max="100"
|
:max="100"
|
||||||
style="width: 200px"
|
:precision="2"
|
||||||
placeholder="请输入分佣比例"
|
:step="1"
|
||||||
|
style="width: 100%"
|
||||||
addon-after="%"
|
addon-after="%"
|
||||||
/>
|
/>
|
||||||
<div class="commission-tip">请输入0-100之间的整数</div>
|
<div class="form-help-text">
|
||||||
|
配送员可获得订单金额的百分比作为佣金
|
||||||
|
</div>
|
||||||
|
</a-form-item>
|
||||||
|
|
||||||
|
<a-form-item
|
||||||
|
v-if="commissionForm.commission_type === 'fixed'"
|
||||||
|
label="固定金额"
|
||||||
|
name="delivery_commission_fixed"
|
||||||
|
:rules="[{ required: commissionForm.commission_type === 'fixed', message: '请输入固定金额' }]"
|
||||||
|
>
|
||||||
|
<a-input-number
|
||||||
|
v-model:value="commissionForm.delivery_commission_fixed"
|
||||||
|
:min="0"
|
||||||
|
:precision="2"
|
||||||
|
:step="1"
|
||||||
|
style="width: 100%"
|
||||||
|
addon-before="¥"
|
||||||
|
/>
|
||||||
|
<div class="form-help-text">
|
||||||
|
配送员每单可获得的固定金额佣金
|
||||||
|
</div>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
</a-form>
|
</a-form>
|
||||||
</a-modal>
|
</a-modal>
|
||||||
@ -148,15 +194,17 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { defineComponent, ref, onMounted } from 'vue'
|
import { defineComponent, ref, onMounted, computed } from 'vue'
|
||||||
import { message } from 'ant-design-vue'
|
import { message, Radio } from 'ant-design-vue'
|
||||||
import request from '@/utils/request'
|
import request from '@/utils/request'
|
||||||
import PageContainer from '@/components/PageContainer.vue'
|
import PageContainer from '@/components/PageContainer.vue'
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'DeliverymanList',
|
name: 'DeliverymanList',
|
||||||
components: {
|
components: {
|
||||||
PageContainer
|
PageContainer,
|
||||||
|
ARadio: Radio,
|
||||||
|
ARadioGroup: Radio.Group
|
||||||
},
|
},
|
||||||
setup() {
|
setup() {
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
@ -175,32 +223,29 @@ export default defineComponent({
|
|||||||
dataIndex: 'userid',
|
dataIndex: 'userid',
|
||||||
key: 'userid',
|
key: 'userid',
|
||||||
width: 80,
|
width: 80,
|
||||||
|
align: 'center'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '昵称',
|
title: '姓名',
|
||||||
dataIndex: 'nickname',
|
dataIndex: 'nickname',
|
||||||
key: 'nickname',
|
key: 'nickname',
|
||||||
width: 120,
|
width: 120
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '手机号',
|
title: '手机号',
|
||||||
dataIndex: 'phone',
|
dataIndex: 'phone',
|
||||||
key: 'phone',
|
key: 'phone',
|
||||||
width: 120,
|
width: 150
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '所属小区',
|
title: '所属小区',
|
||||||
dataIndex: 'community_name',
|
|
||||||
key: 'community_name',
|
key: 'community_name',
|
||||||
width: 200,
|
width: 150
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '分佣比例(%)',
|
title: '分佣设置',
|
||||||
dataIndex: 'delivery_commission_rate',
|
|
||||||
key: 'commission',
|
key: 'commission',
|
||||||
width: 100,
|
width: 150
|
||||||
align: 'right',
|
|
||||||
render: (text) => text ? `${text}%` : '-'
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
@ -320,42 +365,95 @@ export default defineComponent({
|
|||||||
|
|
||||||
// 分佣相关状态和方法
|
// 分佣相关状态和方法
|
||||||
const commissionModalVisible = ref(false)
|
const commissionModalVisible = ref(false)
|
||||||
const commissionSaving = ref(false)
|
const commissionSubmitting = ref(false)
|
||||||
const commissionRate = ref(0)
|
const commissionFormRef = ref(null)
|
||||||
|
const commissionForm = ref({
|
||||||
|
commission_type: 'rate',
|
||||||
|
delivery_commission_rate: 0,
|
||||||
|
delivery_commission_fixed: 0
|
||||||
|
})
|
||||||
|
const commissionRules = {
|
||||||
|
commission_type: [
|
||||||
|
{ required: true, message: '请选择分佣类型' }
|
||||||
|
],
|
||||||
|
delivery_commission_rate: [
|
||||||
|
{ required: false, message: '请输入分佣比例' },
|
||||||
|
{ type: 'number', min: 0, max: 100, message: '分佣比例必须在0-100之间' }
|
||||||
|
],
|
||||||
|
delivery_commission_fixed: [
|
||||||
|
{ required: false, message: '请输入固定金额' },
|
||||||
|
{ type: 'number', min: 0, message: '固定金额必须大于0' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
// 编辑分佣比例
|
// 处理分佣类型变更
|
||||||
const handleEditCommission = (record) => {
|
const handleCommissionTypeChange = (e) => {
|
||||||
|
const type = e.target.value
|
||||||
|
if (type === 'rate') {
|
||||||
|
commissionForm.value.delivery_commission_fixed = 0
|
||||||
|
} else if (type === 'fixed') {
|
||||||
|
commissionForm.value.delivery_commission_rate = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 显示设置分佣模态框
|
||||||
|
const showCommissionModal = (record) => {
|
||||||
currentUserId.value = record.userid
|
currentUserId.value = record.userid
|
||||||
commissionRate.value = record.delivery_commission_rate || 0
|
|
||||||
|
// 根据已有数据判断分佣类型
|
||||||
|
if (record.delivery_commission_fixed > 0) {
|
||||||
|
commissionForm.value.commission_type = 'fixed'
|
||||||
|
commissionForm.value.delivery_commission_fixed = record.delivery_commission_fixed
|
||||||
|
commissionForm.value.delivery_commission_rate = 0
|
||||||
|
} else {
|
||||||
|
commissionForm.value.commission_type = 'rate'
|
||||||
|
commissionForm.value.delivery_commission_rate = record.delivery_commission_rate || 0
|
||||||
|
commissionForm.value.delivery_commission_fixed = 0
|
||||||
|
}
|
||||||
|
|
||||||
commissionModalVisible.value = true
|
commissionModalVisible.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存分佣比例
|
// 提交分佣设置
|
||||||
const handleCommissionSave = async () => {
|
const handleCommissionSubmit = () => {
|
||||||
|
commissionFormRef.value.validate().then(async () => {
|
||||||
try {
|
try {
|
||||||
commissionSaving.value = true
|
commissionSubmitting.value = true
|
||||||
await request.put(`/api/user/delivery-commission-rate`, {
|
|
||||||
user_id : currentUserId.value,
|
|
||||||
delivery_commission_rate: commissionRate.value
|
|
||||||
})
|
|
||||||
|
|
||||||
message.success('设置成功')
|
// 根据分佣类型构建参数
|
||||||
|
const params = {
|
||||||
|
user_id: currentUserId.value,
|
||||||
|
delivery_commission_rate: commissionForm.value.commission_type === 'rate' ? commissionForm.value.delivery_commission_rate : 0,
|
||||||
|
delivery_commission_fixed: commissionForm.value.commission_type === 'fixed' ? commissionForm.value.delivery_commission_fixed : 0
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await request.put('/api/user/delivery-commission', params)
|
||||||
|
|
||||||
|
if (res.code === 200) {
|
||||||
|
message.success('分佣设置成功')
|
||||||
commissionModalVisible.value = false
|
commissionModalVisible.value = false
|
||||||
fetchData()
|
fetchData()
|
||||||
} catch (error) {
|
} else {
|
||||||
console.error('设置分佣比例失败:', error)
|
message.error(res.message || '分佣设置失败')
|
||||||
message.error('设置失败')
|
|
||||||
} finally {
|
|
||||||
commissionSaving.value = false
|
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('设置分佣失败:', error)
|
||||||
|
message.error('分佣设置失败')
|
||||||
|
} finally {
|
||||||
|
commissionSubmitting.value = false
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 取消分佣设置
|
// 取消分佣设置
|
||||||
const handleCommissionCancel = () => {
|
const handleCommissionCancel = () => {
|
||||||
commissionModalVisible.value = false
|
commissionModalVisible.value = false
|
||||||
commissionRate.value = 0
|
|
||||||
currentUserId.value = null
|
currentUserId.value = null
|
||||||
|
commissionForm.value = {
|
||||||
|
commission_type: 'rate',
|
||||||
|
delivery_commission_rate: 0,
|
||||||
|
delivery_commission_fixed: 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理筛选变化
|
// 处理筛选变化
|
||||||
@ -389,7 +487,6 @@ export default defineComponent({
|
|||||||
columns,
|
columns,
|
||||||
tableData,
|
tableData,
|
||||||
pagination,
|
pagination,
|
||||||
handleTableChange,
|
|
||||||
formatPhone,
|
formatPhone,
|
||||||
communityModalVisible,
|
communityModalVisible,
|
||||||
communitySaving,
|
communitySaving,
|
||||||
@ -400,10 +497,13 @@ export default defineComponent({
|
|||||||
handleCommunitySave,
|
handleCommunitySave,
|
||||||
handleCommunityCancel,
|
handleCommunityCancel,
|
||||||
commissionModalVisible,
|
commissionModalVisible,
|
||||||
commissionSaving,
|
commissionSubmitting,
|
||||||
commissionRate,
|
commissionForm,
|
||||||
handleEditCommission,
|
commissionFormRef,
|
||||||
handleCommissionSave,
|
commissionRules,
|
||||||
|
showCommissionModal,
|
||||||
|
handleCommissionSubmit,
|
||||||
|
handleCommissionTypeChange,
|
||||||
handleCommissionCancel,
|
handleCommissionCancel,
|
||||||
filterForm,
|
filterForm,
|
||||||
handleFilterChange,
|
handleFilterChange,
|
||||||
@ -464,7 +564,7 @@ export default defineComponent({
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.commission-tip {
|
.form-help-text {
|
||||||
color: rgba(0, 0, 0, 0.45);
|
color: rgba(0, 0, 0, 0.45);
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user