inspection.vue 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. <template>
  2. <div class="patient-container">
  3. <patient-sidebar :id="patientID" defaultActive="1-3"></patient-sidebar>
  4. <div
  5. class="patient-app-container app-container"
  6. v-loading="pageLoading"
  7. element-loading-text="拼命加载中"
  8. >
  9. <el-row :gutter="20">
  10. <el-col :span="7">
  11. <el-table
  12. :header-cell-style="{
  13. backgroundColor: 'rgb(245, 247, 250)',
  14. color: '#606266'
  15. }"
  16. :row-style="{ color: '#303133' }"
  17. :data="projects"
  18. border
  19. style="width: 100%"
  20. highlight-current-row
  21. @current-change="handleCurrentChange"
  22. ref="singleTable"
  23. >
  24. <el-table-column label="检验检查项目" align="center">
  25. <el-table-column
  26. prop="project_name"
  27. label="检验项目"
  28. align="center"
  29. >
  30. </el-table-column>
  31. <el-table-column
  32. prop="count"
  33. label="次数"
  34. width="80"
  35. align="center"
  36. >
  37. </el-table-column>
  38. </el-table-column>
  39. </el-table>
  40. </el-col>
  41. <el-col :span="17" v-loading="itemLoading">
  42. <div class="filter-container" style="float:right">
  43. <el-button
  44. size="small"
  45. class="filter-item"
  46. type="primary"
  47. @click="openNew()"
  48. icon="el-icon-circle-plus-outline"
  49. :disabled="project ? false : true"
  50. >新增</el-button
  51. >
  52. <el-button
  53. size="small"
  54. class="filter-item"
  55. type="primary"
  56. icon="el-icon-edit-outline"
  57. @click="openEdit()"
  58. :disabled="itemDate ? false : true"
  59. >修改</el-button
  60. >
  61. <el-button
  62. size="small"
  63. class="filter-item"
  64. type="danger"
  65. icon="el-icon-delete"
  66. @click="deleteInspection()"
  67. :disabled="itemDate ? false : true"
  68. >删除</el-button
  69. >
  70. </div>
  71. <div class="filter-container">
  72. <el-button class="filter-item" type="text" style="color:#000"
  73. >{{ itemName }}
  74. <span v-if="itemDate"
  75. >(检查日期:{{ itemDate }})</span
  76. ></el-button
  77. >
  78. </div>
  79. <el-table
  80. :header-cell-style="{
  81. backgroundColor: 'rgb(245, 247, 250)',
  82. color: '#606266'
  83. }"
  84. :row-style="{ color: '#303133' }"
  85. :data="items"
  86. border
  87. style="width: 100%"
  88. id="user-inspection-order"
  89. >
  90. <el-table-column
  91. prop="item_name"
  92. label="检验项目"
  93. align="center"
  94. min-width="180"
  95. >
  96. <template slot-scope="scope">
  97. {{ scope.row.item_name }} {{ scope.row.item_name_addition }}
  98. </template>
  99. </el-table-column>
  100. <el-table-column
  101. prop="name"
  102. label="结果"
  103. align="center"
  104. min-width="80"
  105. >
  106. <template slot-scope="scope">
  107. <span>{{ scope.row.value }}</span>
  108. <span v-if="scope.row.range_type == 1">{{
  109. scope.row.value_direction
  110. }}</span>
  111. </template>
  112. </el-table-column>
  113. <el-table-column
  114. prop="address"
  115. label="参考值"
  116. align="center"
  117. min-width="120"
  118. >
  119. <template slot-scope="scope">
  120. <span v-if="scope.row.range_type == 1"
  121. >{{ scope.row.range_min }}~{{ scope.row.range_max }}</span
  122. >
  123. <span v-else>{{ scope.row.range_value }}</span>
  124. </template>
  125. </el-table-column>
  126. <el-table-column
  127. prop="unit"
  128. label="单位"
  129. align="center"
  130. min-width="80"
  131. >
  132. </el-table-column>
  133. </el-table>
  134. <el-pagination
  135. align="right"
  136. @current-change="handleCurrentChangePage"
  137. :current-page="queryParams.page"
  138. :page-size="1"
  139. background
  140. style="margin-top:20px;"
  141. layout="total, prev, pager, next, jumper"
  142. :total="total"
  143. >
  144. </el-pagination>
  145. </el-col>
  146. </el-row>
  147. </div>
  148. <el-dialog
  149. :title="formTitle"
  150. :visible.sync="dialogFormVisible"
  151. width="1000px"
  152. id="user-inspection-form"
  153. v-loading="formLoading"
  154. >
  155. <el-form :model="form" ref="form" label-position="top">
  156. <el-row>
  157. <el-col :span="24" v-if="form.formItem[0].project_id == 14">
  158. <el-form-item label="传染病周期提醒: ">
  159. <el-radio-group v-model="form.remind_cycle">
  160. <el-radio :label="1">一月一次</el-radio>
  161. <el-radio :label="2">两月一次</el-radio>
  162. <el-radio :label="3">三月一次</el-radio>
  163. <el-radio :label="4">半年一次</el-radio>
  164. <el-radio :label="5">一年一次</el-radio>
  165. </el-radio-group>
  166. </el-form-item>
  167. </el-col>
  168. <el-col :span="7">
  169. <el-form-item
  170. label="检验日期"
  171. prop="inspect_date"
  172. :rules="[
  173. { required: true, message: '请输入检验日期', trigger: 'blur' }
  174. ]"
  175. >
  176. <el-date-picker
  177. style="width:95%"
  178. v-model="form.inspect_date"
  179. type="datetime"
  180. value-format="yyyy-MM-dd HH:mm"
  181. format="yyyy-MM-dd HH:mm"
  182. placeholder="选择日期"
  183. >
  184. </el-date-picker>
  185. </el-form-item>
  186. </el-col>
  187. <el-col :span="1">&nbsp;</el-col>
  188. <template v-for="(item, index) in form.formItem">
  189. <el-col :span="7" :key="index">
  190. <el-form-item
  191. :label="item.item_name"
  192. v-if="item.range_type == 1"
  193. :key="item.item_id"
  194. :prop="'formItem.' + index + '.value'"
  195. >
  196. <el-input
  197. placeholder="请填入"
  198. v-model="item.value"
  199. style="width:95%"
  200. type="number"
  201. >
  202. <template slot="append">{{ item.unit }}</template>
  203. </el-input>
  204. </el-form-item>
  205. <el-form-item
  206. :label="item.item_name"
  207. v-else
  208. :key="item.item_id"
  209. :prop="'formItem.' + index + '.value'"
  210. >
  211. <el-select
  212. v-model="item.value"
  213. placeholder="请选择"
  214. style="width:95%"
  215. >
  216. <el-option
  217. v-for="(optionItem, oidex) in item.select_options"
  218. :key="oidex"
  219. :label="optionItem"
  220. :value="optionItem"
  221. >
  222. </el-option>
  223. </el-select>
  224. </el-form-item>
  225. </el-col>
  226. <el-col :span="1" :key="'form-col' + index">&nbsp;</el-col>
  227. </template>
  228. </el-row>
  229. </el-form>
  230. <div slot="footer" class="dialog-footer">
  231. <el-button @click="dialogFormVisible = false">取 消</el-button>
  232. <el-button
  233. type="primary"
  234. v-if="form.method == 'add'"
  235. @click="submitNew('form')"
  236. >保 存</el-button
  237. >
  238. <el-button type="primary" v-else @click="submitEdit('form')"
  239. >保 存</el-button
  240. >
  241. </div>
  242. </el-dialog>
  243. </div>
  244. </template>
  245. <script>
  246. import PatientSidebar from './components/PatientSidebar'
  247. import {
  248. fetchInspectionReference,
  249. CreatePatientInspection,
  250. fetchPatientInspections,
  251. EditPatientInspection,
  252. DeletePatientInspection
  253. } from '@/api/inspection'
  254. import { uParseTime, isPositiveNumber } from '@/utils/tools'
  255. export default {
  256. name: 'Inspection',
  257. components: { PatientSidebar },
  258. data() {
  259. return {
  260. total: 0,
  261. pageLoading: true,
  262. itemLoading: false,
  263. formLoading: false,
  264. itemDate: '',
  265. patientID: 0,
  266. panelClass: 'patient-app-container',
  267. patientInfo: {
  268. id: 0
  269. },
  270. itemName: '请选择项目',
  271. formTitle: '',
  272. dialogFormVisible: false,
  273. patient_info: null,
  274. form: {
  275. remind_cycle: '',
  276. method: 'add',
  277. project_id: 0,
  278. inspect_date: '',
  279. old_inspect_date: '',
  280. formItem: [{ id: 0, value: '' }]
  281. },
  282. formItem: [],
  283. items: [],
  284. inspections: [],
  285. inspectionsMap: {},
  286. projects: [],
  287. project: null,
  288. queryParams: {
  289. patient: 0,
  290. project_id: 0,
  291. page: 1
  292. }
  293. }
  294. },
  295. methods: {
  296. deleteInspection() {
  297. if (this.project == null || this.itemDate == '') {
  298. this.$message.error('请先选择删除删除的记录')
  299. return false
  300. }
  301. this.$confirm('确认删除此记录?', '删除', {
  302. confirmButtonText: '确定',
  303. cancelButtonText: '取消',
  304. type: 'warning'
  305. })
  306. .then(() => {
  307. var params = {
  308. patient: this.patientID,
  309. date: this.itemDate,
  310. project_id: this.project.project_id
  311. }
  312. DeletePatientInspection(params).then(response => {
  313. if (response.data.state == 0) {
  314. this.$message.error(response.data.msg)
  315. return false
  316. } else {
  317. this.$notify({
  318. title: '成功',
  319. message: '删除成功',
  320. type: 'success',
  321. duration: 2000
  322. })
  323. for (var index in this.projects) {
  324. if (this.projects[index].project_id == params.project_id) {
  325. this.projects[index].count--
  326. break
  327. }
  328. }
  329. this.total -= 1
  330. this.itemDate = ''
  331. this.items = []
  332. if (this.total > 0) {
  333. this.queryParams.page = 1
  334. this.fetchPatientInspections(this.queryParams)
  335. }
  336. }
  337. })
  338. })
  339. .catch(() => {})
  340. },
  341. openEdit() {
  342. if (this.project == null) {
  343. this.$message.error('请先选择项目')
  344. return false
  345. }
  346. this.form.method = 'edit'
  347. this.formTitle = '修改' + this.project.project_name
  348. this.form.project_id = this.project.project_id
  349. this.form.inspect_date = this.itemDate
  350. this.form.old_inspect_date = this.itemDate
  351. this.form.remind_cycle = this.patient_info.remind_cycle
  352. console.log(this.form.remind_cycle)
  353. this.form.formItem = []
  354. for (var index in this.project.inspection_reference) {
  355. this.form.formItem.push({
  356. id: this.project.inspection_reference[index].id in this.inspectionsMap ? this.inspectionsMap[this.project.inspection_reference[index].id].id : 0,
  357. project_id: this.project.inspection_reference[index].project_id,
  358. project_name: this.project.inspection_reference[index].project_name,
  359. item_id: this.project.inspection_reference[index].id,
  360. item: this.project.inspection_reference[index].item,
  361. item_name: this.project.inspection_reference[index].item_name,
  362. range_type: this.project.inspection_reference[index].range_type,
  363. value: this.project.inspection_reference[index].id in this.inspectionsMap ? this.inspectionsMap[this.project.inspection_reference[index].id].inspect_value : '',
  364. select_options: this.project.inspection_reference[index].range_options.split(','),
  365. unit: this.project.inspection_reference[index].unit
  366. })
  367. }
  368. console.log(this.form.formItem)
  369. this.dialogFormVisible = true
  370. },
  371. openNew() {
  372. if (this.project == null) {
  373. this.$message.error('请先选择项目')
  374. return false
  375. }
  376. this.form.method = 'add'
  377. this.formTitle = '新增' + this.project.project_name
  378. this.form.project_id = this.project.project_id
  379. this.form.remind_cycle = this.patient_info.remind_cycle
  380. var today = new Date()
  381. this.form.inspect_date = uParseTime(today, '{y}-{m}-{d} {h}:{i}')
  382. this.form.formItem = []
  383. for (var index in this.project.inspection_reference) {
  384. // var formItem = this.project.inspection_reference[index];
  385. // formItem["value"] = '';
  386. // if (formItem.range_type==2) {
  387. // formItem["select_options"] = formItem.range_options.split(",");
  388. // }
  389. this.form.formItem.push({
  390. id: 0,
  391. project_id: this.project.inspection_reference[index].project_id,
  392. project_name: this.project.inspection_reference[index].project_name,
  393. item_id: this.project.inspection_reference[index].id,
  394. item: this.project.inspection_reference[index].item,
  395. item_name: this.project.inspection_reference[index].item_name,
  396. range_type: this.project.inspection_reference[index].range_type,
  397. value: '',
  398. select_options: this.project.inspection_reference[
  399. index
  400. ].range_options.split(','),
  401. unit: this.project.inspection_reference[index].unit
  402. })
  403. }
  404. this.dialogFormVisible = true
  405. },
  406. submitEdit(formName) {
  407. this.$refs[formName].validate(valid => {
  408. if (valid) {
  409. this.formLoading = true
  410. if (this.form.formItem.length == 0) {
  411. this.$message.error('未填写项目')
  412. return false
  413. }
  414. for (var index in this.form.formItem) {
  415. this.form.formItem[index].value = '' + this.form.formItem[index].value
  416. }
  417. EditPatientInspection(this.patientID, this.form, this.form.remind_cycle, this.form.inspect_date, this.form.project_id).then(response => {
  418. if (response.data.state == 1) {
  419. this.$notify({
  420. title: '成功',
  421. message: '修改成功',
  422. type: 'success',
  423. duration: 2000
  424. })
  425. this.patient_info.remind_cycle =
  426. response.data.data.remind_cycle
  427. this.itemDate = this.form.inspect_date
  428. this.items = []
  429. var inspections = response.data.data.inspections
  430. this.inspections = response.data.data.inspections
  431. if (inspections == null) {
  432. this.inspections = []
  433. return false
  434. }
  435. var inspectionsMap = {}
  436. this.inspectionsMap = {}
  437. for (var index in inspections) {
  438. inspectionsMap[inspections[index].item_id] =
  439. inspections[index]
  440. this.inspectionsMap[inspections[index].item_id] =
  441. inspections[index]
  442. }
  443. var items = this.project.inspection_reference
  444. for (var index in items) {
  445. if (items[index].id in inspectionsMap) {
  446. var item = {}
  447. for (var key in items[index]) {
  448. item[key] = items[index][key]
  449. }
  450. item.value = inspectionsMap[items[index].id].inspect_value
  451. item.value_direction = ''
  452. if (item.range_type == 1) {
  453. var value = parseFloat(item.value)
  454. var range_min = parseFloat(item.range_min)
  455. var range_max = parseFloat(item.range_max)
  456. if (value < range_min) {
  457. item.value_direction = '↓'
  458. } else if (value > range_max) {
  459. item.value_direction = '↑'
  460. }
  461. }
  462. this.items.push(item)
  463. }
  464. }
  465. this.resetForm(formName)
  466. this.dialogFormVisible = false
  467. } else {
  468. this.$message.error(response.data.msg)
  469. return false
  470. }
  471. })
  472. .catch(v => {
  473. this.$message.error(v)
  474. return false
  475. })
  476. this.formLoading = false
  477. return false
  478. } else {
  479. return false
  480. }
  481. })
  482. },
  483. submitNew(formName) {
  484. this.$refs[formName].validate(valid => {
  485. if (valid) {
  486. this.formLoading = true
  487. if (this.form.formItem.length == 0) {
  488. this.$message.error('未填写项目')
  489. return false
  490. }
  491. for (var index in this.form.formItem) {
  492. this.form.formItem[index].value =
  493. '' + this.form.formItem[index].value
  494. }
  495. CreatePatientInspection(
  496. this.patientID,
  497. this.form,
  498. this.form.remind_cycle
  499. )
  500. .then(response => {
  501. if (response.data.state == 1) {
  502. this.$notify({
  503. title: '成功',
  504. message: '新增成功',
  505. type: 'success',
  506. duration: 2000
  507. })
  508. // this.form.remind_reycle = response.data.data.remind_reycc
  509. this.patient_info.remind_cycle =
  510. response.data.data.remind_cycle
  511. console.log(this.patient_info.remind_cycle)
  512. this.itemDate = this.form.inspect_date
  513. this.items = []
  514. for (var index in this.projects) {
  515. if (this.projects[index].project_id == this.form.project_id) {
  516. this.projects[index].count++
  517. break
  518. }
  519. }
  520. this.total += 1
  521. var inspections = response.data.data.inspections
  522. this.inspections = response.data.data.inspections
  523. if (inspections == null) {
  524. this.inspections = []
  525. return false
  526. }
  527. var inspectionsMap = {}
  528. this.inspectionsMap = {}
  529. for (var index in inspections) {
  530. inspectionsMap[inspections[index].item_id] =
  531. inspections[index]
  532. this.inspectionsMap[inspections[index].item_id] =
  533. inspections[index]
  534. }
  535. var items = this.project.inspection_reference
  536. for (var index in items) {
  537. if (items[index].id in inspectionsMap) {
  538. var item = {}
  539. for (var key in items[index]) {
  540. item[key] = items[index][key]
  541. }
  542. item.value = inspectionsMap[items[index].id].inspect_value
  543. item.value_direction = ''
  544. if (item.range_type == 1) {
  545. var value = parseFloat(item.value)
  546. var range_min = parseFloat(item.range_min)
  547. var range_max = parseFloat(item.range_max)
  548. if (value < range_min) {
  549. item.value_direction = '↓'
  550. } else if (value > range_max) {
  551. item.value_direction = '↑'
  552. }
  553. }
  554. this.items.push(item)
  555. }
  556. }
  557. this.resetForm(formName)
  558. this.dialogFormVisible = false
  559. this.queryParams.patient = this.patientID
  560. this.queryParams.project_id = this.project.project_id
  561. this.queryParams.page = 1
  562. this.total = 0
  563. this.fetchPatientInspections(this.queryParams)
  564. } else {
  565. this.$message.error(response.data.msg)
  566. return false
  567. }
  568. })
  569. .catch(v => {
  570. this.$message.error(v)
  571. return false
  572. })
  573. this.formLoading = false
  574. return false
  575. } else {
  576. return false
  577. }
  578. })
  579. },
  580. fetchInspectionReference() {
  581. fetchInspectionReference(this.patientID)
  582. .then(response => {
  583. if (response.data.state == 1) {
  584. var reference = response.data.data.reference
  585. var patient_info = response.data.data.patient_info
  586. this.projects = reference
  587. this.patient_info = patient_info
  588. this.pageLoading = false
  589. this.form.remind_cycle = this.patient_info.remind_cycle
  590. } else {
  591. this.$message.error(response.data.msg)
  592. return false
  593. }
  594. })
  595. .catch(v => {})
  596. },
  597. setCurrent(row) {
  598. this.$refs.singleTable.setCurrentRow(row)
  599. },
  600. resetForm(formName) {
  601. this.$refs[formName].resetFields()
  602. },
  603. handleCurrentChange(row) {
  604. this.itemDate = ''
  605. this.form.method = 'add'
  606. if (typeof row === 'undefined' || row == null) {
  607. this.project = null
  608. this.items = []
  609. this.itemName = '请选择项目'
  610. } else {
  611. this.itemLoading = true
  612. this.project = row
  613. this.items = row.inspection_reference
  614. this.itemName = row.project_name
  615. this.queryParams.patient = this.patientID
  616. this.queryParams.project_id = this.project.project_id
  617. this.queryParams.page = 1
  618. this.total = 0
  619. this.fetchPatientInspections(this.queryParams)
  620. }
  621. },
  622. handleCurrentChangePage(val) {
  623. this.itemLoading = true
  624. this.queryParams.page = val
  625. this.fetchPatientInspections(this.queryParams)
  626. },
  627. fetchPatientInspections(params) {
  628. this.items = []
  629. fetchPatientInspections(params)
  630. .then(response => {
  631. if (response.data.state == 1) {
  632. var inspections = response.data.data.inspections
  633. this.total = response.data.data.total
  634. this.itemDate = response.data.data.date
  635. this.inspections = response.data.data.inspections
  636. if (inspections == null) {
  637. this.inspections = []
  638. return false
  639. }
  640. var inspectionsMap = {}
  641. this.inspectionsMap = {}
  642. for (var index in inspections) {
  643. inspectionsMap[inspections[index].item_id] = inspections[index]
  644. this.inspectionsMap[inspections[index].item_id] = inspections[index]
  645. }
  646. var items = this.project.inspection_reference
  647. for (var index in items) {
  648. if (items[index].id in inspectionsMap || items[index].item_id in inspectionsMap) {
  649. var item = {}
  650. for (var key in items[index]) {
  651. item[key] = items[index][key]
  652. }
  653. if (item.item_id > 0) {
  654. if (inspectionsMap[items[index].item_id] == undefined) {
  655. item.value = inspectionsMap[items[index].id].inspect_value
  656. } else {
  657. item.value = inspectionsMap[items[index].item_id].inspect_value
  658. }
  659. } else {
  660. item.value = inspectionsMap[items[index].id].inspect_value
  661. }
  662. item.value_direction = ''
  663. if (item.range_type == 1) {
  664. var value = parseFloat(item.value)
  665. var range_min = parseFloat(item.range_min)
  666. var range_max = parseFloat(item.range_max)
  667. if (value < range_min) {
  668. item.value_direction = '↓'
  669. } else if (value > range_max) {
  670. item.value_direction = '↑'
  671. }
  672. }
  673. this.items.push(item)
  674. }
  675. }
  676. console.log(this.items)
  677. }
  678. })
  679. .catch(v => {})
  680. setTimeout(() => {
  681. this.itemLoading = false
  682. }, 1000)
  683. }
  684. },
  685. created() {
  686. const id = this.$route.query && this.$route.query.id
  687. this.patientID = parseInt(id)
  688. if (isNaN(this.patientID) || this.patientID <= 0) {
  689. this.$notify.error({
  690. title: '错误',
  691. message: '无效的id'
  692. })
  693. this.$router.push('/patients/patients')
  694. }
  695. this.fetchInspectionReference()
  696. }
  697. }
  698. </script>
  699. <style>
  700. #oictable ::-webkit-scrollbar {
  701. height: 15px;
  702. }
  703. </style>
  704. <style>
  705. #user-inspection-order td {
  706. border-bottom: 0px !important;
  707. border-right: 0px !important;
  708. }
  709. #user-inspection-order th {
  710. border-right: 0px !important;
  711. }
  712. #user-inspection-form .el-form-item__content {
  713. line-height: 0 !important;
  714. }
  715. .el-table td,
  716. .el-table th.is-leaf,
  717. .el-table--border,
  718. .el-table--group {
  719. border-color: #d0d3da;
  720. }
  721. .el-table--border::after,
  722. .el-table--group::after,
  723. .el-table::before {
  724. background-color: #d0d3da;
  725. }
  726. </style>