punchDetail.js
11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
// pages/index/achievement/achievement.js
// 引入插件安装器
import plugin from '../../../component/v2/plugins/index'
import week from '../../../component/v2/plugins/week'
import todo from '../../../component/v2/plugins/todo'
import selectable from '../../../component/v2/plugins/selectable'
import request from '../../../api/request.js'
import moment from 'moment';
plugin
.use(week)
.use(todo)
.use(selectable)
Page({
/**
* 页面的初始数据
*/
data: {
calendarConfig: {
theme: 'elegant',
weekMode: true, // 周视图模式
highlightToday: true, // 是否高亮显示当天
hideHeader: true, // 隐藏日历头部操作栏
disableMode: { // 禁用某一天之前/之后的所有日期
type: 'after', // [‘before’, 'after']
// 无该属性或该属性值为假,则默认为当天
},
},
isDisplay: false,
clockShow: false,
form: {
id: '', //任务ID
isRepair: 1, //是否补卡1立即打卡2补卡
repairDate: '', //补卡日期,当isRepair=2时必传,格式:YYYY-MM-dd
statisticsUnit: '', //统计单位所含内容
taskDesc: '', //打卡描述内容
taskFileUrl: [], //任务文件(含多个)
userId: ''
},
fileList: [],
calendar: {}, //日历
valueId: '', //任务ID
taskVo: {
allowRepairCard: 0,
hasData: 0,
statisticsUnit: "",
submitCondition: "",
id: 0,
releaseTime: "",
signTotal: 0,
taskCycle: 0,
taskDesc: "",
taskFrequency: "",
taskTitle: "",
weekDay: ""
},
resData: [], //成果数据
recordVo: {
commitTime: "",
files: [],
signDate: "",
taskRecordDesc: "",
taskStatisticsParam: ""
}, //成果数据当天
recordVoShow: false,
isToday: true, //是否是今天
isLarge: false, //是否大于今天
repairText: '',
dayMoment: ''
},
/**
* 选择日期后执行的事件
*/
afterTapDate(e) {
let date = e.detail.date
this.resetV2(e.detail.year, e.detail.month, date)
this.setData({
isToday: e.detail.isToday
})
//选择的年月日
let checkDay = e.detail.year + '-' + e.detail.month + '-' + e.detail.date
let checktimeDate = new Date(moment(checkDay).format('YYYY-MM-DD')).getTime()
//选择的日期是否大于今天
if (checktimeDate > new Date().getTime()) {
this.setData({
isLarge: true
})
} else {
this.setData({
isLarge: false
})
}
this.setData({
repairText: e.detail.todoText
})
let recordVo = this.data.resData.eventDetails[date - 1].recordVo
//匹配数据
if (recordVo != null) {
console.log('复制', recordVo)
this.setData({
recordVo: recordVo
})
this.setData({
recordVoShow: true
})
} else {
this.setData({
recordVoShow: false
})
}
},
//获取信息(第一次进来,模拟点击渲染)
getInfo(doday, isOne = 0, e) {
request({
url: `/wx/task/getSignRecord`,
method: 'get',
data: {
// wx.getStorageSync('userInfo_id'),
"taskId": this.data.valueId,
"signDate": doday
},
}).then(res => {
if (res.code == 0) {
this.setData({
resData: res.data
})
this.getV2(res.data)
if (isOne == 1) {
this.afterTapDate(e)
}
} else {
wx.showToast({
title: res.msg,
icon: 'none'
})
}
})
},
//初始化日历
initialize() {
// 设置待办
this.setData({
'calendar': this.selectComponent('#calendar').calendar
})
},
//重置日历
resetV2(year, month, date) {
console.log(year, month, date)
if (this.data.dayMoment == month) {} else {
let e = {
detail: {
date: date,
month: month,
year: year
}
}
this.setData({
dayMoment: month
})
this.getInfo(moment(year + '-' + month + '-' + date).format('YYYY-MM-DD'), 1, e)
}
},
//显示日历
getV2(resData) {
this.setData({
taskVo: resData.taskVo
})
// const calendar = this.selectComponent('#calendar').calendar
this.data.calendar.setTodos({
// 待办点标记设置
pos: 'bottom', // 待办点标记位置 ['top', 'bottom']
dotColor: 'purple', // 待办点标记颜色
circle: false, // 待办圆圈标记设置(如圆圈标记已签到日期),该设置与点标记设置互斥
showLabelAlways: true, // 点击时是否显示待办事项(圆点/文字),在 circle 为 true 及当日历配置 showLunar 为 true 时,此配置失效
dates: resData.eventDetails,
})
this.data.calendar.enableArea([this.data.taskVo.startDate, moment(new Date().getTime()).format('YYYY-MM-DD')])
},
//成果
toAchieve(e) {
wx.navigateTo({
url: '../achievement/achievement?valueId=' + this.data.valueId,
})
},
//唤起 打卡
toClock() {
this.setData({
clockShow: true
})
},
//唤起补卡
toRepairClock() {
let selectData = this.data.calendar.getSelectedDates()
let doday = selectData[0].year + '-' + selectData[0].month + '-' + selectData[0].date
console.log(doday)
let repairDate = moment(doday).format('YYYY-MM-DD')
this.setData({
'form.isRepair': 2
})
this.setData({
'form.repairDate': repairDate
})
this.setData({
clockShow: true
})
},
//确定-打卡
toCardTask() {
this.setData({
'form.id': this.data.valueId
})
this.setData({
'form.userId': wx.getStorageSync('userInfo_id')
})
if (this.data.taskVo.submitCondition == '图片') {
if (this.data.form.taskFileUrl.length == 0) {
return wx.showToast({
title: '请上传图片',
icon: 'none'
})
}
}
request({
url: `/wx/task/commitCardTask`,
method: 'post',
data: this.data.form,
}).then(res => {
if (res.code == 0) {
wx.showToast({
title: '打卡成功',
icon: 'none'
})
let e
if (this.data.form.isRepair == 2) {
e = {
detail: {
date: moment(this.data.form.repairDate).format('DD'),
month: moment(this.data.form.repairDate).format('MM'),
year: moment(this.data.form.repairDate).format('YYYY')
}
}
this.getInfo(moment(this.data.form.repairDate).format('YYYY-MM-DD'), 1, e)
} else {
e = {
detail: {
date: moment().date(),
month: moment().month() + 1,
year: moment().year()
}
}
this.getInfo(moment(new Date().getTime()).format('YYYY-MM-DD'), 0, e)
}
this.closeClockShow()
} else {
wx.showToast({
title: res.msg + res.data,
icon: 'none'
})
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.setData({
valueId: options.valueId
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
this.initialize()
let e = {
detail: {
date: moment().date(),
month: moment().month() + 1,
year: moment().year()
}
}
this.getInfo(moment(new Date().getTime()).format('YYYY-MM-DD'), 1, e)
},
// 统一返回
handleBack() {
wx.navigateBack()
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
},
//统计单位所含内容
onStatisChange(e) {
this.setData({
'form.statisticsUnit': e.detail
})
},
//内容
onTaskDescChange(e) {
this.setData({
'form.taskDesc': e.detail
})
},
//文件上传
afterRead(event) {
const {
file
} = event.detail;
var that = this
// 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
wx.uploadFile({
url: 'https://market.myjxt.com:51311/file/fileUpload', // 仅为示例,非真实的接口地址
filePath: file.url,
name: 'file',
formData: {
user: 'test'
},
success(res) {
// 上传完成需要更新 fileList
const {
fileList = []
} = that.data;
fileList.push({
...file,
url: res.data
});
console.log(res, fileList)
that.setData({
fileList
});
that.setData({
'form.taskFileUrl': fileList.map(v => v.url)
})
},
});
},
//删除
delFile(event) {
let [list, index] = [this.data.fileList, event.detail.index]
list.splice(index, 1)
this.setData({
fileList: list
})
this.setData({
'form.taskFileUrl': this.data.fileList.map(v => v.url)
})
},
//关闭
closeClockShow() {
this.setData({
clockShow: false
})
let form = {
id: '', //任务ID
isRepair: 1, //是否补卡1立即打卡2补卡
repairDate: '', //补卡日期,当isRepair=2时必传,格式:YYYY-MM-dd
statisticsUnit: '', //统计单位所含内容
taskDesc: '', //打卡描述内容
taskFileUrl: [], //任务文件(含多个)
userId: ''
}
this.setData({
form: form
})
}
})