Ver código fonte

feat: 充值配置分组支持默认配置项,小程序端自动选中

每个配置分组可指定一个默认配置项,小程序充值页面加载时自动选中。
数据库新增 is_default 列,后端自动保证同组唯一性。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
skyline 12 horas atrás
pai
commit
13ad3f53c0

+ 13 - 2
admin-web/src/views/admin/platform/rechargeConfig/index.vue

@@ -87,9 +87,10 @@
               <template #empty>
                 <el-empty :image-size="40" description="暂无配置项" />
               </template>
-              <el-table-column label="充值金额" prop="rechargeAmount" width="140">
+              <el-table-column label="充值金额" prop="rechargeAmount" width="170">
                 <template #default="{ row }">
                   {{ u.fmt.fmtMoney(row.rechargeAmount) }}
+                  <el-tag v-if="row.isDefault" type="warning" size="small" effect="light" style="margin-left:4px">默认</el-tag>
                 </template>
               </el-table-column>
               <el-table-column label="赠款金额" prop="grantsAmount" width="140">
@@ -102,8 +103,9 @@
                   {{ row.label || '-' }}
                 </template>
               </el-table-column>
-              <el-table-column label="操作" prop="action" width="160" align="center" fixed="right">
+              <el-table-column label="操作" prop="action" width="220" align="center" fixed="right">
                 <template #default="{ row }">
+                  <el-button v-if="!row.isDefault" v-auth="'rechargeConfig.modify'" type="primary" size="small" text @click="handleSetDefault(row)">设为默认</el-button>
                   <el-button v-auth="'rechargeConfig.modify'" type="warning" size="small" text @click="handleItemEdit(g.group.id, row)">编辑</el-button>
                   <el-button v-auth="'rechargeConfig.remove'" type="danger" size="small" text @click="handleItemRemove(row)">删除</el-button>
                 </template>
@@ -219,4 +221,13 @@ const handleItemRemove = (row: any) => {
     });
   });
 };
+
+const handleSetDefault = (row: any) => {
+  $body('/rechargeConfig/item/modify', { ...row, isDefault: true }).then(() => {
+    Msg.message("已设为默认", 'success');
+    loadData();
+  }).catch(() => {
+    Msg.message("操作失败", 'error');
+  });
+};
 </script>

+ 11 - 0
admin-web/src/views/admin/platform/rechargeConfig/itemDialog.vue

@@ -42,6 +42,14 @@
               clearable>
           </el-input>
         </el-form-item>
+        <el-form-item label="设为默认项" prop="isDefault">
+          <el-switch
+              v-model="state.ruleForm.isDefault"
+              active-text="是"
+              inactive-text="否">
+          </el-switch>
+          <span style="margin-left:8px;font-size:12px;color:#999;">每个分组仅一个默认项,小程序端将默认选中</span>
+        </el-form-item>
       </el-form>
 
       <template #footer>
@@ -70,6 +78,7 @@ const initState = () => ({
     rechargeAmountYuan: 0,
     grantsAmountYuan: 0,
     label: '',
+    isDefault: false,
   },
   btnLoading: false,
   dialog: {
@@ -96,6 +105,7 @@ const open = (action: string = 'add', row: any) => {
       rechargeAmountYuan: (row.rechargeAmount || 0) / 100,
       grantsAmountYuan: (row.grantsAmount || 0) / 100,
       label: row.label || '',
+      isDefault: !!row.isDefault,
     };
   } else if (row) {
     state.ruleForm.groupId = row.groupId;
@@ -121,6 +131,7 @@ const onSubmit = () => {
         rechargeAmount: Math.round(state.ruleForm.rechargeAmountYuan * 100),
         grantsAmount: Math.round(state.ruleForm.grantsAmountYuan * 100),
         label: state.ruleForm.label || null,
+        isDefault: state.ruleForm.isDefault,
       };
       const url = !!state.ruleForm.id ? "/rechargeConfig/item/modify" : "/rechargeConfig/item/add";
       $body(url, payload).then(() => {

+ 5 - 0
car-wash-entity/src/main/java/com/kym/entity/RechargeConfig.java

@@ -37,4 +37,9 @@ public class RechargeConfig extends BaseEntity {
      * 文字标签(用于悬浮在充值金额旁)
      */
     private String label;
+
+    /**
+     * 是否为该分组默认配置项(每个分组仅一个默认项,小程序端默认选中)
+     */
+    private Boolean isDefault;
 }

+ 2 - 0
car-wash-entity/src/main/resources/sql/v17_recharge_config_default.sql

@@ -0,0 +1,2 @@
+-- v17: 充值配置项增加默认标记,每个分组可指定一个默认配置项(小程序端默认选中)
+ALTER TABLE t_recharge_config ADD COLUMN is_default TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否为该分组默认配置项:1=默认,0=非默认';

+ 5 - 0
car-wash-mp/src/pages-user/wallet/recharge.vue

@@ -102,6 +102,11 @@ const loadRechargeConfig = () => {
   get("/common/rechargeConfig", params)
     .then((res: any) => {
       state.configList = res;
+      const defaultIdx = (res || []).findIndex((item: any) => item.isDefault);
+      if (defaultIdx >= 0) {
+        state.chosenIdx = defaultIdx;
+        state.rechargeItem = res[defaultIdx];
+      }
     })
     .catch(() => {
       uni.showToast({ title: "加载失败,请下拉重试", icon: "none" });

+ 21 - 0
car-wash-service/src/main/java/com/kym/service/impl/RechargeConfigServiceImpl.java

@@ -28,6 +28,27 @@ public class RechargeConfigServiceImpl extends MyBaseServiceImpl<RechargeConfigM
         this.groupService = groupService;
     }
 
+    @Override
+    public boolean save(RechargeConfig entity) {
+        if (Boolean.TRUE.equals(entity.getIsDefault())) {
+            lambdaUpdate().eq(RechargeConfig::getGroupId, entity.getGroupId())
+                    .set(RechargeConfig::getIsDefault, false)
+                    .update();
+        }
+        return super.save(entity);
+    }
+
+    @Override
+    public boolean updateById(RechargeConfig entity) {
+        if (Boolean.TRUE.equals(entity.getIsDefault())) {
+            lambdaUpdate().eq(RechargeConfig::getGroupId, entity.getGroupId())
+                    .ne(RechargeConfig::getId, entity.getId())
+                    .set(RechargeConfig::getIsDefault, false)
+                    .update();
+        }
+        return super.updateById(entity);
+    }
+
     @Override
     public List<RechargeConfig> listByStationId(String stationId) {
         log.info("listByStationId: stationId={}", stationId);