department.js 5.6 KB

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