blob: 266d8a0250cc6ffbabd8e47e813134601a2d79ea [file] [log] [blame]
Horacecc758592018-08-23 17:40:39 +08001import { param2Obj } from '@/utils'
2
3const nodeList = [
4 {
5 'id': '26',
6 'name': '后勤处',
huibing.xiec95b6a22018-08-29 14:15:43 +08007 'department': { 'id': '2', 'name': '后勤处' },
Horacecc758592018-08-23 17:40:39 +08008 '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': '财务处',
huibing.xiec95b6a22018-08-29 14:15:43 +080020 'department': { 'id': '3', 'name': '财务处' },
Horacecc758592018-08-23 17:40:39 +080021 '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': '图书馆',
huibing.xiec95b6a22018-08-29 14:15:43 +080033 'department': { 'id': '4', 'name': '图书馆' },
Horacecc758592018-08-23 17:40:39 +080034 '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
Horaceb39866e2018-08-28 21:31:53 +080045const userList = [
46 {
47 'id': '1',
48 'xm': '张三',
49 'xb': { 'value': 'male', 'label': '男' },
50 'ghxh': '11'
51 },
52 {
53 'id': '2',
54 'xm': '李四',
55 'xb': { 'value': 'female', 'label': '女' },
56 'ghxh': '22'
57 }
58]
59
60const auditorList = [
61 {
62 'id': '11',
63 'auditNode': { 'id': '26', 'name': '后勤处' },
64 'user': { 'id': '3', 'ghxh': '33', 'xm': '王五', 'xb': { 'value': 'male', 'label': '男' }}
65 },
66 {
67 'id': '22',
68 'auditNode': { 'id': '28', 'name': '图书馆' },
69 'user': { 'id': '4', 'ghxh': '44', 'xm': '赵六', 'xb': { 'value': 'female', 'label': '女' }}
70 }
71]
72
73const principalList = [
74 {
75 'id': '11',
76 'auditNode': { 'id': '26', 'name': '后勤处' },
77 'user': { 'id': '3', 'ghxh': '33', 'xm': '王六', 'xb': { 'value': 'male', 'label': '男' }}
78 },
79 {
80 'id': '11',
81 'auditNode': { 'id': '28', 'name': '图书馆' },
82 'user': { 'id': '4', 'ghxh': '44', 'xm': '赵七', 'xb': { 'value': 'female', 'label': '女' }}
83 }
84]
85
Horacecc758592018-08-23 17:40:39 +080086export default{
87 getList: config => {
88 const { name, auditType, pageIndex = 1, pageSize = 20 } = param2Obj(config.url)
89 const mockList = nodeList.filter(item => {
90 if (name && item.name !== name) return false
91 if (auditType && item.auditType.id !== auditType) return false
92 return true
93 })
94
95 const pageList = mockList.filter((item, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1))
96 return {
97 items: pageList,
98 recordCount: mockList.length,
99 code: 200
100 }
101 },
102 getItem: config => {
103 const { id } = param2Obj(config.url)
104 const mockList = nodeList.filter(item => item.id + '' === id + '')
105 return {
106 data: mockList.length > 0 ? mockList[0] : null,
107 code: 200
108 }
109 },
110 createData: config => {
111 const node = JSON.parse(config.body)
112 if (!node.id) {
113 node.id = '' + parseInt(Math.random() * 100) + 1024 // mock a id
114 nodeList.unshift(node)
115 } else {
116 for (let i = 0; i < nodeList.length; i++) {
117 if (nodeList[i].id + '' === node.id + '') {
118 nodeList.splice(i, 1, node)
119 break
120 }
121 }
122 }
123 return {
124 item: node,
125 code: 200
126 }
127 },
128 deleteData: config => {
129 const node = JSON.parse(config.body)
130 let index = -1
131 for (let i = 0; i < nodeList.length; i++) {
132 if (nodeList[i].id + '' === node.id + '') {
133 index = i
134 break
135 }
136 }
137 if (index > -1) {
138 nodeList.splice(index, 1)
139 }
140 return {
141 code: 200
142 }
Horaceb39866e2018-08-28 21:31:53 +0800143 },
144 getUser: config => {
145 const { ghxh } = param2Obj(config.url)
146 const mockList = userList.filter(item => item.ghxh + '' === ghxh + '')
147 return {
148 data: mockList.length > 0 ? mockList[0] : null,
149 code: 200
150 }
151 },
152 getAuditorList: config => {
153 const { nodeId } = param2Obj(config.url)
154 const mockList = auditorList.filter(item => item.auditNode.id + '' === nodeId + '')
155 return {
156 items: mockList,
157 code: 200
158 }
159 },
160 createNodeAuditor: config => {
161 const nodeAuditor = JSON.parse(config.body)
162 if (!nodeAuditor.id) {
163 nodeAuditor.id = '' + parseInt(Math.random() * 100) + 1024 // mock a id
164 auditorList.unshift(nodeAuditor)
165 } else {
166 for (let i = 0; i < auditorList.length; i++) {
167 if (auditorList[i].id + '' === nodeAuditor.id + '') {
168 auditorList.splice(i, 1, nodeAuditor)
169 break
170 }
171 }
172 }
173 return {
174 item: nodeAuditor,
175 code: 200
176 }
177 },
178 deleteNodeAuditor: config => {
179 const nodeAuditor = JSON.parse(config.body)
180 let index = -1
181 for (let i = 0; i < auditorList.length; i++) {
182 if (auditorList[i].id + '' === nodeAuditor.id + '') {
183 index = i
184 break
185 }
186 }
187 if (index > -1) {
188 auditorList.splice(index, 1)
189 }
190 return {
191 code: 200
192 }
193 },
194 getPrincipalList: config => {
195 const { nodeId } = param2Obj(config.url)
196 const mockList = principalList.filter(item => item.auditNode.id + '' === nodeId + '')
197 return {
198 items: mockList,
199 code: 200
200 }
201 },
202 createNodePrincipal: config => {
203 const nodePrincipal = JSON.parse(config.body)
204 if (!nodePrincipal.id) {
205 nodePrincipal.id = '' + parseInt(Math.random() * 100) + 1024 // mock a id
206 principalList.unshift(nodePrincipal)
207 } else {
208 for (let i = 0; i < principalList.length; i++) {
209 if (principalList[i].id + '' === nodePrincipal.id + '') {
210 principalList.splice(i, 1, nodePrincipal)
211 break
212 }
213 }
214 }
215 return {
216 item: nodePrincipal,
217 code: 200
218 }
219 },
220 deleteNodePrincipal: config => {
221 const nodePrincipal = JSON.parse(config.body)
222 let index = -1
223 for (let i = 0; i < principalList.length; i++) {
224 if (principalList[i].id + '' === nodePrincipal.id + '') {
225 index = i
226 break
227 }
228 }
229 if (index > -1) {
230 principalList.splice(index, 1)
231 }
232 return {
233 code: 200
234 }
Horacecc758592018-08-23 17:40:39 +0800235 }
236}