123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- var d = dialog({contentType:'load', skin:'bk-popup'});
- var Request = GetRequest();
- var doctorCode = Request["docCode"];
- var page = 0,
- pageSize = 10,
- pagetype = 0,
- firstLevelCategoryId = "", // 文章一级分类
- hospital ="" , // 医生所属社区Code
- // 搜索框
- $searchbar = $('.searchbar'),
- // 搜索输入框
- $searchbarInput = $('.lin-search-ipt input'),
- $searchtResult = $("#articleList");
- $(function(){
- checkUserAgent();
- })
- function toast(msg){
- dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:msg}).show()
- }
- function queryInit(){
- d.show();
- Promise.all([getCategoryByNamePromise(),jimeiHomepagePromise()])
- .then(function(responses) {
- var res0 = responses[0]
- var res1 = responses[1]
- if(res0.status == 200 && res1.status == 200) {
- firstLevelCategoryId = res0.data.cid
- hospital = res1.data.hospital
- } else {
- d.close()
- toast('获取数据失败')
- return Promise.reject()
- }
- }).then(function() {
- getList(true);
- initScroller();
- bindEvents();
- })
- }
- function initScroller(){
- //阻尼系数
- var deceleration = mui.os.ios?0.003:0.0009;
- mui('.mui-scroll-wrapper').scroll({
- bounce: false,
- indicators: true, //是否显示滚动条
- deceleration:deceleration
- });
- // mui.ready(function() {
- mui(".mui-scroll-wrapper").pullRefresh({
- up:{
- callback: function(){
- page++;
- var self = this;
- setTimeout(function(){
- getList(false);
- self.endPullupToRefresh();
- }, 1000)
- }
- },
- down: {
- callback: function(){
- var self = this;
- page = 0;
- getList(true);
- this.endPulldownToRefresh();
- }
- }
- })
- // })
- }
- function getCategoryByNamePromise(){
- return new Promise(function(resolve, reject) {
- sendPost("third/jkEdu/Article/getCategoryByName",{name:'健康文章'},"JSON","GET",function(){
- toast('请求失败')
- },function(res){
- resolve(res)
- })
- })
- }
- function jimeiHomepagePromise(){
- return new Promise(function(resolve, reject) {
- sendPost("patient/family_contract/jimeiHomepage",{
- doctor:doctorCode,pageIndex:page,pageSize:pageSize
- },"JSON","GET",function(){
- toast('请求失败')
- },function(res){
- resolve(res)
- })
- })
- }
- function getList(isInit){
- var url = "patient/jkEdu/article/queryArticlePcList",
- params = {
- doctor: doctorCode,
- articleTitle: $searchbarInput.val(),
- firstLevelCategoryId: firstLevelCategoryId, // 文章一级分类
- isMyArticle: true,
- currentUserRole: hospital,
- currentUserRoleLevel: 4,
- iDisplayStart: page,
- iDisplayLength: pageSize
- };
- d.show();
- sendPost(url, params, 'json', 'GET', queryFailed, function(res){
- d.close();
- if(res.status == 200){
- if(res.data.aaData.length > 0){
- var html = template("articleTmp", {list: res.data.aaData});
- if(isInit){
- $("#articleContent .mui-scroll-wrapper").show();
- $("#articleContent .div-no-info").hide();
- $("#articleList").empty().append(html);
- }else{
- $("#articleList").append(html);
- }
- if(res.data.aaData.length < pageSize){
- mui("#articleContent .mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
- }
- }
- else{
- if(isInit){
- //数据库中无数据
- $("#articleContent .mui-scroll-wrapper").hide();
- $("#articleContent .div-no-info").show();
- }else{
- mui("#articleContent .mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
- }
-
- }
- }else{
- queryFailed(res);
- }
- })
- }
- function queryFailed(res){
- d.close();
- if(res && res.msg) {
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- content: res.msg
- }).show();
- } else {
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- content: '加载失败'
- }).show();
- }
- }
- function bindEvents() {
- $("#articleContent").on('tap','li',function() {
- d.show()
- var articleId = $(this).attr('data-id')
- window.location.href="../../jkjy/html/article2.html?dataId="+articleId+'&articleId='+articleId+'&type='+'1';
- });
-
- //搜索功能
- $searchbarInput.on('keydown',function(e) {
- if (e.which === 13) {
- //按回车键后执行的动作
- page = 0;
- getList(true);
- }else{
- if($searchbarInput.length == 0){
- alert(1);
- }
- }
- });
-
- template.helper('getDate', function(str){
- if(str && str.length > 0){
- return str.substr(0, 10);
- }
- });
- }
- template.helper("setPhoto", function(p) {
- return getImgUrl(p);
- })
- function search(){
- page = 0;
- getList(true);
- }
|