gongzuoshezhi.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. // TODO 临时构造plus对象,使得能够在浏览器中进行调试
  2. //var plus = null;
  3. // 登录者相关信息(包括userAgent)
  4. var loginerInfo = null,
  5. // 基础环境信息(包括当前webview)
  6. baseEnv = null;
  7. // 关闭重新登录检查(防止一个ajax error导致所有请求成功无法回调)
  8. var checkReload = false;
  9. // var isInit = true;
  10. var $switchWrap = $('#switch_wrap'),
  11. $numSettingWrap = $('#num_setting_wrap'),
  12. $timeSettingWrap = $('#time_setting_wrap'),
  13. $numSettingSelector = $numSettingWrap.find('.mobi-selector'),
  14. $switch = $('#zixunSwitch'),
  15. $acceptZiXun = $('#accept_zixun'),
  16. $worktimeCell = $("#worktime_cell"),
  17. $unsetTip = $('#unset_tip');
  18. // 获取登录相关信息
  19. var getLoginerInfo = function() {
  20. // 登录的相关信息
  21. var userAgent = JSON.parse(plus.storage.getItem("userAgent")),
  22. // 登录的医生类别
  23. docType = plus.storage.getItem("docType"),
  24. // 登录的医生信息
  25. docInfo= JSON.parse(plus.storage.getItem("docInfo")),
  26. // 该医生(登录者)所在社区(机构)编码
  27. hospital = plus.storage.getItem("hospital");
  28. return {
  29. userAgent: userAgent,
  30. docInfo: $.extend(docInfo,{docType:docType},{hospital: hospital})
  31. }
  32. },
  33. // 获取基础环境信息
  34. getBaseEnvPromise = function () {
  35. var env = {
  36. webview: plus&&plus.webview.currentWebview()
  37. };
  38. return Promise.resolve().then(function(res) {
  39. return env;
  40. });
  41. },
  42. // 初始化“接受新的咨询”开关
  43. initSwitch = function() {
  44. mui('#zixunSwitch').switch();
  45. },
  46. // 初始化“居民名医咨询次数”下拉列表
  47. initNumSetting = function() {
  48. var keys = _.range(100),
  49. values = _.map(keys,function(k) {
  50. return k+"次";
  51. });
  52. $numSettingSelector.mobiscroll({
  53. theme: 'ios',
  54. lang: 'zh',
  55. customWheels: true,
  56. wheels: [
  57. [{
  58. keys: keys,
  59. values: values
  60. }]
  61. ],
  62. onSelect: function(valueText, inst) {
  63. var dd = eval("[" + valueText + "]"),
  64. name=dd[0].values,
  65. currExpenses = dd[0].keys;
  66. $(this).val(name);
  67. $numSettingSelector.attr("data-code",currExpenses);
  68. //保存咨询次数
  69. saveConsultTimesSetting(currExpenses);
  70. }
  71. });
  72. },
  73. //页面初始化时,检查当前是否接受咨询
  74. isDoctorWorking = function(doctorid){
  75. var url = server+"doctor/work_scheduling/is_doctor_working?doctor="+doctorid;
  76. getReqPromise(url,null,"GET").then(function(res){
  77. if(res.status == 200) {
  78. var status = res.data.status;
  79. if(status && status != 0){
  80. mui('#zixunSwitch').switch();
  81. }
  82. } else {
  83. console && console.error(res);
  84. }
  85. }).catch(function(e){
  86. console && console.error(e);
  87. });
  88. },
  89. getWorkScheduling = function(){
  90. var url = server+"doctor/work_scheduling/all";
  91. getReqPromise(url,null,"GET").then(function(res){
  92. if(res.status == 200) {
  93. var Time=res.data.workTime//时间
  94. var Weeks=res.data.workWeeks//周安排
  95. //名医咨询次数 默认为0
  96. var famousConsultTimes = Time.famousConsultTimes;
  97. //是否接受咨询,1为接受 0不接受
  98. var receiveConsult = Time.receiveConsult;
  99. if(receiveConsult != 0){
  100. $switch.addClass('mui-active')
  101. mui('#zixunSwitch').switch();
  102. $acceptZiXun.show();
  103. // $numSettingWrap.show();
  104. } else {
  105. $acceptZiXun.hide();
  106. // $numSettingWrap.hide();
  107. }
  108. if(!famousConsultTimes)famousConsultTimes = 0;
  109. if(res.data.doctor.isFamous=="1") {
  110. // 是名医才显示
  111. // $switchWrap.show();
  112. $numSettingWrap.show();
  113. initNumSetting();
  114. var scroll = $numSettingSelector.mobiscroll('getInst');
  115. var valueText = "{keys:'"+famousConsultTimes+"',values:'"+famousConsultTimes + "次"+"'}";
  116. scroll.setVal([valueText]);
  117. $numSettingSelector.val(famousConsultTimes + "次");
  118. $numSettingSelector.attr("data-code",famousConsultTimes);
  119. } else {
  120. $acceptZiXun.show();
  121. $numSettingWrap.hide();
  122. //非名医,只有专科可以这是是否接受咨询
  123. if(res.data.doctor.level == 1){
  124. // $switchWrap.show();
  125. }
  126. }
  127. // 没设置工作时间,则隐藏工作计划表
  128. if(!Time || !(Time.morningBegin || Time.morningEnd || Time.afternoonBegin || Time.afternoonEnd || Time.nightBegin || Time.nightEnd )) {
  129. // $timeSettingWrap.find('.cycworktime').hide();
  130. $unsetTip.show()
  131. $worktimeCell.hide();
  132. } else {
  133. // $timeSettingWrap.find('.cycworktime').show();
  134. $unsetTip.hide()
  135. $worktimeCell.show();
  136. }
  137. if(Time.length!=0){//查询成功有数据
  138. // $($(".work .c-list-value i")[0]).html(Time.morningBegin);
  139. // $($(".work .c-list-value i")[1]).html(Time.morningEnd);
  140. // $($(".work .c-list-value i")[2]).html(Time.afternoonBegin);
  141. // $($(".work .c-list-value i")[3]).html(Time.afternoonEnd);
  142. // $($(".work .c-list-value i")[4]).html(Time.nightBegin);
  143. // $($(".work .c-list-value i")[5]).html(Time.nightEnd);
  144. $.each(Weeks,function(i,v){
  145. var obj=$(".cycworktime tr[data-fl="+v.week+"]");
  146. if(v.morning=="1"){
  147. // obj.find("td[data-type='1']").addClass("on");
  148. obj.find("td[data-type='1']").html(Time.morningBegin+"~"+Time.morningEnd);
  149. }
  150. if(v.afternoon=="1"){
  151. // obj.find("td[data-type='2']").addClass("on");
  152. obj.find("td[data-type='2']").html(Time.afternoonBegin+"~"+Time.afternoonEnd);
  153. }
  154. if(v.night=="1"){
  155. // obj.find("td[data-type='3']").addClass("on");
  156. obj.find("td[data-type='3']").html(Time.nightBegin+"~"+Time.nightEnd);
  157. }
  158. });
  159. }
  160. } else {
  161. console && console.error(res);
  162. }
  163. }).catch(function(e){
  164. console && console.error(e);
  165. });
  166. }
  167. ,
  168. saveConsultTimesSetting = function(consultTimes){
  169. var url = server+"/doctor/work_scheduling/consult_times_setting?consultTimes="+consultTimes;
  170. getReqPromise(url,null,"GET").then(function(res){
  171. if(res.status == 200) {
  172. mui.toast("设置成功");
  173. } else {
  174. mui.toast(""+res.msg);
  175. }
  176. }).catch(function(e){
  177. console && console.error(e);
  178. });
  179. },
  180. // 绑定页面事件
  181. bindEvents = function () {
  182. $switch[0].addEventListener("toggle",function(event){
  183. var url = server+"/doctor/work_scheduling/receive_consult_setting";
  184. var params = {
  185. receiveConsult: event.detail.isActive ? 1 : 0
  186. };
  187. //页面初始化时,不提交到后台。
  188. // if(isInit){
  189. // isInit = false;
  190. // return;
  191. // }
  192. getReqPromise(url,params).then(function(res){
  193. if(res.status == 200) {
  194. $acceptZiXun.toggle(event.detail.isActive);
  195. mui.toast("设置成功");
  196. } else {
  197. mui.toast("设置失败");
  198. console && console.error(res);
  199. }
  200. }).catch(function(e){
  201. console && console.error(e);
  202. });
  203. })
  204. };
  205. // 页面业务处理流程开始
  206. new Promise(function(resolve, reject) {
  207. // TODO 临时放开
  208. //resolve(true);
  209. mui.plusReady(function() {
  210. // plus已经准备好,可以往下执行
  211. resolve(true);
  212. });
  213. }).then(function() {
  214. // 获取基础环境信息
  215. return getBaseEnvPromise().then(function(env) {
  216. baseEnv = env;
  217. }).then(function() {
  218. // TODO 防止因为其它ajax error导致存在isLoginOut标识,所有请求回调无法执行的问题
  219. window.localStorage.removeItem("isLoginOut");
  220. // 获取登录医生信息
  221. loginerInfo = getLoginerInfo();
  222. // TODO Switch需等到plusReady触发之后才能初始化,为了测试所以使用setTimeout延迟执行
  223. //setTimeout(function() {
  224. // initSwitch();
  225. //},0);
  226. // 绑定页面事件
  227. bindEvents();
  228. })
  229. .then(function(){
  230. //读取医生的当前是否接受咨询的设置状态
  231. //var doctorid = loginerInfo.docInfo.code;
  232. //isDoctorWorking(doctorid);
  233. getWorkScheduling();
  234. })
  235. }).catch(function(e) {
  236. plus.nativeUI.closeWaiting();
  237. console && console.error(e);
  238. });