mingyizixunliebiao.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. // TODO 临时构造plus对象,使得能够在浏览器中进行调试
  2. //var plus = null;
  3. // 登录者相关信息(包括userAgent)
  4. var loginerInfo = null,
  5. // 基础环境信息(包括当前webview)
  6. baseEnv = null,
  7. docInfo = null,
  8. self = null,
  9. activeItem = null,
  10. pagesize = 100000000;
  11. var $queryTab = $('#query_tab'),
  12. $views = $('.c-view'),
  13. $undoView = $('#undo_view'),
  14. $doingView = $('#doing_view'),
  15. $endView = $('#end_view'),
  16. $undoViewList = $undoView.find('.c-list1'),
  17. $doingViewList = $doingView.find('.c-list1'),
  18. $endViewList = $endView.find('.c-list'),
  19. // 搜索无结果时显示
  20. $noResultWrap = $('#no_result_wrap'),
  21. $searchbar = $(".searchbar-input");
  22. mui.plusReady(function() {
  23. docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  24. if(docInfo.isFamous==1){//是名医,则显示“咨询我的”模块
  25. $("#query_tab").show();
  26. $("#div-zxwd").addClass("curr");
  27. }else{
  28. $("#div-wzxd").addClass("curr");
  29. }
  30. });
  31. // ”待处理”列表分页查询最后一条记录Id
  32. var undoLastId = 0,
  33. // ”进行中”列表分页查询最后一条记录Id
  34. doingLastId = 0,
  35. // ”已结束”列表分页查询最后一条记录Id
  36. endLastId = 0,
  37. // ”待处理”列表iscroll 滚动条实例
  38. undoIscroller,
  39. // ”进行中”列表iscroll 滚动条实例
  40. doingIscroller,
  41. // ”已结束”列表iscroll 滚动条实例
  42. endIscroller;
  43. // 获取登录相关信息
  44. var getLoginerInfo = function() {
  45. // 登录的相关信息
  46. var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"))
  47. return {
  48. userAgent: userAgent
  49. }
  50. },
  51. // 获取基础环境信息
  52. getBaseEnvPromise = function () {
  53. var env = {
  54. webview: plus&&plus.webview.currentWebview()
  55. };
  56. return Promise.resolve().then(function(res) {
  57. return env;
  58. });
  59. },
  60. ellipsisText = function ($el) {
  61. $el.ellipsis({ row: 2 });
  62. },
  63. // 初始化“咨询我的”视图列表
  64. initUndoViewList = function(data) {
  65. console.log(JSON.stringify(data))
  66. var html = template("zixun_li_tmpl", {list: data.list})
  67. $undoViewList.append(html);
  68. ellipsisText($undoViewList.find('.c-dest-content'));
  69. },
  70. // 初始化“我咨询的”视图列表
  71. initDoingViewList = function(data) {
  72. var html = template("wzixun_li_tmpl", {list:data.list})
  73. $doingViewList.append(html);
  74. ellipsisText($doingViewList.find('.c-dest-content'));
  75. },
  76. // "咨询我的"分页查询列表
  77. searchUndoByPaging = function () {
  78. // TODO 示例示例搜索参数
  79. // id: 上次搜索结果列表最后一条记录id,type:5(咨询我的),query:搜素关键字,pageSize:每页条数
  80. var url = "doctor/consult/list",
  81. params = { id:0, pagesize: pagesize, type:5 };
  82. if(!undoIscroller) {
  83. undoIscroller = initScroller($undoView,url,
  84. function() { // 传递分页参数
  85. return params;
  86. },function(data) {
  87. // TODO 示例数据
  88. undoLastId = getLastId(data) || undoLastId;
  89. initUndoViewList(data);
  90. undoIscroller.refresh();
  91. });
  92. }
  93. },
  94. // "我咨询的"分页查询列表
  95. searchDoingByPaging = function () {
  96. // TODO 示例示例搜索参数
  97. // id: 上次搜索结果列表最后一条记录id,type:10(我咨询的),query:搜素关键字,pageSize:每页条数
  98. var url = "doctor/consult/list",
  99. params = { id:0, pagesize: pagesize,type:10 };
  100. if(!doingIscroller) {
  101. doingIscroller = initScroller($doingView,url,
  102. function() { // 传递分页参数
  103. return params;
  104. },function(data) {
  105. // TODO 示例数据
  106. doingLastId = getLastId(data) || doingLastId;
  107. initDoingViewList(data);
  108. doingIscroller.refresh();
  109. });
  110. }
  111. },
  112. // 滚动条分页实例初始化
  113. initScroller = function($el,url,getData,pullUpAction) {
  114. var scroller = $el.initScroll({pullDownAction: function() {
  115. initPage();
  116. },pullUpAction: function() {
  117. getReqPromise(url,getData()).then(function(data) {
  118. if(pullUpAction && $.isFunction(pullUpAction)) {
  119. pullUpAction(data);
  120. updatePullUpText(scroller,data);
  121. }
  122. })
  123. }, pullUp: false});
  124. return scroller;
  125. },
  126. // 获取分页搜索返回的最后一条记录的id
  127. getLastId = function(data) {
  128. var lastObj = data.list && data.list.length && data.list[data.list.length-1];
  129. // 最后一条记录
  130. if(lastObj) {
  131. return lastObj.id;
  132. } else {
  133. return null
  134. }
  135. },
  136. // 更新分页上拉加载的提示文本
  137. updatePullUpText= function(scroller,data) {
  138. var $wrap = $(scroller.wrapper),
  139. $pullupLabel = $wrap.find('.pullUpLabel');
  140. if(data.isLast) {
  141. $pullupLabel.text('没有更多');
  142. } else {
  143. $pullupLabel.text('上拉加载更多');
  144. }
  145. scroller.on('refresh',function() {
  146. if(data.isLast) {
  147. $pullupLabel.text('没有更多');
  148. } else {
  149. $pullupLabel.text('上拉加载更多');
  150. }
  151. });
  152. },
  153. initPage = function() {
  154. plus.nativeUI.showWaiting();
  155. $undoViewList.empty();
  156. $doingViewList.empty();
  157. $endViewList.empty();
  158. var reqUrl = [{url: "doctor/consult/list",data: { id:0, pagesize: pagesize,type:10 }}];//我咨询的
  159. if(docInfo.isFamous==1){//是名医,则显示“咨询我的”模块
  160. reqUrl.push({url: "doctor/consult/list",data: { id:0, pagesize: pagesize,type:5 }}); // 咨询我的
  161. }
  162. getReqPromises(reqUrl).then(function(datas) {
  163. var doingData = datas[0] || [],
  164. undoData = datas[1] || [];
  165. //我咨询的
  166. doingLastId = getLastId(doingData) || doingLastId;
  167. searchDoingByPaging();
  168. initDoingViewList(doingData);
  169. updatePullUpText(doingIscroller, doingData);
  170. doingIscroller.refresh();
  171. //咨询我的
  172. if(docInfo.isFamous==1){
  173. undoLastId = getLastId(undoData) || undoLastId;
  174. searchUndoByPaging();
  175. initUndoViewList(undoData);
  176. updatePullUpText(undoIscroller, undoData);
  177. undoIscroller.refresh();
  178. }
  179. var $active = $queryTab.find(".tab-item.curr").eq(0);
  180. if(activeItem==1){
  181. $active.removeClass("curr");
  182. $active = $queryTab.find(".tab-item").eq(activeItem);
  183. $active.addClass("curr");
  184. }
  185. if($active) {
  186. $active.trigger('click');
  187. activeItem = null;
  188. }
  189. plus.nativeUI.closeWaiting();
  190. });
  191. },
  192. // 绑定页面事件
  193. bindEvents = function () {
  194. $("#zxmy_btn").on("tap", function() {
  195. openWebview("../../mygl/html/zixun-xuanzeyisheng.html");
  196. });
  197. $queryTab.on('click','.tab-item',function() {
  198. var type = $(this).attr('data-type'),
  199. $activeView = $('#'+type),
  200. isNotEmpty = !!$activeView.find('li[data-consult]').length;
  201. if(type=="doing_view"){//我咨询的,则隐藏搜索按钮
  202. if(docInfo.isFamous==1){
  203. $("#doing_wrapper").css("top","137px")
  204. }else{
  205. $("#doing_wrapper").css("top","95px")
  206. }
  207. }else{
  208. $("#undo_wrapper").css("top","137px")
  209. }
  210. $queryTab.find('.tab-item').removeClass('curr');
  211. $views.hide();
  212. $(this).addClass('curr');
  213. if(isNotEmpty) {
  214. $noResultWrap.hide();
  215. $('#'+type).show();
  216. $('#'+type).removeClass('c-vis-none');
  217. $(".searchbar").show();
  218. } else {
  219. $noResultWrap.show();
  220. $(".searchbar").hide();
  221. }
  222. });
  223. $searchbar.on('click',function() {
  224. var activeType = $("#query_tab .tab-item.curr").attr("data-type")=="undo_view"?"1":"2";//1为咨询我的 2为我咨询的
  225. openWebview("sousuozixun.html",{type: activeType});
  226. });
  227. $views.on('click','li',function() {
  228. var $this = $(this),
  229. consult = $this.attr('data-consult'),
  230. code = $this.attr('data-code'),//咨询者的code
  231. name = $this.attr('data-name'),
  232. photo = $this.attr('data-photo'),
  233. sex = $this.attr('data-sex'),
  234. type = $this.attr('data-type'),
  235. doctor = $this.attr('data-doctor'),//被咨询者的code
  236. // (咨询状态(0进行中,1已完成,-1患者取消)
  237. status = $this.attr('data-status');
  238. if(status == "1") {
  239. // flagZx 是为了跳转至咨询详情页面控制聊天对话框的显示
  240. plus.storage.setItem("flagZx","4");
  241. } else {
  242. plus.storage.setItem("flagZx","");
  243. }
  244. var activeItemId = $this.closest(".c-view").attr("id");
  245. mui.openWindow({
  246. id: "p2p",
  247. url: "../../message/html/p2p.html",
  248. extras: {
  249. otherCode: code,
  250. otherName: name,
  251. otherPhoto: photo,
  252. otherSex: sex
  253. }
  254. })
  255. });
  256. window.addEventListener("refresh", function(){
  257. initPage();
  258. });
  259. };
  260. // 页面业务处理流程开始
  261. new Promise(function(resolve, reject) {
  262. // TODO 临时放开
  263. //resolve(true);
  264. mui.plusReady(function() {
  265. // plus已经准备好,可以往下执行
  266. resolve(true);
  267. });
  268. }).then(function() {
  269. // 获取基础环境信息
  270. return getBaseEnvPromise().then(function(env) {
  271. baseEnv = env;
  272. }).then(function() {
  273. // 获取登录医生信息
  274. loginerInfo = getLoginerInfo();
  275. initPage();
  276. $queryTab.find('.tab-item').eq(0).click();
  277. // 绑定页面事件
  278. bindEvents();
  279. })
  280. }).catch(function(e) {
  281. plus.nativeUI.closeWaiting();
  282. console && console.error(e);
  283. });
  284. window.addEventListener("activeItem", function(e) {
  285. activeItem = 1;
  286. initPage();
  287. });
  288. template.helper("setPhoto", function(p) {
  289. return getImgUrl(p);
  290. });