change-chufang2.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. var self,
  2. methodDire,//用药字典
  3. medicineFreqData,//用药频率数据
  4. prescriptionCode,//续方code
  5. diagnosis=[],//疾病
  6. isChangeDiagnosis = 0,//判断是否改变疾病类型
  7. usefulMsg;
  8. mui.plusReady(function() {
  9. self = plus.webview.currentWebview();
  10. usefulMsg = self.jsonStr;
  11. prescriptionCode = usefulMsg.prescriptionCode;//保存续方code
  12. var medi_html = template('medi_tmp',{data:$.map(usefulMsg.prescriptionInfo,function(o,index){
  13. o.jsonVal = JSON.stringify(o);
  14. return o })
  15. })
  16. $("#mainContain").html(medi_html);
  17. startDose();
  18. //展示诊断类型
  19. var diaArr=[]
  20. $.map(usefulMsg.diagnosis,function(item,index){
  21. diaArr.push(item.name)
  22. })
  23. $('#j-sick-choose').html(diaArr.join(','))
  24. function startDose(){
  25. //获取用药频率
  26. sendPost("doctor/prescriptionInfo/getRateList",{}, function(){
  27. mui.toast("获取用药频率数据失败");
  28. }, function(res){
  29. if(res.status == 200){
  30. medicineFreqData = res.data;
  31. addMedicineFreq($('.j-selFreq'),false)
  32. }
  33. },'get')
  34. //获取药品用法
  35. sendPost("doctor/prescriptionInfo/getUsageDict",{}, function(){
  36. mui.toast("获取药品用法数据失败");
  37. }, function(res){
  38. if(res.status == 200){
  39. methodDire = res.data;
  40. }
  41. },'get')
  42. //调整原因
  43. sendPost("doctor/prescriptionInfo/getReasonByType",{type:1}, function(){
  44. mui.toast("请求失败");
  45. }, function(res){
  46. if(res.status = 200){
  47. var str=""
  48. $.map(res.data,function(o,i){
  49. str += '<li data-code="'+o.code+'">'+o.value+'</li>'
  50. })
  51. $('.nopass-list').html(str)
  52. }
  53. },'get')
  54. bindEvents();
  55. addMedicineDate($('.j-selDate'),false)
  56. //添加药品
  57. window.addEventListener("addMedicine", function(){
  58. var content = JSON.parse(plus.storage.getItem("chooseMedicineList"));
  59. var arr=[];
  60. //判断是否重复
  61. var again=false;
  62. for(var i=0;i<$('.j-medi-name').length;i++){
  63. if($('.j-medi-name').eq(i).attr('data-id') == content.drugCode){
  64. again = true;
  65. }
  66. }
  67. if(again){
  68. mui.toast('重复添加药品')
  69. }else{
  70. arr.push(content);
  71. var medi_html = template('medi_tmp',{data:$.map(arr,function(o,index){
  72. o.jsonVal = JSON.stringify(o);
  73. return o })
  74. })
  75. $("#mainContain").append(medi_html);
  76. addMedicineFreq($('.j-selFreq:last'),true)
  77. addMedicineDate($('.j-selDate:last'),true)
  78. }
  79. plus.storage.removeItem("chooseMedicineList")
  80. })
  81. //修改诊断
  82. window.addEventListener("reviseDiagnosis", function(){
  83. var content = JSON.parse(plus.storage.getItem("reviseDiagnosis"));
  84. diagnosis = content;
  85. isChangeDiagnosis = 1;
  86. var diaArr=[]
  87. $.map(content,function(item,index){
  88. diaArr.push(item.name)
  89. })
  90. $('#j-sick-choose').html(diaArr.join(','))
  91. plus.storage.removeItem("reviseDiagnosis")
  92. })
  93. //采用模板
  94. window.addEventListener("chooseTemplate", function(){
  95. var content = JSON.parse(plus.storage.getItem("chooseTemplate"));
  96. content.prescriptionInfo = _.uniq(content.prescriptionInfo)//去重
  97. plus.nativeUI.showWaiting();
  98. //整理药品的数据
  99. var countNum = 1;
  100. var newData=[];
  101. $.map(content.prescriptionInfo,function(o,index){
  102. toMediMsg(o.drugCode,function(msg){
  103. o.subjectClass = msg.subjectClass;
  104. o.storageConditions = msg.storageConditions;
  105. o.physicAmount = '';
  106. o.physicAmountUnit = msg.packUnit;
  107. o.physicAmountUnitName = msg.packUnitName;
  108. o.jsonVal = JSON.stringify(o);
  109. newData.push(o);
  110. if(content.prescriptionInfo.length == countNum){
  111. plus.nativeUI.closeWaiting();
  112. var medi_html = template('medi_tmp',{data:newData})
  113. $("#mainContain").empty().append(medi_html);
  114. addMedicineFreq($('.j-selFreq'),false)
  115. addMedicineDate($('.j-selDate'),false)
  116. plus.storage.removeItem("chooseTemplate")
  117. }else{
  118. countNum++;
  119. }
  120. })
  121. })
  122. })
  123. }
  124. })
  125. function bindEvents(){
  126. var $text_count = $("#text_count");
  127. //文本框
  128. $("textarea").on('keyup', function(){
  129. var count = $(this).val().length;
  130. $text_count.text(count);
  131. })
  132. $("textarea").on('change', function(){
  133. var count = $(this).val().length;
  134. $text_count.text(count);
  135. })
  136. //调整原因
  137. $('.nopass-list').on('click','li',function(){
  138. var $this = $(this)
  139. if($this.hasClass('active')){
  140. $this.removeClass('active')
  141. }else{
  142. $this.addClass('active')
  143. }
  144. fillWord()
  145. })
  146. function fillWord(){
  147. var str=''
  148. $.map($('.nopass-list li.active'),function(o,i){
  149. str += $('.nopass-list li.active').eq(i).text()+',';
  150. })
  151. $('textarea').val(str.substr(0,str.length-1))
  152. $text_count.text(str.length-1);
  153. }
  154. //增减
  155. $("#mainContain").on('click','.add-icon',function(){
  156. var $this = $(this)
  157. var $val = $this.siblings('.j-medi-single').val().trim()
  158. $this.siblings('.j-medi-single').val($val*1+0.25)
  159. countMediSum($(this).closest('.cc-ul'))
  160. })
  161. $("#mainContain").on('click','.desc-icon',function(){
  162. var $this = $(this)
  163. var $val = $this.siblings('.j-medi-single').val().trim()
  164. var num = $val*1-0.25
  165. if(num>=0){
  166. $this.siblings('.j-medi-single').val($val*1-0.25)
  167. }else{
  168. $this.siblings('.j-medi-single').val(0)
  169. }
  170. countMediSum($(this).closest('.cc-ul'))
  171. })
  172. //用法选择
  173. $("#mainContain").on('click','.j-method',function(){
  174. var $this = $(this)
  175. var num = $this.closest('.cc-ul').index()
  176. add_selected_fun(methodDire,$('.j-method').eq(num),'name','code')
  177. })
  178. //删除
  179. $("#medicineType").on('click','.j-delete',function(){
  180. var $this = $(this).closest('.cc-ul');
  181. $this.remove();
  182. })
  183. //添加药品
  184. $('.cc-add-drug').click(function(){
  185. mui.openWindow({
  186. id: "yaopinsousuo",
  187. url: "yaopinsousuo.html",
  188. extras: {
  189. }
  190. })
  191. })
  192. //选择模板
  193. $('.cc-link').click(function(){
  194. mui.openWindow({
  195. id: "chufangmuban",
  196. url: "chufangmuban.html",
  197. extras: {
  198. }
  199. })
  200. })
  201. //修改疾病类型
  202. $('#j-sick-choose').click(function(){
  203. mui.openWindow({
  204. id: "linchuangzhenduan",
  205. url: "linchuangzhenduan.html",
  206. extras: {
  207. diagnosis:isChangeDiagnosis?diagnosis:usefulMsg.diagnosis
  208. }
  209. })
  210. })
  211. //提交
  212. $('#confirm').click(function(){
  213. var $sum = $(".j-sumMedicine");
  214. if($sum.length > 0){
  215. for(var i=0;i<$sum.length;i++){
  216. if(! $sum.eq(i).attr('data-num')){
  217. mui.toast('请完善药品信息')
  218. return
  219. }
  220. }
  221. }else{
  222. mui.toast('请添加药品')
  223. return
  224. }
  225. plus.nativeUI.showWaiting();
  226. var msgArr = [],
  227. $ul = $('.cc-ul');
  228. for(var i=0;i<$ul.length;i++){
  229. var data = {};
  230. var saveData = JSON.parse($ul.eq(i).attr('data-info'));
  231. data.prescriptionCode = prescriptionCode;
  232. data.drugCode = saveData.drugCode;
  233. data.drugName = $ul.eq(i).find('.j-medi-name').val().replace(/\(/,'(').replace(/\)/,')');
  234. data.drugRate = $ul.eq(i).find('.j-selFreq').attr('data-code');
  235. data.drugRateName = $ul.eq(i).find('.j-selFreq').attr('data-name');
  236. data.drugFormat=saveData.drugFormat.replace(/\(/,'(').replace(/\)/,')');
  237. data.subjectClass = $ul.eq(i).find('.j-medi-name').attr('data-class');
  238. data.isRefrigerate = $ul.eq(i).find('.j-medi-name').attr('data-storage')==2?1:0;
  239. data.physicAmount = "";
  240. data.physicAmountUnit = saveData.physicAmountUnit;
  241. data.physicAmountUnitName = saveData.physicAmountUnitName;
  242. data.physicDose = $ul.eq(i).find('.j-medi-single').val().trim();
  243. data.physicDoseUnit = $ul.eq(i).find('.j-medi-unit').attr('data-unit');
  244. data.physicDoseUnitName = $ul.eq(i).find('.j-medi-unit').text();
  245. data.drugNumUnit = $ul.eq(i).find('.j-sumMedicine').attr('data-unit');//取当次用量单位
  246. data.drugNumUnitName = $ul.eq(i).find('.j-sumMedicine').attr('data-name');
  247. data.drugUsage= $ul.eq(i).find('.j-method').attr('data-id');
  248. data.usageName= $ul.eq(i).find('.j-method').val();
  249. data.num= $ul.eq(i).find(".j-sumMedicine").attr('data-num');//取总量
  250. data.dayCount=$ul.eq(i).find('.j-selDate').attr('data-id');
  251. msgArr.push(data);
  252. }
  253. //调整CODE
  254. var reasonCode=[];
  255. $.map($('.nopass-list li.active'),function(o,i){
  256. reasonCode.push($('.nopass-list li.active').eq(i).attr('data-code'))
  257. })
  258. var params= {
  259. code:prescriptionCode,
  260. infos:JSON.stringify(msgArr),
  261. reason:$('textarea').val().trim()?$('textarea').val().trim():'-',
  262. reasonCode:reasonCode.join(','),
  263. diagnosis:isChangeDiagnosis?JSON.stringify(diagnosis):''
  264. }
  265. sendPost("doctor/prescriptionInfo/updatePresInfo",params, function(){
  266. plus.nativeUI.closeWaiting();
  267. mui.toast("保存失败");
  268. }, function(res){
  269. if(res.status == 200){
  270. mui.toast("保存成功");
  271. refreshHz();
  272. setTimeout(function(){
  273. mui.back()
  274. },1000)
  275. }else{
  276. plus.nativeUI.closeWaiting();
  277. mui.toast("保存失败");
  278. }
  279. })
  280. })
  281. //填写药品
  282. $("#mainContain").on("blur",".j-medi-name",function(){
  283. countMediSum($(this).closest('.cc-ul'))
  284. })
  285. //填写次剂量
  286. $("#mainContain").on("blur",".j-medi-single",function(){
  287. countMediSum($(this).closest('.cc-ul'))
  288. })
  289. $("#mainContain").on("change",".j-medi-single",function(){
  290. var $val = $(this).val().trim()
  291. var reg = /^[0-9]+(.[0-9]{1,5})?$/;
  292. if($val && reg.test($val)){
  293. }else{
  294. $(this).val('')
  295. }
  296. })
  297. //刷新页面
  298. function refreshHz(){
  299. var page3 = plus.webview.getWebviewById("xufangxiangqing");
  300. if(page3){
  301. mui.fire(page3, "refreshXufang");
  302. }
  303. var page4 = plus.webview.getWebviewById("juminxufangxiangqing");
  304. if(page4){
  305. mui.fire(page4, "refreshXufang");
  306. }
  307. var page = plus.webview.getWebviewById("xufangguanli");
  308. if(page){
  309. mui.fire(page, "refreshXufang");
  310. }
  311. var page1 = plus.webview.getWebviewById("juminxufangjilu");
  312. if(page1){
  313. mui.fire(page1, "refreshXufang");
  314. }
  315. }
  316. }
  317. //获取频率换算
  318. function toFreqRate(code,fun){
  319. var data={
  320. code:code
  321. }
  322. sendPost("doctor/prescriptionInfo/drugToRate",data, function(){
  323. plus.nativeUI.closeWaiting();
  324. mui.toast("获取用药频率数据失败");
  325. }, function(res){
  326. if(res.status == 200){
  327. fun&&fun.call(this,res.data.rate)
  328. }
  329. },'get')
  330. }
  331. //获取药品信息
  332. function toMediMsg(code,fun){
  333. var data={
  334. code:code
  335. }
  336. sendPost("doctor/prescriptionInfo/getPhysicInfo",data, function(){
  337. mui.toast("获取药品信息失败");
  338. }, function(res){
  339. if(res.status == 200){
  340. fun&&fun.call(this,res.data[0])
  341. }
  342. },'get')
  343. }
  344. //用药频率
  345. function addMedicineFreq($id,newADD){
  346. for(i=0; i<$id.length; i++){
  347. var html = '<option disabled selected></option>';
  348. //取频率code
  349. if(newADD){
  350. var obj = JSON.parse($('.cc-ul:last').attr('data-info'));
  351. }else{
  352. var obj = JSON.parse($('.cc-ul').eq(i).attr('data-info'));
  353. }
  354. var code = obj.drugRate
  355. for(j=0;j<medicineFreqData.length;j++){
  356. if(medicineFreqData[j].code == code){
  357. html += '<option selected value="'+medicineFreqData[j].code+'">'+medicineFreqData[j].name+'</option>';
  358. }else{
  359. html += '<option value="'+medicineFreqData[j].code+'">'+medicineFreqData[j].name+'</option>';
  360. }
  361. }
  362. $id.eq(i).html(html);
  363. $id.eq(i).mobiscroll().select({
  364. theme: 'ios',
  365. lang: 'zh',
  366. display: 'bottom',
  367. placeholder:'请选择用药频次',
  368. rows:7,
  369. onSelect: function ( valueText, inst) {
  370. var selectedData = {};
  371. $.map(medicineFreqData,function(item,index){
  372. if(item.name == valueText){
  373. selectedData = item;
  374. return;
  375. }
  376. })
  377. $(this).closest('.j-selFreq').attr('data-code',selectedData.code);
  378. $(this).closest('.j-selFreq').attr('data-name',selectedData.name);
  379. countMediSum($(this).closest('.cc-ul'))
  380. }
  381. })
  382. }
  383. }
  384. //用药天数
  385. function addMedicineDate($id,newADD){
  386. for(i=0; i<$id.length; i++){
  387. var html = '<option disabled selected></option>'
  388. //取天数
  389. if(newADD){
  390. var obj = JSON.parse($('.cc-ul:last').attr('data-info'));
  391. }else{
  392. var obj = JSON.parse($('.cc-ul').eq(i).attr('data-info'));
  393. }
  394. var num = obj.dayCount;
  395. for(j=1;j<31;j++){
  396. if(num == j){
  397. html += '<option selected value="'+j+'">'+j+'</option>';
  398. }else{
  399. html += '<option value="'+j+'">'+j+'</option>';
  400. }
  401. }
  402. $id.eq(i).html(html);
  403. $id.eq(i).mobiscroll().select({
  404. theme: 'ios',
  405. lang: 'zh',
  406. display: 'bottom',
  407. placeholder:'请选择用药天数',
  408. rows:7,
  409. onSelect: function ( valueText, inst) {
  410. $(this).closest('.j-selDate').attr('data-id',valueText);
  411. countMediSum($(this).closest('.cc-ul'))
  412. }
  413. })
  414. }
  415. }
  416. //计算药品总量
  417. function countMediSum($ul){
  418. $ul.find(".j-sumMedicine").html("")//清空
  419. $ul.find(".j-sumMedicine").attr('data-num','')//清空
  420. var $name = $ul.find(".j-medi-name").val().trim(),
  421. $single = $ul.find(".j-medi-single").val().trim(),
  422. $freq = $ul.find(".j-selFreq").attr('data-code'),
  423. $date = $ul.find(".j-selDate").attr('data-id'),
  424. $info = JSON.parse($ul.attr('data-info'));
  425. if($name && $single && $freq && $date){
  426. toFreqRate($freq,function(rate){
  427. var num = $single*rate*$date
  428. num = Math.round(num*100)/100
  429. var sum="";
  430. if($info.pakeSpec){
  431. //新增药品
  432. sum = Math.ceil(num/$info.minDose)
  433. showResultSum(sum);
  434. }else{
  435. var drugNumUnit = $info.drugNumUnit,
  436. physicDoseUnit = $info.physicDoseUnit;
  437. //请求药品信息
  438. var drugCode = $info.drugCode;
  439. toMediMsg(drugCode,function(msg){
  440. $ul.find(".j-medi-name").attr('data-storage',msg.storageConditions);//冷藏
  441. $ul.find(".j-medi-name").attr('data-class',msg.subjectClass);
  442. if(drugNumUnit == physicDoseUnit){
  443. sum = num
  444. }else{
  445. if(drugNumUnit == msg.pack_unit){
  446. sum = Math.ceil(num/msg.packSpec)
  447. }else{
  448. sum = Math.ceil(num/msg.minDose)
  449. }
  450. }
  451. showResultSum(sum);
  452. })
  453. }
  454. })
  455. }
  456. function showResultSum(sum){
  457. $ul.find(".j-sumMedicine").html(sum+$info.drugNumUnitName);
  458. $ul.find(".j-sumMedicine").attr('data-num',sum);
  459. $ul.find(".j-sumMedicine").attr('data-name',$info.drugNumUnitName);
  460. $ul.find(".j-sumMedicine").attr('data-unit',$info.drugNumUnit);
  461. }
  462. }