zixun-xuanzeyisheng.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. // 基本信息(包括userAgent、上个页面传递的数据)
  2. var baseInfo = null,
  3. // 基础环境信息(包括当前webview)
  4. baseEnv = null;
  5. var $doctorListWrapper = $('#doctor_list_wrap'),
  6. $doctorList = $('#doctor_list'),
  7. // 搜索无结果时显示
  8. $noResultWrap = $('#no_result_wrap');
  9. // 分页查询当前页数
  10. var curPage = 1,
  11. // iscroll 滚动条实例
  12. iscroller;
  13. // 获取基本信息(包括userAgent、上个页面传递的数据)
  14. var getBaseInfoPromise = function() {
  15. // 登录的相关信息
  16. var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"))
  17. return {
  18. userAgent: userAgent
  19. }
  20. },
  21. // 获取基础环境信息
  22. getBaseEnvPromise = function () {
  23. var env = {
  24. webview: plus&&plus.webview.currentWebview()
  25. };
  26. return Promise.resolve().then(function(res) {
  27. return env;
  28. });
  29. },
  30. ellipsisText = function ($el) {
  31. $el.ellipsis({ row: 2 });
  32. },
  33. // 初始化医生列表
  34. initDoctorList = function(data) {
  35. var list = _.filter(data.list,function(d) {
  36. return d.code != baseInfo.userAgent.uid
  37. });
  38. var html = template("yisheng_li_tmpl", {list: list})
  39. $doctorList.empty().append(html);
  40. ellipsisText($doctorList.find('.c-dest-content'))
  41. },
  42. // 分页查询列表
  43. searchByPaging = function () {
  44. // TODO 示例示例搜索参数
  45. // id: 上次搜索结果列表最后一条记录id,type:1(1:名医,0:非名医,key:搜素关键字,pagesize:每页条数
  46. var url = "doctor/consult/famousDoctorList",
  47. params = { type:1,page:curPage,pagesize:15};
  48. plus.nativeUI.showWaiting();
  49. getReqPromise(url,params,'POST',true).then(function(res){
  50. var data = res;
  51. plus.nativeUI.closeWaiting();
  52. if(!data.list || !data.list.length) {
  53. $doctorListWrapper.hide();
  54. $noResultWrap.show();
  55. } else {
  56. $noResultWrap.hide();
  57. $doctorListWrapper.show();
  58. initDoctorList(data);
  59. }
  60. }).catch(function(e) {
  61. plus.nativeUI.closeWaiting();
  62. console && console.error(e)
  63. });
  64. },
  65. // 滚动条分页实例初始化
  66. initScroller = function() {
  67. //阻尼系数
  68. var deceleration = mui.os.ios?0.003:0.0009;
  69. mui('.mui-scroll-wrapper').scroll({
  70. bounce: false,
  71. indicators: true, //是否显示滚动条
  72. deceleration:deceleration
  73. });
  74. mui(".mui-scroll").pullToRefresh({
  75. down: {
  76. callback: function() {
  77. var self = this;
  78. setTimeout(function() {
  79. searchByPaging();
  80. self.endPullDownToRefresh();
  81. }, 1000);
  82. }
  83. }
  84. });
  85. },
  86. // 绑定页面事件
  87. bindEvents = function () {
  88. $doctorList.on('tap','.list-item .c-list',function() {
  89. var code = $(this).closest("li").attr('data-code')||"";
  90. mui.openWindow({
  91. url: "zixun-doctor-homepage.html",
  92. id:"zixun-doctor-homepage",
  93. // 跳转页面传参
  94. extras: {
  95. accessData:{ // 传递数据
  96. doctor: code
  97. }
  98. }
  99. });
  100. return false;
  101. });
  102. var doctorData = null;
  103. $doctorList.on("tap",".list-item .div-lijizixun-btn",function(){
  104. var $li = $(this).closest("li");
  105. var doctorCode = $li.attr("data-code");
  106. var docName = $li.attr("data-name");
  107. service.hasUnfinishedConsult(doctorCode, function(res){
  108. if(res.data.consult){
  109. mui.confirm("您与"+ docName +"医生当前有进行中咨询,不可发起求助,您可直接进入咨询提问",
  110. "提示", ["查看咨询", "我知道了"], function(e){
  111. if(e.index==0){
  112. var wv = mui.openWindow({
  113. url:"../../message/html/p2p.html",
  114. id: "p2p",
  115. extras: {
  116. otherCode: doctorCode,
  117. otherName: docName,
  118. otherSex: $li.attr('data-sex'),
  119. otherPhoto: $li.attr('data-photo'),
  120. consultData: res.data
  121. }
  122. })
  123. }
  124. })
  125. } else
  126. checkWorking(doctorCode)
  127. })
  128. return false;
  129. })
  130. function checkWorking(doctorCode){
  131. var url1 = server+"/doctor/work_scheduling/is_doctor_working";
  132. var data1={doctor:doctorCode};
  133. var url2 = server+"/doctor/baseinfo";
  134. var data2={code:doctorCode};
  135. promise = getReqPromises([{url:url1,data:data1},{url:url2,data:data2}])
  136. return promise.then(function(datas){
  137. var isWorkData = datas[0].data.status,
  138. doctorData = datas[1];
  139. if(isWorkData=="0"){//0:医生不接受咨询 1:医生接受咨询 2:医生当前不在工作时间
  140. dialog({
  141. content: '对不起,该医生已暂停接受咨询,您可选择其他医生进行咨询',
  142. cancelValue: '我知道了',
  143. cancel: function () {
  144. return;
  145. }
  146. }).showModal();
  147. return false;
  148. }else if(isWorkData=="1"){
  149. openWebview("faqizixun.html",{accessData: $.extend({},doctorData.data,{doctor:doctorCode})});
  150. }else if(isWorkData=="2"){
  151. dialog({
  152. content: '医生不在工作时间内哦,请在医生咨询计划时间段内咨询',
  153. cancelValue: '我知道了',
  154. cancel: function () {
  155. return;
  156. }
  157. }).showModal();
  158. }
  159. })
  160. }
  161. /*刷新事件*/
  162. window.addEventListener("refreshPage", function group(e) {
  163. $doctorList.empty();
  164. curPage = 1;
  165. searchByPaging();
  166. });
  167. };
  168. // 页面业务处理流程开始
  169. new Promise(function(resolve, reject) {
  170. // TODO 临时放开
  171. //resolve(true);
  172. mui.plusReady(function() {
  173. // plus已经准备好,可以往下执行
  174. resolve(true);
  175. });
  176. }).then(function() {
  177. // 获取基础环境信息
  178. return getBaseEnvPromise().then(function(env) {
  179. baseEnv = env;
  180. }).then(function() {
  181. // 获取登录医生信息
  182. baseInfo = getBaseInfoPromise();
  183. searchByPaging();
  184. initScroller();
  185. // 绑定页面事件
  186. bindEvents();
  187. })
  188. }).catch(function(e) {
  189. console && console.error(e);
  190. });
  191. template.helper("setPhoto", function(p) {
  192. return getImgUrl(p);
  193. });