// pages/student/student.js
const app = getApp()
const util = require("../../utils/util")
const urlDef = require("../../utils/urls")
Page({
/**
* 页面的初始数据
*/
data: {
height: 0,
animation: {},
left: 750,
shareImg: 'https://app.schoolwisdoms.com/static/app/student/imgs/share-bill.png',
inviteConfig: {},
count: 0,
enroll: 0,
coin: '0',
invitations: [],
showShareImg: false,
showCodeImg: false,
posterConfig: {
'width': 700,
'height': 900,
'backgroundColor': '#fff',
'debug': false,
'preload': true,
'hide-loading': true,
images: [{
x: 0,
y: 0,
url: 'https://app.schoolwisdoms.com/static/app/student/imgs/share-bill.png',
width: 700,
height: 900
}, {
x: 250,
y: 640,
url: 'https://app.schoolwisdoms.com/static/app/student/imgs/share-bill.png',
width: 200,
height: 200
}],
},
},
onPosterSuccess(e) {
let that = this;
let {
detail
} = e;
wx.saveImageToPhotosAlbum({
filePath: detail,
success(res) {
wx.showToast({
title: '图片已保存到本地相册',
icon:'none'
})
that.setData({
showShareImg: false
})
that.triggerEvent("callMethod")
},fail(res){
console.log(res)
that.getSetting()
}
})
},
getSetting:function(){
// 相册授权
wx.getSetting({
success(res) {
// 进行授权检测,未授权则进行弹层授权
if (!res.authSetting["scope.writePhotosAlbum"]) {
wx.showModal({
title: '提示',
content: '您未授权相册使用权限,是否重新授权?',
success:function(res){
if(res.confirm){
wx.openSetting({
success(settingdata) {
if (settingdata.authSetting["scope.writePhotosAlbum"]) {
console.log("获取权限成功,再次点击图片保存到相册")
} else {
console.log("获取权限失败")
}
},fail(res){
console.log(res)
}
})
}
}
})
}
},
fail(res) {
console.log(res);
}
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
wx.getSystemInfo({
success: (result) => {
this.setData({
height: result.windowHeight
})
},
})
this.queryInvitation(null);
let t = this;
setTimeout(() => {
t.doSearch();
}, 1000);
},
showCodeImg:function(){
this.setData({
showCodeImg: true
})
},
closeImg:function(){
this.setData({
showShareImg: false,
showCodeImg: false
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
queryInvitation: function (methodName) {
let urls = urlDef.urls
let stu = wx.getStorageSync('student');
let inviteConfig = {}
util.apiPost(urls.get_activity_share + '&q.orgId=' + stu.orgId).then((rs) => {
if (rs && rs.length > 0) {
let r = rs[0];
inviteConfig.title = (r.name ? r.name : '邀请有礼');
inviteConfig.description = (r.remark ? r.remark : '邀请新学员,赢得奖励');
inviteConfig.imageUrl = r.imgUrl;
if (r.activityUrl && r.activityUrl.length > 0) {
inviteConfig.url = r.activityUrl + (r.activityUrl.indexOf('?') === -1 ? '?' : '&') + 'studentId=' + stu.studentId + '&orgId=' + stu.orgId;
}
this.setData({ inviteConfig: inviteConfig })
if ('billShare' === methodName) {
this.billShare();
}
if ('share' === methodName) {
this.share();
}
if ('codeInvite' === methodName) {
this.codeInvite();
}
}
});
},
doSearch: function () {
let urls = urlDef.urls
let stu = wx.getStorageSync('student');
util.apiPost(urls.get_invitation_count + '&q.introducer=' + stu.studentId).then(rs => {
if (rs) {
this.setData({ count: rs.num })
}
});
util.apiPost(urls.get_invitation_enroll + '&q.introducer=' + stu.studentId).then(rs => {
if (rs) {
this.setData({ enroll: rs.num })
}
});
util.apiPost(urls.get_invitation_coin + '&q.introducer=' + stu.studentId).then(rs => {
if (rs && rs.length > 0) {
let i = 0;
let coin = ''
rs.forEach(r => {
coin += (r.amount + '' + (r.type === 1 ? '元' : '课时') + '');
if (i < rs.length - 1) {
coin += '/';
}
i++;
});
this.setData({ coin: coin })
}
});
util.apiPost(urls.query_invitation_list + '&q.introducer=' + stu.studentId).then(rs => {
if (rs) {
rs.map(o => {
o.name = o.studentName ? o.studentName : o.clientName
o.statusText = this.getStatus(o)
o.face = this.getHead(o)
})
this.setData({ invitations: rs })
}
});
},
getHead(item) {
let urls = urlDef.urls
return item.imageUrl ? urls.oss_file + 'image/' + item.imageUrl : '/images/head.png';
},
getStatus(item) {
if (item.orderCount > 0) { // 有已付款的订单
return '已报名';
} else {
if (item.isAudition === 0) { // 未试听
return '已注册';
}
return '已试听';
}
},
billShare: function () {
if (this.data.inviteConfig.url && this.data.inviteConfig.url.length > 4) {
console.log('弹出海报分享页面')
this.setData({
showShareImg: true
})
// this.modal = this.modalCtrl.create('BillSharePage', { item: this.inviteConfig });
// this.modal.present();
} else {
this.queryInvitation('billShare');
}
},
share: function () {
if (this.data.inviteConfig.url && this.data.inviteConfig.url.length > 4) {
// this.modal = this.modalCtrl.create('SharePage', { item: this.inviteConfig });
// this.modal.present();
console.log('弹出享页面')
} else {
this.queryInvitation('share');
}
},
codeInvite: function () {
let urls = urlDef.urls
if (this.data.inviteConfig.url && this.data.inviteConfig.url.length > 4) {
let regUrl = this.data.inviteConfig.url;
let imgUrl = urls.get_qr_code + '?content=' + encodeURIComponent(regUrl);
this.openModal(imgUrl);
} else {
this.queryInvitation('codeInvite');
}
},
openModal: function (imgUrl) {
// 弹出页面
console.log('...' + imgUrl)
this.setData({
showCodeImg: true
})
}
})