achievement.js 4.53 KB
// 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 request from '../../../api/request.js'
import moment from 'moment';
plugin
    .use(week)
    .use(todo)
Page({

    /**
     * 页面的初始数据
     */
    data: {
        calendarConfig: {
            theme: 'elegant',
            weekMode: true, // 周视图模式
            // highlightToday: true, // 是否高亮显示当天
            hideHeader: true, // 隐藏日历头部操作栏
            autoChoosedWhenJump: true, // 设置默认日期及跳转到指定日期后是否需要自动选中
            defaultDate: moment(new Date().getTime()).format('YYYY-MM-DD'), // 默认选中指定某天,如需选中需配置 autoChoosedWhenJump: true
        },
        isDisplay: false,
        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,
        dayMoment: 0, //数据月份
    },
    /**
     * 选择日期后执行的事件
     */
    afterTapDate(e) {
        let date = e.detail.date
        // let month = e.detail.month
        // let year = e.detail.year
        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) {
        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) {
                    let e = {
                        detail: {
                            date: moment().date(),
                            month: moment().month() + 1,
                            year: moment().year()
                        }
                    }
                    this.afterTapDate(e)
                }
            } else {
                wx.showToast({
                    title: res.msg,
                    icon: 'none'
                })
            }
        })
    },
    //初始化日历
    initialize() {
        // 设置待办
        this.setData({
            'calendar': this.selectComponent('#calendar').calendar
        })
    },
    //显示日历
    getV2(resData) {
        this.setData({
            taskVo: resData.taskVo
        })
        // const calendar = this.selectComponent('#calendar').calendar
        this.data.calendar.setTodos({
            // 待办点标记设置
            pos: 'bottom', // 待办点标记位置 ['top', 'bottom']
            dotColor: 'red', // 待办点标记颜色
            circle: false, // 待办圆圈标记设置(如圆圈标记已签到日期),该设置与点标记设置互斥
            showLabelAlways: true, // 点击时是否显示待办事项(圆点/文字),在 circle 为 true 及当日历配置 showLunar 为 true 时,此配置失效
            dates: resData.eventDetails
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
            valueId: options.valueId
        })
    },
    // 统一返回
    handleBack() {
        wx.navigateBack()
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {
        this.initialize()
        this.getInfo(moment(new Date().getTime()).format('YYYY-MM-DD'), 1)
    },
})