diff --git a/src/views/community/CommunityList.vue b/src/views/community/CommunityList.vue
index bd2ba6e..f78edd8 100644
--- a/src/views/community/CommunityList.vue
+++ b/src/views/community/CommunityList.vue
@@ -36,12 +36,7 @@
{{ formatDateTime(record.create_time) }}
-
+ 查看二维码
-
@@ -52,11 +47,31 @@
+
+
+
+ 平台
+ {{ record.profit_sharing.platform_rate }}%
+ 运营商
+ {{ record.profit_sharing.partner_rate }}%
+
+
+ 管理员
+ {{ record.profit_sharing.admin_rate }}%
+ 配送员
+ {{ record.profit_sharing.delivery_rate }}%
+
+
+ 未设置
+
-
+
@@ -147,16 +162,6 @@
上传群二维码
-
-
-
-
-
@@ -219,7 +224,108 @@
+
+
+
+
+
+
+
+
+ 总比例:{{ getTotalRate() }}%
+ (总比例必须等于100%)
+
+
+
+
+
+
+
@@ -305,10 +411,9 @@ export default defineComponent({
width: 200,
},
{
- title: '地址',
- dataIndex: 'address',
- key: 'address',
- width: 200,
+ title: '分润比例',
+ key: 'profit_sharing',
+ width: 220,
},
{
title: '位置',
@@ -332,7 +437,7 @@ export default defineComponent({
{
title: '操作',
key: 'action',
- width: 120,
+ width: 200,
align: 'center',
fixed: 'right'
},
@@ -501,6 +606,14 @@ export default defineComponent({
// 修改预览图片函数
const previewQRCode = async (file) => {
+ // 如果直接传入URL字符串
+ if (typeof file === 'string') {
+ previewImage.value = file
+ previewVisible.value = true
+ previewTitle.value = '群二维码预览'
+ return
+ }
+
// 如果是已上传的图片,直接使用 url
if (file.url) {
previewImage.value = file.url
@@ -700,6 +813,164 @@ export default defineComponent({
}
}
+ // 添加分润设置相关的状态
+ const profitSharingModalVisible = ref(false)
+ const profitSharingSaving = ref(false)
+ const currentCommunityName = ref('')
+ const isRateValid = ref(true)
+ const profitSharingForm = ref({
+ platform_rate: 10,
+ partner_rate: 10,
+ admin_rate: 10,
+ delivery_rate: 70
+ })
+
+ // 显示分润设置模态框
+ const handleEditProfitSharing = async (record) => {
+ currentCommunityId.value = record.id
+ currentCommunityName.value = record.name
+ profitSharingSaving.value = true
+
+ try {
+ // 检查是否已有分润设置
+ const hasProfitSharing = record.profit_sharing !== null
+
+ if (hasProfitSharing) {
+ // 如果已有分润设置,使用现有数据
+ profitSharingForm.value = {
+ platform_rate: record.profit_sharing.platform_rate,
+ partner_rate: record.profit_sharing.partner_rate,
+ admin_rate: record.profit_sharing.admin_rate,
+ delivery_rate: record.profit_sharing.delivery_rate
+ }
+ } else {
+ // 如果没有分润设置,使用默认值
+ profitSharingForm.value = {
+ platform_rate: 10,
+ partner_rate: 10,
+ admin_rate: 10,
+ delivery_rate: 70
+ }
+ }
+
+ validateTotalRate()
+ profitSharingModalVisible.value = true
+ } catch (error) {
+ console.error('获取分润设置失败:', error)
+ message.error('获取分润设置失败')
+ } finally {
+ profitSharingSaving.value = false
+ }
+ }
+
+ // 计算平台分润比例
+ const calculatePlatformRate = () => {
+ const otherRatesTotal =
+ profitSharingForm.value.partner_rate +
+ profitSharingForm.value.admin_rate +
+ profitSharingForm.value.delivery_rate
+
+ // 确保其他比例之和不超过100%
+ if (otherRatesTotal > 100) {
+ message.warning('其他分润比例之和不能超过100%')
+ return
+ }
+
+ // 计算平台分润比例
+ profitSharingForm.value.platform_rate = 100 - otherRatesTotal
+
+ // 验证总比例
+ validateTotalRate()
+ }
+
+ // 计算总比例
+ const getTotalRate = () => {
+ return (
+ profitSharingForm.value.platform_rate +
+ profitSharingForm.value.partner_rate +
+ profitSharingForm.value.admin_rate +
+ profitSharingForm.value.delivery_rate
+ )
+ }
+
+ // 验证总比例是否为100%
+ const validateTotalRate = () => {
+ const total = getTotalRate()
+ isRateValid.value = total === 100
+ return isRateValid.value
+ }
+
+ // 保存分润设置
+ const handleProfitSharingSave = async () => {
+ if (!validateTotalRate()) {
+ message.error('所有比例之和必须等于100%')
+ return
+ }
+
+ try {
+ profitSharingSaving.value = true
+
+ const params = {
+ platform_rate: profitSharingForm.value.platform_rate,
+ partner_rate: profitSharingForm.value.partner_rate,
+ admin_rate: profitSharingForm.value.admin_rate,
+ delivery_rate: profitSharingForm.value.delivery_rate
+ }
+
+ // 查找当前编辑的小区
+ const currentCommunity = tableData.value.find(item => item.id === currentCommunityId.value)
+ const hasProfitSharing = currentCommunity && currentCommunity.profit_sharing !== null
+
+ let res
+ if (hasProfitSharing) {
+ // 如果已有分润设置,调用修改接口
+ res = await request.put(`/api/community-profit-sharings/community/${currentCommunityId.value}`, params)
+ } else {
+ // 如果没有分润设置,调用创建接口
+ res = await request.post('/api/community-profit-sharings/', {
+ ...params,
+ community_id: currentCommunityId.value
+ })
+ }
+
+ if (res.code === 200) {
+ // 查找当前编辑的小区在表格数据中的索引
+ const index = tableData.value.findIndex(item => item.id === currentCommunityId.value)
+
+ if (index !== -1) {
+ // 更新本地数据,避免重新请求整个列表
+ if (!tableData.value[index].profit_sharing) {
+ tableData.value[index].profit_sharing = {}
+ }
+
+ tableData.value[index].profit_sharing = {
+ platform_rate: params.platform_rate,
+ partner_rate: params.partner_rate,
+ admin_rate: params.admin_rate,
+ delivery_rate: params.delivery_rate
+ }
+ }
+
+ message.success('分润设置保存成功')
+ profitSharingModalVisible.value = false
+ } else {
+ message.error(res.message || '保存失败')
+ }
+ } catch (error) {
+ console.error('保存分润设置失败:', error)
+ message.error('保存失败')
+ } finally {
+ profitSharingSaving.value = false
+ }
+ }
+
+ // 取消分润设置
+ const handleProfitSharingCancel = () => {
+ profitSharingModalVisible.value = false
+ currentCommunityId.value = null
+ currentCommunityName.value = ''
+ }
+
onMounted(() => {
fetchData()
})
@@ -740,7 +1011,18 @@ export default defineComponent({
deliveryPriceForm,
handleEditDeliveryPrice,
handleDeliveryPriceSave,
- handleDeliveryPriceCancel
+ handleDeliveryPriceCancel,
+ profitSharingModalVisible,
+ profitSharingSaving,
+ profitSharingForm,
+ currentCommunityName,
+ isRateValid,
+ handleEditProfitSharing,
+ handleProfitSharingSave,
+ handleProfitSharingCancel,
+ getTotalRate,
+ validateTotalRate,
+ calculatePlatformRate
}
}
})
@@ -1094,4 +1376,142 @@ export default defineComponent({
}
}
}
+
+/* 添加分润设置相关的样式 */
+.profit-sharing-info {
+ margin-bottom: 16px;
+ padding: 12px;
+ background-color: #f9f9f9;
+ border-radius: 4px;
+}
+
+.profit-sharing-header {
+ margin-bottom: 16px;
+ padding: 12px;
+ background-color: #f9f9f9;
+ border-radius: 4px;
+}
+
+.profit-sharing-title {
+ margin-bottom: 8px;
+ font-size: 14px;
+}
+
+.profit-sharing-community-name {
+ font-weight: 500;
+ color: #1890ff;
+}
+
+.profit-sharing-tip {
+ font-size: 12px;
+ color: #ff4d4f;
+}
+
+.profit-sharing-form {
+ margin-bottom: 16px;
+}
+
+.profit-rate-row {
+ display: flex;
+ align-items: center;
+ margin-bottom: 12px;
+}
+
+.profit-rate-label {
+ width: 150px;
+ font-size: 14px;
+ color: rgba(0, 0, 0, 0.85);
+}
+
+.profit-rate-input {
+ width: 100px;
+ margin-right: 12px;
+}
+
+.profit-rate-tip {
+ flex: 1;
+ font-size: 12px;
+ color: rgba(0, 0, 0, 0.45);
+}
+
+.total-rate-info {
+ margin-top: 16px;
+ padding: 8px 12px;
+ background-color: #f6ffed;
+ border-radius: 4px;
+ border: 1px solid #b7eb8f;
+ color: #52c41a;
+ font-weight: 500;
+ text-align: center;
+}
+
+.rate-error {
+ background-color: #fff2f0;
+ border-color: #ffccc7;
+ color: #ff4d4f;
+}
+
+.rate-error-message {
+ margin-left: 8px;
+ font-weight: normal;
+}
+
+/* 表格中分润比例显示样式 */
+.profit-sharing-info-table {
+ display: flex;
+ flex-direction: column;
+ gap: 6px;
+ font-size: 12px;
+ padding: 4px 0;
+}
+
+.profit-rate-item {
+ display: flex;
+ align-items: center;
+ line-height: 1.5;
+}
+
+.rate-label {
+ color: rgba(0, 0, 0, 0.65);
+ margin-right: 4px;
+ margin-left: 8px;
+ white-space: nowrap;
+}
+
+.rate-label:first-child {
+ margin-left: 0;
+}
+
+.rate-value {
+ font-weight: 500;
+ color: #1890ff;
+ margin-right: 12px;
+ white-space: nowrap;
+}
+
+/* 操作列按钮样式 */
+.action-buttons {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ white-space: nowrap;
+}
+
+.action-buttons a {
+ white-space: nowrap;
+}
+
+:deep(.ant-divider-vertical) {
+ margin: 0 8px;
+}
+
+/* 平台分润比例输入框样式 */
+.platform-rate-input {
+ background-color: #f5f5f5;
+}
+
+:deep(.platform-rate-input .ant-input-number-input) {
+ color: #1890ff;
+ font-weight: 500;
+}
\ No newline at end of file
diff --git a/src/views/community/CommunitySetList.vue b/src/views/community/CommunitySetList.vue
index 6d359ad..197ccc3 100644
--- a/src/views/community/CommunitySetList.vue
+++ b/src/views/community/CommunitySetList.vue
@@ -51,7 +51,6 @@
+
+ (可选)未选择运营商
+
@@ -294,11 +296,6 @@ export default defineComponent({
return
}
- if (!formData.user_id) {
- message.warning('请选择运营商')
- return
- }
-
try {
submitting.value = true
let res
@@ -307,13 +304,13 @@ export default defineComponent({
// 修改集合
res = await request.put(`/api/community-sets/${editingSetId.value}`, {
set_name: formData.set_name,
- user_id: formData.user_id
+ user_id: formData.user_id || null
})
} else {
// 创建集合
res = await request.post('/api/community-sets/', {
set_name: formData.set_name,
- user_id: formData.user_id
+ user_id: formData.user_id || null
})
}
@@ -481,4 +478,17 @@ export default defineComponent({
.selected-info .user-phone {
margin-bottom: 0;
}
+
+.no-user-selected {
+ margin-top: 8px;
+ padding: 8px 12px;
+ background-color: #f9f9f9;
+ border-radius: 4px;
+ border: 1px dashed #d9d9d9;
+}
+
+.tip-text {
+ color: #999;
+ font-size: 14px;
+}
\ No newline at end of file