apportionmentLevel.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-07-27 19:23:55
  4. * @LastEditTime: 2021-08-17 09:12:31
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: /TracerMethodology_PC/config/apportionmentLevel.js
  8. */
  9. /*
  10. * @Author: your name
  11. * @Date: 2021-07-26 08:51:42
  12. * @LastEditTime: 2021-07-27 16:42:44
  13. * @LastEditors: Please set LastEditors
  14. * @Description: In User Settings Edit
  15. * @FilePath: /TracerMethodology_PC/mock/department.js
  16. */
  17. import moment from 'moment';
  18. import { parse } from 'url'; // mock tableListDataSource
  19. const genList = (current, pageSize) => {
  20. const tableListDataSource = [];
  21. for (let i = 0; i < pageSize; i += 1) {
  22. const index = (current - 1) * 10 + i;
  23. tableListDataSource.push({
  24. key: index,
  25. id: index,
  26. shareName: `分摊层级名 ${index}`,
  27. targetLevel:1,
  28. leverSort: `分摊层级序号 ${index}`,
  29. calcType:1,
  30. // owner: '曲丽丽',
  31. // desc: '这是一段描述',
  32. // updatedAt: moment().format('YYYY-MM-DD'),
  33. createTime: moment().format('YYYY-MM-DD'),
  34. });
  35. }
  36. // console.log({tableListDataSource});
  37. tableListDataSource.reverse();
  38. return tableListDataSource;
  39. };
  40. let tableListDataSource = genList(1, 100);
  41. function getList(req, res, u) {
  42. let realUrl = u;
  43. if (!realUrl || Object.prototype.toString.call(realUrl) !== '[object String]') {
  44. realUrl = req.url;
  45. }
  46. const { current = 1, pageSize = 10 } = req.query;
  47. const params = parse(realUrl, true).query;
  48. let dataSource = [...tableListDataSource].slice((current - 1) * pageSize, current * pageSize);
  49. if (params.sorter) {
  50. const sorter = JSON.parse(params.sorter);
  51. dataSource = dataSource.sort((prev, next) => {
  52. let sortNumber = 0;
  53. Object.keys(sorter).forEach((key) => {
  54. if (sorter[key] === 'descend') {
  55. if (prev[key] - next[key] > 0) {
  56. sortNumber += -1;
  57. } else {
  58. sortNumber += 1;
  59. }
  60. return;
  61. }
  62. if (prev[key] - next[key] > 0) {
  63. sortNumber += 1;
  64. } else {
  65. sortNumber += -1;
  66. }
  67. });
  68. return sortNumber;
  69. });
  70. }
  71. if (params.filter) {
  72. const filter = JSON.parse(params.filter);
  73. if (Object.keys(filter).length > 0) {
  74. dataSource = dataSource.filter((item) => {
  75. return Object.keys(filter).some((key) => {
  76. if (!filter[key]) {
  77. return true;
  78. }
  79. if (filter[key].includes(`${item[key]}`)) {
  80. return true;
  81. }
  82. return false;
  83. });
  84. });
  85. }
  86. }
  87. if (params.name) {
  88. dataSource = dataSource.filter((data) => data?.name?.includes(params.name || ''));
  89. }
  90. const result = {
  91. data: {
  92. list: dataSource,
  93. totalCount: tableListDataSource.length,
  94. pageSize: pageSize,
  95. },
  96. status: 200,
  97. success: true,
  98. };
  99. return res.json(result);
  100. }
  101. function updateList(req, res, u, b) {
  102. let realUrl = u;
  103. if (!realUrl || Object.prototype.toString.call(realUrl) !== '[object String]') {
  104. realUrl = req.url;
  105. }
  106. // const body = (b && b.body) || req.body;
  107. const { method, body } = req;
  108. const { name,isHospital,parentId,parentName} = body;
  109. switch (method) {
  110. /* eslint no-case-declarations:0 */
  111. case 'DELETE':
  112. const {ids} = body;
  113. // console.log({realUrl});
  114. tableListDataSource = tableListDataSource.filter((item) => !ids.includes(item.id));
  115. break;
  116. case 'POST':
  117. (() => {
  118. const i = Math.ceil(Math.random() * 10000);
  119. const newRule = {
  120. key: tableListDataSource.length,
  121. id:tableListDataSource.length,
  122. avatar: [
  123. 'https://gw.alipayobjects.com/zos/rmsportal/eeHMaZBwmTvLdIwMfBpg.png',
  124. 'https://gw.alipayobjects.com/zos/rmsportal/udxAbMEhpwthVVcjLXik.png',
  125. ][i % 2],
  126. name,isHospital,parentId,parentName,
  127. createdAt: moment().format('YYYY-MM-DD'),
  128. };
  129. tableListDataSource.unshift(newRule);
  130. return res.json(newRule);
  131. })();
  132. return;
  133. case 'update':
  134. (() => {
  135. let newRule = {};
  136. tableListDataSource = tableListDataSource.map((item) => {
  137. if (item.key === key) {
  138. newRule = { ...item, desc, name };
  139. return { ...item, desc, name };
  140. }
  141. return item;
  142. });
  143. return res.json(newRule);
  144. })();
  145. return;
  146. default:
  147. break;
  148. }
  149. const result = {
  150. list: tableListDataSource,
  151. pagination: {
  152. total: tableListDataSource.length,
  153. },
  154. };
  155. res.json(result);
  156. }
  157. export default {
  158. // GET 科室列表
  159. 'GET /api/costAccount/costsharelevel/list':getList,
  160. 'POST /api/costAccount/costsharelevel/save': updateList,
  161. 'DELETE /api/costAccount/costsharelevel/delete': updateList,
  162. };