Index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <div class="component-box-wrapper__half-transparent">
  3. <div class="component-content-box__dialog-like box-width">
  4. <div class="component-header-box">
  5. <div class="component-header__title">{{ title }}</div>
  6. <div class="component-header__close-button">
  7. <el-button plain icon="Close" circle title="关闭" @click="close"></el-button>
  8. </div>
  9. </div>
  10. <div>
  11. <span>检索依据:</span>
  12. <el-select v-model="params.method" style="width: 70px">
  13. <el-option v-for="item in allMethods" :key="item.code" :label="item.name" :value="item.code"></el-option> </el-select
  14. >&nbsp;
  15. <el-input ref="inputRef" v-model="params.content" style="width: 240px" clearable placeholder="请输入检索内容"></el-input>
  16. </div>
  17. <div class="data-box">
  18. <el-table ref="resultRef" :data="data.list" stripe height="360px" highlight-current-row @row-click="clickItem">
  19. <el-table-column prop="code" label="编码"></el-table-column>
  20. <el-table-column prop="name" label="名称"></el-table-column>
  21. <el-table-column v-if="showEmpDept" prop="deptName" label="科室"></el-table-column>
  22. </el-table>
  23. <el-pagination
  24. @current-change="handleCurrentChange"
  25. :current-page="params.page"
  26. :page-size="params.pageSize"
  27. layout="total, pager, next"
  28. :total="data.totalSize"
  29. ></el-pagination>
  30. </div>
  31. </div>
  32. <el-dialog title="请确认诊断类别" v-model="showDiagType" width="360px">
  33. <div style="margin-top: 8px">
  34. 诊断编码:
  35. <el-input v-model="diagItem.icdCode" disabled style="width: 220px"></el-input>
  36. </div>
  37. <div style="margin-top: 8px">
  38. 诊断名称:
  39. <el-input v-model="diagItem.icdText" disabled style="width: 220px"></el-input>
  40. </div>
  41. <div style="margin-top: 8px">
  42. 诊断类别:
  43. <el-select v-model="diagItem.diagType" style="width: 220px">
  44. <el-option v-for="item in diagTypes" :key="item.code" :value="item.code" :label="item.name"></el-option>
  45. </el-select>
  46. </div>
  47. <div style="margin-top: 8px; width: 100%; text-align: right; padding: 8px 20px 8px 0">
  48. <el-button type="primary" icon="Check" @click="confirmDiaginfo">确定</el-button>
  49. </div>
  50. </el-dialog>
  51. </div>
  52. </template>
  53. <script>
  54. import { reactive, ref, watch } from 'vue'
  55. import { searchFromServer } from '@/api/inpatient/dictionary'
  56. import { diagTypes } from '@/data/index'
  57. import Sleep from '@/utils/sleep'
  58. export default {
  59. props: {
  60. title: {
  61. type: String,
  62. required: true,
  63. },
  64. target: {
  65. type: String,
  66. required: true,
  67. },
  68. medType: {
  69. type: String,
  70. default: '',
  71. },
  72. showEmpDept: {
  73. type: Boolean,
  74. default: false
  75. }
  76. },
  77. emits: ['close', 'clickItem'],
  78. setup(props, ctx) {
  79. const inputRef = ref(null)
  80. const resultRef = ref(null)
  81. const allMethods = [
  82. { code: 'alpha', name: '拼音' },
  83. { code: 'code', name: '编码' },
  84. { code: 'name', name: '名称' },
  85. ]
  86. const params = reactive({
  87. method: 'alpha',
  88. target: props.target,
  89. medType: props.medType,
  90. page: 1,
  91. pageSize: 10,
  92. content: '',
  93. })
  94. const data = reactive({
  95. list: [],
  96. totalSize: 0,
  97. })
  98. const showDiagType = ref(false)
  99. const diagItem = reactive({
  100. icdCode: null,
  101. icdText: null,
  102. diagType: null,
  103. })
  104. const executeSearch = () => {
  105. if (params.content.trim().length > 1) {
  106. searchFromServer(params).then((res) => {
  107. data.list = res.list
  108. data.totalSize = res.totalSize
  109. currentIndex.value = currentIndex.value > data.list.length - 1 ? data.list.length - 1 : currentIndex.value
  110. resultRef.value.setCurrentRow(data.list[currentIndex.value])
  111. })
  112. } else {
  113. data.list = []
  114. data.totalSize = 0
  115. }
  116. }
  117. const currentIndex = ref(0)
  118. const handleCurrentChange = (val) => {
  119. params.page = val
  120. executeSearch()
  121. }
  122. const confirmDiaginfo = () => {
  123. ctx.emit('clickItem', diagItem)
  124. }
  125. const clickItem = (item) => {
  126. if (props.target === 'diag' || props.target === 'injurydiag') {
  127. diagItem.icdCode = item.code
  128. diagItem.icdText = item.name
  129. diagItem.diagType = '1'
  130. showDiagType.value = true
  131. } else {
  132. ctx.emit('clickItem', item)
  133. }
  134. }
  135. const close = () => {
  136. ctx.emit('close')
  137. }
  138. watch(
  139. () => params.content,
  140. () => {
  141. executeSearch()
  142. }
  143. )
  144. onMounted(async () => {
  145. await Sleep(100)
  146. inputRef.value.focus()
  147. document.onkeydown = (e) => {
  148. switch (e.code) {
  149. case 'ArrowUp':
  150. resultRef.value.setCurrentRow(data.list[currentIndex.value === 0 ? 0 : --currentIndex.value])
  151. return false
  152. case 'ArrowDown':
  153. resultRef.value.setCurrentRow(data.list[currentIndex.value === data.list.length - 1 ? data.list.length - 1 : ++currentIndex.value])
  154. return false
  155. case 'ArrowLeft':
  156. if (params.page > 1) {
  157. handleCurrentChange(params.page - 1)
  158. }
  159. return false
  160. case 'ArrowRight':
  161. if (params.page * params.pageSize < data.totalSize) {
  162. handleCurrentChange(params.page + 1)
  163. }
  164. return false
  165. case 'Enter':
  166. clickItem(data.list[currentIndex.value])
  167. break
  168. case 'Escape':
  169. close()
  170. break
  171. }
  172. }
  173. })
  174. return {
  175. inputRef,
  176. resultRef,
  177. data,
  178. params,
  179. allMethods,
  180. diagItem,
  181. diagTypes,
  182. showDiagType,
  183. confirmDiaginfo,
  184. executeSearch,
  185. handleCurrentChange,
  186. clickItem,
  187. close,
  188. }
  189. },
  190. }
  191. </script>
  192. <style scoped>
  193. .box-width {
  194. width: 420px;
  195. }
  196. .data-box {
  197. margin-top: 16px;
  198. overflow-y: auto;
  199. border-top: 1px solid rgb(231, 231, 231);
  200. }
  201. </style>