| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 | // nova-lesson/pages/lesson-detail/write-comment/index.jslet Parse = getApp().Parse;Page({    /**     * 页面的初始数据     */    data: {        rate: 0,        content: '',        uploadURL: "",        domain: "",        uptokenURL: "",        fileList: [],        activeColor: getApp().globalData.activeColor,        titleColor: getApp().globalData.titleColor,    },    onChange(e) {        let rate = this.data.rate        this.setData({            rate: e.detail        })    },    blur(e) {        let content = e.currentTarget.dataset.name        this.setData({            content: e.detail.value        })    },    changeFile(e) {        console.log(e)        if (e.detail && e.detail.length > 0) {            let fileList = []            let filearr = e.detail            filearr.forEach(file => {                fileList.push(file.url)            })            this.setData({                image: fileList            })        } else {            this.setData({                image: []            })        }    },    /**     * 生命周期函数--监听页面加载     */    onLoad: async function(options) {        let activeColor = getApp().globalData.activeColor        let titleColor = getApp().globalData.titleColor        let {            id        } = options        this.setData({            id: id,            activeColor: activeColor,            titleColor: titleColor        })        console.log(id);    },    async confirm(e) {        let type = e.currentTarget.dataset.type        console.log(this.data.rate, this.data.content, this.data.fileList);        switch (type) {            case "cencle":                wx.navigateBack();                break;            case "submit":                if (this.data.rate < 0 || !this.data.content) {                    wx.showToast({                        title: '请填写内容',                        icon: 'none',                        duration: 1500,                    });                    return                } else {                    wx.showModal({                        title: '提交评价',                        content: '是否确认提交评价',                        showCancel: true,                        cancelText: '取消',                        cancelColor: '#000000',                        confirmText: '确定',                        confirmColor: '#3CC51F',                        success: async(result) => {                            let dis = await this.setDiscuss()                            if (result.confirm) {                                if (dis) {                                    wx.showToast({                                        title: '提交成功',                                        icon: 'success',                                    });                                    wx.redirectTo({                                        url: '/nova-lesson/pages/lesson-detail/lesson-detail?id=' + this.data.id                                    });                                } else {                                    wx.showToast({                                        title: '提交失败',                                        icon: 'none',                                    });                                }                            } else {                                wx.showToast({                                    title: '取消提交',                                    icon: 'none',                                });                            }                        },                        fail: () => {},                        complete: () => {}                    });                }                break;        }    },    async setDiscuss() {        let LessonComment = Parse.Object.extend("LessonComment")        let lessonComment = new LessonComment()        lessonComment.set("score", this.data.rate)        lessonComment.set("content", this.data.content)        lessonComment.set("images", this.data.images)        lessonComment.set("user", {            __type: "Pointer",            className: "_User",            objectId: Parse.User.current().id        });        lessonComment.set("company", {            __type: "Pointer",            className: "Company",            objectId: getApp().globalData.company        })        lessonComment.set("lesson", {            __type: "Pointer",            className: "Lesson",            objectId: this.data.id        })        let result = await lessonComment.save();        if (result && result.id) {            return result        } else {            return false        }    },    /**     * 生命周期函数--监听页面初次渲染完成     */    onReady: function() {    },    /**     * 生命周期函数--监听页面显示     */    onShow: function() {    },    /**     * 生命周期函数--监听页面隐藏     */    onHide: function() {    },    /**     * 生命周期函数--监听页面卸载     */    onUnload: function() {    },    /**     * 页面相关事件处理函数--监听用户下拉动作     */    onPullDownRefresh: function() {    },    /**     * 页面上拉触底事件的处理函数     */    onReachBottom: function() {    },    /**     * 用户点击右上角分享     */    onShareAppMessage: function() {    }})
 |