123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- var page = 1,
- pagesize = 15,
- hasMore = true;
- mui.init();
- mui.plusReady(function(){
- getTemplateLabel();
- getTemplateList(true);
- initScroll();
- bindEvents();
- });
- function initScroll(){
- //阻尼系数
- var deceleration = mui.os.ios?0.003:0.0009;
- mui('.mui-scroll-wrapper').scroll({
- bounce: false,
- indicators: true, //是否显示滚动条
- deceleration:deceleration
- });
-
- mui('.mui-scroll-wrapper').pullRefresh({
- down: {
- callback: function() {
- setTimeout(function() {
- getTemplateList(true);
- mui('.mui-scroll-wrapper').pullRefresh().endPulldownToRefresh();
- }, 1000);
- }
- },
- up:{
- contentrefresh: '正在加载...',
- callback: function(){
- var self = this;
- setTimeout(function() {
- getTemplateList(false);
- mui('.mui-scroll-wrapper').pullRefresh().endPullupToRefresh(!hasMore);
- }, 1000);
- }
- }
- });
- }
- function getTemplateLabel(){
- plus.nativeUI.showWaiting();
- var url = "/doctor/questionnaire/getTemplateLabel";
- sendGet(url, {}, null, function(res){
- if(res.status == 200){
- if(res.data.length == 0){
- $(".header-link").hide();
- }else{
- var html = template("label_tmp", {list: res.data});
- $("#group_label_list").append(html);
- }
-
- }else{
- $(".header-link").hide();
- }
- plus.nativeUI.closeWaiting();
- }, true);
- }
- function getTemplateList(isInit, label){
- page = isInit ? 1: page;
- var url = "/doctor/questionnaire/getTemplateByLabel",
- labels = label ? label.join(",") : "",
- params = {labels: labels, pageNo: page, pageSize: pagesize};
- plus.nativeUI.showWaiting();
- sendGet(url, params, null, function(res){
- if(res.status == 200){
- page ++;
- if(isInit && res.data.length == 0){
- $("#no_result_wrap").show();
- $("#search_bar").hide();
- $(".mui-scroll-wrapper").hide();
- // $("#newTemplate").hide();
- $(".header-link").hide();
- }else{
- $("#no_result_wrap").hide();
- $("#search_bar").show();
- $(".mui-scroll-wrapper").show();
- $("#newTemplate").show();
- if(res.data.length < pagesize){
- hasMore = false;
- isInit && mui(".mui-scroll-wrapper").pullRefresh().endPullupToRefresh(!hasMore);
- }else{
- hasMore = true;
- }
-
- var list = _.map(res.data, function(o){
- o.jsonStr = JSON.stringify(o);
- return o;
- });
- var html = template("list_tmp", {list: list});
-
- if(isInit){
- $(".mui-scroll").empty().append(html);
- }else{
- $(".mui-scroll").append(html);
- }
- }
- }else{
- mui.toast(res.msg);
- }
- plus.nativeUI.closeWaiting();
- }, true);
- }
- function bindEvents(){
- $(".header-link").on('tap', function(){
- showGroupSel();
- });
-
- $(".sel-group").on("click",'.icon-checkbox', function(){
- //发送请求
- var $labels = $(".icon-checkbox:checked"),
- len = $labels.length,
- ids = [];
- for(i=0; i<len; i++){
- var item = $labels[i];
- ids.push(item.value);
- }
- getTemplateList(true, ids);
- });
-
- $("body").on("tap", '.tmpl', function(){
- var jsonStr = $(this).attr("data-json"),
- template_id = $(this).attr("data-code");
- openWebview("template_info.html", {
- template_id: template_id,
- info: JSON.parse(jsonStr)
- });
- });
-
- $("#newTemplate").on('tap', function(){
- openWebview("new_summary.html");
- });
-
- $(".search-bar").on('tap', function(){
- openWebview("search_template.html");
- });
-
- $(".lin-mask").on('tap', function(){
- showGroupSel();
- });
-
- window.addEventListener("refresh", function(e){
- getTemplateList(true);
- });
- }
- function showGroupSel(){
- var isShow = isShow || $('.sel-group:hidden').length != 0;
- $('.lin-mask').fadeToggle(isShow);
- $('.sel-group').fadeToggle(isShow);
- }
|