Horace | cc75859 | 2018-08-23 17:40:39 +0800 | [diff] [blame] | 1 | import { param2Obj } from '@/utils' |
| 2 | |
| 3 | const nodeList = [ |
| 4 | { |
| 5 | 'id': '26', |
| 6 | 'name': '后勤处', |
| 7 | 'department': { 'id': '2', 'dwmc': '后勤处' }, |
| 8 | 'contact': '张三', |
| 9 | 'phoneNumber': '021-65431991', |
| 10 | 'scope': { 'id': '27', 'name': '全校范围' }, |
| 11 | 'auditType': { 'id': '25', 'name': '手动' }, |
| 12 | 'defaultAuditStatus': { 'id': '22', 'name': '待审核' }, |
| 13 | 'auditNodeDuty': '', |
| 14 | 'auditNodeAddress': '', |
| 15 | 'deleted': '0' |
| 16 | }, |
| 17 | { |
| 18 | 'id': '27', |
| 19 | 'name': '财务处', |
| 20 | 'department': { 'id': '3', 'dwmc': '财务处' }, |
| 21 | 'contact': '李四', |
| 22 | 'phoneNumber': '021-65431921', |
| 23 | 'scope': { 'id': '27', 'name': '全校范围' }, |
| 24 | 'auditType': { 'id': '26', 'name': '自动' }, |
| 25 | 'defaultAuditStatus': { 'id': '22', 'name': '待审核' }, |
| 26 | 'auditNodeDuty': '', |
| 27 | 'auditNodeAddress': '', |
| 28 | 'deleted': '0' |
| 29 | }, |
| 30 | { |
| 31 | 'id': '28', |
| 32 | 'name': '图书馆', |
| 33 | 'department': { 'id': '4', 'dwmc': '图书馆' }, |
| 34 | 'contact': '王五', |
| 35 | 'phoneNumber': '021-65431931', |
| 36 | 'scope': { 'id': '27', 'name': '全校范围' }, |
| 37 | 'auditType': { 'id': '25', 'name': '手动' }, |
| 38 | 'defaultAuditStatus': { 'id': '22', 'name': '待审核' }, |
| 39 | 'auditNodeDuty': '', |
| 40 | 'auditNodeAddress': '', |
| 41 | 'deleted': '0' |
| 42 | } |
| 43 | ] |
| 44 | |
| 45 | export default{ |
| 46 | getList: config => { |
| 47 | const { name, auditType, pageIndex = 1, pageSize = 20 } = param2Obj(config.url) |
| 48 | const mockList = nodeList.filter(item => { |
| 49 | if (name && item.name !== name) return false |
| 50 | if (auditType && item.auditType.id !== auditType) return false |
| 51 | return true |
| 52 | }) |
| 53 | |
| 54 | const pageList = mockList.filter((item, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1)) |
| 55 | return { |
| 56 | items: pageList, |
| 57 | recordCount: mockList.length, |
| 58 | code: 200 |
| 59 | } |
| 60 | }, |
| 61 | getItem: config => { |
| 62 | const { id } = param2Obj(config.url) |
| 63 | const mockList = nodeList.filter(item => item.id + '' === id + '') |
| 64 | return { |
| 65 | data: mockList.length > 0 ? mockList[0] : null, |
| 66 | code: 200 |
| 67 | } |
| 68 | }, |
| 69 | createData: config => { |
| 70 | const node = JSON.parse(config.body) |
| 71 | if (!node.id) { |
| 72 | node.id = '' + parseInt(Math.random() * 100) + 1024 // mock a id |
| 73 | nodeList.unshift(node) |
| 74 | } else { |
| 75 | for (let i = 0; i < nodeList.length; i++) { |
| 76 | if (nodeList[i].id + '' === node.id + '') { |
| 77 | nodeList.splice(i, 1, node) |
| 78 | break |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | return { |
| 83 | item: node, |
| 84 | code: 200 |
| 85 | } |
| 86 | }, |
| 87 | deleteData: config => { |
| 88 | const node = JSON.parse(config.body) |
| 89 | let index = -1 |
| 90 | for (let i = 0; i < nodeList.length; i++) { |
| 91 | if (nodeList[i].id + '' === node.id + '') { |
| 92 | index = i |
| 93 | break |
| 94 | } |
| 95 | } |
| 96 | if (index > -1) { |
| 97 | nodeList.splice(index, 1) |
| 98 | } |
| 99 | return { |
| 100 | code: 200 |
| 101 | } |
| 102 | } |
| 103 | } |