search.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. <template>
  2. <view class="content">
  3. <view class="search-box">
  4. <!-- mSearch组件 如果使用原样式,删除组件元素-->
  5. <mSearch class="mSearch-input-box" :mode="2" button="inside" :placeholder="defaultKeyword"
  6. @search="doSearch(false)" @input="changeInp" @confirm="doSearch(false)" v-model="keyword"></mSearch>
  7. </view>
  8. <view class="search-keyword">
  9. <scroll-view class="keyword-list-box" v-show="isShowKeywordList" scroll-y>
  10. <block v-for="(row, index) in keywordList" :key="index">
  11. <view class="keyword-entry" hover-class="keyword-entry-tap">
  12. <view class="keyword-text" @tap.stop="doSearch(keywordList[index].keyword)">
  13. <rich-text :nodes="row.htmlStr"></rich-text>
  14. </view>
  15. <view class="keyword-img" @tap.stop="doSearch(keywordList[index].keyword)">
  16. <image src="/static/HM-search/back.png"></image>
  17. </view>
  18. </view>
  19. </block>
  20. </scroll-view>
  21. <scroll-view class="keyword-box" v-show="!isShowKeywordList" scroll-y>
  22. <view class="keyword-block" v-if="oldKeywordList.length > 0">
  23. <view class="keyword-list-header">
  24. <view>历史搜索</view>
  25. <view>
  26. <image @tap="oldDelete" src="/static/HM-search/delete.png"></image>
  27. </view>
  28. </view>
  29. <view class="keyword">
  30. <view v-for="(keyword, index) in oldKeywordList" @tap="changeInp(keyword)" :key="index">{{ keyword }}
  31. </view>
  32. </view>
  33. </view>
  34. </scroll-view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. //引用mSearch组件,如不需要删除即可
  40. import mSearch from "@/components/mehaotian-search-revision/mehaotian-search-revision.vue";
  41. import {
  42. post,
  43. webHandle
  44. } from "../../http/http.js";
  45. export default {
  46. data() {
  47. return {
  48. type: "", //进入该页面的类型
  49. configName: "", //快速组合名称
  50. id: "", //快速组合id
  51. changedept: 0, //是否从列表过来的切换负责科室
  52. hosId: "",
  53. defaultKeyword: "",
  54. keyword: "",
  55. oldKeywordList: [],
  56. keywordList: [],
  57. isShowKeywordList: false,
  58. deptList: [],
  59. //送回病房扫码 start
  60. code: '',
  61. infoDATA: '',
  62. patientOrders: '',
  63. workData: '',
  64. //送回病房扫码 end
  65. //送回病房-患者列表 start
  66. cid: '',
  67. cdept: '',
  68. currentItem: '',
  69. scrollYY: '',
  70. //送回病房-患者列表 end
  71. // 设置科室二维码 start
  72. uniName: '',
  73. queryDept: '',
  74. queryDeptId: '',
  75. qrCode: '',
  76. // 设置科室二维码 end
  77. timer: null, //定时器
  78. searchText: '', //搜索文本
  79. searchData: [], //搜索结果
  80. };
  81. },
  82. onUnload() {
  83. if (this.timer) {
  84. clearTimeout(this.timer);
  85. this.timer = null;
  86. }
  87. },
  88. onLoad(options) {
  89. this.type = options.type;
  90. if (this.type == "setDept") {
  91. this.configName = options.configName;
  92. this.id = options.id;
  93. this.changedept = options.changedept;
  94. } else if (this.type == "sendBack") {
  95. this.code = options.code;
  96. this.infoDATA = options.infoDATA;
  97. this.patientOrders = options.patientOrders;
  98. this.workData = options.workData;
  99. } else if (this.type == "sendBackPatientList") {
  100. this.cid = options.cid;
  101. this.cdept = options.cdept;
  102. this.currentItem = options.currentItem;
  103. this.scrollYY = options.scrollYY;
  104. } else if (this.type == "settingCode") { //设置科室二维码
  105. this.uniName = options.uniName;
  106. this.queryDept = options.queryDept;
  107. this.queryDeptId = options.queryDeptId;
  108. this.qrCode = options.qrCode;
  109. }
  110. this.init();
  111. // #ifdef APP-PLUS
  112. webHandle("no", "app");
  113. // #endif
  114. // #ifdef H5
  115. webHandle("no", "wx");
  116. // #endif
  117. },
  118. components: {
  119. //引用mSearch组件,如不需要删除即可
  120. mSearch,
  121. },
  122. methods: {
  123. init() {
  124. this.hosId = uni.getStorageSync("userData").user.currentHospital.id;
  125. this.loadDefaultKeyword();
  126. this.loadOldKeyword();
  127. },
  128. blur() {
  129. uni.hideKeyboard();
  130. },
  131. //加载默认搜索关键字
  132. loadDefaultKeyword() {
  133. //定义默认搜索关键字,可以自己实现ajax请求数据再赋值,用户未输入时,以水印方式显示在输入框,直接不输入内容搜索会搜索默认关键字
  134. this.defaultKeyword = "请输入科室名称";
  135. },
  136. //加载历史搜索,自动读取本地Storage
  137. loadOldKeyword() {
  138. uni.getStorage({
  139. key: "OldKeys",
  140. success: (res) => {
  141. var OldKeys = JSON.parse(res.data);
  142. this.oldKeywordList = OldKeys;
  143. },
  144. });
  145. },
  146. //防抖搜索
  147. changeInp(event) {
  148. this.searchText = event;
  149. clearTimeout(this.timer);
  150. this.timer = setTimeout(() => {
  151. this.inputChange(event);
  152. }, 500)
  153. },
  154. //监听输入
  155. inputChange(event) {
  156. //兼容引入组件时传入参数情况
  157. var keyword = event.detail ? event.detail.value : event;
  158. if (!keyword) {
  159. this.keywordList = [];
  160. this.isShowKeywordList = false;
  161. return;
  162. }
  163. this.keyword = keyword;
  164. this.isShowKeywordList = true;
  165. let postData = {
  166. idx: 0,
  167. sum: 20,
  168. department: {
  169. hospital: {
  170. id: this.hosId,
  171. },
  172. dept: keyword,
  173. },
  174. };
  175. //不是送回病房
  176. if (this.type != "sendBack" && this.type != "sendBackPatientList" && this.type != "settingCode") {
  177. postData.department.type = {
  178. id: "281"
  179. }
  180. }
  181. uni.showLoading({
  182. title: "加载中",
  183. });
  184. post("/data/fetchDataList/department", postData).then((res) => {
  185. if (res.status == 200) {
  186. this.searchData.push({
  187. name: keyword,
  188. list: res.list
  189. });
  190. let searchText = this.searchText.detail ? this.searchText.detail.value : this.searchText;
  191. let index = this.searchData.findIndex(item => item.name === searchText);
  192. this.deptList = index >= 0 ? this.searchData[index].list : [];
  193. this.keywordList = this.drawCorrelativeKeyword(this.deptList, keyword);
  194. uni.hideLoading();
  195. } else {
  196. uni.hideLoading();
  197. uni.showToast({
  198. icon: "none",
  199. title: "请求失败!",
  200. });
  201. }
  202. });
  203. },
  204. //高亮关键字
  205. drawCorrelativeKeyword(keywords, keyword) {
  206. var len = keywords.length,
  207. keywordArr = [];
  208. for (var i = 0; i < len; i++) {
  209. var row = keywords[i];
  210. //定义高亮#9f9f9f
  211. var html = row.dept.replace(
  212. keyword,
  213. "<span style='color: #9f9f9f;'>" + keyword + "</span>"
  214. );
  215. html = "<div>" + html + "</div>";
  216. var tmpObj = {
  217. keyword: row.dept,
  218. htmlStr: html,
  219. };
  220. keywordArr.push(tmpObj);
  221. }
  222. return keywordArr;
  223. },
  224. //清除历史搜索
  225. oldDelete() {
  226. uni.showModal({
  227. content: "确定清除历史搜索记录?",
  228. success: (res) => {
  229. if (res.confirm) {
  230. console.log("用户点击确定");
  231. this.oldKeywordList = [];
  232. uni.removeStorage({
  233. key: "OldKeys",
  234. });
  235. } else if (res.cancel) {
  236. console.log("用户点击取消");
  237. }
  238. },
  239. });
  240. },
  241. //执行搜索
  242. doSearch(keyword) {
  243. keyword = keyword === false ? this.keyword : keyword;
  244. this.keyword = keyword;
  245. this.saveKeyword(keyword); //保存为历史
  246. let arr = this.deptList.filter((item) => item.dept === keyword);
  247. if (arr.length) {
  248. let msg = "";
  249. if (this.type == "patientInformationList" || this.type == "inspectList") {
  250. msg = "切换科室成功";
  251. uni.showToast({
  252. title: msg,
  253. icon: "none",
  254. duration: 2000,
  255. });
  256. } else if (this.type == "setDept") {
  257. msg = "添加科室成功";
  258. uni.showToast({
  259. title: msg,
  260. icon: "none",
  261. duration: 2000,
  262. });
  263. }
  264. if (this.type == "patientInformationList") {
  265. //患者列表进入
  266. uni.setStorageSync("patientCurrentDept", arr[0]); //科室切换存本地
  267. uni.navigateTo({
  268. url: `../patientInformationList/patientInformationList?id=${arr[0].id}&dept=${arr[0].dept}`,
  269. });
  270. } else if (this.type == "inspectList") {
  271. //患者列表进入
  272. uni.setStorageSync("patientCurrentDept", arr[0]); //科室切换存本地
  273. uni.navigateTo({
  274. url: `../inspectList/inspectList?id=${arr[0].id}&dept=${arr[0].dept}`,
  275. });
  276. } else if (this.type == "setDept") {
  277. //上班添加科室进入
  278. let obj = uni.getStorageSync("setDepts");
  279. if (obj) {
  280. let i = obj.findIndex((item) => item.id == arr[0].id);
  281. if (i < 0) {
  282. uni.setStorageSync("setDepts", [arr[0], ...obj]);
  283. }
  284. } else {
  285. uni.setStorageSync("setDepts", [arr[0]]);
  286. }
  287. uni.navigateTo({
  288. url: `../setDept/setDept?configName=${this.configName}&id=${this.id}&changedept=${this.changedept}`,
  289. });
  290. } else if (this.type == "sendBack") {
  291. uni.navigateTo({
  292. url: `../scanning_ins/scanning_ins?id=${arr[0].id}&dept=${arr[0].dept}&code=${this.code}&infoDATA=${this.infoDATA}&patientOrders=${this.patientOrders}&workData=${this.workData}`,
  293. });
  294. } else if (this.type == "sendBackPatientList") {
  295. uni.navigateTo({
  296. url: `../patientInformationList/patientInformationList?did=${arr[0].id}&ddept=${arr[0].dept}&currentItem=${this.currentItem}&id=${this.cid}&dept=${this.cdept}&scrollYY=${this.scrollYY}`,
  297. });
  298. } else if (this.type == "settingCode") {
  299. if (this.queryDept) { //替换
  300. uni.navigateTo({
  301. url: `../settingCode/settingCode?targetId=${arr[0].id}&targetDept=${arr[0].dept}&uniName=${this.uniName}&queryDept=${this.queryDept}&queryDeptId=${this.queryDeptId}&qrCode=${this.qrCode}`,
  302. });
  303. } else { //设置
  304. uni.navigateTo({
  305. url: `../settingCode/settingCode?targetId=${arr[0].id}&targetDept=${arr[0].dept}&uniName=${this.uniName}&qrCode=${this.qrCode}`,
  306. });
  307. }
  308. }
  309. }
  310. },
  311. //保存关键字到历史记录
  312. saveKeyword(keyword) {
  313. uni.getStorage({
  314. key: "OldKeys",
  315. success: (res) => {
  316. var OldKeys = JSON.parse(res.data);
  317. var findIndex = OldKeys.indexOf(keyword);
  318. if (findIndex == -1) {
  319. OldKeys.unshift(keyword);
  320. } else {
  321. OldKeys.splice(findIndex, 1);
  322. OldKeys.unshift(keyword);
  323. }
  324. //最多10个纪录
  325. OldKeys.length > 10 && OldKeys.pop();
  326. uni.setStorage({
  327. key: "OldKeys",
  328. data: JSON.stringify(OldKeys),
  329. });
  330. this.oldKeywordList = OldKeys; //更新历史搜索
  331. },
  332. fail: (e) => {
  333. var OldKeys = [keyword];
  334. uni.setStorage({
  335. key: "OldKeys",
  336. data: JSON.stringify(OldKeys),
  337. });
  338. this.oldKeywordList = OldKeys; //更新历史搜索
  339. },
  340. });
  341. },
  342. },
  343. };
  344. </script>
  345. <style>
  346. view {
  347. display: block;
  348. }
  349. .search-box {
  350. width: 95%;
  351. background-color: rgb(242, 242, 242);
  352. padding: 15upx 2.5%;
  353. display: flex;
  354. justify-content: space-between;
  355. position: sticky;
  356. top: 0;
  357. }
  358. .search-box .mSearch-input-box {
  359. width: 100%;
  360. }
  361. .search-box .input-box {
  362. width: 85%;
  363. flex-shrink: 1;
  364. display: flex;
  365. justify-content: center;
  366. align-items: center;
  367. }
  368. .search-box .search-btn {
  369. width: 15%;
  370. margin: 0 0 0 2%;
  371. display: flex;
  372. justify-content: center;
  373. align-items: center;
  374. flex-shrink: 0;
  375. font-size: 28upx;
  376. color: #fff;
  377. background: linear-gradient(to right, #ff9801, #ff570a);
  378. border-radius: 60upx;
  379. }
  380. .search-box .input-box>input {
  381. width: 100%;
  382. height: 60upx;
  383. font-size: 32upx;
  384. border: 0;
  385. border-radius: 60upx;
  386. -webkit-appearance: none;
  387. -moz-appearance: none;
  388. appearance: none;
  389. padding: 0 3%;
  390. margin: 0;
  391. background-color: #ffffff;
  392. }
  393. .placeholder-class {
  394. color: #9e9e9e;
  395. }
  396. .search-keyword {
  397. width: 100%;
  398. background-color: rgb(242, 242, 242);
  399. }
  400. .keyword-list-box {
  401. height: calc(100vh - 110upx);
  402. padding-top: 10upx;
  403. border-radius: 20upx 20upx 0 0;
  404. background-color: #fff;
  405. }
  406. .keyword-entry-tap {
  407. background-color: #eee;
  408. }
  409. .keyword-entry {
  410. width: 94%;
  411. height: 80upx;
  412. margin: 0 3%;
  413. font-size: 30upx;
  414. color: #333;
  415. display: flex;
  416. justify-content: space-between;
  417. align-items: center;
  418. border-bottom: solid 1upx #e7e7e7;
  419. }
  420. .keyword-entry image {
  421. width: 60upx;
  422. height: 60upx;
  423. }
  424. .keyword-entry .keyword-text,
  425. .keyword-entry .keyword-img {
  426. height: 80upx;
  427. display: flex;
  428. align-items: center;
  429. }
  430. .keyword-entry .keyword-text {
  431. width: 90%;
  432. }
  433. .keyword-entry .keyword-img {
  434. width: 10%;
  435. justify-content: center;
  436. }
  437. .keyword-box {
  438. height: calc(100vh - 110upx);
  439. border-radius: 20upx 20upx 0 0;
  440. background-color: #fff;
  441. }
  442. .keyword-box .keyword-block {
  443. padding: 10upx 0;
  444. }
  445. .keyword-box .keyword-block .keyword-list-header {
  446. width: 94%;
  447. padding: 10upx 3%;
  448. font-size: 27upx;
  449. color: #333;
  450. display: flex;
  451. justify-content: space-between;
  452. }
  453. .keyword-box .keyword-block .keyword-list-header image {
  454. width: 40upx;
  455. height: 40upx;
  456. }
  457. .keyword-box .keyword-block .keyword {
  458. width: 94%;
  459. padding: 3px 3%;
  460. display: flex;
  461. flex-flow: wrap;
  462. justify-content: flex-start;
  463. }
  464. .keyword-box .keyword-block .hide-hot-tis {
  465. display: flex;
  466. justify-content: center;
  467. font-size: 28upx;
  468. color: #6b6b6b;
  469. }
  470. .keyword-box .keyword-block .keyword>view {
  471. display: flex;
  472. justify-content: center;
  473. align-items: center;
  474. border-radius: 60upx;
  475. padding: 0 20upx;
  476. margin: 10upx 20upx 10upx 0;
  477. height: 60upx;
  478. font-size: 28upx;
  479. background-color: rgb(242, 242, 242);
  480. color: #6b6b6b;
  481. }
  482. </style>