UNPKG

h5-cli

Version:

hello

112 lines (94 loc) 3.67 kB
"use strict"; define("pages/news", function (require, exports, module) { var PageModule = require("component/PageModule"); var MulitpeTab = require("mods/muliteTab/index"); var page = PageModule.render({ init: function init() { var unionId = this.query.unionId; var corpId = this.query.corpId; if (!this.query.corpId && !this.query.unionId) { this.util.alert("\u7f3a\u5c11corpId or unionId"); } this.get("/user-web/restapi/common/corpNews/newsInfo", { corpId: corpId, unionId: unionId, types: "1,2,3,4,5,6,7,9" }); this.uid = this.util.getUID(); }, //\u76d1\u542c\u7528\u6237\u767b\u5f55\u72b6\u6001\u53d1\u751f\u53d8\u5316\uff0c\u9700\u8981\u5237\u65b0\u9875\u9762\u91cd\u65b0\u8f7d\u5165\u6570\u636e onActivation: function onActivation() { if (this.uid != this.util.getUID()) { window.location.reload(true); } }, initTabs: function initTabs() { var self = this; var tab = new MulitpeTab($('#J_Tabs'), { //tab\u4e4b\u95f4\u7684\u95f4\u8ddd gap: 20 }); tab.go(0); // \u4ece0\u5f00\u59cb\uff0c\u8fd9\u91cc\u521d\u59cb\u5316\u5230\u7b2c2\u4e2atab tab.addEventListener("onChange", function (index, prevIndex, $element) { // console.log(index) self.filterType($element.data("type")); }); }, filterType: function filterType(type) { if (type) { // console.log(1) var list = this.cacheData.introsNews.filter(function (item) { return item.classifyId == type; }); this.renderList(list); } else { this.renderList(this.cacheData.introsNews); } }, onSuccess: function onSuccess(result) { if (result.success || result.success == "true") { // console.log( result.data ) this.renderTabs(result.data); $('#J_Page').removeClass("wait"); } else { this.onError(result); } }, renderTabs: function renderTabs(data) { //result.data data.classifys = data.classifys || []; data.introsNews = data.introsNews || []; this.cacheData = data; var classifys = []; data.classifys.forEach(function (row) { // && row.name != "\u536b\u8ba1\u59d4\u4e4b\u58f0" if (row.name.indexOf("\u5e38\u89c1\u95ee\u9898") == -1) { classifys.push(row); } }); var tmpl = '{@each list as item}<li data-type="${item.id}" ><a>${item.name}</a></li>{@/each}'; var html = this.juicer(tmpl, { list: classifys }); $('#J_TabList').html(html); if (data.classifys.length) { this.initTabs(); } }, renderList: function renderList(data) { var self = this; var tmpl = '{@each list as item}' + '<div class="item-news">' + '<a href="../news-detail.html?id=${item.id}&target=_blank" class="ui-border-b">' + '<div class="img" style="background-image:url(${item.titleImg})"></div>' + '<div class="text">' + '<div class="h1">${item.title}</div>' + '<div class="sub ui-nowrap-flex">${item.summary}</div>' + '<div class="time">${dateFormat(item.gmtCreate)}</div>' + '</div>' + '</a>' + '</div>' + '{@/each}'; //\u5904\u7406 \u5047\u503c this.juicer.register("dateFormat", function (value) { return self.util.dateFormat(value, "MM-dd hh:mm"); }); if (data && data.length) { this.renderTo(tmpl, { list: data }, "#J_NewsList"); } else { $("#J_NewsList").html('<div class="ui-tips center">\u6ca1\u6709\u8d44\u8baf</div>'); } } }); //\u9875\u9762 page.init(); module.exports = page; });