question.js 4.7 KB
const app = getApp()
const innerAudioContext = wx.createInnerAudioContext();

Page({

    /**
     * 页面的初始数据
     */
    data: {
        id: '',
        nav: -1,
        list: '', //第一道题
        clockData: {}, //所有题型
        curent: '', //当前题号
        countdown: '', //倒计时
        player: false,//语音
        show: false, //解析
        analysis: ''

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

        this.getlist()

    },

    onShow: function () {
        // 倒计时
        var that = this
        that.countDown();
    },
    // 获取题目 
    getlist() {
        var that = this;
        app.post("evaluation/EvaluationQuestion", {
            evaluation_id: this.id

        }).then(res => {
            let list = res.data.List
            console.log(list)
            list.forEach(item => {
                console.log(item)
                item.UserChoose = ''

            })

            // console.log(list)
            console.log(res.data)
            if (res.code == 1) {
                that.setData({
                    list: res.data.List[0], //第一道题
                    clockData: res.data, //所有题型
                    curent: 1
                })
            }
        }).catch(err => {

        })
    },
    //倒计时
    countDown() {
        // var alltime = 60
        // var h = alltime / 60
        // var m = alltime
        // var s = alltime * 60
        // console.log(h, m, s)


    },
    // 选择答案
    bind_choose(e) {
        let Index = e.currentTarget.dataset.index
        let answer = e.currentTarget.dataset.answer
        console.log(answer, '222')
        console.log(e, '222')
        this.setData({
            nav: Index
        })

        let listindex = this.data.curent
        let list = this.data.clockData.List
        console.log(list)

        list.forEach((item, index) => {
            console.log(item)
            if (this.data.curent - 1 == index) {
                item.UserChoose = answer
            }
        })
        this.setData({
            clockData: this.data.clockData
        })


    },

    // 下一题 提交
    nextClick() {


        if (this.data.curent < this.data.clockData.Count) {
            var curent = this.data.curent * 1 + 1
            this.setData({
                nav: -1,
                curent: curent,
                list: this.data.clockData.List[curent - 1]
            })
        } else {
            var that = this;
            app.post("evaluation/EvaluationTask", {
                evaluation_id: this.id,
                json: JSON.stringify(this.data.clockData)

            }).then(res => {

                let analysis = res.data
                if (res.code == 1) {
                    that.setData({
                        show: true,
                        analysis: analysis
                    })
                } else {
                    wx.showToast({
                        title: res.msg,
                        icon: 'none'
                    })
                }
            }).catch(err => {

            })


        }


    },


    //播放单词
    goAudio(e) {

        this.setData({
            player: !this.data.player
        })

        if (this.data.player) {
            let audio = e.currentTarget.dataset.audio
            console.log(audio)
            innerAudioContext.src = audio;
            innerAudioContext.play();

            innerAudioContext.onPlay(() => {
                console.log('开始播放');
            });
            innerAudioContext.onError((res) => {
                console.log(res.errMsg);
                console.log(res.errCode);
            });
        } else {
            console.log('停止');
            innerAudioContext.stop()

        }

    },


    // 测评分析 
    gototram() {
        let data = JSON.stringify( this.data.analysis)  
        // console.log(data)
        wx.navigateTo({
            url: '/pages/quest-5/quest-5?data='+data,
        })

    },
    // 播放音频
    PlayState() {
        this.selectComponent("#audio").changePlayState()
    },

    onReady: function () {

    },




    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

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

    },

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

    },

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

    }
})