detail.js 2.07 KB
import detailModel from '../../models/classroom/detail';
import wx from '../../utils/wx';
import Yas from '../../common/yas';
import { stringify } from '../../vendors/query-stringify';

let yas;
let app = getApp();

Page({
    data: {
        info: {},
        shareTitle: '',
        shareTag: '',
        type: 1,
        content: {}
    },
    onShareAppMessage: function(res) {
        let pages = getCurrentPages();
        let path = pages[pages.length - 1].route || '/pages/index/index';
        let pageParams = stringify(pages[pages.length - 1].options) || '';
        let params = {
            FROM: res.from,
            SHARE_RESULT: 1,
            TITLE: `${this.data.shareTag} | ${this.data.shareTitle}`,
            DESC: '',
            PATH: path,
            PAGE_PARAM: pageParams
        };

        return {
            title: params.TITLE,
            success: function() {
                yas.report('YB_SHARE_RESULT_L', params); // 首页分享上报
            },
            fail: function() {
                params.SHARE_RESULT = 2;
                yas.report('YB_SHARE_RESULT_L', params); // 首页分享上报
            }
        };
    },
    onLoad: function(qs) {
        wx.showLoading();
        let params = {
            id: qs.activityId,
            isFront: 1
        };

        detailModel.getDetail(params).then(result => {
            let type = 1;
            let content = '';

            if (result.contentSection) {
                content = result.contentSection;
                type = 2;
            } else if (result.detail) {
                content = result.detail;
            }

            this.setData({
                info: result.info,
                shareTitle: result.info.name || '',
                shareTag: result.info.tagName || '',
                type,
                content
            });
        });

        yas = new Yas(app);
        yas.pageOpenReport();
    },
    onReady: function() {
        wx.hideLoading();
    },
    onImageUrl({detail: {url}}) {
        console.log('open=>', url);
        global.router.goUrl(url);
    }
});