daifenpei.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. var baseInfo = null, // 基本信息(包括userAgent)
  2. baseEnv = null;
  3. var $queryTab = $("#query_tab");
  4. var $views = $('.c-view');
  5. var $undoView = $('#undo_view');
  6. var $undoViewList = $undoView.find('#dest_list');
  7. var $sendCount = $("#sendCount"); //发送人的数量
  8. var $dest_list = $('#dest_list');
  9. var ServiceName = ''; //服务站的名字
  10. var $no_result_wrap = $('#no_result_wrap');
  11. var $doing_view = $('#doing_view')//获取待分配列表的id
  12. var self,
  13. docCode,
  14. level,
  15. type,
  16. teamCode,
  17. groupId,
  18. groupData = '',
  19. allOrder,
  20. sendCount = 0, //记录发送的数量
  21. ArRR = [],
  22. allpData=[],
  23. allpCode=[],
  24. cd,
  25. Arr = []; //创建一个空数组来接 服务站返回的数组
  26. // 获取登陆者信息
  27. var getBaseInfo = function() {
  28. var userAgent = JSON.parse(plus.storage.getItem("userAgent"));
  29. self = plus.webview.currentWebview();
  30. docCode = self.docCode;
  31. level = self.level;
  32. type = self.type;
  33. teamCode = self.teamCode;
  34. console.log(teamCode);
  35. return {
  36. userAgent: userAgent,
  37. teamInfo: JSON.parse(plus.storage.getItem("teamInfo"))
  38. }
  39. },
  40. // 获取基础环境信息
  41. getBaseEnvPromise = function() {
  42. var env = {
  43. webview: plus && plus.webview.currentWebview()
  44. };
  45. return Promise.resolve().then(function(res) {
  46. return env;
  47. });
  48. },
  49. // 初始化待分配分组列表
  50. //获取服务站列表url:GET /doctor/prescriptionInfo/getHospitalListTitle
  51. initPatientGroupsList = function() {
  52. plus.nativeUI.closeWaiting();
  53. teamCode = self.teamCode;
  54. console.log(teamCode);
  55. var Url = 'doctor/prescriptionInfo/getHospitalListTitle';
  56. sendGet(Url, { teamCode: teamCode }, null, function(res) {
  57. if(res.status == 200) {
  58. console.log(res);
  59. groupData = res.data; //储存的服务站
  60. var html = template("groups_tmpl", { list: groupData });
  61. $('#groupList').empty().append(html);
  62. countHeight(groupData);
  63. changeServiceNum($('#groupList').find('li').eq(0));
  64. _.map(groupData, function(item) {
  65. Arr.push(item.hospitalCode);
  66. return Arr;
  67. })
  68. }
  69. })
  70. },
  71. //弹窗自适应高度
  72. countHeight = function(data) {
  73. var num = data.length;
  74. if(num > 5) {
  75. $('#sheet3_area').css('height', '276px');
  76. } else {
  77. $('#sheet3_area').css('height', 46 * (num + 1));
  78. }
  79. },
  80. changeServiceNum = function(obj) {
  81. // var ServiceNum;
  82. groupId = obj.data('id'); //储存的服务站位置
  83. $('#ServiceName').text(obj.find('a').text());
  84. if(groupId > 0) {
  85. // 先清空数组 再push
  86. allpCode = [];
  87. var _Url = 'doctor/prescriptionInfo/getDoctorPrescriptionExpressage';
  88. var str = Arr[groupId - 1];
  89. sendGet(_Url, { teamCode: teamCode, hospital: str, dispensaryType: 3, allocationType: 1 }, null, function(res) {
  90. if(res.status == 200) {
  91. console.log(res);
  92. ArRR = res.data;
  93. console.log(ArRR);
  94. _.map(ArRR,function(item){
  95. return allpCode.push(item.code);
  96. })
  97. cd = res.data.length;
  98. $('#OrderNum').text(cd);
  99. var html = template("num_tmpl", { data: cd });
  100. $('#numList').empty().append(html);
  101. changeOrderNum($('#numList').find('li').eq(0));
  102. //获取 订单的 code 为下一个页面确定传参;
  103. }
  104. })
  105. } else {
  106. var uRl = 'doctor/prescriptionInfo/getDoctorPrescriptionExpressage';
  107. sendGet(uRl, { teamCode: teamCode, dispensaryType: 3, allocationType: 1}, null, function(res) {
  108. if(res.status == 200) {
  109. console.log(res);
  110. ArRR = res.data;
  111. console.log(ArRR);
  112. _.map(ArRR,function(item){
  113. return allpCode.push(item.code)
  114. })
  115. cd = res.data.length;
  116. $('#OrderNum').text(cd);
  117. var html = template("num_tmpl", {data: cd});
  118. $('#numList').empty().append(html);
  119. changeOrderNum($('#numList').find('li').eq(0)); //取订单初始值
  120. }
  121. })
  122. }
  123. },
  124. changeOrderNum = function(obj) {
  125. sendCount = obj.data('num');
  126. $sendCount.text(sendCount); //发送订单数
  127. if(sendCount > 0) {
  128. $('#sendBtn').addClass('active'); //变色
  129. } else {
  130. $('#sendBtn').removeClass('active');
  131. }
  132. },
  133. // 待分配 列表的 循环遍历
  134. chackVal = function() {
  135. var uRl = 'doctor/prescriptionInfo/getDoctorPrescriptionExpressage';
  136. sendGet(uRl, { teamCode: teamCode, dispensaryType: 3, allocationType: 1 }, null, function(res) {
  137. if(res.status == 200) {
  138. console.log(res);
  139. var data = res.data
  140. if(data.length == 0) {
  141. $no_result_wrap.removeClass('c-hide');
  142. }
  143. if(data.length && data.length > 0) {
  144. var html = template('wait_list_temp', { list: data });
  145. $dest_list.empty().append(html);
  146. }
  147. }
  148. })
  149. },
  150. // 绑定页面事件
  151. bindEvents = function() {
  152. //tab切换事件
  153. // ul 里面li 的点击事件 (待分配列表的点击)
  154. $doing_view.on('click', 'li', function() {
  155. var $this = $(this),
  156. codep = $this.attr("data-pcode");
  157. console.log(codep);
  158. console.log(teamCode);
  159. mui.openWindow({
  160. id: "dingdangenzong",
  161. url: "dingdangenzong.html",
  162. extras: {
  163. prescriptionCode:codep,
  164. teamCode : teamCode
  165. }
  166. })
  167. });
  168. $queryTab.on('click', '.tab-item', function() {
  169. var type = $(this).attr('data-type'),
  170. $activeView = $('#' + type);
  171. $queryTab.find('.tab-item').removeClass('curr');
  172. $views.hide();
  173. $(this).addClass('curr');
  174. $activeView.show();
  175. chackVal();
  176. });
  177. $('#groupList').on('click', '.j-choose-name', function() {
  178. var $this = $(this);
  179. changeServiceNum($this);
  180. mui('#sheet3').popover('toggle');
  181. })
  182. $('#numList').on('click', '.j-choose-name', function() {
  183. var $this = $(this);
  184. changeOrderNum($this);
  185. mui('#sheet4').popover('toggle');
  186. })
  187. //为点击点击下一步 的订单 增加点击事件
  188. $("#sendBtn").on('click', function() {
  189. console.log(cd);
  190. if (cd!=0) {
  191. to_next();
  192. }
  193. })
  194. // 点击下一步 打开新页面 传递参数
  195. function to_next() {
  196. console.log(allpCode);
  197. mui.openWindow({
  198. id: "Distribution.html",
  199. url: "Distribution.html",
  200. extras: {
  201. team_id: teamCode,
  202. codes:allpCode
  203. }
  204. })
  205. }
  206. }
  207. //返回刷新
  208. function backParent(){
  209. var old_back = mui.back;
  210. mui.back = function() {
  211. if(self.opener()){
  212. mui.fire(self.opener(), "refreshPage");
  213. }
  214. old_back();
  215. }
  216. }
  217. new Promise(function(resolve, reject) {
  218. mui.plusReady(function() {
  219. resolve(true);
  220. });
  221. }).then(function() {
  222. // 获取基础环境信息
  223. return getBaseEnvPromise().then(function(env) {
  224. baseEnv = env;
  225. }).then(function() {
  226. // 获取登录基本信息
  227. baseInfo = getBaseInfo();
  228. // 绑定页面事件
  229. bindEvents();
  230. // initTeams();
  231. // 刷新事件
  232. backParent();
  233. initPatientGroupsList();
  234. })
  235. }).catch(function(e) {
  236. plus.nativeUI.closeWaiting();
  237. console && console.error(e);
  238. })
  239. window.addEventListener('refresh', function(e){//执行刷新
  240. plus.webview.getWebviewById("daifenpei").reload(true);
  241. })