var _defaultimg = './images/default-bg-image169.png'; var app = new vue({ el: "#app", data: { defaultimg: _defaultimg, lastfileid: "0", columnsdata: [],//栏目数据列表 rownumber: 0, listcontent: [], isshowbottomtips: false, id: "", parentid: "",//用于控制显示的形式是列表还是图片 columnname: "", activeid: 0, rightheight: 0, imgurl: '', subcolumns: [], activechildid: 0, morestatus: true }, created: function () { this.id = this.geturlqueryprams('id'); if (this.id) { this.getparentid(); } }, methods: { //通过id获取父栏目id getparentid: function () { var url = pageconfig.baseurl + "/api/getcolumn?cid=" + this.id;//获取条数定义: 0:3条;1: 5条;2:20条;3:50条;4:100条 axios.get(url).then(function (result) { if (result.data && result.data.siteid) { util.handlesitejump(result.data.siteid); } if (result.data && result.data.parentid) { app.parentid = result.data.parentid; app.getcolumnsdata(result.data); } else { app.$message.error(result.data.msg); } }).catch(function (error) { console.log(error); }); }, //获取父栏目的子栏目列表(左侧导航) getcolumnsdata: function (data) { var url = pageconfig.baseurl + '/api/getcolumnsex?cid=' + data.parentid + '&order=asc'; axios.get(url).then(function (result) { if (result && result.data && result.data.columns && result.data.columns.length > 0) { app.columnsdata = result.data; app.rightheight = app.columnsdata.columns.length * 57 + 70 + 32 - 130; if (app.geturlqueryprams('subid') && app.geturlqueryprams('subid') > 0) { app.viewdetailrow(data, true, app.geturlqueryprams('subid')); } else { app.viewdetailrow(data, true, 0); } } if (result.data && result.data.column && result.data.column.imgurl) { app.imgurl = result.data.column.imgurl; document.title = result.data.column.columnname; } }).catch(function (error) { console.log(error); }); }, //点击查看单个栏目列表 viewdetailrow: function (data, type, subid) { if (type) { this.activeid = data.columnid; } else { this.activechildid = data.columnid; } this.morestatus = type; this.columnname = data.columnname; this.isshowbottomtips = false; this.lastfileid = 0; this.rownumber = 0; this.listcontent = []; this.newslist(data.columnid, type, subid); }, //新闻列表 newslist: function (id, type, subid) { var url = ''; if (id == 5829) { url = pageconfig.baseurl + '/api/getarticles?cid=' + id + ',4848&lastfileid=' + this.lastfileid + '&rownumber=' + this.rownumber + '&containsubcols=2'; } else { url = pageconfig.baseurl + '/api/getarticles?cid=' + id + '&lastfileid=' + this.lastfileid + '&rownumber=' + this.rownumber + '&containsubcols=0'; } axios.get(url).then(function (result) { if (result && result.data && result.data.list && result.data.list.length > 0) { var list = result.data.list; if (list.length > 0) { app.listcontent = app.listcontent.concat(app.processarticles(list)); app.lastfileid = app.listcontent[app.listcontent.length - 1].fileid; app.rownumber = app.listcontent.length; } if (app.listcontent.length % 20 != 0) { app.isshowbottomtips = true; } if (id == 5829) { app.subcolumns = []; } else { if (type) { app.subcolumns = []; if (result.data.subcolumns && result.data.subcolumns.length > 0) { app.subcolumns = result.data.subcolumns; if (subid > 0) { app.subcolumns.foreach((item) => { if (item.columnid == number(subid)) { app.viewdetailrow(item, false, 0); } }) } } else { app.subcolumns = []; } } } } }).catch(function (error) { console.log(error); }); }, //栏目加载更多 loadmorenews: function () { if (this.morestatus) { this.newslist(this.activeid, true); } else { this.newslist(this.activechildid, false); } }, //获取url参数 geturlqueryprams: function (name) { var reg = new regexp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; }, //稿件数据处理 processarticles: function (list) { for (var i in list) { if (list[i].articletype == 3) {//链接稿件 list.articleurl = list.articleurl; } else if (list[i].articletype == 4) {//专题稿件 list[i].articleurl = './special.html?cid=' + list[i].linkid; } else {//其他稿件 list[i].articleurl = './news.html?aid=' + list[i].fileid; } } return list; }, } })