responsibilityCenter.js 5.5 KB

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