123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- /*
- * @Author: your name
- * @Date: 2021-07-27 14:29:29
- * @LastEditTime: 2021-07-27 16:09:51
- * @LastEditors: Please set LastEditors
- * @Description: In User Settings Edit
- * @FilePath: /TracerMethodology_PC/mock/districtMana.js
- */
- /*
- * @Author: your name
- * @Date: 2021-07-26 08:51:42
- * @LastEditTime: 2021-07-27 14:12:56
- * @LastEditors: Please set LastEditors
- * @Description: In User Settings Edit
- * @FilePath: /TracerMethodology_PC/mock/department.js
- */
- import moment from 'moment';
- import { parse } from 'url'; // mock tableListDataSource
- // const departmentListList = (current, pageSize) => {
- // const tableListDataSource = [];
- // for (let i = 0; i < pageSize; i += 1) {
- // const index = (current - 1) * 10 + i;
- // tableListDataSource.push({
- // key: index,
- // id:index,
- // disabled: i % 6 === 0,
- // department_name: `科室 ${index}`,
- // department_code:`科室编码 ${index}`,
- // hosp_id:`医院Id ${index}`,
- // owner: '曲丽丽',
- // desc: '这是一段描述',
- // callNo: Math.floor(Math.random() * 1000),
- // status: Math.floor(Math.random() * 10) % 4,
- // updatedAt: moment().format('YYYY-MM-DD'),
- // create_time: moment().format('YYYY-MM-DD'),
- // progress: Math.ceil(Math.random() * 100),
- // });
- // }
- // tableListDataSource.reverse();
- // return {
- // data:{
- // list:tableListDataSource,
- // totalCount:tableListDataSource.length,
- // pageSize
- // }
- // };
- // };
- const genList = (current, pageSize) => {
- const tableListDataSource = [];
- for (let i = 0; i < pageSize; i += 1) {
- const index = (current - 1) * 10 + i;
- tableListDataSource.push({
- key: index,
- id: index,
- name: `医院名 ${index}`,
- isHospital:'1',
- departmentCode: `科室编码 ${index}`,
- sign: `医院标识 ${index}`,
- parentId:1,
- parentName:`parentName ${index}`,
- // owner: '曲丽丽',
- // desc: '这是一段描述',
- // updatedAt: moment().format('YYYY-MM-DD'),
- createTime: moment().format('YYYY-MM-DD'),
- });
- }
- // console.log({tableListDataSource});
- tableListDataSource.reverse();
- return tableListDataSource;
- };
- let tableListDataSource = genList(1, 100);
- function getList(req, res, u) {
- let realUrl = u;
- if (!realUrl || Object.prototype.toString.call(realUrl) !== '[object String]') {
- realUrl = req.url;
- }
- const { current = 1, pageSize = 10 } = req.query;
- const params = parse(realUrl, true).query;
- let dataSource = [...tableListDataSource].slice((current - 1) * pageSize, current * pageSize);
- if (params.sorter) {
- const sorter = JSON.parse(params.sorter);
- dataSource = dataSource.sort((prev, next) => {
- let sortNumber = 0;
- Object.keys(sorter).forEach((key) => {
- if (sorter[key] === 'descend') {
- if (prev[key] - next[key] > 0) {
- sortNumber += -1;
- } else {
- sortNumber += 1;
- }
- return;
- }
- if (prev[key] - next[key] > 0) {
- sortNumber += 1;
- } else {
- sortNumber += -1;
- }
- });
- return sortNumber;
- });
- }
- if (params.filter) {
- const filter = JSON.parse(params.filter);
- if (Object.keys(filter).length > 0) {
- dataSource = dataSource.filter((item) => {
- return Object.keys(filter).some((key) => {
- if (!filter[key]) {
- return true;
- }
- if (filter[key].includes(`${item[key]}`)) {
- return true;
- }
- return false;
- });
- });
- }
- }
- if (params.name) {
- dataSource = dataSource.filter((data) => data?.name?.includes(params.name || ''));
- }
- const result = {
- data: {
- list: dataSource,
- totalCount: tableListDataSource.length,
- pageSize: pageSize,
- },
- status: 200,
- success: true,
- };
- return res.json(result);
- }
- function updateList(req, res, u, b) {
- let realUrl = u;
- if (!realUrl || Object.prototype.toString.call(realUrl) !== '[object String]') {
- realUrl = req.url;
- }
- // const body = (b && b.body) || req.body;
- const { method, body } = req;
- const { name,isHospital,parentId,parentName} = body;
- switch (method) {
- /* eslint no-case-declarations:0 */
- case 'DELETE':
- const {ids} = body;
- // console.log({realUrl});
- tableListDataSource = tableListDataSource.filter((item) => !ids.includes(item.id));
- break;
- case 'POST':
- (() => {
- const i = Math.ceil(Math.random() * 10000);
- const newRule = {
- key: tableListDataSource.length,
- id:tableListDataSource.length,
- avatar: [
- 'https://gw.alipayobjects.com/zos/rmsportal/eeHMaZBwmTvLdIwMfBpg.png',
- 'https://gw.alipayobjects.com/zos/rmsportal/udxAbMEhpwthVVcjLXik.png',
- ][i % 2],
- name,isHospital,parentId,parentName,
- createdAt: moment().format('YYYY-MM-DD'),
- };
- tableListDataSource.unshift(newRule);
- return res.json(newRule);
- })();
- return;
- case 'update':
- (() => {
- let newRule = {};
- tableListDataSource = tableListDataSource.map((item) => {
- if (item.key === key) {
- newRule = { ...item, desc, name };
- return { ...item, desc, name };
- }
- return item;
- });
- return res.json(newRule);
- })();
- return;
- default:
- break;
- }
- const result = {
- list: tableListDataSource,
- pagination: {
- total: tableListDataSource.length,
- },
- };
- res.json(result);
- }
- export default {
- // GET 科室列表
- 'GET /api/hosptail/list':getList,
- 'POST /api/hosptail/save': updateList,
- 'DELETE /api/hosptail/delete': updateList,
- };
|