detail.js 2.04 KB
import cmsModel from '../../models/cms/index';
import helper from '../../utils/helper';
import Yas from '../../common/yas';
import { stringify } from '../../vendors/query-stringify';

let app = getApp();
let yas;

Page({
    data: {
        title: '',
        pic: '',
        content: '',
        time: '',
        type: 1
    },
    onLoad: function(options) {
        cmsModel.cmsData(options.id || 0).then(result => {
            if (result.wechatUrl) {
                return global.router.go('webView', {url: result.wechatUrl});
            }

            let type = 1;
            let content;

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

            this.setData({
                title: result.title || '',
                time: result.time || '',
                pic: result.pic || '',
                type,
                content
            });
        });

        app = app || getApp();
        yas = new Yas(app);
        yas.pageOpenReport();
    },
    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: 0,
            TITLE: this.data.title || '潮人汇聚、尖货集结,一个城市,一个潮流中心!南京新街口艾尚天地YOHO!STORE',
            imageUrl: helper.imgView(this.data.pic, 750, 480),
            PATH: path,
            PAGE_PARAM: pageParams
        };

        return {
            title: params.TITLE, // 分享标题
            imageUrl: params.imageUrl,
            success: function() {
                yas.report('YB_SHARE_RESULT_L', params); // 分享上报
            }
        };
    },
    onImageUrl({detail: {url}}) {
        console.log('open=>', url);
        global.router.goUrl(url);
    }
});