123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- // pages/supermama/supermama.js
- const app = getApp()
- const util = require("../../utils/util.js");
- Page({
- data: {
- isFullSucreen: app.globalData.isFullSucreen ? true : false, //判断机型
- stepIcon: 'https://yuesuo.yueguanjia.com/MiniProgram/images/phaseI/box.png', // 进度条礼物盒-关闭
- stepIconO: 'https://yuesuo.yueguanjia.com/MiniProgram/images/phaseI/boxOpen.png', // 进度条礼物盒-打开
- process: 0,
- info: {}, // 超人信息
- showGift: false, // 显示礼品弹窗
- giftData: {}, // 礼物弹窗信息
- taskNum: 0, // 待完成任务
- isFirst: '',
- loaddisplay: true,
- isSet: false,
- currentmama: 0
- },
- onLoad: function(options) {
- this.setData({
- navH: app.globalData.navHeight
- })
- let xu_content_type = wx.getStorageSync('xu_content_type');
- if (xu_content_type == 'B01') {
- this.setData({
- isSet: true
- })
- }
- },
- // 生命周期函数--监听页面显示
- onShow: function() {
-
- if (wx.getStorageSync('branche_name') == '北京') {
- wx.reLaunch({
- url: '/pages/yuesuo/yuesuo'
- })
- return
- }
- var isFirst = wx.getStorageSync('isFirst');
- const _this = this;
- wx.checkSession({
- success(res) { //已经登陆
- app.setUserInfo().then(() => {
- _this.getInfo();
- });
- }
- })
- },
- //微信登陆及手机号授权
- toLoginAuthorization: function() {
- return new Promise((resolve, reject) => {
- app.checkSession().then(res => {
- app.ifAuthorization();
- resolve();
- });
- })
- },
- //点击加入
- setNotFirst: function() {
- const _this = this
- _this.setData({
- isFirst: 1
- });
- wx.setStorageSync('isFirst', 1)
- app.checkSession({
- fromwhere: 'mama'
- }).then(res => {
- util.postData('/college/enableCollege?openid=' + app.globalData.openid, {});
- _this.getInfo({
- shouldphone: true
- });
- }); //第一次进来就是没登陆所以不进入then
- },
- // 获取列表数据
- getInfo: function(shouldphone) {
- let _this = this;
- util.postData('/college/queryUserPoints', {
- openid: app.globalData.openid,
- city: wx.getStorageSync('branche_code')
- }).then(res => {
- if (res.errStatus * 1 != 9) {
- //开启过,收到设置页面展示
- _this.setData({
- isFirst: 1
- });
- wx.setStorageSync('isFirst', 1)
- }
- if (res.stage) {
- _this.compontsNum(res)
- _this.setData({
- info: res,
- loaddisplay: 'none',
- nickName: app.globalData.userInfo ? app.globalData.userInfo.nickName : ''
- })
- _this.setProcess(res.credit, res.present_received)
- if (res.surprise) {
- if (res.surprise_type == 1) {
- _this.openGift(res.credit, 'fn')
- } else {
- // 实物
- }
- }
- _this.setData({
- currentmama: 0
- })
- for (var i = 0; i < res.present_received.length; i++) {
- if (res.present_received[i].received == 1) {
- _this.setData({
- currentmama: _this.data.currentmama + 1
- })
- }
- }
- } else if (res.errStatus * 1 == 6) {
- // if (shouldphone && shouldphone.shouldphone) {
- app.ifAuthorization();
- // }
- } else if (res.errStatus * 1 == 5) {
- //开启过,收到设置页面展示
- _this.toLoginAuthorization().then(res => {
- wx.navigateTo({
- url: '/pages/select/select'
- })
- });
- }
- })
- },
- babyBorn() {
- wx.navigateTo({
- url: '/pages/select/select?page=babyBorn'
- })
- },
- // 计算已完成、待完成任务的数量
- compontsNum: function(res) {
- let ing = {
- all: 0
- },
- end = {
- all: 0
- };
- ['college_core', 'college_practice', 'college_experience'].forEach(o => {
- ing[o] = 0;
- end[o] = 0;
- if (res[o] && res[o].length > 0) {
- res[o].map(item => {
- if (item.status != '已完成' && item.learningStatus != '已过期') {
- ing.all += 1;
- ing[o] += 1;
- } else {
- end.all += 1;
- end[o] += 1;
- }
- })
- }
- })
- this.setData({
- taskNum: ing,
- taskEnd: end
- })
- },
- goRule() {
- wx.navigateTo({
- url: '/pages/supermama/rules/rules'
- });
- },
- // 计算分数进度条的百分比
- setProcess: function(credit, arr) {
- let i = this.getPresentInd(credit, arr)
- let preCredit = arr[i].value
- let nextCredit = arr[i + 1].value
- let a = i / (arr.length - 1)
- let b = (credit - preCredit) / (nextCredit - preCredit) * (1 / (arr.length - 1))
- this.setData({
- process: (a + b) * 0.8 * 100 > 80 ? 80 : (a + b) * 0.8 * 100
- })
- },
- // 获取分数在礼物进度中的位置下标
- getPresentInd: function(credit, arr) {
- let ind = null;
- if (arr && arr.length > 0) {
- for (let i = 0; i < arr.length - 1; i++) {
- if (credit >= arr[i].value && credit < arr[i + 1].value) {
- ind = i;
- break;
- }
- }
- }
- if (ind != null) {
- return ind
- } else {
- return 0
- }
- },
- // 设置礼物弹窗参数并展示
- openGift: function(event, type = 'tap') {
- let arr = this.data.info.present_received,
- o;
- if (type == 'tap') {
- o = arr[event.currentTarget.dataset['ind']]
- } else if (type == 'fn') {
- let ind = this.getPresentInd(event, arr)
- o = arr[ind]
- }
- if (type == 'fn' || o.received == 1) {
- this.setData({
- giftData: {
- isReady: true,
- one: '恭喜您',
- two: '升级为' + o.name,
- surprise_name: type == 'fn' ? this.data.info.surprise_name : o.present_name
- },
- showGift: true
- })
- } else {
- this.setData({
- giftData: {
- isReady: false,
- one: '学分达' + o.value + '分',
- two: '将成为' + o.name,
- surprise_name: o.present_name
- },
- showGift: true
- })
- }
- },
- // 关闭弹窗
- closeGift: function() {
- this.setData({
- showGift: false
- })
- this.getInfo()
- }
- })
|