dingdangenzong.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. var $drugsInfo = $('#drugsInfo'),
  2. $logs = $('#logs'),
  3. $receiveInfo = $('#receiveInfo'),
  4. $orderRecord = $('#orderRecord'),
  5. $xufangRecord = $('#xufangRecord'),
  6. $drugTakingQrCode = $('#drugTakingQrCode');
  7. var docInfo = {};
  8. // 医生角色: 3 健管师;2 全科医生
  9. var level;
  10. // 是否是团队长
  11. var isLeader;
  12. var hospital;
  13. var picker;
  14. //取药类型:1 自取 2快递配送 3健管师配送
  15. var dispensaryDispensaryType;
  16. var dispensaryDispensaryTypeName;
  17. //状态 (-3 支付过期 -2 患者自己取消 -1 审核不通过 , 0 待审核, 2调整中 10 审核通过/开方中 , 20开方完成/待支付, 21 支付失败 , 30 支付成功/待配药 , 40配药成功/待配送 41配送失败 42配送中 43配送到服务站 100配送到患者手中/已完成)
  18. //(-3 支付过期 -2 患者自己取消 )续方取消, -1 审核不通过 ,(0 待审核, 2调整中,3调整成功, 4调整失败 ,10 医生审核(CA)通过)审核中,
  19. // 20药师审核中,21.药师审核失败,30 开方中/药师审核成功,31.开方失败/预结算失败,(40开方完成/待支付 ,41 支付失败 )待支付,
  20. // 50 支付成功/待配药,(60配药成功/待配送)等待领药,(61配送失败62分配健管师 65配送中,69配送到服务站)配送中,(100配送到患者手中/已完成)已完成
  21. var prescriptionStatus;
  22. var prescriptionExpressage;
  23. var prescriptionCode = '';
  24. var teamCode = '';
  25. // 订单所属团队团队长code
  26. var leadCode = '';
  27. var isShowQuYaoCode;
  28. // 续方订单(健管师)选择类型:需跟踪订单、已接收订单、团队(team),当前只有team值
  29. var selectType="";
  30. mui.plusReady(function() {
  31. var cur = plus.webview.currentWebview(),
  32. opener = cur.opener();
  33. var oldBack = mui.back;
  34. if(opener.id == "shurushuzima") {
  35. mui.back = backToWebviewById("home2.html")
  36. } else {
  37. mui.back = function() {
  38. mui.fire(opener, 'refresh');
  39. mui.fire(opener, 'refreshPage');
  40. oldBack();
  41. }
  42. }
  43. docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  44. level = docInfo.level;
  45. hospital = docInfo.hospital || plus.storage.getItem("hospital");
  46. isLeader = docInfo.isLeader;
  47. var self = plus.webview.currentWebview();
  48. prescriptionCode = self.prescriptionCode;
  49. teamCode = self.teamCode;
  50. isShowQuYaoCode = self.isShowQuYaoCode;
  51. selectType = self.selectType;
  52. pageInit();
  53. })
  54. template.helper('setStatusName',function(o){
  55. if(o == '续方申请通过'){ return '<span style="color:#18d5c5">续方申请通过</span>' }
  56. if(o == ' 订单已支付'){ return '<span style="color:#06bf04">订单已支付</span>' }
  57. if(o == '配药完成'){ return '<span style="color:#ffa54d">配药完成</span>' }
  58. if(o == '配送中 '){ return '<span style="color:#ff6a56">配送中</span>' }
  59. if(o == '药品到达服务站'){ return '<span style="color:#db6bbd">药品到达服务站</span>' }
  60. if(o == '续方完成'){ return '<span style="color:#17b3ec">续方完成</span>' }
  61. })
  62. function getPrescriptionFollowPromise() {
  63. return getReqPromise("doctor/prescriptionInfo/prescriptionFollow", {
  64. prescriptionCode: prescriptionCode // 处方code
  65. }, 'GET')
  66. }
  67. function getTeamsPromise() {
  68. return getReqPromise("doctor/admin-teams/teams/" + hospital+'/noTranslateAdminTeamLeaderName', {}, 'GET')
  69. }
  70. function getJGMembersPromise(teamId) {
  71. return getReqPromise("doctor/admin-teams/" + teamId + "/jgsmembers", {}, 'GET')
  72. }
  73. function getOrderFollowPromise() {
  74. return getReqPromise("doctor/prescriptionlog/orderFollow", {
  75. prescriptionCode: prescriptionCode // 处方code
  76. }, 'GET')
  77. }
  78. function expressageJGSPromise() {
  79. var $senderSelect = $('#senderSelect');
  80. var name = $senderSelect.text(),
  81. code = $senderSelect.attr('data-code'),
  82. mobile = $senderSelect.attr('data-mobile')
  83. return getReqPromise("doctor/prescription/expressage/expressageJGS", {
  84. code: code,
  85. name : name,
  86. mobile: mobile,
  87. prescriptionCode: prescriptionCode
  88. }, 'POST')
  89. }
  90. function showJGInfo() {
  91. showReceiveDrugsInfoForJG(
  92. $.extend({},prescriptionExpressage,{
  93. dispensaryDispensaryTypeName: dispensaryDispensaryTypeName
  94. }));
  95. $('.jg-info').show();
  96. if(isShowQuYaoCode) { // 需跟踪订单
  97. $drugTakingQrCode.closest('ul').show();
  98. } else {
  99. $drugTakingQrCode.closest('ul').hide();
  100. }
  101. if(prescriptionStatus > 61 && prescriptionStatus < 69 && selectType != 'team') { // (61配送失败62分配健管师 65配送中,69配送到服务站)配送中
  102. $('#confirmBtn').show()
  103. }
  104. if(prescriptionStatus == 69 && prescriptionExpressage.patientHospitalCode == prescriptionExpressage.acceptHospital && selectType != 'team') {
  105. $('#quyaoBtn').show();
  106. }
  107. }
  108. function showQKInfo() {
  109. showReceiveDrugsInfoForQK(
  110. $.extend({},prescriptionExpressage,{
  111. dispensaryDispensaryTypeName: dispensaryDispensaryTypeName
  112. }));
  113. if( level==2 && (isLeader && leadCode == docInfo.code) // 医生为当前团队团队长
  114. && dispensaryDispensaryType == 3 // 健管师配送
  115. && (prescriptionStatus == "50" || prescriptionStatus == "60") // 等待领药(待分配)
  116. && !prescriptionExpressage.expressageName // 还未分配配送员
  117. ) {
  118. getTeamsPromise().then(function(res) {
  119. initPicker(res)
  120. })
  121. } else {
  122. $('#senderLi').hide();
  123. $('#ok_btn').hide();
  124. }
  125. $('.qk-info').show()
  126. }
  127. // 显示订单记录
  128. function showOrderRecord(data) {
  129. var html = template('record_tmpl',data);
  130. $orderRecord.html(html)
  131. }
  132. // 显示药品信息
  133. function showDrugsInfo(drugs) {
  134. var html = template('drug_tmpl',{list: drugs});
  135. $drugsInfo.html(html)
  136. }
  137. // 显示订单跟踪
  138. function showLogsInfo(logs) {
  139. if(logs && logs.length) {
  140. var html = template('log_tmpl',{list: logs});
  141. $logs.html(html)
  142. } else {
  143. $logs.text("暂无信息")
  144. }
  145. }
  146. // 显示收药信息(全科医生)
  147. function showReceiveDrugsInfoForQK(data) {
  148. var html = ""
  149. if(dispensaryDispensaryType == 3) { // 健管师配送
  150. if(prescriptionStatus >= 50 && prescriptionStatus <= 60 && !data.expressageName) { //50 支付成功/待配药,(60配药成功/待配送)等待领药
  151. html = template('unassigned_tmpl',data)
  152. } else {
  153. html = template('qk_delivery_tmpl',data)
  154. }
  155. } else {
  156. if(dispensaryDispensaryType == 1) {
  157. html = template('personal_tmpl',data)
  158. } else if(dispensaryDispensaryType == 2){
  159. html = template('delivery_tmpl',data)
  160. }
  161. }
  162. $receiveInfo.html(html)
  163. }
  164. // 显示收药信息(健管师)
  165. function showReceiveDrugsInfoForJG(data) {
  166. var html = ""
  167. if(dispensaryDispensaryType == 3) { // 健管师配送
  168. html = template('jgs_delivery_tmpl',data)
  169. } else {
  170. if(dispensaryDispensaryType == 1) {
  171. html = template('personal_tmpl',data)
  172. } else if(dispensaryDispensaryType == 2){
  173. html = template('delivery_tmpl',data)
  174. }
  175. }
  176. $receiveInfo.html(html)
  177. }
  178. function initPicker(res) {
  179. var data = res.data;
  180. picker = new mui.PopPicker({
  181. layer: 2,
  182. layerNames: ["所属团队","健管师"]
  183. });
  184. var teams = _.map(data, function(v) {
  185. return {
  186. value: v.id + '',
  187. text: v.name
  188. }
  189. });
  190. teams = [{value:'',text:' ',mobile: ''}].concat(teams)
  191. picker.setData(teams)
  192. //picker.pickers[0].setSelectedIndex(1);
  193. //picker.pickers[1].setSelectedIndex(1);
  194. $(picker.pickers[0].holder).on('change', function(event) {
  195. var eventData = event.originalEvent.detail || {},
  196. item = eventData.item;
  197. if(!item.value) {
  198. return ;
  199. }
  200. getJGMembersPromise(item.value).then(function(res) {
  201. picker.pickers[1].setItems(_.map(res.data, function(v) {
  202. return {
  203. value: v.code + '',
  204. text: v.name,
  205. mobile: v.mobile
  206. }
  207. }))
  208. }).catch(function(e) {
  209. console && console.error(e)
  210. })
  211. })
  212. }
  213. function bindEvents() {
  214. $xufangRecord.on('click',function(){
  215. openWebview("xufangxiangqing.html",{
  216. teamCode: teamCode,
  217. prescriptionCode: prescriptionCode
  218. })
  219. })
  220. $drugTakingQrCode.on('click',function(){
  221. openWebview("quyaoma.html",{
  222. teamCode: teamCode,
  223. prescriptionCode: prescriptionCode
  224. })
  225. })
  226. $(document.body).on("click",'#ok_btn',function() {
  227. var $senderSelect = $('#senderSelect');
  228. var name = $senderSelect.text()
  229. if(name) {
  230. expressageJGSPromise().then(function(res) {
  231. if(res.status == 200) {
  232. mui.toast("分配成功!");
  233. pageRefresh();
  234. } else {
  235. mui.toast(res.msg);
  236. }
  237. }).catch(function(e) {
  238. console && console.error(e)
  239. })
  240. } else {
  241. mui.toast("请选择配送人员");
  242. }
  243. }).on('click', '#senderSelect', function() {
  244. picker.show(function(selected) {
  245. var $senderSelect = $('#senderSelect');
  246. $senderSelect.text(selected[1].text);
  247. $senderSelect.attr('data-code',selected[1].value);
  248. $senderSelect.attr('data-mobile',selected[1].mobile);
  249. })
  250. }).on('click','li[data-milno]',function() {
  251. var milno = $(this).attr('data-milno');
  252. openWebview("express-info.html",{
  253. prescriptionCode: prescriptionCode
  254. })
  255. }).on('click', '#confirmBtn', function() {
  256. openWebview("peisongma.html",{
  257. prescriptionCode: prescriptionCode
  258. })
  259. }).on('click', '#quyaoBtn', function() {
  260. openWebview("querensongda.html",{
  261. prescriptionCode: prescriptionCode
  262. })
  263. })
  264. }
  265. function pageInit() {
  266. pageRefresh();
  267. bindEvents();
  268. }
  269. function pageRefresh() {
  270. getPrescriptionFollowPromise().then(function(res) {
  271. var data;
  272. if(res.status == 200) {
  273. data = res.data;
  274. prescriptionStatus = data.prescriptionStatus;
  275. dispensaryDispensaryType = data.dispensaryDispensaryType;
  276. dispensaryDispensaryTypeName = data.dispensaryDispensaryTypeName;
  277. prescriptionExpressage = data.prescriptionExpressage;
  278. leadCode = data.leadCode;
  279. showOrderRecord({
  280. payNum: (data.prescriptionExpressage && data.prescriptionExpressage.code) || "",
  281. prescriptionHospital: data.prescriptionHospital||"",
  282. prescriptionStatusName: data.prescriptionStatusName||""
  283. })
  284. showDrugsInfo(data.prescriptionInfos)
  285. if(level == 3) {
  286. showJGInfo()
  287. } else if(level == 2) {
  288. showQKInfo()
  289. }
  290. } else {
  291. mui.toast(res.msg);
  292. }
  293. }).catch(function(e) {
  294. console && console.error(e)
  295. })
  296. getOrderFollowPromise().then(function(res) {
  297. if(res.status == 200) {
  298. showLogsInfo(res.data)
  299. }
  300. }).catch(function(e) {
  301. console && console.error(e)
  302. })
  303. }
  304. /*刷新事件*/
  305. window.addEventListener("updateOrderStatus", function refresh(e) {
  306. pageRefresh();
  307. });