yuminge-app/yun-min-program-plugin-master/packageA/mycomponent/course_goods/course_goods.js

1052 lines
29 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.

// pages/member/course/CourseDetail/CourseDetail.js
import Dialog from "../../../dist/dialog/dialog";
import polyvLive from "../../../utils/polyvlive.js";
var CryptoJS = require("../../../utils/CryptoJS.js");
var yz_pay = require('../../../mycomponent/yz_pay/yz_pay');
var app = getApp();
Component({
behaviors: [yz_pay],
properties: {
// 属性值可以在组件使用时指定
prop_goods_info: {
type: Object, //父组件的商品详情数据
value: {},
},
goodsId: {
type: Number,
},
goodsType: {
type: String,
},
mark: {
type: String,
},
mark_id: {
type: String,
},
ipnonexbol: {
type: null,
},
is_open: {
type: null,
},
},
observers: {
is_open: function (num) {
this.setData({
questionnaire_is_open: num == "close" ? false : "",
});
},
},
/**
* 页面的初始数据
*/
data: {
is_try_time: null,
is_questionnaire_time: null,
// 问卷调查
questionnaire_is_open: false,
language: "",
goods_id: "",
is_show: true,
is_vshow: false,
isVideo: true,
isLook: true,
is_update: false,
is_buy: false,
showPopup: false,
rewardMoneyBtn: false,
actionSheetShow: false,
rewardBtnShow: false,
// 打赏金额
rewardMoney: "",
goodTit: "",
goodPrice: "",
chapterNum: "",
teacherImg: "",
teacherName: "",
goodsContent: "",
chapterList: [],
article_content: "",
courseShare: {},
courseData: {},
codeUrl: "",
vedioSrc: "",
coverImg: "",
active: "",
// 章节id
chapter_id: "",
// 课程id
courseId: "",
pushGoodList: [],
// pushGoodList: [{
// "id": 93,
// "goods_id": 206,
// "lecturer_id": 3,
// "title": "3333",
// "thumb": "https://dev5.yunzshop.com/attachment/images/2/2018/08/L8Ia553RrZH83rEiLocYIY3L9o5885.jpg",
// "price": "100.00",
// "has_one_lecturer": {
// "id": 3,
// "real_name": "\u6d4b\u8bd5",
// "mobile": "13800138000"
// },
// "course_chapter_num": 1
// }],
actionSheetItems: [],
isLoding: false,
activeNames: ["1"],
//章节列表
chapterdigList: [],
// 价格权限
vip_level_status: {},
islive: false,
video_err: false,
is_playLive: false,
live: false,
videoErr: true,
// islive:false,
ios_virtual_pay: false,
point_goods: "",
integral: "积分",
show1: false,
posterShow: false,
styleSetOptions: {}, //后台基础设置-样式设置
countDownTime: null,
timeData: {},
iscCountDownFinish: false, //课程有效期是否到了
HasBuyPermissions: false //是否有购买权限true则不可以下单
},
lifetimes: {
attached(e) {
let language = wx.getStorageSync("langIndex");
this.setData({
language: language.en
});
// 在组件实例进入页面节点树时执行
this.setData({
goods_id: this.data.goodsId,
});
// this.getQrCode()
this._getData();
this.footSet();
try {
var value = wx.getStorageSync("ios_virtual_pay");
if (value) {
this.setData({
ios_virtual_pay: value,
});
}
} catch (e) {
console.log(e);
}
try {
let name = wx.getStorageSync("yz_basic_info");
this.setData({
shopName: name.home.mailInfo.name,
});
} catch (err) {
console.log(err);
}
if (this.data.prop_goods_info.plugin && this.data.prop_goods_info.plugin.point_goods) {
this.setData({
point_goods: this.data.prop_goods_info.plugin.point_goods,
});
}
// console.log(this.data.point_goods, "point_goods");
wx.setStorageSync("GoddsShareImg", this.data.prop_goods_info.get_goods.thumb);
const integral = wx.getStorageSync("integral");
if (integral) {
this.setData({
integral: integral,
});
}
},
detached() {
this.data.is_try_time = null;
this.data.is_questionnaire_time = null;
clearTimeout(this.data.is_try_time);
clearTimeout(this.data.is_questionnaire_time);
// 在组件实例被从页面节点树移除时执行
},
},
pageLifetimes: {
hide: function () {
this.data.is_try_time = null;
this.data.is_questionnaire_time = null;
clearTimeout(this.data.is_try_time);
clearTimeout(this.data.is_questionnaire_time);
},
},
methods: {
handleContact(e){
let _url = e.currentTarget.dataset.url;
if(_url){
wx.navigateTo({
url: _url,
fail:function(err){
app.tips('客服路径错误');
}
});
}
},
tapkefu() {
this.setData({
show1: true,
});
},
callPhone() {
wx.makePhoneCall({
phoneNumber: this.data.service_mobile,
});
},
closePop() {
this.setData({
show1: false,
});
},
changeLoading() {
this.setData({
isLoding: true,
});
},
setPosterShow() {
this.setData({
posterShow: !this.data.posterShow
});
},
videoErr() {
wx.showToast({
title: "视频加载出错了!",
icon: "none",
duration: 2000,
});
this.setData({
videoErr: false,
// is_vshow:false,
});
},
getQrCode() {
var that = this;
app._getNetWork({
url: app.getNetAddresss("member.member.getArticleQr"),
success: function (res) {
if (res.data.result == 1 && !app._isTextEmpty(res.data.data)) {
let _data = res.data.data;
that.setData({
codeUrl: _data,
});
} else {
console.error(res);
}
},
fail: function (res) {
console.error(res);
},
});
},
secret(string, code, operation) {
code = CryptoJS.MD5(code).toString();
var iv = CryptoJS.enc.Utf8.parse(code.substring(0, 16));
var key = CryptoJS.enc.Utf8.parse(code.substring(16));
if (operation) {
return CryptoJS.AES.decrypt(string, key, {
iv: iv,
padding: CryptoJS.pad.Pkcs7
}).toString(CryptoJS.enc.Utf8);
}
return CryptoJS.AES.encrypt(string, key, {
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
}).toString();
},
// 点击直播请求
addzhibo() {
var that = this;
app._getNetWork({
url: app.getNetAddresss("plugin.video-demand.api.video-course-goods.get-live-info"),
data: {
goods_id: that.data.goods_id,
},
success: function (res) {
if (res.data.result == 1) {
if (that.data.islive == true) {
wx.showToast({
title: "正在直播",
icon: "none",
duration: 1000,
});
return;
}
let info = JSON.parse(that.secret(res.data.data, "zoQUA@257ggflNmMppKzcU7QgYyp!tU&h54VNN3u!PAU$8FxBW", true));
that.is_onlive(info.userId, info.channelId);
that.setData({
islive: true,
});
} else {
wx.showToast({
title: res.data.msg,
icon: "none",
duration: 1000,
});
that.setData({
is_update: true,
is_buy: true,
});
}
},
fail: function (res) {
console.error(res);
},
});
},
// 唤起直播
is_onlive(liveUid, liveVid) {
wx.showLoading({
title: "加载直播中",
icon: "none",
});
const liveVideoContext = wx.createLivePlayerContext("polyvLiveVideo");
this.setData({
islive: true,
});
polyvLive.getVideo({
uid: liveUid,
vid: liveVid,
videoContext: liveVideoContext,
success: (videoInfo) => {
// set video src and poster
console.log(videoInfo);
this.setPlayerSrc(videoInfo);
},
error: (res) => {
console.log(res.error);
},
onStartLive: () => {
console.log("start live");
wx.hideLoading();
// set latest video src
this.setNewPlayerSrc();
},
onApiStatus: (status) => {
console.log(status);
if (status == "end") {
this.setData({
is_playLive: false,
islive: false,
videoErr: true,
is_vshow: true,
});
wx.hideLoading();
wx.showToast({
title: "当前无直播",
icon: "none",
duration: 1000,
});
polyvLive.destroy();
} else if (status == "live") {
this.setData({
is_playLive: true,
});
}
},
});
},
// 直播赋值
setPlayerSrc(videoInfo) {
this.setData({
video: {
src: videoInfo.src, // 如果播放组件为video,只能用videoInfo.src(m3u8地址)如果为live-player则用videoInfo.flvSrc
poster: videoInfo.poster,
},
is_bisrc: videoInfo.src,
});
console.log(videoInfo.src);
},
setNewPlayerSrc() {
polyvLive.getNewVideo((videoInfo) => {
this.setPlayerSrc(videoInfo);
});
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function (res) {
var value = wx.getStorageSync("yz_uid");
var path = "";
if (value) {
path = value;
}
let _title = app._isTextEmpty(this.data.courseShare.share_title) ? this.data.goodTit : this.data.courseShare.share_title;
let _link = "/packageA/detail_v2/detail_v2?id=" + this.data.chapter_id + "&mid=" + path;
let _imgUrl = app._isTextEmpty(this.data.courseShare.share_thumb) ? this.data.courseData.has_one_goods.thumb : this.data.courseShare.share_thumb;
let _desc = this.data.courseShare.share_desc;
return {
title: _title,
desc: _desc,
imageUrl: _imgUrl,
path: _link,
success: function (shareTickets) {
console.info(shareTickets + "成功");
// 转发成功
},
fail: function (res) {
console.log(res + "失败");
// 转发失败
},
complete: function (res) {
// 不管成功失败都会执行
},
};
},
goSurvey() {
wx.navigateTo({
url: "/packageE/questionnaire/questions/questions?goods_id=" + this.data.goods_id + "&tag=video",
});
},
_getData() {
var that = this;
// 初次获取数据
app._getNetWork({
url: app.getNetAddresss("plugin.video-demand.api.video-course-goods.get-course-goods-detail"),
data: {
goods_id: that.data.goods_id,
},
success: function (res) {
if (res.data.result === 1) {
let _data = res.data.data;
if (app._isTextEmpty(_data.has_many_dig_chapter) || _data.has_many_dig_chapter.length == 0) {
Dialog.alert({
title: "提示",
message: "课程已下架!",
context: that,
}).then(() => {
// on close
wx.navigateBack({
delta: 1,
});
});
return;
} else {
that.setData({
chapterdigList: _data.has_many_dig_chapter,
});
}
_data.has_one_goods.content = _data.has_one_goods.content.replace(/<img/gi, '<img style="max-width:100%;height:auto;display:block" ');
let playCourse = "";
let playActive = 0;
let has_many_dig_chapter = _data.has_many_dig_chapter;
for (let j = 0; j < has_many_dig_chapter.length; j++) {
if (has_many_dig_chapter[j].has_many_chapter.length > 0 && that.data.chapter_id) {
for (let i = 0; i < has_many_dig_chapter[j].has_many_chapter.length; i++) {
if (has_many_dig_chapter[j].has_many_chapter[i].id === Number(that.data.chapter_id)) {
playCourse = has_many_dig_chapter[j].has_many_chapter[i];
playActive = i;
}
}
} else {
playActive = 0;
playCourse = has_many_dig_chapter[0].has_many_chapter[0];
}
}
let goodPrice = "";
if (that.data.point_goods) {
goodPrice = that.data.point_goods.point;
} else {
goodPrice = _data.has_one_goods.price;
}
let countDownTime = _data.course_expiration_time?app.getTimeDifference(_data.course_expiration_time):null;
that.setData({
courseData: _data,
rewardBtnShow: _data.is_reward,
goodTit: _data.has_one_goods.title,
goodPrice: goodPrice,
vip_level_status: _data.has_one_goods.vip_level_status,
chapterNum: _data.course_chapter_num,
teacherImg: _data.has_one_lecturer && _data.has_one_lecturer.has_one_member ? _data.has_one_lecturer.has_one_member.avatar : '',
teacherName: _data.has_one_lecturer && _data.has_one_lecturer.real_name||'',
goodsContent: _data.has_one_goods.content,
chapter_id: playCourse && playCourse.id || 0,
isLook: playCourse && playCourse.is_audition || true,
courseId: _data.id,
pushGoodList: _data.pushGoods,
courseShare: _data.has_one_goods.has_one_share,
live: _data.live,
live_title: _data.live_title,
questionnaire_time: _data.questionnaire_time,
service_QRcode: _data.shopSet.service_QRcode,
service_mobile: _data.shopSet.service_mobile,
shopSet: _data.shopSet,
plugin_point_name: _data.plugin_point_name ? _data.plugin_point_name : '',
styleSetOptions: _data.styleSet,
countDownTime: countDownTime,
HasBuyPermissions: _data.buyPermissions||false
});
let sec = _data.questionnaire_time * 1000;
if (_data.questionnaire_is_open) {
if (that.data.is_opens == "close") {
console.log(that.data.is_opens);
} else {
that.data.is_questionnaire_time = setTimeout(() => {
if (!that.data.is_questionnaire_time) {
return;
}
that.setData({
questionnaire_is_open: _data.questionnaire_is_open,
});
}, sec);
}
}
switch (_data.watch) {
case 0:
// Dialog.alert({
// title: '提示',
// message: '请升级会员或者购买课程',
// context: that
// }).then(() => {
// // on close
// })
that.setData({
is_update: false,
is_buy: false,
});
that.videoInit(playActive, playCourse);
break;
case 1:
// 判断是否免费章节
if (playCourse.is_audition == 1) {
that.setData({
is_update: false,
is_buy: false,
is_show: false,
is_vshow: true,
});
that.videoInit(playActive, playCourse);
break;
} else if (playCourse.is_audition == 0) {
Dialog.alert({
title: "提示",
message: "请升级会员或者购买课程",
context: that,
}).then(() => {
// on close
});
that.setData({
is_update: true,
is_buy: true,
});
break;
} else {
break;
}
case 2:
that.setData({
is_update: false,
is_buy: false,
});
that.videoInit(playActive, playCourse);
break;
case 3:
case 4:
that.setData({
is_update: false,
is_buy: false,
});
that.videoInit(playActive, playCourse);
break;
default:
break;
}
wx.setStorageSync("orderErrReturnUrl", _data.mini_not_permit_link);//无权限购买时,下单弹出框确认按钮跳转路径
} else {
wx.showToast({
title: "视频加载出错",
icon: "none",
duration: 1500,
});
console.error(res);
}
},
fail: function (res) {
console.error(res);
},
});
},
videoInit(index, item) {
// if(!item) return;
this.setData({
is_show: false,
is_vshow: true,
active: item.id,
});
this.viewPermission(item.id, index, item.course_id, item.is_audition);
this.isMp4(this.data.vedioSrc);
},
viewPermissionBtn(e) {
let dataset = e.currentTarget.dataset;
let id = dataset.item.id;
let index = dataset.index;
let course_id = dataset.item.course_id;
let audition = dataset.item.is_audition;
this.viewPermission(id, index, course_id, audition);
},
// 根据观看权限
viewPermission(id, index, course_id, audition) {
// id, index, address, course_id, audition
let that = this;
this.setData({
is_show: true,
is_vshow: false,
islive: false,
});
this.setData({
chapter_id: id,
active: id,
});
let param = {
goods_id: this.data.goods_id,
chapter_id: id,
};
let url = app.getNetAddresss("plugin.video-demand.api.video-course-goods.get-video-address");
app._getNetWork({
url: url,
data: param,
success: function (res) {
if (res.data.result == 1) {
let _data = res.data.data;
that.viewType(_data.watch, index, _data.video_address, course_id, id, audition, _data.video_cover_address, _data.is_try, _data.try_time);
} else {
console.error(res);
}
},
fail: function (res) {
console.error(res);
},
});
},
viewType(type, index, address, course_id, id, audition, coverSrc, is_try, try_time) {
if (is_try == 1 && type == 1 && audition == 1) {
console.log("执行1");
this.setData({
coverImg: coverSrc,
is_update: false,
is_buy: false,
isLook: true,
is_vshow: true,
is_show: false,
});
this.videoPlay(index, address, course_id, id, coverSrc);
return;
} else if (type != 2 && type != 3 && type != 4 && is_try == 1 && try_time > 0) {
console.log("执行2");
this.setData({
is_update: false,
is_buy: false,
isLook: true,
});
this.videoPlay(index, address, course_id, id, coverSrc);
if (!this.data.is_try_time) {
// 防止重复设置定时器
this.data.is_try_time = setTimeout(() => {
this.setData({
islive: false,
is_show: true,
is_vshow: false
});
this.isNoPlay();
}, try_time * 1000);
}
return;
} else {
console.log("执行3");
this.setData({
vedioSrc: address,
coverImg: coverSrc,
});
this.isMp4(this.data.vedioSrc);
}
switch (type) {
case 0:
this.setData({
is_vshow: false,
is_show: true,
});
this.isNoPlay();
break;
case 1:
if (audition == 1) {
this.setData({
is_update: false,
is_buy: false,
isLook: true,
is_vshow: true,
is_show: false,
});
this.videoPlay(index, address, course_id, id, coverSrc);
break;
} else if (audition == 0) {
this.isNoPlay();
break;
} else {
break;
}
case 2:
this.setData({
is_update: false,
is_buy: false,
isLook: true,
});
this.videoPlay(index, address, course_id, id, coverSrc);
break;
case 3:
case 4:
this.setData({
is_update: false,
is_buy: false,
isLook: true,
});
this.videoPlay(index, address, course_id, id, coverSrc);
break;
default:
break;
}
},
isNoPlay() {
this.setData({
is_update: true,
is_buy: true,
isLook: false,
});
if (!this.data.styleSetOptions.buy_now_button) return;
this.openBuyDialog();
},
openBuyDialog(){
Dialog.alert({
title: "提示",
message: "请升级会员或者购买课程",
context: this,
}).then(() => {
// on close
});
},
// 观看视频
videoPlay(index, src, course_id, id, coverSrc) {
this.setData({
is_show: false,
is_vshow: true,
active: id,
vedioSrc: src,
coverImg: coverSrc,
});
// 判断当前路径
this.isMp4(this.data.vedioSrc);
app._getNetWork({
url: app.getNetAddresss("plugin.video-demand.api.video-demand-member.set-watch-history"),
data: {
course_id: course_id,
chapter_id: id,
},
success: function (res) {},
});
},
// 判断是否MP4
isMp4(src) {
if (src == "") return;
if (src.endsWith(".mp4") || src.endsWith(".MP4")) {
this.setData({
isVideo: true,
is_show: false,
});
} else {
this.setData({
isVideo: false,
is_show: false,
});
}
},
study() {
this.setData({
is_show: false,
is_vshow: true,
});
},
// 升级会员
update() {
if (this.data.ios_virtual_pay) {
wx.showModal({
title: "提示",
content: "十分抱歉,由于相关规定,你暂时无法在这里充值!",
confirmText: "知道了",
showCancel: false,
success(res) {
if (res.confirm) {
console.log(res);
}
},
});
return false;
}
wx.navigateTo({
url: "/packageA/member/course/CourseMemberUpdate/CourseMemberUpdate?goods_id=" + this.data.goods_id,
});
},
// 立即购买
buy() {
if(this.data.HasBuyPermissions){
wx.showModal({
title: "提示",
content: this.data.HasBuyPermissions,
confirmText: "确定",
showCancel: false,
success(res) {},
});
return false;
}
if (this.data.ios_virtual_pay) {
wx.showModal({
title: "提示",
content: "十分抱歉,由于相关规定,你暂时无法在这里充值!",
confirmText: "知道了",
showCancel: false,
success(res) {
if (res.confirm) {
console.log(res);
}
},
});
return false;
}
//价格权限
if (this.data.vip_level_status && this.data.vip_level_status.status == 1) {
wx.showToast({
title: this.data.vip_level_status.tips,
icon: "none",
duration: 1500,
});
return false;
}
wx.navigateTo({
url: "/packageD/buy/myOrder_v2/myOrder_v2?tag=-2&total=1&optionsId=&goodsId=" + this.data.goods_id,
});
},
// 跳转至我的课程
toMyCourse() {
wx.navigateTo({
url: "/packageA/member/course/CourseMy/CourseMy",
});
},
// 推荐商品跳转
pushGoodGoto(val) {
let item = val.currentTarget.dataset.item;
wx.navigateTo({
url: "/packageA/detail_v2/detail_v2?id=" + item.id,
});
},
// 选择打赏金额
chooseMoney(e) {
let money = e.currentTarget.dataset.money;
this.setData({
rewardMoney: money,
});
},
moneyInput(e) {
this.setData({
rewardMoney: e.detail,
});
},
// 确定打赏
confirmReward() {
console.log(this.data.rewardMoney);
if (app._isTextEmpty(this.data.rewardMoney)) {
wx.showToast({
title: "请输入或选择打赏金额",
icon: "none",
duration: 1500,
});
return;
}
if (this.data.rewardMoney <= 0) {
wx.showToast({
title: "打赏金额必须大于0",
icon: "none",
duration: 1500,
});
return;
}
this.getPayData();
},
// 获取支付类型参数
getPayData() {
var that = this;
app._getNetWork({
url: app.getNetAddresss("plugin.video-demand.api.lecturer-reward.pay-type"),
success: function (res) {
if (res.data.result === 1) {
let btnData = res.data.data.buttons;
that.setData({
showPopup: false,
btnData: btnData,
rewardPayshow: true,
});
} else {
console.error(res);
}
},
fail: function (res) {
console.error(res);
},
});
},
// 支付
payPost(e) {
this.setData({
rewardPayshow: false,
});
let type, name, btn = null;
if (e.currentTarget) {
type = e.currentTarget.dataset.info.value;
name = e.currentTarget.dataset.info.name;
btn = e.currentTarget.dataset.info;
} else {
type = e.value;
name = e.name;
btn = e;
}
let dataJson = {
pay_method: type,
amount: this.data.rewardMoney,
pay_name: name,
goods_id: this.data.goodsId,
trick_id: this.data.stickid,
client_type: "2",
};
app._getNetWork({
url: app.getNetAddresss("plugin.video-demand.api.lecturer-reward.run-reward-pay"),
data: dataJson,
success: (res) => {
if (res.data.result === 1) {
this.handleOtherPay(btn, type, res.data.data);
this.onClose();
} else {
Dialog.alert({
title: "提示",
message: res.data.msg,
context: this,
}).then(() => {
// on close
});
}
},
fail: (res) => {
console.error(res);
},
});
},
moneyShow() {
this.setData({
showPopup: true,
});
},
openInputReward() {
this.setData({
showPopup: false,
rewardMoneyBtn: true,
});
},
onClose() {
this.setData({
showPopup: false,
rewardMoneyBtn: false,
actionSheetShow: false,
questionnaire_is_open: false,
});
},
openActionSheet() {
this.setData({
showPopup: false,
actionSheetShow: true,
});
},
previewImage: function (e) {
var current = e.target.dataset.src; // 这里获取到的是一张本地的图片
wx.previewImage({
current: current, // 需要预览的图片链接列表
urls: [current], // 当前显示图片的链接
});
},
// 足迹记录
footSet() {
if (!this.data.isGoods) {
return;
}
let urlStr = app.getNetAddresss("member.member-history.store");
urlStr += "&goods_id=" + this.properties.goodsId + "&mark=" + this.properties.mark + "&mark_id=" + this.properties.mark_id;
app._getNetWork({
showToastIn: false,
url: urlStr,
success: (resdata) => {
var res = resdata.data;
if (res.result == 1) {
console.log(res);
} else {
wx.showToast({
icon: "none",
title: res.msg,
duration: 1500,
});
}
},
fail: function (res) {},
});
},
onChange(event) {
this.setData({
activeNames: event.detail,
});
},
rewardPayshowClose() {
this.setData({
rewardPayshow: false,
});
},
rewardPayCancelBtn() {
this.setData({
rewardPayshow: false,
});
},
onChangecountDown(e) {
this.setData({
timeData: e.detail,
});
},
countDownFinish(){
this.setData({
iscCountDownFinish: true
});
}
},
});