diff --git a/pages/detail/detail.vue b/pages/detail/detail.vue index bdcc016..1c30efb 100755 --- a/pages/detail/detail.vue +++ b/pages/detail/detail.vue @@ -128,9 +128,15 @@ 当前逻辑模型 - - 参数配置 - + + + + 编辑 + + + 参数配置 + + @@ -163,6 +169,28 @@ + + + + + @@ -441,6 +469,84 @@ + + + + + 编辑组合 + + + + + + + + 组合名称 + + + + + 绑定策略 + + + {{ editForm.strategyName || '不绑定策略' }} + + + + + + + 状态 + + + {{ statusOptions.find(s => s.value === editForm.status)?.label || '运行中' }} + + + + + + + + + 取消 + + + 保存 + + + + + @@ -638,6 +744,98 @@ const transactionForm = ref({ const maxSellAmount = ref(0); +// 编辑弹窗相关 +const showEditModal = ref(false); +const editForm = ref({ + name: '', + strategyId: null, + strategyName: '', + status: '运行中' +}); +const strategyOptions = ref([{ id: null, name: '不绑定策略' }]); +const statusOptions = ref([ + { label: '运行中', value: '运行中' }, + { label: '已暂停', value: '已暂停' }, + { label: '已清仓', value: '已清仓' } +]); + +// 打开编辑弹窗 +const openEditModal = async () => { + editForm.value = { + name: portfolioData.value.name || '', + strategyId: portfolioData.value.strategy?.id || null, + strategyName: portfolioData.value.strategy?.name || '不绑定策略', + status: portfolioData.value.status || '运行中' + }; + + // 获取策略列表 + try { + const res = await api.strategies.getStrategies(); + if (res.code === 200 && res.data) { + strategyOptions.value = [ + { id: null, name: '不绑定策略' }, + ...res.data.map(s => ({ id: s.id, name: s.name })) + ]; + } + } catch (e) { + console.error('获取策略列表失败:', e); + } + + showEditModal.value = true; +}; + +const onStrategyChange = (e) => { + const idx = e.detail.value; + const selected = strategyOptions.value[idx]; + editForm.value.strategyId = selected.id; + editForm.value.strategyName = selected.name; +}; + +const onStatusChange = (e) => { + const idx = e.detail.value; + editForm.value.status = statusOptions.value[idx].value; +}; + +const submitEdit = async () => { + if (!editForm.value.name?.trim()) { + proxy?.$refs.uToastRef?.show({ + type: 'warning', + message: '请输入组合名称', + icon: 'warning' + }); + return; + } + + uni.showLoading({ title: '保存中...', mask: true }); + + try { + const response = await api.assets.updatePortfolio(portfolioId.value, { + name: editForm.value.name, + strategyId: editForm.value.strategyId, + status: editForm.value.status + }); + + if (response.code === 200) { + uni.hideLoading(); + proxy?.$refs.uToastRef?.show({ + type: 'success', + message: '保存成功', + icon: 'success' + }); + showEditModal.value = false; + await fetchPortfolioData(); + } + } catch (error) { + console.error('更新组合失败:', error); + uni.hideLoading(); + proxy?.$refs.uToastRef?.show({ + type: 'error', + message: '保存失败,请重试', + icon: 'error' + }); + } +}; + // 股票搜索相关 const searchResults = ref([]); const searchTimer = ref(null); @@ -1054,6 +1252,24 @@ const deletePortfolio = async () => { .bg-green-100 { background-color: #ECFDF5; } .bg-red { background-color: #EF4444; } .bg-green { background-color: #10B981; } +.bg-gray-100 { background-color: #F3F4F6; } +.text-gray { color: #9CA3AF; } + +/* 编辑按钮 */ +.edit-btn { + display: flex; + align-items: center; + gap: 4rpx; + padding: 8rpx 16rpx; + background-color: #D1FAE5; + border-radius: 12rpx; +} + +.edit-text { + font-size: 24rpx; + color: #064E3B; + font-weight: 500; +} .header-section { padding: 20rpx 32rpx; } .asset-card { diff --git a/utils/api.js b/utils/api.js index 6d60ede..328bf6d 100755 --- a/utils/api.js +++ b/utils/api.js @@ -353,6 +353,16 @@ export const api = { console.log('📤 发起 createPortfolio 请求:', data); return post('/api/v1/portfolio', data); }, + /** + * 更新投资组合 + * @param {string|number} id - 投资组合ID + * @param {object} data - 更新数据 {name, strategyId, status} + * @returns {Promise} 返回更新结果 + */ + updatePortfolio: (id, data) => { + console.log('📤 发起 updatePortfolio 请求:', id, data); + return put(`/api/v1/portfolio/${id}`, data); + }, /** * 获取投资组合策略信号 * @param {string|number} id - 投资组合ID