detail.vue 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. <template>
  2. <!-- <div class="main-contain outpatientChargesManagement">
  3. <div class="position">
  4. <bread-crumb :crumbs='crumbs'></bread-crumb>
  5. </div> -->
  6. <div>
  7. <div style="display: flex;justify-content: space-between;margin-bottom:10px;">
  8. <div>
  9. <!--<el-button size="small" style="margin-left:10px;" class="filter-item" type="primary"-->
  10. <!--@click="Action">-->
  11. <!--导出-->
  12. <!--</el-button>-->
  13. <el-input size="small" style="width:150px;" v-model="keywords" @input="searchAction"
  14. @keyup.enter.native='searchAction'
  15. placeholder="请输入患者姓名"
  16. class="filter-item"/>
  17. <el-select size="small" v-model="item_type" placeholder="请选择"
  18. style="width:150px;margin-left:10px;" @change="changeItem">
  19. <el-option
  20. label="全部"
  21. value="0">
  22. </el-option>
  23. <el-option
  24. v-for="item,index in items"
  25. :key="index"
  26. :label="item.name"
  27. :value="item.id">
  28. </el-option>
  29. </el-select>
  30. <el-date-picker
  31. v-model="chargeDate"
  32. type="daterange"
  33. value-format="yyyy-MM-dd"
  34. range-separator="至"
  35. start-placeholder="开始日期"
  36. @change="changeDate"
  37. end-placeholder="结束日期">
  38. </el-date-picker>
  39. <!--<el-radio v-model="radio" label="1">明细</el-radio>-->
  40. <!--<el-radio v-model="radio" label="2">汇总</el-radio>-->
  41. </div>
  42. <div>
  43. <!-- <el-popover
  44. placement="bottom"
  45. width="210"
  46. trigger="click">
  47. <el-button size="small" ref="button_two" @click="open(1)">打印清单</el-button>
  48. <el-button size="small" ref="button_six" @click="open(2)">打印汇总</el-button>
  49. <el-button slot="reference" style="margin:0 10px;" type="primary" size="small">打印</el-button>
  50. </el-popover> -->
  51. <el-button size="small" type="primary" @click="export_detail">报表下载</el-button>
  52. </div>
  53. </div>
  54. <el-table :data="tableData" border :row-style="{ color: '#303133' }" ref="table"
  55. :header-cell-style="{backgroundColor: 'rgb(245, 247, 250)',color: '#606266'}"
  56. :span-method="merge"
  57. show-summary
  58. :summary-method="getTotal"
  59. max-height="600"
  60. v-loading="detail_loading"
  61. highlight-current-row>
  62. <el-table-column align="center" prop="name" label="患者名字">
  63. <template slot-scope="scope">{{ scope.row.name }}</template>
  64. </el-table-column>
  65. <!--<el-table-column align="center" prop="name" label="患者类型">-->
  66. <!--<template slot-scope="scope"></template>-->
  67. <!--</el-table-column>-->
  68. <el-table-column align="center" prop="name" label="项目名称">
  69. <template slot-scope="scope">{{scope.row.item_name}}</template>
  70. </el-table-column>
  71. <el-table-column align="center" prop="name" label="规格">
  72. <template slot-scope="scope">{{scope.row.item_spec}}</template>
  73. </el-table-column>
  74. <el-table-column align="center" prop="name" label="数量">
  75. <template slot-scope="scope">{{scope.row.count}}</template>
  76. </el-table-column>
  77. <el-table-column align="center" prop="name" label="单价">
  78. <template slot-scope="scope">{{scope.row.price.toFixed(2)}}</template>
  79. </el-table-column>
  80. <el-table-column align="center" prop="name" label="费用">
  81. <template slot-scope="scope">
  82. <div>{{((scope.row.price*scope.row.count).toFixed(2))}}</div>
  83. </template>
  84. </el-table-column>
  85. <el-table-column align="center" prop="total" label="费用总额">
  86. <template slot-scope="scope">
  87. <div>{{scope.row.total}}</div>
  88. </template>
  89. </el-table-column>
  90. </el-table>
  91. </div>
  92. <!-- </div> -->
  93. </template>
  94. <script>
  95. import BreadCrumb from '@/xt_pages/components/bread-crumb'
  96. import { GetSummaryDetail } from '@/api/his/his'
  97. import { uParseTime } from '@/utils/tools'
  98. import axios from 'axios'
  99. // import NewStatementPrint from './newStatementPrint'
  100. const moment = require('moment')
  101. export default {
  102. components: {
  103. BreadCrumb
  104. },
  105. data() {
  106. return {
  107. detail_loading: false,
  108. tempArr: [],
  109. pos: 0,
  110. sameRowArr: [],
  111. keywords: '',
  112. tableData: [],
  113. chargeDate: [moment(new Date()).add('year', 0).format('YYYY-MM-DD'), moment(new Date()).add('year', 0).format('YYYY-MM-DD')],
  114. item_type: '0',
  115. items: [
  116. { id: 1, name: '药品' },
  117. { id: 2, name: '项目' },
  118. { id: 3, name: '耗材' }
  119. ]
  120. }
  121. },
  122. methods: {
  123. Action(){
  124. var that = this
  125. axios.get('http://127.0.0.1:9531/handelExcel', {
  126. params: {}
  127. })
  128. .then(function(response) {
  129. if (response.data.state == 0) {
  130. that.$message.error(response.data.msg)
  131. return false
  132. } else {
  133. var list = []
  134. for(let i = 0; i < response.data.data.list.length; i++){
  135. let team = response.data.data.list[i]
  136. for(let b = 0; b < team.list.length; b++){
  137. let name = ""
  138. if(team.list[b].type == 2){
  139. name = team.list[b].project.project_name
  140. }else{
  141. name = team.list[b].good_info.good_name
  142. }
  143. let obj = {
  144. '客户组合编码': team.id,
  145. '客户组合名称': team.project_team,
  146. '客户单项编码': team.list[b].id,
  147. '客户单项名称': name,
  148. '中心组合编码': '',
  149. '中心组合名称': '',
  150. '中心单项编码': '',
  151. '中心单项名称': '',
  152. }
  153. list.push(obj)
  154. }
  155. }
  156. import('@/vendor/Export2Excel').then(excel => {
  157. const tHeader = [ '客户组合编码', '客户组合名称', '客户单项编码', '客户单项名称', '中心组合编码', '中心组合名称', '中心单项编码', '中心单项名称']
  158. const filterVal = [ '客户组合编码', '客户组合名称', '客户单项编码', '客户单项名称', '中心组合编码', '中心组合名称', '中心单项编码', '中心单项名称']
  159. const data = that.formatJson(filterVal, list)
  160. excel.export_json_to_excel({
  161. header: tHeader,
  162. data,
  163. filename: "消费明细"
  164. })
  165. })
  166. }
  167. })
  168. .catch(function(error) {
  169. })
  170. },formatJson(filterVal, jsonData) {
  171. return jsonData.map(v => filterVal.map(j => v[j]))
  172. },
  173. objectSpanMethod({ row, column, rowIndex, columnIndex }) {
  174. if (columnIndex === 0) {
  175. if (rowIndex % 2 === 0) {
  176. return {
  177. rowspan: 2,
  178. colspan: 1
  179. }
  180. } else {
  181. return {
  182. rowspan: 0,
  183. colspan: 0
  184. }
  185. }
  186. }
  187. },
  188. unique(arr) {
  189. const res = new Map()
  190. return arr.filter((arr) => !res.has(arr.id) && res.set(arr.id, 1))
  191. },
  192. changeDate() {
  193. this.getSummaryDetailList()
  194. },
  195. changeItem() {
  196. this.getSummaryDetailList()
  197. },
  198. searchAction() {
  199. this.item_type = '0'
  200. this.getSummaryDetailList()
  201. },
  202. getSummaryDetailList() {
  203. this.detail_loading = true
  204. let start_time = this.chargeDate[0]
  205. let end_time = this.chargeDate[1]
  206. let params = {
  207. start_time: start_time,
  208. end_time: end_time,
  209. type: this.item_type,
  210. keyword: this.keywords
  211. }
  212. GetSummaryDetail(params).then(response => {
  213. if (response.data.state == 0) {
  214. this.detail_loading = false
  215. this.$message.error(response.data.msg)
  216. return false
  217. } else {
  218. this.detail_loading = false
  219. this.tableData = []
  220. let tempPatients = []
  221. let tempPatientsTwo = []
  222. let tempData = response.data.data.patients
  223. let data = response.data.data.patients
  224. let orders = this.unique(tempData)
  225. for (let i = 0; i < orders.length; i++) {
  226. let obj = {
  227. patient_id: orders[i].id,
  228. name: orders[i].name,
  229. orders: []
  230. }
  231. for (let b = 0; b < data.length; b++) {
  232. if (orders[i].id == data[b].id) {
  233. obj.orders = obj.orders.concat(data[b].orders)
  234. }
  235. }
  236. tempPatients.push(obj)
  237. }
  238. for (let i = 0; i < tempPatients.length; i++) {
  239. let obj = {
  240. patient_id: tempPatients[i].patient_id,
  241. name: tempPatients[i].name,
  242. order_info: []
  243. }
  244. let orders = tempPatients[i].orders
  245. for (let b = 0; b < orders.length; b++) {
  246. for (let c = 0; c < orders[b].order_info.length; c++) {
  247. let newObj = {}
  248. newObj['count'] = orders[b].order_info[c].cnt
  249. newObj['price'] = orders[b].order_info[c].pric
  250. newObj['item_total'] = orders[b].order_info[c].det_item_fee_sumamt
  251. if (orders[b].order_info[c].advice_id > 0 && orders[b].order_info[c].project_id == 0) {
  252. newObj['type'] = 1
  253. newObj['item_name'] = orders[b].order_info[c].advice.advice_name
  254. newObj['item_id'] = orders[b].order_info[c].advice.drug_id
  255. if (orders[b].order_info[c].advice.drug.min_unit != orders[b].order_info[c].advice.drug.dose_unit) {
  256. newObj['item_spec'] = orders[b].order_info[c].advice.drug.dose + orders[b].order_info[c].advice.drug.dose_unit + '*' + orders[b].order_info[c].advice.drug.min_number + orders[b].order_info[c].advice.drug.min_unit + '/' + orders[b].order_info[c].advice.drug.max_unit
  257. } else {
  258. newObj['item_spec'] = ''
  259. }
  260. }
  261. if (orders[b].order_info[c].advice_id == 0 && orders[b].order_info[c].project_id > 0) {
  262. newObj['type'] = 2
  263. newObj['item_id'] = orders[b].order_info[c].project.project_id
  264. if (orders[b].order_info[c].project.type == 2) {
  265. newObj['item_spec'] =""
  266. newObj['item_name'] = orders[b].order_info[c].project.project.project_name
  267. } else if (orders[b].order_info[c].project.type == 3) {
  268. newObj['item_spec'] = orders[b].order_info[c].project.good_info.specification_name
  269. newObj['item_name'] = orders[b].order_info[c].project.good_info.good_name
  270. }
  271. }
  272. obj.order_info.push(newObj)
  273. }
  274. }
  275. tempPatientsTwo.push(obj)
  276. }
  277. for (let d = 0; d < tempPatientsTwo.length; d++) {
  278. tempPatientsTwo[d]['new_order_info'] = []
  279. let project = []
  280. let advice = []
  281. for (let b = 0; b < tempPatientsTwo[d].order_info.length; b++) {
  282. if (tempPatientsTwo[d].order_info[b].type == 1) {
  283. advice.push(tempPatientsTwo[d].order_info[b])
  284. } else {
  285. project.push(tempPatientsTwo[d].order_info[b])
  286. }
  287. }
  288. project = this.uniqueProjectAndAdvice(project)
  289. advice = this.uniqueProjectAndAdvice(advice)
  290. for (let i = 0; i < project.length; i++) {
  291. let obj = {}
  292. let count = 0
  293. for (let a = 0; a < tempPatientsTwo[d].order_info.length; a++) {
  294. if (project[i].item_id == tempPatientsTwo[d].order_info[a].item_id && project[i].price == tempPatientsTwo[d].order_info[a].price) {
  295. count = count + tempPatientsTwo[d].order_info[a].count
  296. }
  297. }
  298. obj['price'] = project[i].price
  299. obj['type'] = project[i].type
  300. obj['item_name'] = project[i].item_name
  301. obj['item_spec'] = project[i].item_spec
  302. obj['item_total'] = project[i].item_total
  303. obj['item_id'] = project[i].item_id
  304. obj['name'] = tempPatientsTwo[d].name
  305. obj['patient_id'] = tempPatientsTwo[d].patient_id
  306. obj['count'] = count
  307. tempPatientsTwo[d].new_order_info.push(obj)
  308. }
  309. for (let i = 0; i < advice.length; i++) {
  310. let obj = {}
  311. let count = 0
  312. for (let a = 0; a < tempPatientsTwo[d].order_info.length; a++) {
  313. if (advice[i].item_id == tempPatientsTwo[d].order_info[a].item_id && advice[i].price == tempPatientsTwo[d].order_info[a].price) {
  314. count = count + tempPatientsTwo[d].order_info[a].count
  315. }
  316. }
  317. obj['price'] = advice[i].price
  318. obj['type'] = advice[i].type
  319. obj['item_name'] = advice[i].item_name
  320. obj['item_spec'] = advice[i].item_spec
  321. obj['item_id'] = advice[i].item_id
  322. obj['name'] = tempPatientsTwo[d].name
  323. obj['item_total'] = advice[i].item_total
  324. obj['patient_id'] = tempPatientsTwo[d].patient_id
  325. obj['count'] = count
  326. tempPatientsTwo[d].new_order_info.push(obj)
  327. }
  328. }
  329. for (let i = 0; i < tempPatientsTwo.length; i++) {
  330. let total = 0
  331. for (let b = 0; b < tempPatientsTwo[i].new_order_info.length; b++) {
  332. let new_name = tempPatientsTwo[i].new_order_info[b].item_name
  333. if (new_name != undefined){
  334. if (new_name.length != 0) {
  335. console.log(total)
  336. console.log(tempPatientsTwo[i].new_order_info[b].item_total)
  337. total = parseFloat(total) + parseFloat(tempPatientsTwo[i].new_order_info[b].item_total).toFixed(2)
  338. }
  339. }
  340. }
  341. tempPatientsTwo[i]['total'] = total
  342. }
  343. console.log('tempPatientsTwo', tempPatientsTwo)
  344. for (let i = 0; i < tempPatientsTwo.length; i++) {
  345. // console.log(111,tempPatientsTwo[i].total)
  346. if (tempPatientsTwo[i].new_order_info.length > 0) {
  347. for (let b = 0; b < tempPatientsTwo[i].new_order_info.length; b++) {
  348. // let new_name = tempPatientsTwo[i].new_order_info[b].item_name
  349. // console.log('2 ' + new_name)
  350. //
  351. // new_name = new_name.replace('( ', '')
  352. // new_name = new_name.replace(' )', '')
  353. let obj = {
  354. name: tempPatientsTwo[i].name,
  355. patient_id: tempPatientsTwo[i].patient_id,
  356. price: tempPatientsTwo[i].new_order_info[b].price,
  357. type: tempPatientsTwo[i].new_order_info[b].type,
  358. item_name: tempPatientsTwo[i].new_order_info[b].item_name,
  359. item_id: tempPatientsTwo[i].new_order_info[b].item_id,
  360. count: tempPatientsTwo[i].new_order_info[b].count,
  361. item_spec: tempPatientsTwo[i].new_order_info[b].item_spec
  362. }
  363. // if(b == 0){
  364. obj['total'] = tempPatientsTwo[i].total
  365. // }else{
  366. // obj['total'] = 0
  367. // }
  368. this.tableData.push(obj)
  369. }
  370. }
  371. }
  372. this.handleSpanTempArr()
  373. // this.tableData = tempPatientsTwo
  374. // console.log(tempPatientsTwo.length)
  375. //
  376. }
  377. //
  378. // console.log('去重前')
  379. // console.log(advice)
  380. // console.log(project)
  381. // //
  382. // //
  383. // //
  384. // console.log('去重后')
  385. //
  386. // console.log(advice.length)
  387. // console.log(project.length)
  388. //
  389. // for (let i = 0; i < project.length; i++) {
  390. // let obj = {}
  391. // let count = 0
  392. // for (let a = 0; a < tempPatientsTwo.length; a++) {
  393. // if (project[i].patient_id == tempPatientsTwo[a].patient_id && project[i].item_id == tempPatientsTwo[a].item_id && project[i].price == tempPatientsTwo[a].price) {
  394. // count = count + tempPatientsTwo[a].count
  395. // obj['count'] = count
  396. //
  397. // }
  398. // obj['price'] = project[i].price
  399. // obj['type'] = project[i].type
  400. // obj['item_name'] = project[i].item_name
  401. // obj['item_id'] = project[i].item_id
  402. // obj['name'] = project[i].name
  403. // obj['patient_id'] = project[i].patient_id
  404. // obj['count'] = count
  405. // this.tableData.push(obj)
  406. // }
  407. // }
  408. //
  409. //
  410. // for (let i = 0; i < advice.length; i++) {
  411. // let obj = {}
  412. // let count = 0
  413. // for (let a = 0; a < tempPatientsTwo.length; a++) {
  414. // if (advice[i].patient_id == tempPatientsTwo[a].patient_id && advice[i].item_id == tempPatientsTwo[a].item_id && advice[i].price == tempPatientsTwo[a].price) {
  415. // count = count + tempPatientsTwo[a].count
  416. // obj['count'] = count
  417. //
  418. // }
  419. // obj['price'] = advice[i].price
  420. // obj['type'] = advice[i].type
  421. // obj['item_name'] = advice[i].item_name
  422. // obj['item_id'] = advice[i].item_id
  423. // obj['name'] = advice[i].name
  424. // obj['patient_id'] = advice[i].patient_id
  425. // this.tableData.push(obj)
  426. // }
  427. // }
  428. // console.log(this.tableData.length)
  429. // this.tableData = this.sort(this.tableData)
  430. })
  431. }, uniqueProjectAndAdvice(array) {
  432. // res用来存储结果
  433. var res = []
  434. for (var i = 0, arrayLen = array.length; i < arrayLen; i++) {
  435. for (var j = 0, resLen = res.length; j < resLen; j++) {
  436. if (array[i].item_id === res[j].item_id && array[i].price === res[j].price) {
  437. break
  438. }
  439. }
  440. // 如果array[i]是唯一的,那么执行完循环,j等于resLen
  441. if (j === resLen) {
  442. res.push(array[i])
  443. }
  444. }
  445. return res
  446. }, sort(arr) {
  447. for (var i = 0; i < arr.length - 1; i++) {
  448. for (var j = 0; j < arr.length - i - 1; j++) {
  449. if (arr[j].patient_id > arr[j + 1].patient_id) {// 相邻元素两两对比
  450. var hand = arr[j]
  451. arr[j] = arr[j + 1]
  452. arr[j + 1] = hand
  453. }
  454. }
  455. }
  456. return arr
  457. }, handleSpanTempArr() {
  458. this.tempArr = []
  459. for (let i = 0; i < this.tableData.length; i++) {
  460. if (i === 0) {
  461. this.tempArr.push(1)
  462. this.pos = 0
  463. } else {
  464. // 判断当前元素与上一个元素是否相同
  465. if (this.tableData[i].patient_id === this.tableData[i - 1].patient_id) {
  466. this.tempArr[this.pos] += 1
  467. this.tempArr.push(0)
  468. } else {
  469. this.tempArr.push(1)
  470. this.pos = i
  471. }
  472. }
  473. }
  474. let sameRowArr = [], sIdx = 0
  475. this.tableData.forEach((item, index) => {
  476. item.index = index
  477. if (index === 0) {
  478. sameRowArr.push([index])
  479. } else {
  480. if (item.patient_id === this.tableData[index - 1].patient_id) {
  481. sameRowArr[sIdx].push(index)
  482. } else {
  483. sIdx = sIdx + 1
  484. sameRowArr.push([index])
  485. }
  486. }
  487. })
  488. this.sameRowArr = sameRowArr
  489. }, merge({ row, column, rowIndex, columnIndex }) {
  490. if (columnIndex === 0 || columnIndex === 6) {
  491. const _row = this.tempArr[rowIndex]
  492. const _col = _row > 0 ? 1 : 0
  493. return {
  494. rowspan: _row,
  495. colspan: _col
  496. }
  497. }
  498. }, export_detail() {
  499. let list = []
  500. for (let i = 0; i < this.tableData.length; i++) {
  501. let order = this.tableData[i]
  502. let name = order.name
  503. let item_name = order.item_name
  504. let count = order.count
  505. let price = order.price.toFixed(2)
  506. let pay_sumamt = (order.price.toFixed(2) * order.count).toFixed(2)
  507. let total = order.total.toFixed(2)
  508. let obj = {
  509. '患者姓名': name,
  510. '项目名称': item_name,
  511. '数量': count,
  512. '单价': price,
  513. '费用': pay_sumamt,
  514. '费用总额': total
  515. }
  516. list.push(obj)
  517. }
  518. import('@/vendor/Export2Excel').then(excel => {
  519. const tHeader = ['患者姓名', '项目名称', '数量', '单价', '费用', '费用总额']
  520. const filterVal = ['患者姓名', '项目名称', '数量', '单价', '费用', '费用总额']
  521. const data = this.formatJson(filterVal, list)
  522. excel.export_json_to_excel1({
  523. header: tHeader,
  524. data,
  525. filename: '明细',
  526. ref: this.$refs['table'].$el
  527. })
  528. })
  529. }, formatJson(filterVal, jsonData) {
  530. return jsonData.map(v => filterVal.map(j => v[j]))
  531. }, getTotal(param) {
  532. const { columns, data } = param
  533. const sums = []
  534. columns.forEach((column, index) => {
  535. if (index === 0) {
  536. sums[index] = '合计'
  537. return
  538. }
  539. console.log(data)
  540. const values = data.map(item => Number(item[column.property]))
  541. if (column.property === 'total') {
  542. // sums[index] = values.reduce((prev, curr) => {
  543. // const value = Number(curr)
  544. // if (!isNaN(value)) {
  545. // return prev + curr
  546. // } else {
  547. // return prev
  548. // }
  549. // }, 0)
  550. // sums[index] = sums[index].toFixed(2)
  551. let num = 0
  552. data.map(item => {
  553. num += item.price.toFixed(2) * item.count
  554. })
  555. sums[index] = num.toFixed(2)
  556. } else {
  557. sums[index] = ''
  558. }
  559. })
  560. return sums
  561. }
  562. },
  563. created() {
  564. this.getSummaryDetailList()
  565. }
  566. }
  567. </script>