add_drug.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. var self,
  2. classes;
  3. mui.plusReady(function(){
  4. self = plus.webview.currentWebview();
  5. classes = self.classes;
  6. var $searchbarInput = $('#searchPut'),
  7. $searchSuggest = $('#search_suggest_text'),// 搜索框下面悬浮的搜索提示
  8. search_keyword = "",//记录搜索框的内容
  9. $noResultWrap = $('#no_result_wrap'),
  10. $del = $('.u-icon-delete'),
  11. $ul = $('.lc-list'),
  12. $searchResult = $('#search_result');
  13. $searchbarInput.focus();
  14. //监视输入
  15. $searchbarInput.on('input', function() {
  16. var text = $(this).val().trim();
  17. if(text){
  18. $del.show()
  19. }else{
  20. $del.hide()
  21. }
  22. $searchResult.hide();
  23. $noResultWrap.hide();
  24. showSearchSuggest(text);
  25. }).on('keydown',function(e) {
  26. if (e.which === 13) {
  27. searchByPaging()
  28. }
  29. })
  30. //查询
  31. function searchByPaging(){
  32. $searchbarInput.blur();
  33. search_keyword = $searchbarInput.val();
  34. if(!$.trim(search_keyword)) {
  35. return ;
  36. }
  37. $searchSuggest.hide();
  38. var params = {
  39. name:search_keyword,
  40. isinsulin:classes==0?1:2
  41. }
  42. plus.nativeUI.showWaiting();
  43. sendPost("doctor/prescriptionInfo/findDictByName",params, function(){
  44. plus.nativeUI.closeWaiting();
  45. mui.toast("获取数据失败");
  46. }, function(res){
  47. plus.nativeUI.closeWaiting();
  48. if(res.status == 200){
  49. if(res.data.length>0){
  50. var html = template('result_tmp',{data:$.map(res.data,function(o,index){
  51. o.isRefrigerate = o.storageConditions;
  52. o.physicAmountUnit = o.packUnit;
  53. o.physicAmountUnitName = o.packUnitName;
  54. o.jsonStr = JSON.stringify(o);
  55. return o })
  56. })
  57. $ul.empty().html(html)
  58. ellipsisText($searchResult.find('.yp-one'),search_keyword)
  59. $noResultWrap.hide();
  60. $searchResult.show();
  61. }else{
  62. $noResultWrap.show()
  63. $ul.empty()
  64. $searchResult.hide()
  65. }
  66. }else{
  67. mui.toast("获取数据失败");
  68. }
  69. },'get')
  70. }
  71. $searchSuggest.on('click',function() {
  72. searchByPaging()
  73. })
  74. mui('.mui-scroll-wrapper').scroll({
  75. bounce: true
  76. })
  77. // 控制搜索关键字悬浮提示的显示
  78. function showSearchSuggest(text) {
  79. var suggestText = '搜索“'+text+'”';
  80. if(text&&text.trim().length) {
  81. $searchSuggest.text(suggestText);
  82. $searchSuggest.show();
  83. } else {
  84. $searchSuggest.text('');
  85. $searchSuggest.hide();
  86. }
  87. }
  88. //关键字变色
  89. function ellipsisText($elements, searchText) {
  90. _.each($elements,function(el) {
  91. var $textEl = $(el).find(".j-text-ellipsis");
  92. _.each($textEl, function(t){
  93. highlineKeyword($(t),searchText)
  94. })
  95. })
  96. }
  97. function highlineKeyword($el,searchText) {
  98. var props = getRowProps($el),
  99. chartWidth = props.chartWidth,
  100. rowHeight = props.rowHeight,
  101. rowWidth = props.rowWidth,
  102. // 每行显示字符数(以中文字符为标准计算)
  103. chartNum = Math.floor(rowWidth / chartWidth.zh),
  104. // 排除指定数量字符所占宽度
  105. exceptNum = 0,
  106. // 行数
  107. rowNum = 1,
  108. // 预计显示总字符数
  109. expectedNum = chartNum * rowNum - exceptNum,
  110. $target = $el,
  111. // 目标文本
  112. text = $.trim($target.attr('data-text')),
  113. length = text.length,
  114. // 关键字数组
  115. kws = $.trim(searchText).replace(/\s+/g," ").split(" ");
  116. var fidx = 0,preFidx,diff = 0;
  117. $target.html(replaceAll(text, kws));
  118. if(Math.floor($target.height() / rowHeight) <= rowNum) {
  119. return ;
  120. }
  121. }
  122. function getRowProps($el) {
  123. var $textEllipsis = $el,
  124. $text = $textEllipsis.eq(0),
  125. $chart = $text.text('a'),
  126. enWidth = $chart.width(),
  127. $chart = $text.text('中'),
  128. zhWidth = $chart.width(),
  129. lineHeight = parseFloat($chart.css("lineHeight"), 10),
  130. rowHeight = $chart.height();
  131. $chart.text('');
  132. return {
  133. chartWidth: {
  134. zh: zhWidth,
  135. en: enWidth
  136. },
  137. rowHeight: Math.max(rowHeight, lineHeight),
  138. rowWidth: $el.width()
  139. };
  140. }
  141. function replaceAll(text, arr) {
  142. var html = text;
  143. _.each(arr,function(kw) {
  144. var reg = new RegExp(kw+"(?!>)","gi");
  145. html = html.replace(reg,'<em>'+kw+'</em>');
  146. });
  147. return html;
  148. }
  149. //清空
  150. $del.click(function(){
  151. $searchbarInput.val('')
  152. $del.hide()
  153. $noResultWrap.hide()
  154. $searchResult.hide()
  155. $searchSuggest.empty().hide()
  156. $searchbarInput.focus()
  157. })
  158. //选取用药
  159. $ul.on('click','.yp-one',function(){
  160. var $val = $(this).attr('data-json');
  161. plus.storage.setItem("chooseMedicineList",$val)
  162. plus.storage.setItem("medicineType",classes)
  163. //新增
  164. var page = plus.webview.getWebviewById("drugs");
  165. if(page){
  166. mui.fire(page, "addMedicine");
  167. }
  168. mui.back()
  169. })
  170. })