inspection.vue 22KB

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