123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- // pages/student/student.js
- const app = getApp()
- const util = require("../../utils/util")
- const urlDef = require("../../utils/urls")
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- height: 0,
- animation: {},
- left: 750,
- inviteConfig: {},
- count: 0,
- enroll: 0,
- coin: '0',
- invitations: []
- },
- closeCamera: function () {
- this.animation = wx.createAnimation({
- timingFunction: 'linear',
- duration: 400
- })
- const left = 750
- this.animation.translateX(left).step()
- this.setData({
- animation: this.animation.export()
- })
- },
- showCamaer: function () {
- this.animation = wx.createAnimation({
- timingFunction: 'linear',
- duration: 100
- })
- const left = 0
- this.animation.translateX(left).step()
- this.setData({
- animation: this.animation.export(),
- left
- })
- },
- scanCode: function (e) {
- console.log(JSON.stringify(e))
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- wx.getSystemInfo({
- success: (result) => {
- this.setData({
- height: result.windowHeight
- })
- },
- })
- this.queryInvitation(null);
- let t = this;
- setTimeout(() => {
- t.doSearch();
- }, 1000);
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- 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 + '<view class=\'unit\'>' + (r.type === 1 ? '元' : '课时') + '</view>');
- if (i < rs.length - 1) {
- coin += '<view class=\'sl\'>/</view>';
- }
- 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.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)
- }
- })
|