血透系统PC前端

inspection.vue 21KB

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