search.vue 19 KB

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