feat: 购油方案功能 #28

Merged
hera merged 13 commits from fix/next-batch-2 into main 2026-04-13 13:07:09 +00:00
Showing only changes of commit fe74f45bca - Show all commits

View File

@@ -56,15 +56,17 @@
<label class="form-label">描述你的健康需求</label>
<textarea v-model="planHealthDesc" class="form-textarea" rows="4"
placeholder="例如:家里有老人膝盖痛,小孩经常感冒咳嗽,我自己想改善睡眠..."></textarea>
<label class="form-label" style="margin-top:12px">选择老师</label>
<select v-model="planTeacherId" class="form-select">
<option value="">请选择</option>
<option v-for="t in plansStore.teachers" :key="t.id" :value="t.id">
{{ t.display_name }}
</option>
</select>
<label class="form-label" style="margin-top:12px">输入老师的名字</label>
<input v-model="planTeacherName" class="form-input" placeholder="请输入老师告诉你的名字"
@input="matchTeacher" />
<div v-if="matchedTeacher" class="teacher-matched">
已匹配{{ matchedTeacher.display_name }}
</div>
<div v-else-if="planTeacherName.trim() && !matchedTeacher" class="teacher-no-match">
未找到该老师请确认名字是否正确
</div>
<button class="btn-primary" style="width:100%;margin-top:16px"
:disabled="!planHealthDesc.trim() || !planTeacherId"
:disabled="!planHealthDesc.trim() || !matchedTeacher"
@click="submitPlanRequest">
发送请求
</button>
@@ -311,7 +313,16 @@ async function toggleOil(name) {
// Plan request
const showPlanRequest = ref(false)
const planHealthDesc = ref('')
const planTeacherId = ref('')
const planTeacherName = ref('')
const matchedTeacher = ref(null)
function matchTeacher() {
const name = planTeacherName.value.trim()
if (!name) { matchedTeacher.value = null; return }
matchedTeacher.value = plansStore.teachers.find(t =>
t.display_name === name || t.username === name
) || null
}
const shoppingTotal = computed(() =>
plansStore.shoppingList.filter(i => !i.in_inventory).reduce((s, i) => s + i.total_cost, 0).toFixed(2)
@@ -319,10 +330,11 @@ const shoppingTotal = computed(() =>
async function submitPlanRequest() {
try {
await plansStore.createPlan(planHealthDesc.value, planTeacherId.value)
await plansStore.createPlan(planHealthDesc.value, matchedTeacher.value.id)
showPlanRequest.value = false
planHealthDesc.value = ''
planTeacherId.value = ''
planTeacherName.value = ''
matchedTeacher.value = null
ui.showToast('已发送方案请求')
} catch {
ui.showToast('发送失败')
@@ -629,5 +641,6 @@ onMounted(async () => {
.overlay-header h3 { margin: 0; font-size: 16px; }
.form-label { display: block; font-size: 13px; color: #6b6375; margin-bottom: 4px; font-weight: 500; }
.form-textarea { width: 100%; border: 1.5px solid #e5e4e7; border-radius: 8px; padding: 8px; font-size: 13px; font-family: inherit; resize: vertical; box-sizing: border-box; }
.form-select { width: 100%; border: 1.5px solid #e5e4e7; border-radius: 8px; padding: 8px; font-size: 13px; font-family: inherit; box-sizing: border-box; }
.teacher-matched { color: #2e7d5a; font-size: 13px; margin-top: 4px; font-weight: 500; }
.teacher-no-match { color: #c62828; font-size: 12px; margin-top: 4px; }
</style>