duidui_mini_program/pages/classcommunityitemlist/classcommunityitemlist.js
2026-03-27 10:41:46 +08:00

185 lines
4.4 KiB
JavaScript

const baseUrl = getApp();
const api = require('../../config/api.js');
const util = require('../../config/util.js');
Page({
/**
* 页面的初始数据
*/
data: {
pareid: 0,
listdata: [],
liveclickopen: 1, //2
baseurl: baseUrl.globalData.baseimgurl,
coursename: ''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
pareid: options.typeid
});
// this.pageScrollToBottom();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.getcousrethree();
this.getcouresename();
// this.pageScrollToBottom();
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
liveopen(e) {
let arr = [];
arr = this.data.listdata;
console.log(e.currentTarget.dataset.itemid);
console.log(this.data.listdata);
arr.forEach(function (item, index) {
if (index == e.currentTarget.dataset.itemid) {
item['liveclickopen'] = 1; //1
arr[index] = item;
} else {
item['liveclickopen'] = 1; //2
arr[index] = item
}
})
this.setData({
listdata: arr
})
},
liveclose(e) {
let arr = [];
arr = this.data.listdata;
console.log(e.currentTarget.dataset.itemid);
arr.forEach(function (item, index) {
if (index == e.currentTarget.dataset.itemid) {
item['liveclickopen'] = 2;
arr[index] = item;
} else {
item['liveclickopen'] = 2;
arr[index] = item
}
})
this.setData({
listdata: arr
})
},
getcouresename: function () {
let id = this.data.pareid;
const that = this;
let url = baseUrl.globalData.baseUrl + '/classcourse/getcousretwoname';
var param = {
id: that.data.pareid,
};
//此处为使用封装的post请求
util.post(url, param).then((res) => {
console.log(res);
that.setData({
coursename: res.data['name']
});
}).catch((errMsg) => {
console.log(errMsg);
});
},
getcousrethree: function () {
const that = this;
let url = baseUrl.globalData.baseUrl + '/classcourse/getcoursethree';
var param = {
pareid: that.data.pareid,
user_id:wx.getStorageSync('wxuserid')
};
//此处为使用封装的post请求
util.post(url, param).then((res) => {
console.log(res);
that.setData({
listdata: res.data
});
}).catch((errMsg) => {
console.log(errMsg);
});
},
itemclickurl: function (e) {
console.log(e);
// return;
let typeid = e.currentTarget.dataset.typeid;
wx.navigateTo({
url: '/pages/classcourselearning/classcourselearning?id=' + e.currentTarget.id + '&typeid=' + typeid,
})
},
pageScrollToBottom() {
wx.createSelectorQuery().select('#time-mo').boundingClientRect(function (rect) {
// rect.id // 节点的ID
rect.dataset // 节点的dataset
rect.left // 节点的左边界坐标
rect.right // 节点的右边界坐标
rect.top // 节点的上边界坐标
rect.bottom // 节点的下边界坐标
rect.width // 节点的宽度
rect.height
console.log(rect.bottom + 2000)
// 使页面滚动到底部
wx.pageScrollTo({
scrollTop: rect.bottom + 2000
})
}).exec()
},
})