1
This commit is contained in:
@@ -1,7 +1,15 @@
|
||||
import request from "@/utils/request"
|
||||
Page({
|
||||
|
||||
data: {
|
||||
detail: {
|
||||
overview: {},
|
||||
tasks: [{}, {}, {}],
|
||||
},
|
||||
loading: true,
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.init()
|
||||
},
|
||||
|
||||
onShow() {
|
||||
@@ -10,5 +18,31 @@ Page({
|
||||
selected: '首页',
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
async init() {
|
||||
let res = await request.get("/home")
|
||||
this.setData({
|
||||
detail: res,
|
||||
loading: false,
|
||||
})
|
||||
},
|
||||
//手动标记是否完成
|
||||
handDone(e) {
|
||||
const { data } = e.currentTarget.dataset;
|
||||
const newTasks = this.data.detail.tasks.map(v => {
|
||||
if (v.task_id == data.task_id) {
|
||||
// 如果当前是 1 则变为 0,如果是 0 则变为 1
|
||||
return { ...v, is_completed: v.is_completed == 1 ? 0 : 1 };
|
||||
}
|
||||
return v;
|
||||
});
|
||||
request.post("/home/task-record", {
|
||||
...data,
|
||||
is_completed: data.is_completed == 1 ? 0 : 1
|
||||
})
|
||||
this.setData({
|
||||
'detail.tasks': newTasks
|
||||
});
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user