123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- // TODO 临时构造plus对象,使得能够在浏览器中进行调试
- //var plus = null;
- // 登录者相关信息(包括userAgent)
- var loginerInfo = null,
- // 基础环境信息(包括当前webview)
- baseEnv = null,
- docInfo = null,
- self = null,
- activeItem = null,
- pagesize = 100000000;
- var $queryTab = $('#query_tab'),
- $views = $('.c-view'),
- $undoView = $('#undo_view'),
- $doingView = $('#doing_view'),
- $endView = $('#end_view'),
- $undoViewList = $undoView.find('.c-list1'),
- $doingViewList = $doingView.find('.c-list1'),
- $endViewList = $endView.find('.c-list'),
- // 搜索无结果时显示
- $noResultWrap = $('#no_result_wrap'),
- $searchbar = $(".searchbar-input");
-
- mui.plusReady(function() {
- docInfo = JSON.parse(plus.storage.getItem("docInfo"));
- if(docInfo.isFamous==1){//是名医,则显示“咨询我的”模块
- $("#query_tab").show();
- $("#div-zxwd").addClass("curr");
- }else{
- $("#div-wzxd").addClass("curr");
- }
- });
- // ”待处理”列表分页查询最后一条记录Id
- var undoLastId = 0,
- // ”进行中”列表分页查询最后一条记录Id
- doingLastId = 0,
- // ”已结束”列表分页查询最后一条记录Id
- endLastId = 0,
- // ”待处理”列表iscroll 滚动条实例
- undoIscroller,
- // ”进行中”列表iscroll 滚动条实例
- doingIscroller,
- // ”已结束”列表iscroll 滚动条实例
- endIscroller;
-
- // 获取登录相关信息
- var getLoginerInfo = function() {
- // 登录的相关信息
- var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"))
- return {
- userAgent: userAgent
- }
- },
- // 获取基础环境信息
- getBaseEnvPromise = function () {
-
- var env = {
- webview: plus&&plus.webview.currentWebview()
- };
- return Promise.resolve().then(function(res) {
- return env;
- });
- },
- ellipsisText = function ($el) {
- $el.ellipsis({ row: 2 });
- },
- // 初始化“咨询我的”视图列表
- initUndoViewList = function(data) {
- console.log(JSON.stringify(data))
- var html = template("zixun_li_tmpl", {list: data.list})
- $undoViewList.append(html);
- ellipsisText($undoViewList.find('.c-dest-content'));
- },
- // 初始化“我咨询的”视图列表
- initDoingViewList = function(data) {
- var html = template("wzixun_li_tmpl", {list:data.list})
- $doingViewList.append(html);
- ellipsisText($doingViewList.find('.c-dest-content'));
- },
- // "咨询我的"分页查询列表
- searchUndoByPaging = function () {
- // TODO 示例示例搜索参数
- // id: 上次搜索结果列表最后一条记录id,type:5(咨询我的),query:搜素关键字,pageSize:每页条数
- var url = "doctor/consult/list",
- params = { id:0, pagesize: pagesize, type:5 };
- if(!undoIscroller) {
- undoIscroller = initScroller($undoView,url,
- function() { // 传递分页参数
- return params;
- },function(data) {
- // TODO 示例数据
- undoLastId = getLastId(data) || undoLastId;
- initUndoViewList(data);
- undoIscroller.refresh();
- });
- }
- },
- // "我咨询的"分页查询列表
- searchDoingByPaging = function () {
- // TODO 示例示例搜索参数
- // id: 上次搜索结果列表最后一条记录id,type:10(我咨询的),query:搜素关键字,pageSize:每页条数
- var url = "doctor/consult/list",
- params = { id:0, pagesize: pagesize,type:10 };
-
- if(!doingIscroller) {
- doingIscroller = initScroller($doingView,url,
- function() { // 传递分页参数
- return params;
- },function(data) {
- // TODO 示例数据
- doingLastId = getLastId(data) || doingLastId;
- initDoingViewList(data);
- doingIscroller.refresh();
- });
- }
- },
- // 滚动条分页实例初始化
- initScroller = function($el,url,getData,pullUpAction) {
- var scroller = $el.initScroll({pullDownAction: function() {
- initPage();
- },pullUpAction: function() {
- getReqPromise(url,getData()).then(function(data) {
- if(pullUpAction && $.isFunction(pullUpAction)) {
- pullUpAction(data);
- updatePullUpText(scroller,data);
- }
- })
- }, pullUp: false});
-
- return scroller;
- },
- // 获取分页搜索返回的最后一条记录的id
- getLastId = function(data) {
- var lastObj = data.list && data.list.length && data.list[data.list.length-1];
- // 最后一条记录
- if(lastObj) {
- return lastObj.id;
- } else {
- return null
- }
- },
- // 更新分页上拉加载的提示文本
- updatePullUpText= function(scroller,data) {
- var $wrap = $(scroller.wrapper),
- $pullupLabel = $wrap.find('.pullUpLabel');
- if(data.isLast) {
- $pullupLabel.text('没有更多');
- } else {
- $pullupLabel.text('上拉加载更多');
- }
- scroller.on('refresh',function() {
- if(data.isLast) {
- $pullupLabel.text('没有更多');
- } else {
- $pullupLabel.text('上拉加载更多');
- }
- });
- },
- initPage = function() {
- plus.nativeUI.showWaiting();
- $undoViewList.empty();
- $doingViewList.empty();
- $endViewList.empty();
- var reqUrl = [{url: "doctor/consult/list",data: { id:0, pagesize: pagesize,type:10 }}];//我咨询的
- if(docInfo.isFamous==1){//是名医,则显示“咨询我的”模块
- reqUrl.push({url: "doctor/consult/list",data: { id:0, pagesize: pagesize,type:5 }}); // 咨询我的
- }
- getReqPromises(reqUrl).then(function(datas) {
- var doingData = datas[0] || [],
- undoData = datas[1] || [];
- //我咨询的
- doingLastId = getLastId(doingData) || doingLastId;
- searchDoingByPaging();
- initDoingViewList(doingData);
- updatePullUpText(doingIscroller, doingData);
- doingIscroller.refresh();
-
- //咨询我的
- if(docInfo.isFamous==1){
- undoLastId = getLastId(undoData) || undoLastId;
- searchUndoByPaging();
- initUndoViewList(undoData);
- updatePullUpText(undoIscroller, undoData);
- undoIscroller.refresh();
- }
-
- var $active = $queryTab.find(".tab-item.curr").eq(0);
- if(activeItem==1){
- $active.removeClass("curr");
- $active = $queryTab.find(".tab-item").eq(activeItem);
- $active.addClass("curr");
- }
- if($active) {
- $active.trigger('click');
- activeItem = null;
- }
- plus.nativeUI.closeWaiting();
- });
- },
- // 绑定页面事件
- bindEvents = function () {
- $("#zxmy_btn").on("tap", function() {
- openWebview("../../mygl/html/zixun-xuanzeyisheng.html");
- });
-
- $queryTab.on('click','.tab-item',function() {
- var type = $(this).attr('data-type'),
- $activeView = $('#'+type),
- isNotEmpty = !!$activeView.find('li[data-consult]').length;
-
- if(type=="doing_view"){//我咨询的,则隐藏搜索按钮
- if(docInfo.isFamous==1){
- $("#doing_wrapper").css("top","137px")
- }else{
- $("#doing_wrapper").css("top","95px")
- }
- }else{
- $("#undo_wrapper").css("top","137px")
- }
-
- $queryTab.find('.tab-item').removeClass('curr');
- $views.hide();
- $(this).addClass('curr');
-
- if(isNotEmpty) {
- $noResultWrap.hide();
- $('#'+type).show();
- $('#'+type).removeClass('c-vis-none');
- $(".searchbar").show();
- } else {
- $noResultWrap.show();
- $(".searchbar").hide();
- }
- });
-
- $searchbar.on('click',function() {
- var activeType = $("#query_tab .tab-item.curr").attr("data-type")=="undo_view"?"1":"2";//1为咨询我的 2为我咨询的
- openWebview("sousuozixun.html",{type: activeType});
- });
-
- $views.on('click','li',function() {
- var $this = $(this),
- consult = $this.attr('data-consult'),
- code = $this.attr('data-code'),//咨询者的code
- name = $this.attr('data-name'),
- photo = $this.attr('data-photo'),
- sex = $this.attr('data-sex'),
- type = $this.attr('data-type'),
- doctor = $this.attr('data-doctor'),//被咨询者的code
- // (咨询状态(0进行中,1已完成,-1患者取消)
- status = $this.attr('data-status');
- if(status == "1") {
- // flagZx 是为了跳转至咨询详情页面控制聊天对话框的显示
- plus.storage.setItem("flagZx","4");
- } else {
- plus.storage.setItem("flagZx","");
- }
- var activeItemId = $this.closest(".c-view").attr("id");
- mui.openWindow({
- id: "p2p",
- url: "../../message/html/p2p.html",
- extras: {
- otherCode: code,
- otherName: name,
- otherPhoto: photo,
- otherSex: sex
- }
- })
-
- });
-
- window.addEventListener("refresh", function(){
- initPage();
- });
- };
- // 页面业务处理流程开始
- new Promise(function(resolve, reject) {
- // TODO 临时放开
- //resolve(true);
- mui.plusReady(function() {
- // plus已经准备好,可以往下执行
- resolve(true);
- });
- }).then(function() {
-
- // 获取基础环境信息
- return getBaseEnvPromise().then(function(env) {
- baseEnv = env;
- }).then(function() {
- // 获取登录医生信息
- loginerInfo = getLoginerInfo();
-
- initPage();
-
- $queryTab.find('.tab-item').eq(0).click();
- // 绑定页面事件
- bindEvents();
- })
- }).catch(function(e) {
- plus.nativeUI.closeWaiting();
- console && console.error(e);
- });
- window.addEventListener("activeItem", function(e) {
- activeItem = 1;
- initPage();
- });
- template.helper("setPhoto", function(p) {
- return getImgUrl(p);
- });
|