123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476 |
- import httpRequestApi from '../../../utils/APIClient';
- import {
- formatDate
- } from '../../../utils/util';
- const app = getApp()
- Page({
- data: {
- fullScreenBtn: false,
- playBtn: true,
- gesture: false,
- author: '',
- videoSrc: '',
- total: '',
- authorAvatar: '',
- user: [],
- inputValue: '',
- inputSBValue: '',
- replyList: [],
- howMuch: '200',
- moneySelect: 'moneySelect',
- moneyNormal: 'moneyNormal',
- ifReward: false,
- id: '',
- path: '',
- replyModal: false,
- totalRead: 0,
- pageNo: 1,
- pageSize: 3,
- goBackHome: false,
- isIOS: app.globalData.isIOS
- // shareFlag: false
- },
- onLoad: function (option) {
- let id = option.id ? option.id : option.scene.replace('QR', '')
- if (option.scene || option.shareCard) {
- this.setData({
- goBackHome: true
- })
- }
- wx.setNavigationBarTitle({
- title: option.title //页面标题为路由参数
- })
- this.uid = wx.getStorageSync('uid');
- let stackSize = 1;
- console.log(option.stackSize)
- if (option.stackSize) {
- stackSize = option.stackSize;
- }
- this.setData({
- title: option.title,
- id,
- myUid: this.uid,
- stackSize
- })
- this.getWorks(this.uid, id);
- },
- onHide: function () {
- // this.data.stackSize >= 2
- console.log(this.data.stackSize)
- if (this.innerAudioContext) {
- this.innerAudioContext.pause();
- }
- let videoCtx = wx.createVideoContext('worksVideo', this);
- videoCtx.stop();
- },
- onUnload: function () {
- if (this.innerAudioContext) {
- this.innerAudioContext.pause();
- }
- let videoCtx = wx.createVideoContext('worksVideo', this);
- videoCtx.stop();
- },
- getWorks: function (uid, id) {
- httpRequestApi.getWorksDetail(uid, id).success((res) => {
- const others = res.data.data.otherRead;
- const author = res.data.data.user;
- const works = res.data.data.userRead;
- const othersTemp = [];
- others.forEach((item) => {
- const temp = {};
- temp.uid = item.userRead.id;
- temp.title = item.userRead.title;
- temp.image = item.user.avatar;
- temp.nickName = item.user.wechatName;
- othersTemp.push(temp);
- });
- this.setData({
- user: othersTemp,
- totalRead: res.data.data.totalRead,
- author: author.wechatName,
- authorAvatar: author.avatar,
- authorProfession: author.profession,
- authorUid: author.uid,
- videoSrc: works.originVideo,
- audioSrc: works.audioPath,
- iconImg: works.iconImg,
- classId: works.lessonId,
- isLike: res.data.data.isLike,
- isFans: res.data.data.isFans,
- })
- // 设置音频路径
- this.innerAudioContext = wx.createInnerAudioContext();
- this.innerAudioContext.onError((res) => {
- // 播放音频失败的回调
- })
- this.innerAudioContext.src = this.data.audioSrc; // 这里可以是录音的临时路径
- });
- },
- onShow() {
- console.log(this.data.stackSize)
- this.setData({
- replyList: [],
- pageNo: 1,
- pageSize: 2
- }, () => {
- this.getReply();
- })
- },
- videoPlayHandler: function () {
- this.setData({
- videoLoad: true
- }, () => {
- this.videoCtx = wx.createVideoContext('worksVideo', this);
- this.videoCtx.play();
- })
- },
- likeWorks: function (e) {
- if (this.data.isLike) {
- wx.showToast({
- title: '不要重复点赞哦',
- icon: 'fail',
- duration: 1000
- })
- return;
- }
- httpRequestApi.likeWorks(this.uid, this.data.id).success(res => {
- this.setData({
- isLike: true
- }, () => {
- wx.showToast({
- title: '点赞数+1',
- icon: 'success',
- duration: 1000
- })
- });
- })
- },
- // 弹出分享框
- openShare: function (e) {
- this.shareDialog = this.selectComponent("#share-dialog");
- const data = {
- avatar: this.data.authorAvatar,
- author: this.data.author,
- iconImg: this.data.iconImg,
- title: this.data.title,
- path: `pages/social/works/works`,
- scene: this.data.id
- // tip: this.data.tip,
- }
- this.shareDialog.share(data);
- },
- videoPlay: function () {
- this.innerAudioContext.play();
- httpRequestApi.playWorks(this.uid, this.data.id);
- },
- // 视频播放完毕销毁录音
- videoEnd: function () {
- this.innerAudioContext.destroy();
- },
- videoPause: function () {
- this.innerAudioContext.pause();
- },
- goToReading: function () {
- const classId = this.data.classId;
- httpRequestApi.checkLesson(classId).success(res => {
- const productId = res.data.data[0];
- httpRequestApi.areYouSuper(res.data.data).success(res => {
- if (res.data.success) {
- wx.navigateTo({
- url: `../../main/reading/reading?id=${classId}`
- })
- } else {
- // ios用户 并且没有购买过此书
- // if (this.data.isIOS) {
- // wx.showModal({
- // title: '暂不支持',
- // content: '十分抱歉,由于相关规定,您暂时无法在这里朗读',
- // success(res) {
- // if (res.confirm) {
- // console.log('用户点击确定')
- // } else if (res.cancel) {
- // console.log('用户点击取消')
- // }
- // }
- // })
- // return;
- // }
- wx.showModal({
- title: '您未购买过本书,不能朗读',
- content: '超值团购进行中,快去看看',
- success(res) {
- if (res.confirm) {
- console.log('用户点击确定')
- wx.navigateTo({
- url: `../../groupPage/grade-details/grade-details?productId=${productId}`
- })
- } else if (res.cancel) {
- console.log('用户点击取消')
- }
- }
- })
- }
- })
- });
- },
- onShareAppMessage: function (res) {
- if (res.from === 'button') {
- // 来自页面内转发按钮
- console.log(res.target)
- }
- return {
- title: '一样的课文,不一样的味道!我的配音表演已开始,求各位大咖围观、点评!',
- path: `pages/social/works/works?id=${this.data.id}&title=${this.data.title}&shareCard=true`,
- imageUrl: '../../../static/share/works_icon.jpg'
- }
- },
- follow: function () {
- let followUid = this.data.authorUid;
- if (this.data.isFans) {
- httpRequestApi.cancerFollow(this.uid, followUid).success((res) => {
- this.setData({
- isFans: false
- })
- wx.showToast({
- title: '取消关注',
- icon: 'success',
- duration: 1000
- })
- });
- } else {
- httpRequestApi.followUser(this.uid, followUid).success((res) => {
- this.setData({
- isFans: true
- })
- wx.showToast({
- title: '关注啦',
- icon: 'success',
- duration: 1000
- })
- });
- }
- },
- // 点赞评论
- likeCommend: function (e) {
- console.log(e);
- // let uid = wx.getStorageSync('uid');
- let followUid = e.currentTarget.dataset.id;
- let index = e.currentTarget.dataset.index;
- httpRequestApi.likeCommend(this.uid, followUid).success(res => {
- console.log(res);
- const str = `replyList[${index}].likes`;
- this.setData({
- [str]: res.data.data.favors
- })
- });
- },
- // 去用户主页
- goToUsers: function (e) {
- let uid = e.currentTarget.dataset.uid;
- wx.navigateTo({
- url: `../../user/myworks/myworks?uid=${uid}`
- });
- },
- // 去其他用户的作品页
- goToOthers: function (e) {
- this.data.stackSize++;
- console.log(this.data.stackSize)
- if (this.data.stackSize >= 3) {
- console.log('跳转',this.data.stackSize)
- wx.redirectTo({
- url: `../../social/works/works?id=${e.currentTarget.dataset.uid}&title=${e.currentTarget.dataset.title}&stackSize=${this.data.stackSize}`
- })
- } else {
- console.log('下一个页面',this.data.stackSize)
- wx.navigateTo({
- url: `../../social/works/works?id=${e.currentTarget.dataset.uid}&title=${e.currentTarget.dataset.title}&stackSize=${this.data.stackSize}`
- })
- }
- },
- // 查询回复
- getReply: function () {
- // let uid = wx.getStorageSync('uid');
- let columnId = this.data.id;
- let pageNo = this.data.pageNo;
- let pageSize = this.data.pageSize;
- httpRequestApi.getReply(this.uid, columnId, pageNo, pageSize).success((res) => {
- const replyList = res.data.data.list;
- // const replyTemp = [];
- replyList.forEach((item) => {
- const temp = {};
- temp.nickName = item.user.wechatName;
- temp.avatar = item.user.avatar;
- temp.profession = item.user.profession;
- temp.uid = item.user.uid;
- temp.text = item.detailDesc;
- temp.id = item.id;
- temp.replyCount = item.replyCount;
- temp.time = formatDate(item.gmtModified, 3);
- temp.likes = item.postsAttributeInfo.favors || 0;
- this.data.replyList.push(temp);
- });
- this.setData({
- replyList: this.data.replyList,
- total: res.data.data.totalSize,
- totalPage: res.data.data.totalNo
- })
- });
- },
- // 打开回复详情页
- goToDetail: function (e) {
- let id = e.currentTarget.dataset.id;
- let count = e.currentTarget.dataset.count;
- wx.navigateTo({
- url: `../../social/replyDetail/replyDetail?id=${id}&count=${count}`
- })
- },
- // 绑定输入框内容
- inputValue: function (e) {
- this.setData({
- inputValue: e.detail.value
- });
- },
- // 发布回复
- sendHandler: function () {
- if (this.data.inputValue !== '') {
- // let uid = wx.getStorageSync('uid');
- let data = {
- "columnId": this.data.id,
- colunmNames: 'what',
- "detailDesc": this.data.inputValue
- }
- httpRequestApi.postReply(this.uid, data).success(res => {
- this.setData({
- inputValue: '',
- pageNo: 1,
- replyList: [],
- })
- this.getReply();
- });
- // 评论成功后刷新数据
- }
- },
- // 触底加载
- onReachBottom: function () {
- // 当前在推荐页面 加载推荐
- if (this.data.pageNo <= this.data.totalPage) {
- this.setData({
- pageNo: this.data.pageNo + 1
- }, () => {
- this.getReply();
- })
- }
- },
- // 设置点击时的id
- setSBId: function (e) {
- this.setData({
- replySBId: e.currentTarget.dataset.id,
- replyModal: true,
- replyIndex: e.currentTarget.dataset.index
- })
- },
- // 回复某个评论
- replySB: function () {
- const data = {
- postsId: this.data.replySBId,
- content: this.data.inputSBValue
- }
- httpRequestApi.postReplyComment(this.uid, data).success(res => {
- const replyWho = this.data.replyList[this.data.replyIndex];
- const indexStr = `replyList[${this.data.replyIndex}]`;
- replyWho.replyCount++;
- this.setData({
- replyModal: false,
- [indexStr]: replyWho
- })
- });
- },
- // 获取回复楼中楼的内容
- inputSBValue: function (e) {
- this.setData({
- inputSBValue: e.detail.value
- });
- },
- // 选择金额
- setMoney: function (e) {
- this.setData({
- howMuch: e.currentTarget.dataset.money
- })
- },
- reward: function () {
- // if(this.data.isIOS){
- // wx.showToast({
- // title: '奖励成功!',
- // icon: 'success',
- // duration: 1000
- // })
- // return
- // };
- this.setData({
- ifReward: true
- })
- },
- quitReward: function () {
- this.setData({
- ifReward: false
- })
- },
- // 奖励
- rewardMoney: function () {
- const data = {
- targetUid: this.data.authorUid,
- amount: this.data.howMuch
- }
- // let uid = wx.getStorageSync('uid');
- httpRequestApi.rewardMoney(this.uid, data).success(res => {
- this.payMoneyt(res.data.data);
- })
- },
- //支付
- payMoneyt: function (orderInfo) {
- wx.requestPayment({
- 'appId': orderInfo.appId,
- 'timeStamp': orderInfo.timeStamp,
- 'nonceStr': orderInfo.nonceStr,
- 'package': orderInfo.package,
- 'signType': orderInfo.signType,
- 'paySign': orderInfo.sign,
- 'success': function (res) {
- wx.showModal({
- title: '提示',
- content: '支付成功',
- success(res) {
- if (res.confirm) {
- this.setData({
- ifReward: false
- })
- } else if (res.cancel) {
- this.setData({
- ifReward: false
- })
- }
- }
- })
- },
- 'fail': function (res) {
- this.setData({
- ifReward: false
- })
- console.log('支付失败', res)
- }
- })
- },
- // 回到首页
- goBackHome: function () {
- wx.redirectTo({
- url: '../../index/index'
- })
- }
- })
|