search.vue 16 KB

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