gather.vue 17KB

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