// pages/index/rank/rank.js import request from '../../../api/request.js' import moment from 'moment'; Page({ /** * 页面的初始数据 */ data: { tempId: 0, form: { taskTitle: '', //任务标题 taskDesc: '', //任务描述内容 allowRepairCard: false, //是否允许补卡 1是 2否 hasData: false, //是否需要提交数据 1是 2否 // id: '', // 任务ID lackNum: '', // 缺卡次数 remindTime: '', // 打卡提醒时间点 startDate: '', // 打卡开始时间 statisticsUnit: '', // 统计单位 hasData=1 时,必传 submitCondition: '', //提交包含条件:图片、视频、音频 taskCycle: '', //打卡周期 taskFileUrl: [], //任务文件(含多个) taskFrequency: '', //打卡频次 userId: '', //所属用户ID }, fileList: [], //弹出层 //统计单位 unitShow: false, columnsUnit: ['小时', '天', '月'], //开始时间 startTimeShow: false, columnsStartTime: ['9', '10', '11', '12'], minDate: new Date().getTime(), currentDate: new Date().getTime(), formatter(type, value) { if (type === 'year') { return `${value}年`; } if (type === 'month') { return `${value}月`; } return value; }, //打卡周期 clockCycleShow: false, columnsClockCycle: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'], //打卡频次 clockRateShow: false, columnsClockRate: ['每天', '7天', '一个月'], //打卡提醒 clockRemindShow: false, columnsClockRemind: [ { values: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'], defaultIndex: 2, }, // 第二列 { values: ['8:00', '9:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00'], defaultIndex: 1, }, ], //打卡缺卡提醒 clockLackShow: false, columnsClockLack: [1,2,3], //必须包含 containShow: false, columnsContain: ['图片'], }, //获取模板详情 / 空模板 getDetail() { request({ url: `/wx/temp/getTempDetail`, method: 'get', data: { "tempId": this.data.tempId, }, }).then(res => { if (res.code == 0) { const data = res.data this.setData({ 'form.taskTitle': data.taskTitle }) this.setData({ 'form.taskDesc': data.taskDesc }) this.setData({ 'form.allowRepairCard': data.allowRepairCard }) this.setData({ 'form.hasData': data.hasData }) this.setData({ 'form.lackNum': data.lackNum }) this.setData({ 'form.remindTime': data.remindTime }) this.setData({ 'form.startDate': data.startDate }) this.setData({ 'form.statisticsUnit': data.statisticsUnit }) this.setData({ 'form.submitCondition': data.submitCondition }) this.setData({ 'form.taskCycle': data.taskCycle }) this.setData({ 'form.taskFileUrl': [] }) this.setData({ 'form.taskFrequency': data.taskFrequency }) } else { wx.showToast({ title: res.msg, icon: 'none', duration: 1000 }) } }) }, //输入 onfieldChange(e) { this.setData({ 'form.taskTitle': e.detail }) }, //输入 onfieldDescChange(e) { this.setData({ 'form.taskDesc': e.detail }) }, //开关 onSwitch(e) { console.log(e) this.setData({ 'form.hasData': e.detail }) }, onChange(e) { console.log(e) this.setData({ 'form.allowRepairCard': 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) }) }, }); }, //开关 onswitchChange({ detail }) { this.setData({ 'form.checked': detail }); }, //创建 createTask() { console.log(this.data.form) request({ url: `/wx/task/addCardTask`, method: 'post', data: this.data.form, }).then(res => { if (res.code == 0) { wx.navigateTo({    url: '../../mine/record/record' }) }else { wx.showToast({ title: res.msg, icon: 'none', duration: 1000 }) } }) }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.setData({ 'form.userId': wx.getStorageSync('userInfo_id') }) this.setData({ tempId: options.tempId }, () => { this.getDetail() }) }, // 创建完成 handleCreate() { // console.log(111) wx.switchTab({ url: '/pages/index/index', }) }, // 统一返回 handleBack() { wx.navigateBack() }, /** * 用户点击右上角分享 */ onShareAppMessage() { }, /* 弹出层 - 统计单位 */ openUnitShow() { this.setData({ unitShow: true }) }, closeUnitShow() { this.setData({ unitShow: false }) }, changeUnitShow(e) { console.log(e) this.setData({ 'form.statisticsUnit': e.detail.value }) this.setData({ unitShow: false }) }, /* 弹出层 - 开始时间 */ openStartTimeShow() { this.setData({ startTimeShow: true }) }, closeStartTimeShow() { this.setData({ startTimeShow: false }) }, changeStartTimeShow(e) { let time = moment(e.detail).format('YYYY-MM-DD') this.setData({ 'form.startDate': time, }); this.setData({ startTimeShow: false }) }, /* 弹出层 - 打卡周期 */ openClockCycleShow() { this.setData({ clockCycleShow: true }) }, closeClockCycleShow() { this.setData({ clockCycleShow: false }) }, changeClockCycleShow(e) { this.setData({ 'form.taskCycle': e.detail.value }) this.setData({ clockCycleShow: false }) }, /* 弹出层 - 打卡频次 */ openClockRateShow() { this.setData({ clockRateShow: true }) }, closeClockRateShow() { this.setData({ clockRateShow: false }) }, changeClockRateShow(e) { this.setData({ 'form.taskFrequency': e.detail.value }) this.setData({ clockRateShow: false }) }, /* 弹出层 - 打卡提醒 */ openClockRemindShow() { this.setData({ clockRemindShow: true }) }, closeClockRemindShow() { this.setData({ clockRemindShow: false }) }, changeClockRemindShow(e) { this.setData({ 'form.remindTime': e.detail.value[0] + '::' + e.detail.value[1] }) this.setData({ clockRemindShow: false }) }, /* 弹出层 - 打卡缺卡提醒 */ openClockLackShow() { this.setData({ clockLackShow: true }) }, closeClockLackShow() { this.setData({ clockLackShow: false }) }, changeClockLackShow(e) { this.setData({ 'form.lackNum': e.detail.value }) this.setData({ clockLackShow: false }) }, /* 弹出层 - 必须包含 */ openContainShow() { this.setData({ containShow: true }) }, closeContainShow() { this.setData({ containShow: false }) }, changeContainShow(e) { this.setData({ 'form.submitCondition': e.detail.value }) this.setData({ containShow: false }) }, })