blob: 32cd9dd4f6fea185453e90360782235ab22febe1 [file] [log] [blame]
huibing.xief40b2b92018-08-22 17:12:47 +08001import Mock from 'mockjs'
2import { param2Obj } from '@/utils'
3
4const recordList = Mock.mock({
5 'list|26': [{
6 'id': '@increment',
7 'xh': '@word(5)',
8 'xm': '@cword(2, 3)',
9 'yx': '@cword(6, 15)',
10 'zy': '@cword(6, 15)',
11 'bj': '@cword(6, 15)',
12 'xslb': '@cword(3, 5)',
13 'sfzylx|1': ['准予', '不准予'],
14 'shjllist|4': [{
15 'shhj': '@cword(6, 8)',
16 'shzt|1': ['通过', '不通过'],
17 'shyj|3': [{
18 'shzt|1': ['通过', '不通过'],
19 'shsj': '@datetime',
20 'shr': '@cword(2, 3)',
21 'shyj': '@cword(6, 10)'
22 }]
23 }],
24 'blbmlist': [{
25 'bmmc': '后勤处',
26 'shjg|1': ['—', '×', '√']
27 },
28 {
29 'bmmc': '财务处',
30 'shjg|1': ['—', '×', '√']
31 },
32 {
33 'bmmc': '学生处',
34 'shjg|1': ['—', '×', '√']
35 },
36 {
37 'bmmc': '图书馆',
38 'shjg|1': ['—', '×', '√']
39 }]
40 }]
41}).list
42
43export default{
44 getList: config => {
45 const { pcmc, xh, xm, sfzylx, yx, zy, bj, xslb, pageIndex = 1, pageSize = 20 } = param2Obj(config.url)
46 const mockList = recordList.filter(item => {
47 if (pcmc && item.pcmc + '' !== pcmc + '') return false
48 if (xh && item.xh !== xh) return false
49 if (xm && item.xm !== xm) return false
50 if (sfzylx && item.sfzylx !== sfzylx) return false
51 if (yx && item.yx !== yx) return false
52 if (zy && item.zy !== zy) return false
53 if (bj && item.bj !== bj) return false
54 if (xslb && item.xslb !== xslb) return false
55 return true
56 })
57
58 const pageList = mockList.filter((item, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1))
59 return {
60 items: pageList,
61 recordCount: mockList.length,
62 code: 200
63 }
64 },
65 getAllList: config => {
66 return {
67 items: recordList,
68 code: 200
69 }
70 },
71 getItem: config => {
72 const { id } = param2Obj(config.url)
73 const mockList = recordList.filter(item => item.id + '' === id + '')
74 return {
75 data: mockList.length > 0 ? mockList[0] : null,
76 code: 200
77 }
78 },
79 createData: config => {
80 const record = JSON.parse(config.body)
81 if (!record.id) {
82 record.id = '' + parseInt(Math.random() * 100) + 1024 // mock a id
83 recordList.unshift(record)
84 } else {
85 for (let i = 0; i < recordList.length; i++) {
86 if (recordList[i].id + '' === record.id + '') {
87 recordList.splice(i, 1, record)
88 break
89 }
90 }
91 }
92 return {
93 item: record,
94 code: 200
95 }
96 },
97 deleteData: config => {
98 const record = JSON.parse(config.body)
99 let index = -1
100 for (let i = 0; i < recordList.length; i++) {
101 if (recordList[i].id + '' === record.id + '') {
102 index = i
103 break
104 }
105 }
106 if (index > -1) {
107 recordList.splice(index, 1)
108 }
109 return {
110 code: 200
111 }
112 }
113}