Ver Fonte

商城制单小程序增加动态配置

cgp há 3 dias atrás
pai
commit
446ecbd0dc
1 ficheiros alterados com 111 adições e 2 exclusões
  1. 111 2
      src/views/system/config/config.vue

+ 111 - 2
src/views/system/config/config.vue

@@ -2544,7 +2544,7 @@
           <el-form-item label="每天可领取红包次数" prop="redPacketNum">
             <el-input-number v-model="form31.redPacketNum" :min="1" />
           </el-form-item>
-          
+
         </el-form>
 
         <div class="footer">
@@ -2584,6 +2584,35 @@
         </div>
       </el-tab-pane>
 
+      <!-- 制单商城小程序配置 -->
+      <el-tab-pane label="制单商城小程序配置" name="appStore.appId.config">
+        <el-form ref="form33" :model="form33" label-width="160px">
+          <el-form-item label="选择小程序配置" prop="selected">
+            <el-select
+              v-model="form33.selected.appId"
+              placeholder="请选择配置"
+              filterable
+              style="width: 400px;"
+              @change="handleSelectChange"
+              :loading="form33.loading"
+            >
+              <el-option
+                v-for="item in form33.options"
+                :key="item.appId"
+                :label="`${item.appName} (${item.appId})`"
+                :value="item.appId"
+              />
+            </el-select>
+            <div style="color: #909399; font-size: 12px; margin-top: 8px;">
+              当前选中:{{ form33.selected ? `${form33.selected.appName} (${form33.selected.appId})` : '未选择' }}
+            </div>
+          </el-form-item>
+          <div class="footer">
+            <el-button type="primary" @click="submitForm33">提 交</el-button>
+          </div>
+        </el-form>
+      </el-tab-pane>
+
     </el-tabs>
 
 
@@ -2600,6 +2629,7 @@
 
 <script>
 import { getConfigByKey, updateConfigByKey, clearCache, updateIsTownOn } from '@/api/system/config'
+import { listAll } from '@/api/course/coursePlaySourceConfig.js'
 import { listStore } from '@/api/his/storeProduct'
 import { js } from 'js-beautify'
 import Material from '@/components/Material'
@@ -2771,6 +2801,11 @@ export default {
       },
       form31: {},
       form32: {},
+      form33: {
+        selected: { appName: '', appId: '' },   // 初始化为空对象
+        options: [],
+        loading: false,
+      },
       storeProductScrmColumns:[],
       storeScrmColumns: [],
       photoArr: [],
@@ -3354,6 +3389,17 @@ export default {
           console.log("----------"+response.data.configValue)
           this.form32 = JSON.parse(response.data.configValue)
         }
+        if (key == 'appStore.appId.config') {
+          this.getPlaySourceList();
+          const configValue = JSON.parse(response.data.configValue);
+          // 假设存储的数据格式为 { appName, appId }
+          if (configValue && configValue.appId) {
+            this.form33.selected = {
+              appName: configValue.appName || '',
+              appId: configValue.appId
+            };
+          }
+        }
       })
     },
     /** 提交按钮 */
@@ -3751,7 +3797,70 @@ export default {
     },
     removeDisabledTime(index) {
       this.form18.disabledTimeList.splice(index, 1)
-    }
+    },
+    /** 获取制单商城小程序配置下拉列表 */
+    getPlaySourceList() {
+      const companyId = 1;
+      this.form33.loading = true;
+      listAll(companyId).then(response => {
+        // 映射字段,确保每个选项都有 appName 和 appId
+        this.form33.options = (response.data || [])
+          .filter(item => item.name && item.appid)  // 过滤空数据
+          .map(item => ({
+            appName: item.name,
+            appId: item.appid,
+            ...item
+          }));
+        this.form33.loading = false;
+      }).catch(() => {
+        this.form33.loading = false;
+      });
+    },
+
+    /** 处理下拉选择变化(弹窗确认) */
+    handleSelectChange(val) {
+      if (!val) {
+        // 如果清空选择,重置选中对象
+        this.form33.selected = { appName: '', appId: '' };
+        return;
+      }
+      const selectedItem = this.form33.options.find(item => item.appId === val);
+      if (!selectedItem) return;
+      this.$confirm(`即将选择:${selectedItem.appName} (${selectedItem.appId}),是否确认?`, '提示', {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'info'
+      }).then(() => {
+        this.form33.selected = { appName: selectedItem.appName, appId: selectedItem.appId };
+        this.$message.success('已选中');
+      }).catch(() => {
+        // 取消后恢复之前选中的值(或清空)
+        this.form33.selected = { appName: '', appId: '' };
+        // 由于 v-model 绑定的是 selected.appId,直接置空即可
+        // 但为了安全,重新赋值整个对象
+        this.$set(this.form33, 'selected', { appName: '', appId: '' });
+      });
+    },
+
+    /** 提交制单商城小程序配置 */
+    submitForm33() {
+      if (!this.form33.selected) {
+        this.$message.warning('请先选择一个配置');
+        return;
+      }
+      const param = {
+        configId: this.configId,    // 从 getConfigByKey 中获取
+        configKey: 'appStore.appId.config',
+        configValue: JSON.stringify(this.form33.selected)
+      };
+      updateConfigByKey(param).then(response => {
+        if (response.code === 200) {
+          this.msgSuccess('保存成功');
+        }
+      }).catch(() => {
+        this.msgError('保存失败');
+      });
+    },
   }
 }
 </script>