yuminge-app/yun-min-program-plugin-master/packageD/directSeeding/liveList/liveList.js

889 lines
24 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// packageD/directSeeding/liveList/liveList.js
var app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
active: 1,
status: 3,
//more
isLoadMore: true,
page: 1,
total_page: 0,
myConcern: "",
announceList: "",
broadcastlist: "",
apiType: "AllLivelist",
playBackData: "",
allLivelistData: "",
liveBanner: [],
// 是否显示面板指示点
indicatorDots: true,
// 方向
vertical: false,
// 是否自动切换
autoplay: true,
// 自动切换时间间隔
interval: 4000,
// 滑动动画时长
duration: 300,
playBackShow: false,
myConcern_activitys1: [],
myConcern_activitys2: [],
allLivelistData_activitys1: [],
allLivelistData_activitys2: [],
recommendData_activitys1: [],
recommendData_activitys2: [],
broadcastlist_activitys1: [],
broadcastlist_activitys2: [],
announceList_activitys1: [],
announceList_activitys2: [],
playBackData_activitys1: [],
playBackData_activitys2: [],
recommendData: [],
live_search: "",
my_colOneHeight: 0,
my_colTwoHeight: 0,
re_colOneHeight: 0,
re_colTwoHeight: 0,
br_colOneHeight: 0,
br_colTwoHeight: 0,
an_colOneHeight: 0,
an_colTwoHeight: 0,
pl_colOneHeight: 0,
pl_colTwoHeight: 0,
all_colOneHeight: 0,
all_colTwoHeight: 0,
navlistData: [],
list_style: 0, //直播列表样式 0为瀑布流布局
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// this.getMyConcern();
// this.getRecommend()
this.getBanner();
this.getRoomPage();
// this.getLiveList(3);
this.getPlayBackShow();
this.getAllLivelist();
if (options.mid) {
app._setMid(options.mid);
}
},
//去首页
gotoIndex(){
wx.reLaunch({
url: '/packageG/index/index'
});
},
//自定义图标跳转
intbtn(e) {
let id = e.currentTarget.dataset.id;
wx.navigateTo({
url:
"/packageD/directSeeding/liveClassification/liveClassification?id=" +
id,
});
},
getRoomPage() {
let that = this;
let urlStr = app.getNetAddresss(
"plugin.room.frontend.live-list.get-room-page"
);
app._postNetWork({
url: urlStr,
showToastIn: false,
data: {},
success: function (resdata) {
var res = resdata.data;
if (res.result == 1) {
let category = res.data.category ? res.data.category : [];
let category_10 = that.chunk(category, 10);
that.setData({
navlistData: category_10,
list_style: Number(res.data.list_style)
});
//-1关注0全部1推荐2直播中3预告4精彩回复
if (res.data.wait_page) {
that.setData({
wait_page: res.data.wait_page,
});
if (that.data.wait_page == -1) {
that.data.apiType = "myConcern";
that.data.my_colOneHeight = 0;
that.data.my_colTwoHeight = 0;
that.setData({
myConcern: [],
myConcern_activitys1: [],
myConcern_activitys2: [],
active: 0,
});
that.getMyConcern();
} else if (that.data.wait_page == 0) {
that.data.all_colOneHeight = 0;
that.data.all_colTwoHeight = 0;
that.setData({
allLivelistData: [],
allLivelistData_activitys1: [],
allLivelistData_activitys2: [],
active: 1,
});
that.getAllLivelist();
} else if (that.data.wait_page == 1) {
that.data.re_colOneHeight = 0;
that.data.re_colTwoHeight = 0;
that.setData({
recommendData: [],
recommendData_activitys1: [],
recommendData_activitys2: [],
active: 2,
});
that.getRecommend();
} else if (that.data.wait_page == 2) {
that.data.apiType = "liveList";
that.data.status = 3;
that.data.br_colOneHeight = 0;
that.data.br_colTwoHeight = 0;
that.setData({
broadcastlist: [],
broadcastlist_activitys1: [],
broadcastlist_activitys2: [],
active: 3,
});
that.getLiveList(3);
} else if (that.data.wait_page == 3) {
that.data.apiType = "liveList";
that.data.status = 2;
that.data.an_colOneHeight = 0;
that.data.an_colTwoHeight = 0;
that.setData({
announceList: [],
announceList_activitys1: [],
announceList_activitys2: [],
active: 4,
});
that.getLiveList(2);
} else if (that.data.wait_page == 4) {
that.data.apiType = "playBack";
that.data.pl_colOneHeight = 0;
that.data.pl_colTwoHeight = 0;
that.setData({
playBackData: [],
playBackData_activitys1: [],
playBackData_activitys2: [],
active: 5,
});
that.getplayBack();
}
}
} else {
wx.showToast({
icon: "none",
title: res.msg,
duration: 1500,
});
}
},
fail: function (res) {
console.log(res.msg);
},
});
},
searchbtn(e) {
let val = e.detail.value;
this.setData({
live_search: val,
});
},
searchConfirm() {
if (this.data.apiType == "myConcern") {
this.data.my_colOneHeight = 0;
this.data.my_colTwoHeight = 0;
this.setData({
myConcern: [],
myConcern_activitys1: [],
myConcern_activitys2: [],
});
this.getMyConcern();
} else if (this.data.apiType == "recommend") {
this.data.re_colOneHeight = 0;
this.data.re_colTwoHeight = 0;
this.setData({
recommendData: [],
recommendData_activitys1: [],
recommendData_activitys2: [],
});
this.getRecommend();
} else if (this.data.apiType == "liveList") {
if (this.data.status == 3) {
this.data.br_colOneHeight = 0;
this.data.br_colTwoHeight = 0;
this.setData({
broadcastlist: [],
broadcastlist_activitys1: [],
broadcastlist_activitys2: [],
});
this.getLiveList(3);
} else if (this.data.status == 2) {
this.data.an_colOneHeight = 0;
this.data.an_colTwoHeight = 0;
this.setData({
announceList: [],
announceList_activitys1: [],
announceList_activitys2: [],
});
this.getLiveList(2);
}
} else if (this.data.apiType == "playBack") {
this.data.pl_colOneHeight = 0;
this.data.pl_colTwoHeight = 0;
this.setData({
playBackData: [],
playBackData_activitys1: [],
playBackData_activitys2: [],
});
this.getplayBack();
} else if (this.data.apiType == "AllLivelist") {
this.data.all_colOneHeight = 0;
this.data.all_colTwoHeight = 0;
this.setData({
allLivelistData: [],
allLivelistData_activitys1: [],
allLivelistData_activitys2: [],
});
this.getAllLivelist();
}
},
getPlayBackShow() {
let that = this;
let urlStr = app.getNetAddresss("plugin.room.frontend.live-list.record");
app._postNetWork({
url: urlStr,
showToastIn: false,
data: {},
success: function (resdata) {
var res = resdata.data;
if (res.result == 1) {
that.setData({
playBackShow: res.data.result == 1 ? true : false,
});
} else {
wx.showToast({
icon: "none",
title: res.msg,
duration: 1500,
});
}
},
fail: function (res) {
console.log(res.msg);
},
});
},
chunk(arr, n) {
var result = [];
for (var i = 0, len = arr.length; i < len; i += n) {
result.push(arr.slice(i, i + n));
}
return result;
},
getBanner() {
let that = this;
let urlStr = app.getNetAddresss("plugin.room.frontend.live-list.banner");
app._postNetWork({
url: urlStr,
showToastIn: false,
data: {},
success: function (resdata) {
var res = resdata.data;
if (res.result == 1) {
that.setData({
liveBanner: res.data,
});
} else {
wx.showToast({
icon: "none",
title: res.msg,
duration: 1500,
});
}
},
fail: function (res) {
console.log(res.msg);
},
});
},
goUrl(e) {
let url = e.currentTarget.dataset.url;
if (url) {
try {
wx.navigateTo({
url: url,
});
} catch (e) {
wx.showToast({
title: "链接设置错误:" + url,
icon: "none",
duration: 2000,
});
//TODO handle the exception
}
}
},
getMyConcern() {
let that = this;
let urlStr = app.getNetAddresss(
"plugin.room.frontend.live-list.get-live-concern"
);
app._postNetWork({
url: urlStr,
showToastIn: false,
data: {
page: 1,
keyword: 1,
},
// this.data.live_search
success: function (resdata) {
var res = resdata.data;
if (res.result == 1) {
that.setData({
myConcern: res.data.data,
total_page: res.data.last_page,
});
} else {
wx.showToast({
icon: "none",
title: res.msg,
duration: 1500,
});
}
},
fail: function (res) {
console.log(res.msg);
},
});
},
getLiveList(type) {
let that = this;
let urlStr = app.getNetAddresss(
"plugin.room.frontend.live-list.get-live-list"
);
app._postNetWork({
url: urlStr,
showToastIn: false,
data: {
status: type,
page: 1,
keyword: this.data.live_search,
},
success: function (resdata) {
var res = resdata.data;
if (res.result == 1) {
if (type == 2) {
that.setData({
total_page: res.data.last_page,
announceList: res.data.data,
});
} else if (type == 3) {
that.setData({
total_page: res.data.last_page,
broadcastlist: res.data.data,
});
}
} else {
wx.showToast({
icon: "none",
title: res.msg,
duration: 1500,
});
}
},
fail: function (res) {
console.log(res.msg);
},
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
var value = wx.getStorageSync("yz_uid");
var mid = "";
if (value) {
mid = value;
}
return {
path: "/packageD/directSeeding/liveList/liveList?mid=" + mid,
};
},
//跳转直播页
golivePage(e) {
let id = e.currentTarget.dataset.id;
let status = e.currentTarget.dataset.status;
let memberid = e.currentTarget.dataset.memberid;
console.log(e);
if (status == 1) {
wx.navigateTo({
url:
"/packageD/directSeeding/livePage/livePage?id=" +
id +
"&playerType=live",
});
} else {
wx.navigateTo({
url: "/packageD/directSeeding/anchorDetail/anchorDetail?id=" + memberid,
});
}
},
//跳转直播预告
goforeshow(e) {
let id = e.currentTarget.dataset.id;
wx.navigateTo({
url: "/packageD/directSeeding/foreshow/foreshow?id=" + id,
});
},
gopage(e) {
let status = e.currentTarget.dataset.status;
let id = e.currentTarget.dataset.id;
let backid = e.currentTarget.dataset.backid;
if (status == 1) {
wx.navigateTo({
url:
"/packageD/directSeeding/livePage/livePage?id=" +
id +
"&playerType=live",
});
} else if (status == 2) {
wx.navigateTo({
url:
"/packageD/directSeeding/livePage/livePage?id=" +
id +
"&playerType=video" +
"&backid=" +
backid,
});
}
},
golistPage(e) {
let status = e.currentTarget.dataset.status;
let id = e.currentTarget.dataset.id;
let backid = e.currentTarget.dataset.backid;
if (status == 3) {
wx.navigateTo({
url:
"/packageD/directSeeding/livePage/livePage?id=" +
id +
"&playerType=live",
});
} else if (status == 2) {
wx.navigateTo({
url: "/packageD/directSeeding/foreshow/foreshow?id=" + id,
});
} else if (status == 4) {
wx.navigateTo({
url:
"/packageD/directSeeding/livePage/livePage?id=" +
id +
"&playerType=video" +
"&backid=" +
backid,
});
}
},
//获取更多数据
_getMoreData() {
const that = this;
let json = {};
let api = "";
let urlStr = "";
that.data.isLoadMore = false; // 防止多次请求分页数据
if (this.data.page >= this.data.total_page) {
return;
} else {
this.data.page = this.data.page + 1;
if (this.data.apiType == "myConcern") {
api = "plugin.room.frontend.live-list.get-live-concern";
json = {
page: this.data.page,
};
} else if (that.data.apiType == "AllLivelist") {
api = "plugin.room.frontend.live-list.get-all-live-list";
json = {
page: this.data.page,
};
} else if (that.data.apiType == "playBack") {
api = "plugin.room.frontend.live-list.play-back";
json = {
page: this.data.page,
};
}
// else if (that.data.apiType == "recommend") {
// }
else {
api = "plugin.room.frontend.live-list.get-live-list";
json = {
status: this.data.status,
page: this.data.page,
};
}
json.keyword = this.data.live_search;
urlStr = app.getNetAddresss(api);
app._postNetWork({
url: urlStr,
showToastIn: false,
data: json,
success: function (resdata) {
var res = resdata.data;
if (res.result == 1) {
if (that.data.apiType == "myConcern") {
that.setData({
isLoadMore: true,
myConcern: that.data.myConcern.concat(res.data.data),
});
} else if (that.data.apiType == "playBack") {
that.setData({
isLoadMore: true,
playBackData: that.data.playBackData.concat(res.data.data),
});
} else if (that.data.apiType == "AllLivelist") {
that.setData({
isLoadMore: true,
allLivelistData: that.data.allLivelistData.concat(
res.data.data
),
});
}
// else if (that.data.apiType == "recommend") {
// }
else {
if (that.data.status == 2) {
that.setData({
isLoadMore: true,
announceList: that.data.announceList.concat(res.data.data),
});
} else if (that.data.status == 3) {
that.setData({
isLoadMore: true,
broadcastlist: that.data.broadcastlist.concat(res.data.data),
});
}
}
} else {
that.setData({
page: that.data.page - 1,
isLoadMore: false,
});
return;
}
},
fail: function (res) {
console.log(res.msg);
},
});
}
},
getplayBack() {
let that = this;
let urlStr = app.getNetAddresss("plugin.room.frontend.live-list.play-back");
app._postNetWork({
url: urlStr,
showToastIn: false,
data: {
page: 1,
keyword: this.data.live_search,
},
success: function (resdata) {
var res = resdata.data;
if (res.result == 1) {
that.setData({
playBackData: res.data.data,
total_page: res.data.last_page,
});
} else {
wx.showToast({
icon: "none",
title: res.msg,
duration: 1500,
});
}
},
fail: function (res) {
console.log(res.msg);
},
});
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
if (this.data.isLoadMore) {
if (this.data.apiType !== "recommend") {
this._getMoreData();
}
} else {
console.log("没有更多数据");
}
},
swichTabTItem(e) {
let index = e.detail.index;
this.setData({
isLoadMore: true,
page: 1,
total_page: 0,
live_search: "",
});
if (index == 0) {
this.data.apiType = "myConcern";
this.getMyConcern();
} else if (index == 1) {
this.data.apiType = "AllLivelist";
this.getAllLivelist();
} else if (index == 2) {
this.data.apiType = "recommend";
this.getRecommend();
} else if (index == 3) {
this.data.apiType = "liveList";
this.data.status = 3;
this.getLiveList(3);
} else if (index == 4) {
this.data.apiType = "liveList";
this.data.status = 2;
this.getLiveList(2);
} else if (index == 5) {
this.data.apiType = "playBack";
this.getplayBack();
}
},
getAllLivelist() {
let that = this;
let urlStr = app.getNetAddresss(
"plugin.room.frontend.live-list.get-all-live-list"
);
app._postNetWork({
url: urlStr,
showToastIn: false,
data: {
page: 1,
keyword: this.data.live_search,
},
success: function (resdata) {
var res = resdata.data;
if (res.result == 1) {
that.setData({
allLivelistData: res.data.data,
total_page: res.data.last_page,
});
} else {
wx.showToast({
icon: "none",
title: res.msg,
duration: 1500,
});
}
},
fail: function (res) {
console.log(res.msg);
},
});
},
getRecommend() {
let that = this;
let urlStr = app.getNetAddresss(
"plugin.room.frontend.live-list.get-live-recommend"
);
app._postNetWork({
url: urlStr,
showToastIn: false,
data: {
keyword: this.data.live_search,
},
success: function (resdata) {
var res = resdata.data;
if (res.result == 1) {
that.setData({
recommendData: res.data,
});
} else {
wx.showToast({
icon: "none",
title: res.msg,
duration: 1500,
});
}
},
fail: function (res) {
console.log(res.msg);
},
});
},
goPlayBackData(e) {
let roomid = e.currentTarget.dataset.roomid;
let backid = e.currentTarget.dataset.backid;
wx.navigateTo({
url:
"/packageD/directSeeding/livePage/livePage?id=" +
roomid +
"&playerType=video" +
"&backid=" +
backid,
});
},
onImageError(options) {
let index = options.target.dataset.index;
let seltype = options.target.dataset.seltype;
// let currentId = options.currentTarget.id;
console.log("图片加载发生错误");
this.onImageLoad({
target: {
dataset: {
index: index,
seltype: seltype,
},
},
detail: {
width: 2340,
height: 1080,
},
});
},
/**
* 图片加载函数
* 图片加载完成后,根据图片的高度,依次往第一列和第二列中推入数据
*/
onImageLoad(options) {
let index = options.target.dataset.index;
let seltype = options.target.dataset.seltype;
let imageWidth = options.detail.width; // 图片宽度
let imageHeight = options.detail.height; // 图片高度
let activityObj = null;
let scle = imageWidth / imageHeight;
if (seltype == "myConcern") {
let activitys = this.data.myConcern; // 获取所有的数据资源
activityObj = activitys[index];
let activitys1 = this.data.myConcern_activitys1;
let activitys2 = this.data.myConcern_activitys2;
if (this.data.my_colOneHeight <= this.data.my_colTwoHeight) {
this.data.my_colOneHeight += 176 / scle + 60;
activitys1.push(activityObj);
} else {
this.data.my_colTwoHeight += 176 / scle + 60;
activitys2.push(activityObj);
}
this.setData({
myConcern_activitys1: activitys1,
myConcern_activitys2: activitys2,
});
} else if (seltype == "recommend") {
let activitys = this.data.recommendData; // 获取所有的数据资源
activityObj = activitys[index];
let activitys1 = this.data.recommendData_activitys1;
let activitys2 = this.data.recommendData_activitys2;
if (this.data.re_colOneHeight <= this.data.re_colTwoHeight) {
this.data.re_colOneHeight += 176 / scle + 60;
activitys1.push(activityObj);
} else {
this.data.re_colTwoHeight += 176 / scle + 60;
activitys2.push(activityObj);
}
this.setData({
recommendData_activitys1: activitys1,
recommendData_activitys2: activitys2,
});
} else if (seltype == "AllLivelist") {
let activitys = this.data.allLivelistData; // 获取所有的数据资源
activityObj = activitys[index];
let activitys1 = this.data.allLivelistData_activitys1;
let activitys2 = this.data.allLivelistData_activitys2;
if (this.data.all_colOneHeight <= this.data.all_colTwoHeight) {
this.data.all_colOneHeight += 176 / scle + 60;
activitys1.push(activityObj);
} else {
this.data.all_colTwoHeight += 176 / scle + 60;
activitys2.push(activityObj);
}
this.setData({
allLivelistData_activitys1: activitys1,
allLivelistData_activitys2: activitys2,
});
} else if (seltype == "liveList_1") {
let activitys = this.data.broadcastlist; // 获取所有的数据资源
activityObj = activitys[index];
let activitys1 = this.data.broadcastlist_activitys1;
let activitys2 = this.data.broadcastlist_activitys2;
if (this.data.br_colOneHeight <= this.data.br_colTwoHeight) {
this.data.br_colOneHeight += 176 / scle + 60;
activitys1.push(activityObj);
} else {
this.data.br_colTwoHeight += 176 / scle + 60;
activitys2.push(activityObj);
}
this.setData({
broadcastlist_activitys1: activitys1,
broadcastlist_activitys2: activitys2,
});
} else if (seltype == "liveList_2") {
let activitys = this.data.announceList; // 获取所有的数据资源
activityObj = activitys[index];
let activitys1 = this.data.announceList_activitys1;
let activitys2 = this.data.announceList_activitys2;
if (this.data.an_colOneHeight <= this.data.an_colTwoHeight) {
this.data.an_colOneHeight += 176 / scle + 60;
activitys1.push(activityObj);
} else {
this.data.an_colTwoHeight += 176 / scle + 60;
activitys2.push(activityObj);
}
this.setData({
announceList_activitys1: activitys1,
announceList_activitys2: activitys2,
});
} else if (seltype == "playBack") {
let activitys = this.data.playBackData; // 获取所有的数据资源
activityObj = activitys[index];
let activitys1 = this.data.playBackData_activitys1;
let activitys2 = this.data.playBackData_activitys2;
if (this.data.pl_colOneHeight <= this.data.pl_colTwoHeight) {
this.data.pl_colOneHeight += 176 / scle + 60;
activitys1.push(activityObj);
} else {
this.data.pl_colTwoHeight += 176 / scle + 60;
activitys2.push(activityObj);
}
this.setData({
playBackData_activitys1: activitys1,
playBackData_activitys2: activitys2,
});
}
},
});