answer.js 3.7 KB
const app = getApp();
Page({


    data: {
        id: '',
        list: '',
        answers:[],
        finaAnswer:[],
        showAnswer: false
    },

    onLoad: function (options) {
        // console.log(options)
        this.setData({
            id: options.id
        })
    },
    onReady: function () {

    },
    onShow: function () {
        let that = this;
        that.getlist();

    },
    // 题
    getlist() {

        let that = this;
        let url = '/index/second/getClassQuestion';
        let head = {
            'XX-Token': wx.getStorageSync('token')
        }
        let params = {
            class_id: that.data.id
        }
        app.post(url, params, head).then((res) => {
            console.log(res)
            that.setData({
                list: res,
                tempList:JSON.parse(JSON.stringify(res))
            })
        }).catch((err) => {

        })

    },
    radioChange(e){
        let tempAnswer = e.detail.value.split(',');
        this.data.answers[tempAnswer[1]] = tempAnswer[0];
        this.data.finaAnswer[tempAnswer[1]]={
            key: tempAnswer[0],
            answer: tempAnswer[1]
        }
        this.data.list[tempAnswer[1]].choose = tempAnswer[2]
        this.setData({  
            answers: this.data.answers,
            finaAnswer:this.data.finaAnswer,
            list:this.data.list
        })
    },

    // 确认
    getcomfirm() {

        let that = this;
        let url = '/index/second/commitAnswer';
        let head = {
            'XX-Token': wx.getStorageSync('token')
        }
        let params = {
            class_id: that.data.id,
        }
        app.post(url, params, head).then((res) => {
            
            if (res.code == '40000') {
                let answer = res
                wx.showModal({
                    title: '提示',
                    content: '很遗憾你没有获得学时',
                    confirmText: '重新答题',
                    cancelText: '查看答案',
                    success(res) {
                        if (res.confirm) {
                            wx.redirectTo({
                                url: '/pages/getStudycontent/answer/answer?id='+that.data.id,
                            })
                            // let tempList = JSON.stringify(that.data.tempList)
                            // that.setData({
                            //     showAnswer: false,
                            //     // list: JSON.parse(tempList)
                            // })
                            console.log('用户点击确定')
                        } else if (res.cancel) {

                            // wx.navigateTo({
                            //     url: '/pages/getStudycontent/answer/answer',
                            // })
                            that.setData({
                                showAnswer: true
                            })

                            console.log('用户点击取消')
                        }
                    }
                })


            } else {
                wx.showModal({
                    title: '提示',
                    content: '恭喜',
                    showCancel: false,
                    success: function (res) {

                    }
                })
            }


        }).catch((err) => {
            console.log(err)
        })


    },


    onHide: function () {

    },


    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})