allgather.vue 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <template>
  2. <div>
  3. <div style="display: flex;justify-content: space-between;margin-bottom:10px;">
  4. <div>
  5. <el-select size="small" v-model="item_time_type" placeholder="请选择"
  6. style="width:150px;margin-left:10px;" @change="changeTimeItem">
  7. <el-option
  8. label="处方时间"
  9. value="0">
  10. </el-option>
  11. <el-option
  12. label="结算时间"
  13. value="1">
  14. </el-option>
  15. </el-select>
  16. <el-date-picker
  17. v-model="chargeDate"
  18. type="daterange"
  19. value-format="yyyy-MM-dd"
  20. range-separator="至"
  21. start-placeholder="开始日期"
  22. @change="changeDate"
  23. end-placeholder="结束日期">
  24. </el-date-picker>
  25. </div>
  26. <div>
  27. <el-button size="small" type="primary" @click="export_detail">报表下载</el-button>
  28. </div>
  29. </div>
  30. <el-table :data="tableData" border :row-style="{ color: '#303133' }" ref="tables"
  31. :header-cell-style="{backgroundColor: 'rgb(245, 247, 250)',color: '#606266'}"
  32. v-loading="gather_loading"
  33. max-height="600"
  34. :span-method="merge"
  35. highlight-current-row>
  36. <el-table-column align="center" prop="item_name" label="项目类别">
  37. <template slot-scope="scope">{{ scope.row.item_name }}</template>
  38. </el-table-column>
  39. <el-table-column align="center" prop="price" label="费用">
  40. <template slot-scope="scope">{{ scope.row.price.toFixed(2) }}</template>
  41. </el-table-column>
  42. <el-table-column align="center" prop="sum" label="费用总额">
  43. <template slot-scope="scope">
  44. <div>{{ scope.row.sum.toFixed(2) }}</div>
  45. </template>
  46. </el-table-column>
  47. </el-table>
  48. </div>
  49. </template>
  50. <script>
  51. import { getDictionaryDataConfig } from '@/utils/data'
  52. import BreadCrumb from '@/xt_pages/components/bread-crumb'
  53. import { GetSummaryDetail } from '@/api/his/his'
  54. // import NewStatementPrint from './newStatementPrint'
  55. const moment = require('moment')
  56. export default {
  57. components: {
  58. BreadCrumb
  59. },
  60. data() {
  61. return {
  62. gather_loading: false,
  63. crumbs: [],
  64. tempArr: [],
  65. sameRowArr: [],
  66. keywords: '',
  67. pos: 0,
  68. all_table_data: [],
  69. costClassify: getDictionaryDataConfig('system', 'cost_classify'),
  70. tableData: [],
  71. chargeDate: [moment(new Date()).add('year', 0).format('YYYY-MM-DD'), moment(new Date()).add('year', 0).format('YYYY-MM-DD')],
  72. item_type: '0',
  73. new_item_type: 0,
  74. item_time_type: '1',
  75. items: [
  76. { id: 1, name: '药品' },
  77. { id: 4, name: '检验费' },
  78. { id: 5, name: '治疗费' },
  79. { id: 6, name: '护理费' },
  80. { id: 7, name: '其他' },
  81. { id: 3, name: '耗材' }
  82. ]
  83. }
  84. },
  85. methods: {
  86. objectSpanMethod({ row, column, rowIndex, columnIndex }) {
  87. if (columnIndex === 0) {
  88. if (rowIndex % 2 === 0) {
  89. return {
  90. rowspan: 2,
  91. colspan: 1
  92. }
  93. } else {
  94. return {
  95. rowspan: 0,
  96. colspan: 0
  97. }
  98. }
  99. }
  100. },
  101. unique(arr) {
  102. const res = new Map()
  103. return arr.filter((arr) => !res.has(arr.id) && res.set(arr.id, 1))
  104. },
  105. changeDate() {
  106. // console.log(this.chargeDate)
  107. this.getSummaryDetailList()
  108. }, changeTimeItem() {
  109. this.getSummaryDetailList()
  110. },
  111. changeItem() {
  112. this.new_item_type = this.item_type
  113. if (this.item_type == 1) {
  114. this.new_item_type = -100
  115. } else if (this.item_type == 5) {
  116. this.new_item_type = -200
  117. }
  118. this.getSummaryDetailList()
  119. }, uniquepid(arr) {
  120. const res = new Map()
  121. return arr.filter((arr) => !res.has(arr.p_id) && res.set(arr.p_id, 1))
  122. },
  123. searchAction() {
  124. this.item_type = '0'
  125. this.getSummaryDetailList()
  126. },
  127. getSummaryDetailList() {
  128. this.gather_loading = true
  129. let start_time = this.chargeDate[0]
  130. let end_time = this.chargeDate[1]
  131. let params = {
  132. start_time: start_time,
  133. end_time: end_time,
  134. type: 0,
  135. keyword: this.keywords,
  136. time_type: this.item_time_type
  137. }
  138. GetSummaryDetail(params).then(response => {
  139. if (response.data.state == 0) {
  140. this.gather_loading = false
  141. this.$message.error(response.data.msg)
  142. return false
  143. } else {
  144. this.gather_loading = false
  145. let tempPatients = []
  146. let tempPatientsTwo = []
  147. this.tableData = []
  148. this.all_table_data = []
  149. let tempData = response.data
  150. tempPatientsTwo = tempData
  151. let infos = this.unique2(tempPatientsTwo)
  152. let sum = 0
  153. for (let e = 0; e < infos.length; e++) {
  154. let obj = {
  155. 'sum': 0,
  156. 'price': 0,
  157. 'cost_classify': infos[e].cost_classify,
  158. 'item_name': this.getName(infos[e].cost_classify)
  159. }
  160. let price = 0
  161. for (let d = 0; d < tempPatientsTwo.length; d++) {
  162. if (tempPatientsTwo[d].cost_classify == infos[e].cost_classify) {
  163. price = parseFloat(price.toString()) + parseFloat((parseFloat(tempPatientsTwo[d].cnt.toString()) * parseFloat(tempPatientsTwo[d].pric.toString()).toFixed(2)).toString())
  164. }
  165. obj.price = price
  166. }
  167. sum = sum + price
  168. this.tableData.push(obj)
  169. }
  170. for(let i = 0; i < this.tableData.length;i++){
  171. this.tableData[i].sum = sum
  172. }
  173. // for (let i = 0; i < tempPatientsThree.length; i++) {
  174. // let sum = 0
  175. // for (let b = 0; b < tempPatientsThree[i].length; b++) {
  176. // let obj = {
  177. // cost_classify: tempPatientsThree[i].items[b].cost_classify,
  178. // price: tempPatientsThree[i].items[b].price,
  179. // item_name: tempPatientsThree[i].items[b].item_name,
  180. // sum: 0
  181. // }
  182. // sum = sum + tempPatientsThree[i].items[b].price
  183. // this.tableData.push(obj)
  184. // this.all_table_data.push(obj)
  185. // }
  186. // for (let c = 0; c < this.tableData.length; c++) {
  187. // this.tableData[c].sum = sum
  188. // }
  189. // }
  190. console.log(this.tableData)
  191. this.handleSpanTempArr()
  192. }
  193. })
  194. }, getName(cost_classify) {
  195. if (cost_classify == -1000) {
  196. return '药品费'
  197. } else if (cost_classify == -100) {
  198. return '耗材费'
  199. } else {
  200. var costClassify = getDictionaryDataConfig('system', 'cost_classify')
  201. var name = ''
  202. for (let i = 0; i < costClassify.length; i++) {
  203. if (cost_classify == costClassify[i].id) {
  204. name = costClassify[i].name
  205. }
  206. }
  207. return name
  208. }
  209. }, uniqueProjectAndAdvice(array) {
  210. // res用来存储结果
  211. var res = []
  212. for (var i = 0, arrayLen = array.length; i < arrayLen; i++) {
  213. for (var j = 0, resLen = res.length; j < resLen; j++) {
  214. if (array[i].item_id === res[j].item_id && array[i].price === res[j].price) {
  215. break
  216. }
  217. }
  218. // 如果array[i]是唯一的,那么执行完循环,j等于resLen
  219. if (j === resLen) {
  220. res.push(array[i])
  221. }
  222. }
  223. return res
  224. }, unique2(array) {
  225. // res用来存储结果
  226. var res = []
  227. for (var i = 0, arrayLen = array.length; i < arrayLen; i++) {
  228. for (var j = 0, resLen = res.length; j < resLen; j++) {
  229. if (array[i].cost_classify === res[j].cost_classify) {
  230. break
  231. }
  232. }
  233. // 如果array[i]是唯一的,那么执行完循环,j等于resLen
  234. if (j === resLen) {
  235. res.push(array[i])
  236. }
  237. }
  238. return res
  239. }, unique3(array) {
  240. console.log('-----11122222')
  241. console.log(array)
  242. // res用来存储结果
  243. var res = []
  244. for (var i = 0, arrayLen = array.length; i < arrayLen; i++) {
  245. for (var j = 0, resLen = res.length; j < resLen; j++) {
  246. if (array[i].patient_id === res[j].patient_id) {
  247. break
  248. }
  249. }
  250. // 如果array[i]是唯一的,那么执行完循环,j等于resLen
  251. if (j === resLen) {
  252. res.push(array[i])
  253. }
  254. }
  255. return res
  256. }, sort(arr) {
  257. for (var i = 0; i < arr.length - 1; i++) {
  258. for (var j = 0; j < arr.length - i - 1; j++) {
  259. if (arr[j].patient_id > arr[j + 1].patient_id) {// 相邻元素两两对比
  260. var hand = arr[j]
  261. arr[j] = arr[j + 1]
  262. arr[j + 1] = hand
  263. }
  264. }
  265. }
  266. return arr
  267. }, handleSpanTempArr() {
  268. this.tempArr = []
  269. for (let i = 0; i < this.tableData.length; i++) {
  270. if (i === 0) {
  271. this.tempArr.push(1)
  272. this.pos = 0
  273. } else {
  274. // 判断当前元素与上一个元素是否相同
  275. if (this.tableData[i].patient_id === this.tableData[i - 1].patient_id) {
  276. this.tempArr[this.pos] += 1
  277. this.tempArr.push(0)
  278. } else {
  279. this.tempArr.push(1)
  280. this.pos = i
  281. }
  282. }
  283. }
  284. let sameRowArr = [], sIdx = 0
  285. this.tableData.forEach((item, index) => {
  286. item.index = index
  287. if (index === 0) {
  288. sameRowArr.push([index])
  289. } else {
  290. if (item.patient_id === this.tableData[index - 1].patient_id) {
  291. sameRowArr[sIdx].push(index)
  292. } else {
  293. sIdx = sIdx + 1
  294. sameRowArr.push([index])
  295. }
  296. }
  297. })
  298. this.sameRowArr = sameRowArr
  299. }, merge({ row, column, rowIndex, columnIndex }) {
  300. if ( columnIndex === 2) {
  301. const _row = this.tempArr[rowIndex]
  302. const _col = _row > 0 ? 1 : 0
  303. return {
  304. rowspan: _row,
  305. colspan: _col
  306. }
  307. }
  308. }, getTotal(param) {
  309. const { columns, data } = param
  310. const sums = []
  311. columns.forEach((column, index) => {
  312. if (index === 0) {
  313. sums[index] = '合计'
  314. return
  315. }
  316. console.log(data)
  317. const values = data.map(item => Number(item[column.property]))
  318. if (column.property === 'sum') {
  319. sums[index] = values.reduce((prev, curr) => {
  320. const value = Number(curr)
  321. if (!isNaN(value)) {
  322. return prev + curr
  323. } else {
  324. return prev
  325. }
  326. }, 0)
  327. sums[index] = sums[index].toFixed(2)
  328. } else {
  329. sums[index] = ''
  330. }
  331. })
  332. return sums
  333. }, export_detail() {
  334. let list = []
  335. for (let i = 0; i < this.tableData.length; i++) {
  336. let order = this.tableData[i]
  337. let name = order.name
  338. let item_name = order.item_name
  339. let pay_sumamt = order.price.toFixed(2)
  340. let total = order.sum.toFixed(2)
  341. let obj = {
  342. '患者姓名': name,
  343. '项目类别': item_name,
  344. '费用': pay_sumamt,
  345. '费用总额': total
  346. }
  347. list.push(obj)
  348. }
  349. import('@/vendor/Export2Excel').then(excel => {
  350. const tHeader = ['患者姓名', '项目名称', '费用', '费用总额']
  351. const filterVal = ['患者姓名', '项目名称', '费用', '费用总额']
  352. const data = this.formatJson(filterVal, list)
  353. excel.export_json_to_excel1({
  354. header: tHeader,
  355. data,
  356. filename: '汇总',
  357. ref: this.$refs['tables'].$el
  358. })
  359. })
  360. }, formatJson(filterVal, jsonData) {
  361. return jsonData.map(v => filterVal.map(j => v[j]))
  362. }
  363. },
  364. created() {
  365. this.getSummaryDetailList()
  366. }
  367. }
  368. </script>