feat(fe): 建档挑方案、计划页套方案、阶段漂移提示

后端上一轮做完了但小程序上看不到,这次接上。

## 建档第四步:挑方案
方案按阶段取,所以必须排在「资料」之后(阶段是第三步定的)。卡片上按重复方式
分开报数(每天 3 项 / 每周 2 项 / 一次性 2 项),不报一个总数——4 条「每天」
套一整月就是 120 多条,只给总数用户会以为出 bug。

「先空着,我自己排」是个平等的选项,和方案卡长一样、就在下面一眼能看到,
不是藏起来的退路:已经养熟的宠物主人有自己的节奏,硬塞一套只会被删掉。

默认选第一套——多数用户是新手,给一个合理默认比让他面对空白好。

编辑档案时不出现第四步:改档案不该顺手改计划。

套方案失败不算建档失败:档案已经建好了,方案之后在计划页还能套,
不该把用户退回表单。

## 计划页:空月份和平时都能套
空月份的提示条带「套一套方案」按钮 —— 空着让用户从零排,多数人会直接退出去。
但「+ 加一件」始终在,不能只给套用。

浮层里写明「套用是往里加,不会覆盖你已经排好的」,因为服务端就是按
「日期+标题」去重的,这句话是真的。套完 toast 报排了几件;一件都没排
(全都已存在)时说「这个月已经有这些安排了」,不说「成功」。

## 阶段漂移提示
首页门面卡下面一张卡:「钞票已经 17个月,从幼年期进入成年期了」,
带上新阶段的划分依据、养护重点和体型说明,点进去到建档页改。

用主色不用红色 —— 这是「可以做一下」不是「出问题了」。
改完回首页 onShow 重拉一次,卡片自然消失。

不在首页直接改阶段:改完要不要套新方案是同一件事,放在建档页一起做才连贯。

## 顺手把合并的尾巴清了
manageTasks 那一支删了:它管的是 DailyTask,而今日任务已经并进计划节点,
增删改都在计划页。留着会出现「这里加的任务」和「计划页加的节点」进不同的表。

连带清掉 7 个死方法 + taskSheets + 一个死 require(简易表单那套早随记录表单
搬到 pages/addrecord 了)。首页现在一个弹层都不开,bottom-sheet 组件也去掉了。

弹层累计:js 1110 → 689 行,wxml 485 → 278 行。

## 验证(预生产库实跑)
  建档四步    6 个月柯基 → 幼年期 → 拉到「幼犬标准照护」→ 套用本月 7 条
              → 首页今日任务 4 条
  先空着      今日任务 0 条,疫苗驱虫提醒仍然建
  计划页套用  0 → 7 条;重复套用 0 条(去重生效)
  漂移检测    17 个月柯基存着幼年期 → drifted=true,给出依据/重点/体型
              改成成年期 → drifted=false
              没生日 → 不提示(算不出就不猜)
              「刚到家」→ 不提示(叠加层不是年龄段)

第一版验证脚本把阶段改成了和算出来一样的值,drifted=False 是对的,
但我的 print 无条件打了提示文案,看着像 bug。重测才验到真的。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Blizzard
2026-07-30 12:59:27 +08:00
parent cff6982613
commit 6fd4977f46
13 changed files with 228 additions and 112 deletions
@@ -1,5 +1,4 @@
const store = require('../../utils/store.js');
const recordTypes = require('../../utils/recordTypes.js');
const api = require('../../utils/api.js');
const upload = require('../../utils/upload.js');
@@ -33,16 +32,6 @@ function fmtAgo(iso) {
return (sameYear ? '' : d.getFullYear() + '-') + p(d.getMonth() + 1) + '-' + p(d.getDate());
}
// 任务可关联的记录弹层类型
// 任务能关联的记录类型。原来这里也是写死的 6 种,后台加了类型这个下拉里看不到,
// 于是「自定义任务关联新类型」这条路是断的。改成读同一份类型缓存
function taskSheets() {
const list = [{ key: '', label: '不关联' }];
(recordTypes.groups() || []).forEach((g) =>
g.items.forEach((t) => list.push({ key: t.code, label: t.label })),
);
return list;
}
// 提醒类型(与后端 model.Reminder* 常量对应)
const REMINDER_TYPES = [
@@ -73,9 +62,6 @@ Component({
// 通用简易记录(洗护/清洁那 15 种共用)
postContent: '',
postImages: [],
manageTasks: [],
taskForm: { id: '', title: '', description: '', priority: '', sheetIdx: 0 },
taskSheetLabels: [],
remForm: { id: '', typeIdx: 0, title: '', date: '', freq: '' },
remTypeLabels: REMINDER_LABELS,
myPets: [],
@@ -122,9 +108,6 @@ Component({
patch.postContent = '';
patch.postImages = [];
patch.medDose = '';
patch.manageTasks = [];
patch.taskForm = { id: '', title: '', description: '', priority: '', sheetIdx: 0 };
patch.taskSheetLabels = taskSheets().map((x) => x.label);
patch.remForm = { id: '', typeIdx: 0, title: '', date: '', freq: '' };
patch.exportText = '';
patch.fbContent = '';
@@ -527,49 +510,6 @@ Component({
if (!id) return;
api.getTasks(id).then((tasks) => this.setData({ manageTasks: tasks || [] })).catch(() => {});
},
onTaskTitle(e) { this.setData({ 'taskForm.title': e.detail.value }); },
onTaskDesc(e) { this.setData({ 'taskForm.description': e.detail.value }); },
onTaskPriority() {
this.setData({ 'taskForm.priority': this.data.taskForm.priority === '重要' ? '' : '重要' });
},
onTaskSheet(e) { this.setData({ 'taskForm.sheetIdx': Number(e.detail.value) }); },
onEditTaskItem(e) {
const t = this.data.manageTasks[e.currentTarget.dataset.index];
const sheets = taskSheets();
let sheetIdx = sheets.findIndex((s) => s.key === (t.sheet_type || ''));
if (sheetIdx < 0) sheetIdx = 0;
this.setData({
taskForm: { id: t.id, title: t.title, description: t.description || '', priority: t.priority || '', sheetIdx },
});
},
onSaveTask() {
const f = this.data.taskForm;
const title = (f.title || '').trim();
if (!title) return wx.showToast({ title: '填个任务名', icon: 'none' });
const sheets = taskSheets();
const body = { title, description: f.description, priority: f.priority, sheet_type: (sheets[f.sheetIdx] || sheets[0]).key };
const id = store.currentPetId();
const p = f.id ? api.updateTask(f.id, body) : api.createTask(id, body);
p.then(() => {
this.setData({ taskForm: { id: '', title: '', description: '', priority: '', sheetIdx: 0 } });
this.loadManageTasks();
this.triggerEvent('saved');
}).catch((e) => wx.showToast({ title: e.message || '保存失败', icon: 'none' }));
},
onDeleteTaskItem(e) {
const t = this.data.manageTasks[e.currentTarget.dataset.index];
wx.showModal({
title: '删除任务',
content: '确定删除「' + t.title + '」?',
success: (r) => {
if (!r.confirm) return;
api.deleteTask(t.id).then(() => {
this.loadManageTasks();
this.triggerEvent('saved');
}).catch((err) => wx.showToast({ title: err.message || '删除失败', icon: 'none' }));
},
});
},
onPickPostImages() {
const left = 9 - this.data.postImages.length;
if (left <= 0) return wx.showToast({ title: '最多 9 张', icon: 'none' });
@@ -218,37 +218,8 @@ module.exports.sel = function (map, key, index, def) {
<button class="btn btn-primary btn-block" bindtap="onCreatePost">发布到宠友圈</button>
</block>
<!-- 管理任务 -->
<block wx:elif="{{innerType === 'manageTasks'}}">
<view class="sheet-h3">管理任务</view>
<view class="sheet-p">增删改今日任务,改动会自动顺延到以后每天。</view>
<view wx:for="{{manageTasks}}" wx:key="id" class="mtask-row">
<view class="mtask-body">
<text class="mtask-b">{{item.title}}<text wx:if="{{item.priority}}" class="mtask-pri">{{item.priority}}</text></text>
<view wx:if="{{item.description}}" class="mtask-p">{{item.description}}</view>
</view>
<view class="mtask-op" catchtap="onEditTaskItem" data-index="{{index}}">改</view>
<view class="mtask-op del" catchtap="onDeleteTaskItem" data-index="{{index}}">删</view>
</view>
<view wx:if="{{!manageTasks.length}}" class="sheet-p">今天还没有任务,下面加一条吧。</view>
<view class="field" style="margin-top:12rpx"><label>{{taskForm.id ? '修改任务' : '新增任务'}}</label>
<input class="input" placeholder="任务名,例如:喂驱虫药" placeholder-class="placeholder" value="{{taskForm.title}}" bindinput="onTaskTitle"/></view>
<view class="field"><input class="input" placeholder="说明(可选)" placeholder-class="placeholder" value="{{taskForm.description}}" bindinput="onTaskDesc"/></view>
<view class="field"><label>优先级 / 关联记录</label>
<view class="mtask-form-row">
<view class="seg-btn {{taskForm.priority === '重要' ? 'selected' : ''}}" catchtap="onTaskPriority">重要</view>
<picker mode="selector" range="{{taskSheetLabels}}" value="{{taskForm.sheetIdx}}" bindchange="onTaskSheet">
<view class="picker-box">关联:{{taskSheetLabels[taskForm.sheetIdx]}}</view>
</picker>
</view>
</view>
<button class="btn btn-primary btn-block" bindtap="onSaveTask">{{taskForm.id ? '保存修改' : '添加任务'}}</button>
</block>
<!-- 评论 -->
<!-- 多宠物管理 -->
<!-- 任务管理那一支删了:它管的是 DailyTask,而「今日任务」已经并进计划节点,
增删改都在计划页做。留着会出现「这里加的任务」和「计划页加的节点」进不同的表 -->
<block wx:elif="{{innerType === 'managePets'}}">
<view class="sheet-h3">多宠物管理</view>
<view class="sheet-p">点一只切换为当前宠物,或编辑它的档案。</view>
+18 -12
View File
@@ -34,13 +34,12 @@ Page({
sexTone: '',
tasks: [],
planHint: '',
drift: {},
needNextPlan: false,
monthCost: 0,
timeline: [],
tlPage: 1,
hasMore: false,
sheetShow: false,
sheetType: '',
},
onLoad() {
this._unsub = store.subscribe((pet) => {
@@ -80,6 +79,7 @@ Page({
this.loadTasks();
this.loadTimeline(1);
this.loadEntries();
this.loadDrift();
},
loadTasks() {
const id = store.currentPetId();
@@ -91,6 +91,16 @@ Page({
},
// 两个入口上的副标题:计划还剩几件、本月花了多少。
// 空着的话入口就是两个没有信息量的图标
// 阶段漂移检查。放在 loadEntries 里而不是单独一次 —— 它和「计划还剩几件」
// 都是首页那一屏要的,一起拉省一个来回
loadDrift() {
const id = store.currentPetId();
if (!id) return;
api
.petStageDrift(id)
.then((d) => this.setData({ drift: d || {} }))
.catch(() => this.setData({ drift: {} }));
},
loadEntries() {
const id = store.currentPetId();
if (!id) return;
@@ -187,6 +197,12 @@ Page({
goPlan() {
wx.navigateTo({ url: '/pages/plan/plan' });
},
// 去建档页改阶段。改完回来 onShow 会重新拉一次漂移状态,提示自然消失。
// 不在首页直接改:改阶段之后要不要套新方案是同一件事,放在一起做才连贯
goStageUpdate() {
const id = this.data.pet && this.data.pet.id;
if (id) wx.navigateTo({ url: '/pages/petform/petform?id=' + id });
},
goExpense() {
wx.navigateTo({ url: '/pages/expense/expense' });
},
@@ -196,16 +212,6 @@ Page({
onQuickRecord() {
wx.navigateTo({ url: '/pages/record/record' });
},
openSheet(e) {
this.setData({ sheetType: e.currentTarget.dataset.type, sheetShow: true });
},
closeSheet() {
this.setData({ sheetShow: false });
},
onSheetSave() {
this.loadTasks();
this.loadTimeline(1);
},
onAddPet() {
wx.navigateTo({ url: '/pages/petform/petform' });
},
-1
View File
@@ -2,7 +2,6 @@
"usingComponents": {
"nav-bar": "/components/nav-bar/nav-bar",
"pet-switch": "/components/pet-switch/pet-switch",
"bottom-sheet": "/components/bottom-sheet/bottom-sheet",
"fab": "/components/fab/fab",
"pt-icon": "/components/pt-icon/index"
}
+15 -2
View File
@@ -26,6 +26,19 @@
<view wx:if="{{daysTogether}}" class="hero-days">我们一起生活的第 <text class="hd-n">{{daysTogether}}</text> 天</view>
</view>
<!-- 阶段漂移。系统只负责发现,换不换由用户点 —— 偷偷换会让他莫名发现
计划变了却找不到原因,而且已经排好的这个月不该被推翻 -->
<view wx:if="{{drift.drifted}}" class="card drift-card" bindtap="goStageUpdate">
<view class="drift-top">
<pt-icon name="trend" size="{{32}}"></pt-icon>
<view class="drift-b">{{pet.name}}已经 {{drift.age_label}},从{{drift.stored}}进入{{drift.computed}}了</view>
</view>
<view class="drift-p">{{drift.basis}}</view>
<view class="drift-focus">这个阶段的重点:{{drift.focus}}</view>
<view wx:if="{{drift.size}}" class="drift-size">{{drift.size}}</view>
<view class="btn btn-primary btn-block drift-cta">去更新阶段和方案</view>
</view>
<!-- 两个入口。竞品那一排是买商品/上豪车/领猫砂盆,是电商和广告位,去掉 -->
<view class="card entry-card">
<view class="entry" bindtap="goPlan">
@@ -49,8 +62,9 @@
<view wx:if="{{tasks.length}}" class="card">
<view class="section-head">
<view class="sh-title">今日任务</view>
<!-- 任务的增删改都在计划页 —— 合并之后首页这个「管理」不该再开一个弹层 -->
<view class="head-links">
<view class="link" data-type="manageTasks" bindtap="openSheet">管理</view>
<view class="link" bindtap="goPlan">管理</view>
<view class="link" bindtap="completeTasks">全部完成</view>
</view>
</view>
@@ -96,4 +110,3 @@
</scroll-view>
<fab icon="plus" bind:tap="onQuickRecord"></fab>
<bottom-sheet show="{{sheetShow}}" type="{{sheetType}}" bind:close="closeSheet" bind:saved="onSheetSave"></bottom-sheet>
+9
View File
@@ -78,3 +78,12 @@
border-radius:50%;background:var(--red);border:3rpx solid #fff;
}
.entry-p.warn{color:var(--red-ink);font-weight:var(--fw-b)}
/* 阶段漂移提示。用主色不用红色:这是「可以做一下」不是「出问题了」 */
.drift-card{border:2rpx solid var(--primary-line);background:var(--primary-soft)}
.drift-top{display:flex;align-items:flex-start;gap:var(--sp-2);color:var(--primary-dark)}
.drift-b{flex:1;min-width:0;font-size:var(--fs-md);font-weight:var(--fw-b);line-height:1.5}
.drift-p{font-size:var(--fs-sm);color:var(--primary-ink);line-height:1.6;margin-top:var(--sp-2)}
.drift-focus{font-size:var(--fs-sm);color:var(--primary-ink);line-height:1.6;margin-top:6rpx}
.drift-size{font-size:var(--fs-cap);color:var(--primary-dark);opacity:.8;margin-top:6rpx}
.drift-cta{margin-top:var(--sp-4)}
+38 -2
View File
@@ -41,7 +41,7 @@ Page({
editing: false,
petId: '',
step: 0,
steps: ['名字', '品种', '资料'],
steps: ['名字', '品种', '资料', '方案'],
genders: GENDERS,
stages: [],
stageRules: [],
@@ -54,7 +54,11 @@ Page({
species: 'cat', breed: '',
gender: '不确定', birthday: '', arrived_at: '',
weight: '', color: '', stage: '',
// 第四步挑的方案。'' 是「先空着自己排」,不是「没选」——
// 所以初始值给 null,用来区分「还没走到第四步」
template_id: null,
},
tplOptions: [],
breedShow: false,
breedGroups: [],
breedAnchor: '',
@@ -192,6 +196,25 @@ Page({
this.setData({ breedAnchor: 'bi-' + e.currentTarget.dataset.i });
},
loadTemplates() {
const f = this.data.form;
api
.careTemplates(f.species, f.stage)
.then((opts) => {
const list = opts || [];
this.setData({
tplOptions: list,
// 默认选第一套:多数用户是新手,给一个合理默认比让他面对空白好。
// 但「先空着」就在下面,一眼能看到,不是藏起来的
'form.template_id': list.length ? list[0].id : '',
});
})
.catch(() => this.setData({ tplOptions: [], 'form.template_id': '' }));
},
pickTemplate(e) {
this.setData({ 'form.template_id': e.currentTarget.dataset.id });
},
// ── 分步 ──
prev() {
if (this.data.step > 0) this.setData({ step: this.data.step - 1 });
@@ -202,6 +225,7 @@ Page({
const f = this.data.form;
if (this.data.step === 0 && !f.name.trim()) return '先给它起个名字';
if (this.data.step === 1 && !f.species) return '选一下是猫还是狗';
if (this.data.step === 2 && !f.stage) return '选一下现在是哪个阶段 —— 方案是按阶段配的';
return '';
},
next() {
@@ -209,7 +233,12 @@ Page({
if (!this.data.editing) {
const err = this.stepError();
if (err) return wx.showToast({ title: err, icon: 'none' });
if (this.data.step < 2) return this.setData({ step: this.data.step + 1 });
if (this.data.step < 3) {
const next = this.data.step + 1;
this.setData({ step: next });
if (next === 3) this.loadTemplates(); // 方案按阶段取,得等第三步填完
return;
}
} else if (!this.data.form.name.trim()) {
return wx.showToast({ title: '名字不能空', icon: 'none' });
}
@@ -239,8 +268,15 @@ Page({
submit() {
this.setData({ saving: true });
const b = this.body();
const tplID = this.data.form.template_id;
const req = this.data.editing ? api.updatePet(this.data.petId, b) : api.createPet(b);
req
// 套方案要等档案建出来才有 pet id。套用失败不算建档失败——
// 档案已经建好了,方案之后在计划页还能套,不该把用户退回表单
.then((pet) => {
if (this.data.editing || !tplID || !pet || !pet.id) return;
return api.applyTemplate(pet.id, tplID, 0).catch(() => {});
})
.then(() => store.loadPets())
.then(() => {
this.setData({ saving: false });
+38 -1
View File
@@ -86,6 +86,43 @@
</view>
</view>
</block>
<!-- ④ 挑一套养护方案(编辑时不出现:改档案不该顺手改计划) -->
<block wx:if="{{!editing && step === 3}}">
<view class="card">
<view class="pf-h">要不要套一套养护方案?</view>
<view class="pf-sub">按 {{form.stage}} 配的,套用后会排进本月的计划。之后随时能改、能删。</view>
<view wx:for="{{tplOptions}}" wx:key="id"
class="pf-tpl {{form.template_id === item.id ? 'on' : ''}}"
data-id="{{item.id}}" bindtap="pickTemplate">
<view class="pf-tpl-top">
<view class="pf-tpl-name">{{item.name}}</view>
<view wx:if="{{form.template_id === item.id}}" class="pf-tpl-tick"><pt-icon name="check" size="{{26}}"></pt-icon></view>
</view>
<view class="pf-tpl-sum">{{item.summary}}</view>
<view class="pf-tpl-meta">
<text wx:if="{{item.daily}}">每天 {{item.daily}} 项</text>
<text wx:if="{{item.weekly}}">每周 {{item.weekly}} 项</text>
<text wx:if="{{item.monthly}}">每月 {{item.monthly}} 项</text>
<text wx:if="{{item.once}}">一次性 {{item.once}} 项</text>
</view>
</view>
<!-- 「先空着」必须是个平等的选项,不是藏起来的退路:
已经养熟的宠物主人有自己的节奏,硬塞一套只会被删掉 -->
<view class="pf-tpl {{form.template_id === '' ? 'on' : ''}}" data-id="" bindtap="pickTemplate">
<view class="pf-tpl-top">
<view class="pf-tpl-name">先空着,我自己排</view>
<view wx:if="{{form.template_id === ''}}" class="pf-tpl-tick"><pt-icon name="check" size="{{26}}"></pt-icon></view>
</view>
<view class="pf-tpl-sum">之后在「管理计划」里随时能套用</view>
</view>
<view wx:if="{{!tplOptions.length}}" class="empty">这个阶段还没有配方案,建完档可以自己排</view>
<view class="tiny pf-tpl-note">疫苗和驱虫提醒不管选哪个都会建 —— 漏针是真会出事的</view>
</view>
</block>
</view>
</scroll-view>
@@ -93,7 +130,7 @@
<view class="pf-foot">
<view wx:if="{{!editing && step > 0}}" class="btn btn-ghost pf-back" bindtap="prev">上一步</view>
<view class="btn btn-primary pf-next {{saving ? 'pf-busy' : ''}}" bindtap="next">
{{saving ? '保存中…' : (editing ? '保存' : (step < 2 ? '下一步' : '完成建档'))}}
{{saving ? '保存中…' : (editing ? '保存' : (step < 3 ? '下一步' : '完成建档'))}}
</view>
</view>
+15
View File
@@ -91,3 +91,18 @@
border-radius:var(--r-sm);padding:var(--sp-2) var(--sp-3);
font-size:var(--fs-cap);line-height:1.6;
}
/* 第四步:方案卡 */
.pf-sub{font-size:var(--fs-sm);color:var(--muted);line-height:1.6;margin:calc(-1 * var(--sp-2)) 0 var(--sp-4)}
.pf-tpl{
border:2rpx solid var(--line);border-radius:var(--r-md);
padding:var(--sp-4);margin-bottom:var(--sp-3);background:var(--surface-2);
}
.pf-tpl.on{border-color:var(--primary);background:var(--primary-soft)}
.pf-tpl-top{display:flex;align-items:center;gap:var(--sp-2)}
.pf-tpl-name{flex:1;font-size:var(--fs-md);font-weight:var(--fw-b);color:var(--text)}
.pf-tpl-tick{flex:none;color:var(--primary-dark);display:flex;align-items:center}
.pf-tpl-sum{font-size:var(--fs-sm);color:var(--text-2);margin-top:6rpx;line-height:1.5}
.pf-tpl-meta{display:flex;flex-wrap:wrap;gap:var(--sp-3);margin-top:var(--sp-2);
font-size:var(--fs-cap);color:var(--muted)}
.pf-tpl-note{margin-top:var(--sp-2)}
+43
View File
@@ -55,6 +55,9 @@ Page({
monthLabel: '',
monthEndLabel: '',
nextCount: 0,
monthEmpty: false,
tplOptions: [],
tplShow: false,
pickStart: '',
pickEnd: '',
selDate: '',
@@ -89,6 +92,7 @@ Page({
load() {
const id = store.currentPetId();
if (!id) return;
this.loadTemplates();
api
.getPlan(id)
.then((plan) => this.apply(plan))
@@ -127,11 +131,50 @@ Page({
cells: buildCells(m.year, m.month, byDate, todayStr),
nextCount: Object.keys(byDate).filter((d) => d.indexOf(monthOf(1).year + '-' + pad2(monthOf(1).month)) === 0)
.reduce((n, d) => n + byDate[d].length, 0),
// 当前看的这个月一条都没有 —— 空月份要给套方案的入口
monthEmpty: !Object.keys(byDate).some((d) => d.indexOf(prefix) === 0),
});
// 切到本月默认选今天;切到下月默认选 1 号(今天不在那个月里)
const inMonth = todayStr.indexOf(prefix) === 0;
this.selectDay(inMonth ? todayStr : prefix + '-01', todayStr);
},
// 方案按宠物当前阶段取。宠物换了(pet-switch)阶段也可能不同,所以跟着 load 走
loadTemplates() {
const pet = this.data.pet || {};
if (!pet.stage) return;
api
.careTemplates(pet.type === '狗狗' ? 'dog' : 'cat', pet.stage)
.then((opts) => this.setData({ tplOptions: opts || [] }))
.catch(() => this.setData({ tplOptions: [] }));
},
openTpl() {
this.setData({ tplShow: true });
},
closeTpl() {
this.setData({ tplShow: false });
},
applyTpl(e) {
const id = e.currentTarget.dataset.id;
const petID = store.currentPetId();
if (!petID || !id) return;
wx.showLoading({ title: '排进去…' });
api
.applyTemplate(petID, id, this.data.monthOff)
.then((res) => {
wx.hideLoading();
this.setData({ tplShow: false });
const r = res || {};
wx.showToast({
title: r.plans > 0 ? '排了 ' + r.plans + ' 件事' : '这个月已经有这些安排了',
icon: 'none',
});
this.load();
})
.catch((err) => {
wx.hideLoading();
toastErr(err, '套用失败');
});
},
switchMonth(e) {
this.renderMonth(Number(e.currentTarget.dataset.off));
},
+29 -3
View File
@@ -23,8 +23,12 @@
<view class="link {{monthOff === 1 ? 'on' : ''}}" data-off="1" bindtap="switchMonth">下月</view>
</view>
</view>
<view wx:if="{{monthOff === 1 && !nextCount}}" class="plan-tip">
<pt-icon name="warn" size="{{28}}"></pt-icon>{{monthLabel}}还没有安排,点某天加几件
<!-- 这个月一条都没有时给套方案的入口。空着让用户自己从零排,
多数人会直接退出去 —— 但「自己排」也得留着,不能只给套用 -->
<view wx:if="{{monthEmpty}}" class="plan-tip">
<pt-icon name="warn" size="{{28}}"></pt-icon>
<view class="plan-tip-b">{{monthLabel}}还没有安排</view>
<view wx:if="{{tplOptions.length}}" class="link" catchtap="openTpl">套一套方案</view>
</view>
<view class="cal-grid">
<text class="cal-w">一</text><text class="cal-w">二</text><text class="cal-w">三</text><text class="cal-w">四</text><text class="cal-w">五</text><text class="cal-w">六</text><text class="cal-w">日</text>
@@ -38,7 +42,10 @@
<view class="card">
<view class="section-head">
<view class="sh-title">{{selLabel}}</view>
<view class="link" bindtap="openAdd"> 加一件</view>
<view class="link-tabs">
<view wx:if="{{tplOptions.length}}" class="link on" bindtap="openTpl">套方案</view>
<view class="link on" bindtap="openAdd"> 加一件</view>
</view>
</view>
<view wx:for="{{dayTasks}}" wx:key="id" class="plan-task {{item.done ? 'done' : ''}}">
<view class="pk-check" catchtap="toggleTask" data-id="{{item.id}}">
@@ -88,4 +95,23 @@
</view>
</view>
<!-- 套用养护方案 -->
<view wx:if="{{tplShow}}" class="pe-mask" bindtap="closeTpl">
<view class="pe-sheet" catchtap="noop">
<view class="pe-h">套一套方案到{{monthLabel}}</view>
<view class="tiny pt-sub">按 {{pet.stage}} 配的。套用是「往里加」,不会覆盖你已经排好的。</view>
<view wx:for="{{tplOptions}}" wx:key="id" class="pt-item" data-id="{{item.id}}" bindtap="applyTpl">
<view class="pt-name">{{item.name}}</view>
<view class="pt-sum">{{item.summary}}</view>
<view class="pt-meta">
<text wx:if="{{item.daily}}">每天 {{item.daily}} 项</text>
<text wx:if="{{item.weekly}}">每周 {{item.weekly}} 项</text>
<text wx:if="{{item.monthly}}">每月 {{item.monthly}} 项</text>
<text wx:if="{{item.once}}">一次性 {{item.once}} 项</text>
</view>
</view>
<view wx:if="{{!tplOptions.length}}" class="empty">这个阶段还没有配方案</view>
</view>
</view>
<bottom-sheet show="{{sheetShow}}" type="{{sheetType}}" bind:close="closeSheet"></bottom-sheet>
+14
View File
@@ -54,3 +54,17 @@
.pe-daily{display:flex;align-items:center;gap:var(--sp-4)}
.pe-daily-main{flex:1;min-width:0}
/* 空月份的提示条:一行放不下「文案 + 按钮」,改成 flex */
.plan-tip-b{flex:1;min-width:0}
/* 套方案浮层 */
.pt-sub{margin:calc(-1 * var(--sp-2)) 0 var(--sp-4);text-align:center}
.pt-item{
border:2rpx solid var(--line);border-radius:var(--r-md);
padding:var(--sp-4);margin-bottom:var(--sp-3);background:#fff;
}
.pt-name{font-size:var(--fs-md);font-weight:var(--fw-b);color:var(--text)}
.pt-sum{font-size:var(--fs-sm);color:var(--text-2);margin-top:6rpx;line-height:1.5}
.pt-meta{display:flex;flex-wrap:wrap;gap:var(--sp-3);margin-top:var(--sp-2);
font-size:var(--fs-cap);color:var(--muted)}
+7
View File
@@ -54,6 +54,13 @@ const api = {
getPets: () => request({ url: '/api/pets' }),
homeSummary: (id) => request({ url: `/api/pets/${id}/home-summary` }),
getPet: (id) => request({ url: `/api/pets/${id}` }),
// 养护方案:可选列表 + 套用到某个月
careTemplates: (species, stage) =>
request({ url: '/api/care-templates?species=' + species + '&stage=' + encodeURIComponent(stage) }),
applyTemplate: (petId, templateID, monthOffset) =>
request({ url: `/api/pets/${petId}/apply-template`, method: 'POST',
data: { template_id: templateID, month_offset: monthOffset || 0 } }),
// 生命阶段的划分标准。判定和展示用同一份数据 —— 不另写一份说明文案,
// 否则改了阈值忘了改文案,用户看到的依据和实际行为对不上
lifeStages: (species, size) =>