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


    data: {
        id: '',
        list: '',
        answers:[]
    },

    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

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

        })

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

    // 确认
    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) {
                wx.showModal({
                    title: '提示',
                    content: '很遗憾你没有获得学时',
                    confirmText: '重新答题',
                    cancelText: '查看答案',
                    success(res) {
                        if (res.confirm) {

                            wx.navigateTo({
                                url: '/pages/getStudycontent/answer/answer',
                            })

                            console.log('用户点击确定')
                        } else if (res.cancel) {

                            wx.navigateTo({
                                url: '/pages/getStudycontent/answer/answer',
                            })

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


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

                    }
                })
            }


        }).catch((err) => {

        })


    },


    onHide: function () {

    },


    onUnload: function () {

    },

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

    },

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

    },

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

    }
})