districtMana.js 5.7 KB

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