detail.vue 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  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.count}}</template>
  73. </el-table-column>
  74. <el-table-column align="center" prop="name" label="单价">
  75. <template slot-scope="scope">{{scope.row.price.toFixed(2)}}</template>
  76. </el-table-column>
  77. <el-table-column align="center" prop="name" label="费用">
  78. <template slot-scope="scope">
  79. <div>{{(scope.row.price.toFixed(2)*scope.row.count).toFixed(2)}}</div>
  80. </template>
  81. </el-table-column>
  82. <el-table-column align="center" prop="total" label="费用总额">
  83. <template slot-scope="scope">
  84. <div>{{scope.row.total.toFixed(2)}}</div>
  85. </template>
  86. </el-table-column>
  87. </el-table>
  88. </div>
  89. <!-- </div> -->
  90. </template>
  91. <script>
  92. import BreadCrumb from '@/xt_pages/components/bread-crumb'
  93. import { GetSummaryDetail } from '@/api/his/his'
  94. import { uParseTime } from '@/utils/tools'
  95. // import NewStatementPrint from './newStatementPrint'
  96. const moment = require('moment')
  97. export default {
  98. components: {
  99. BreadCrumb
  100. },
  101. data() {
  102. return {
  103. detail_loading: false,
  104. tempArr: [],
  105. pos: 0,
  106. sameRowArr: [],
  107. keywords: '',
  108. tableData: [],
  109. chargeDate: [moment(new Date()).add('year', 0).format('YYYY-MM-DD'), moment(new Date()).add('year', 0).format('YYYY-MM-DD')],
  110. item_type: '0',
  111. items: [
  112. { id: 1, name: '药品' },
  113. { id: 2, name: '项目' },
  114. { id: 3, name: '耗材' }
  115. ]
  116. }
  117. },
  118. methods: {
  119. objectSpanMethod({ row, column, rowIndex, columnIndex }) {
  120. if (columnIndex === 0) {
  121. if (rowIndex % 2 === 0) {
  122. return {
  123. rowspan: 2,
  124. colspan: 1
  125. }
  126. } else {
  127. return {
  128. rowspan: 0,
  129. colspan: 0
  130. }
  131. }
  132. }
  133. },
  134. unique(arr) {
  135. const res = new Map()
  136. return arr.filter((arr) => !res.has(arr.id) && res.set(arr.id, 1))
  137. },
  138. changeDate() {
  139. this.getSummaryDetailList()
  140. },
  141. changeItem() {
  142. this.getSummaryDetailList()
  143. },
  144. searchAction() {
  145. this.item_type = '0'
  146. this.getSummaryDetailList()
  147. },
  148. getSummaryDetailList() {
  149. this.detail_loading = true
  150. let start_time = this.chargeDate[0]
  151. let end_time = this.chargeDate[1]
  152. let params = {
  153. start_time: start_time,
  154. end_time: end_time,
  155. type: this.item_type,
  156. keyword: this.keywords
  157. }
  158. GetSummaryDetail(params).then(response => {
  159. if (response.data.state == 0) {
  160. this.detail_loading = false
  161. this.$message.error(response.data.msg)
  162. return false
  163. } else {
  164. this.detail_loading = false
  165. this.tableData = []
  166. let tempPatients = []
  167. let tempPatientsTwo = []
  168. let tempData = response.data.data.patients
  169. let data = response.data.data.patients
  170. let orders = this.unique(tempData)
  171. for (let i = 0; i < orders.length; i++) {
  172. let obj = {
  173. patient_id: orders[i].id,
  174. name: orders[i].name,
  175. orders: []
  176. }
  177. for (let b = 0; b < data.length; b++) {
  178. if (orders[i].id == data[b].id) {
  179. obj.orders = obj.orders.concat(data[b].orders)
  180. }
  181. }
  182. tempPatients.push(obj)
  183. }
  184. for (let i = 0; i < tempPatients.length; i++) {
  185. let obj = {
  186. patient_id: tempPatients[i].patient_id,
  187. name: tempPatients[i].name,
  188. order_info: []
  189. }
  190. let orders = tempPatients[i].orders
  191. for (let b = 0; b < orders.length; b++) {
  192. for (let c = 0; c < orders[b].order_info.length; c++) {
  193. let newObj = {}
  194. newObj['count'] = orders[b].order_info[c].cnt
  195. newObj['price'] = orders[b].order_info[c].pric
  196. if (orders[b].order_info[c].advice_id > 0 && orders[b].order_info[c].project_id == 0) {
  197. newObj['type'] = 1
  198. // newObj['item_name'] = orders[b].order_info[c].advice.advice_name
  199. newObj['item_id'] = orders[b].order_info[c].advice.drug_id
  200. if (orders[b].order_info[c].advice.drug.min_unit != orders[b].order_info[c].advice.drug.dose_unit) {
  201. newObj['item_name'] = orders[b].order_info[c].advice.advice_name + '( ' + 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 + ' )'
  202. } else {
  203. newObj['item_name'] = ''
  204. }
  205. }
  206. if (orders[b].order_info[c].advice_id == 0 && orders[b].order_info[c].project_id > 0) {
  207. newObj['type'] = 2
  208. newObj['item_id'] = orders[b].order_info[c].project.project_id
  209. if (orders[b].order_info[c].project.type == 2) {
  210. newObj['item_name'] = orders[b].order_info[c].project.project.project_name
  211. } else if (orders[b].order_info[c].project.type == 3) {
  212. newObj['item_name'] = orders[b].order_info[c].project.good_info.good_name + '( ' + orders[b].order_info[c].project.good_info.specification_name + ' )'
  213. }
  214. }
  215. obj.order_info.push(newObj)
  216. }
  217. }
  218. tempPatientsTwo.push(obj)
  219. }
  220. for (let d = 0; d < tempPatientsTwo.length; d++) {
  221. tempPatientsTwo[d]['new_order_info'] = []
  222. let project = []
  223. let advice = []
  224. for (let b = 0; b < tempPatientsTwo[d].order_info.length; b++) {
  225. if (tempPatientsTwo[d].order_info[b].type == 1) {
  226. advice.push(tempPatientsTwo[d].order_info[b])
  227. } else {
  228. project.push(tempPatientsTwo[d].order_info[b])
  229. }
  230. }
  231. project = this.uniqueProjectAndAdvice(project)
  232. advice = this.uniqueProjectAndAdvice(advice)
  233. for (let i = 0; i < project.length; i++) {
  234. let obj = {}
  235. let count = 0
  236. for (let a = 0; a < tempPatientsTwo[d].order_info.length; a++) {
  237. if (project[i].item_id == tempPatientsTwo[d].order_info[a].item_id && project[i].price == tempPatientsTwo[d].order_info[a].price) {
  238. count = count + tempPatientsTwo[d].order_info[a].count
  239. }
  240. }
  241. obj['price'] = project[i].price
  242. obj['type'] = project[i].type
  243. obj['item_name'] = project[i].item_name
  244. obj['item_id'] = project[i].item_id
  245. obj['name'] = tempPatientsTwo[d].name
  246. obj['patient_id'] = tempPatientsTwo[d].patient_id
  247. obj['count'] = count
  248. tempPatientsTwo[d].new_order_info.push(obj)
  249. }
  250. for (let i = 0; i < advice.length; i++) {
  251. let obj = {}
  252. let count = 0
  253. for (let a = 0; a < tempPatientsTwo[d].order_info.length; a++) {
  254. if (advice[i].item_id == tempPatientsTwo[d].order_info[a].item_id && advice[i].price == tempPatientsTwo[d].order_info[a].price) {
  255. count = count + tempPatientsTwo[d].order_info[a].count
  256. }
  257. }
  258. obj['price'] = advice[i].price
  259. obj['type'] = advice[i].type
  260. obj['item_name'] = advice[i].item_name
  261. obj['item_id'] = advice[i].item_id
  262. obj['name'] = tempPatientsTwo[d].name
  263. obj['patient_id'] = tempPatientsTwo[d].patient_id
  264. obj['count'] = count
  265. tempPatientsTwo[d].new_order_info.push(obj)
  266. }
  267. }
  268. for (let i = 0; i < tempPatientsTwo.length; i++) {
  269. let total = 0
  270. for (let b = 0; b < tempPatientsTwo[i].new_order_info.length; b++) {
  271. let new_name = tempPatientsTwo[i].new_order_info[b].item_name
  272. new_name = new_name.replace('( ', '')
  273. new_name = new_name.replace(' )', '')
  274. if (new_name.length != 0) {
  275. total = parseFloat(total) + parseFloat((parseFloat(tempPatientsTwo[i].new_order_info[b].count.toString()) * parseFloat(tempPatientsTwo[i].new_order_info[b].price.toString().toString())).toFixed(2))
  276. }
  277. }
  278. tempPatientsTwo[i]['total'] = total
  279. }
  280. console.log('tempPatientsTwo', tempPatientsTwo)
  281. for (let i = 0; i < tempPatientsTwo.length; i++) {
  282. // console.log(111,tempPatientsTwo[i].total)
  283. if (tempPatientsTwo[i].new_order_info.length > 0) {
  284. for (let b = 0; b < tempPatientsTwo[i].new_order_info.length; b++) {
  285. let new_name = tempPatientsTwo[i].new_order_info[b].item_name
  286. console.log('2 ' + new_name)
  287. new_name = new_name.replace('( ', '')
  288. new_name = new_name.replace(' )', '')
  289. if (new_name.length != 0) {
  290. let obj = {
  291. name: tempPatientsTwo[i].name,
  292. patient_id: tempPatientsTwo[i].patient_id,
  293. price: tempPatientsTwo[i].new_order_info[b].price,
  294. type: tempPatientsTwo[i].new_order_info[b].type,
  295. item_name: tempPatientsTwo[i].new_order_info[b].item_name,
  296. item_id: tempPatientsTwo[i].new_order_info[b].item_id,
  297. count: tempPatientsTwo[i].new_order_info[b].count
  298. }
  299. // if(b == 0){
  300. obj['total'] = tempPatientsTwo[i].total
  301. // }else{
  302. // obj['total'] = 0
  303. // }
  304. this.tableData.push(obj)
  305. }
  306. }
  307. }
  308. }
  309. this.handleSpanTempArr()
  310. // this.tableData = tempPatientsTwo
  311. // console.log(tempPatientsTwo.length)
  312. //
  313. }
  314. //
  315. // console.log('去重前')
  316. // console.log(advice)
  317. // console.log(project)
  318. // //
  319. // //
  320. // //
  321. // console.log('去重后')
  322. //
  323. // console.log(advice.length)
  324. // console.log(project.length)
  325. //
  326. // for (let i = 0; i < project.length; i++) {
  327. // let obj = {}
  328. // let count = 0
  329. // for (let a = 0; a < tempPatientsTwo.length; a++) {
  330. // if (project[i].patient_id == tempPatientsTwo[a].patient_id && project[i].item_id == tempPatientsTwo[a].item_id && project[i].price == tempPatientsTwo[a].price) {
  331. // count = count + tempPatientsTwo[a].count
  332. // obj['count'] = count
  333. //
  334. // }
  335. // obj['price'] = project[i].price
  336. // obj['type'] = project[i].type
  337. // obj['item_name'] = project[i].item_name
  338. // obj['item_id'] = project[i].item_id
  339. // obj['name'] = project[i].name
  340. // obj['patient_id'] = project[i].patient_id
  341. // obj['count'] = count
  342. // this.tableData.push(obj)
  343. // }
  344. // }
  345. //
  346. //
  347. // for (let i = 0; i < advice.length; i++) {
  348. // let obj = {}
  349. // let count = 0
  350. // for (let a = 0; a < tempPatientsTwo.length; a++) {
  351. // if (advice[i].patient_id == tempPatientsTwo[a].patient_id && advice[i].item_id == tempPatientsTwo[a].item_id && advice[i].price == tempPatientsTwo[a].price) {
  352. // count = count + tempPatientsTwo[a].count
  353. // obj['count'] = count
  354. //
  355. // }
  356. // obj['price'] = advice[i].price
  357. // obj['type'] = advice[i].type
  358. // obj['item_name'] = advice[i].item_name
  359. // obj['item_id'] = advice[i].item_id
  360. // obj['name'] = advice[i].name
  361. // obj['patient_id'] = advice[i].patient_id
  362. // this.tableData.push(obj)
  363. // }
  364. // }
  365. // console.log(this.tableData.length)
  366. // this.tableData = this.sort(this.tableData)
  367. })
  368. }, uniqueProjectAndAdvice(array) {
  369. // res用来存储结果
  370. var res = []
  371. for (var i = 0, arrayLen = array.length; i < arrayLen; i++) {
  372. for (var j = 0, resLen = res.length; j < resLen; j++) {
  373. if (array[i].item_id === res[j].item_id && array[i].price === res[j].price) {
  374. break
  375. }
  376. }
  377. // 如果array[i]是唯一的,那么执行完循环,j等于resLen
  378. if (j === resLen) {
  379. res.push(array[i])
  380. }
  381. }
  382. return res
  383. }, sort(arr) {
  384. for (var i = 0; i < arr.length - 1; i++) {
  385. for (var j = 0; j < arr.length - i - 1; j++) {
  386. if (arr[j].patient_id > arr[j + 1].patient_id) {// 相邻元素两两对比
  387. var hand = arr[j]
  388. arr[j] = arr[j + 1]
  389. arr[j + 1] = hand
  390. }
  391. }
  392. }
  393. return arr
  394. }, handleSpanTempArr() {
  395. this.tempArr = []
  396. for (let i = 0; i < this.tableData.length; i++) {
  397. if (i === 0) {
  398. this.tempArr.push(1)
  399. this.pos = 0
  400. } else {
  401. // 判断当前元素与上一个元素是否相同
  402. if (this.tableData[i].patient_id === this.tableData[i - 1].patient_id) {
  403. this.tempArr[this.pos] += 1
  404. this.tempArr.push(0)
  405. } else {
  406. this.tempArr.push(1)
  407. this.pos = i
  408. }
  409. }
  410. }
  411. let sameRowArr = [], sIdx = 0
  412. this.tableData.forEach((item, index) => {
  413. item.index = index
  414. if (index === 0) {
  415. sameRowArr.push([index])
  416. } else {
  417. if (item.patient_id === this.tableData[index - 1].patient_id) {
  418. sameRowArr[sIdx].push(index)
  419. } else {
  420. sIdx = sIdx + 1
  421. sameRowArr.push([index])
  422. }
  423. }
  424. })
  425. this.sameRowArr = sameRowArr
  426. }, merge({ row, column, rowIndex, columnIndex }) {
  427. if (columnIndex === 0 || columnIndex === 5) {
  428. const _row = this.tempArr[rowIndex]
  429. const _col = _row > 0 ? 1 : 0
  430. return {
  431. rowspan: _row,
  432. colspan: _col
  433. }
  434. }
  435. }, export_detail() {
  436. let list = []
  437. for (let i = 0; i < this.tableData.length; i++) {
  438. let order = this.tableData[i]
  439. let name = order.name
  440. let item_name = order.item_name
  441. let count = order.count
  442. let price = order.price.toFixed(2)
  443. let pay_sumamt = (order.price.toFixed(2) * order.count).toFixed(2)
  444. let total = order.total.toFixed(2)
  445. let obj = {
  446. '患者姓名': name,
  447. '项目名称': item_name,
  448. '数量': count,
  449. '单价': price,
  450. '费用': pay_sumamt,
  451. '费用总额': total
  452. }
  453. list.push(obj)
  454. }
  455. import('@/vendor/Export2Excel').then(excel => {
  456. const tHeader = ['患者姓名', '项目名称', '数量', '单价', '费用', '费用总额']
  457. const filterVal = ['患者姓名', '项目名称', '数量', '单价', '费用', '费用总额']
  458. const data = this.formatJson(filterVal, list)
  459. excel.export_json_to_excel1({
  460. header: tHeader,
  461. data,
  462. filename: '明细',
  463. ref: this.$refs['table'].$el
  464. })
  465. })
  466. }, formatJson(filterVal, jsonData) {
  467. return jsonData.map(v => filterVal.map(j => v[j]))
  468. }, getTotal(param) {
  469. const { columns, data } = param
  470. const sums = []
  471. columns.forEach((column, index) => {
  472. if (index === 0) {
  473. sums[index] = '合计'
  474. return
  475. }
  476. console.log(data)
  477. const values = data.map(item => Number(item[column.property]))
  478. if (column.property === 'total') {
  479. // sums[index] = values.reduce((prev, curr) => {
  480. // const value = Number(curr)
  481. // if (!isNaN(value)) {
  482. // return prev + curr
  483. // } else {
  484. // return prev
  485. // }
  486. // }, 0)
  487. // sums[index] = sums[index].toFixed(2)
  488. let num = 0
  489. data.map(item => {
  490. num += item.price.toFixed(2) * item.count
  491. })
  492. sums[index] = num.toFixed(2)
  493. } else {
  494. sums[index] = ''
  495. }
  496. })
  497. return sums
  498. }
  499. },
  500. created() {
  501. this.getSummaryDetailList()
  502. }
  503. }
  504. </script>