123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- const Parse = getApp().Parse;
- const company = getApp().globalData.company
- const dateF = require('../../../utils/date')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- list: null
- },
- async getBehaviorLog(id) {
- let BehaviorLog = new Parse.Query('BehaviorLog')
- BehaviorLog.equalTo('company', company)
- BehaviorLog.equalTo('user', id)
- BehaviorLog.descending('createdAt')
- BehaviorLog.include('targetObject')
- let behaviorLog = await BehaviorLog.find()
- let listJSON = []
- if (behaviorLog && behaviorLog.length > 0) {
- behaviorLog.forEach(behaviorLog => {
- let b = behaviorLog.toJSON()
- b.joinTime = dateF.formatTime("YYYY-mm-dd HH:MM:SS", b.createdAt)
- listJSON.push(b)
- })
- this.setData({ list: listJSON })
- }
- console.log(this.data.list);
- },
- lesson(e) {
- let id = e.currentTarget.dataset.item.targetObject[0].objectId
- console.log(id);
- wx.navigateTo({
- url: '/nova-lesson/pages/lesson-detail/lesson-detail?id=' + id
- })
- },
- goods(e) {
- let id = e.currentTarget.dataset.item.targetObject[0].objectId
- console.log(id);
- wx.navigateTo({
- url: '/nova-shop/pages/shop-goods/goods-detail/index?id=' + id
- })
- },
- async collection(e) {
- console.log(e.currentTarget.dataset.item);
- // if (schemaName == "ShopGoods") {
- // let name = e.currentTarget.dataset.item.targetObject[0].name
- // }
- // if (schemaName == "Lesson") {
- // let name = e.currentTarget.dataset.item.targetObject[0].title
- // }
- let collectId = e.currentTarget.dataset.item.targetObject[0].objectId
- let schemaName = e.currentTarget.dataset.item.targetClassName
- let image = e.currentTarget.dataset.item.targetObject[0].image
- console.log(collectId, schemaName, image);
- let Collecti = new Parse.Query('Collect')
- Collecti.equalTo('company', company)
- Collecti.equalTo('user', Parse.User.current().id)
- Collecti.equalTo('collectId', collectId)
- let res = await Collecti.first()
- if (res && res.id) {
- wx.showToast({
- title: '您已收藏该课程',
- icon: 'none'
- })
- return
- }
- let collect
- let Collect = Parse.Object.extend("Collect")
- collect = new Collect()
- collect.set("company", {
- __type: "Pointer",
- className: "Company",
- objectId: company
- })
- collect.set("user", {
- __type: "Pointer",
- className: "_User",
- objectId: Parse.User.current().id
- })
- if (schemaName == "ShopGoods") {
- collect.set("collectTarget", [{
- __type: "Pointer",
- className: "ShopGoods",
- objectId: collectId
- }])
- collect.set("name", e.currentTarget.dataset.item.targetObject[0].name)
- collect.set("type", "goods")
- }
- if (schemaName == "Lesson") {
- collect.set("collectTarget", [{
- __type: "Pointer",
- className: "Lesson",
- objectId: collectId
- }])
- collect.set("name", e.currentTarget.dataset.item.targetObject[0].title)
- collect.set("type", "lesson")
- }
- // if (schemaName == "Lesson") {
- // collect.set("collectTarget", [{
- // __type: "Pointer",
- // className: "Lesson",
- // objectId: collectId
- // }])
- // }
- collect.set("collectId", collectId)
- collect.set("schemaName", schemaName)
- collect.set("image", image)
- collect.save().then(a => {
- console.log(a)
- wx.showToast({
- title: '收藏成功',
- icon: 'none'
- })
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {
- let id = Parse.User.current().id
- console.log(id);
- this.getBehaviorLog(id)
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function() {
- }
- })
|