blob: aba104ccaa46056aeff818806587f2c5a5bad53d [file] [log] [blame]
import { param2Obj } from '@/utils'
const nodeList = [
{
'id': '26',
'name': '后勤处',
'department': { 'id': '2', 'name': '后勤处' },
'contact': '张三',
'phoneNumber': '021-65431991',
'scope': { 'id': '27', 'name': '全校范围' },
'auditType': { 'id': '25', 'name': '手动' },
'defaultAuditStatus': { 'id': '22', 'name': '待审核' },
'auditNodeDuty': '',
'auditNodeAddress': '',
'deleted': '0'
},
{
'id': '27',
'name': '财务处',
'department': { 'id': '3', 'name': '财务处' },
'contact': '李四',
'phoneNumber': '021-65431921',
'scope': { 'id': '27', 'name': '全校范围' },
'auditType': { 'id': '26', 'name': '自动' },
'defaultAuditStatus': { 'id': '22', 'name': '待审核' },
'auditNodeDuty': '',
'auditNodeAddress': '',
'deleted': '0'
},
{
'id': '28',
'name': '图书馆',
'department': { 'id': '4', 'name': '图书馆' },
'contact': '王五',
'phoneNumber': '021-65431931',
'scope': { 'id': '27', 'name': '全校范围' },
'auditType': { 'id': '25', 'name': '手动' },
'defaultAuditStatus': { 'id': '22', 'name': '待审核' },
'auditNodeDuty': '',
'auditNodeAddress': '',
'deleted': '0'
}
]
export default{
getList: config => {
const { name, auditType, pageIndex = 1, pageSize = 20 } = param2Obj(config.url)
const mockList = nodeList.filter(item => {
if (name && item.name !== name) return false
if (auditType && item.auditType.id !== auditType) return false
return true
})
const pageList = mockList.filter((item, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1))
return {
items: pageList,
recordCount: mockList.length,
code: 200
}
},
getItem: config => {
const { id } = param2Obj(config.url)
const mockList = nodeList.filter(item => item.id + '' === id + '')
return {
data: mockList.length > 0 ? mockList[0] : null,
code: 200
}
},
createData: config => {
const node = JSON.parse(config.body)
if (!node.id) {
node.id = '' + parseInt(Math.random() * 100) + 1024 // mock a id
nodeList.unshift(node)
} else {
for (let i = 0; i < nodeList.length; i++) {
if (nodeList[i].id + '' === node.id + '') {
nodeList.splice(i, 1, node)
break
}
}
}
return {
item: node,
code: 200
}
},
deleteData: config => {
const node = JSON.parse(config.body)
let index = -1
for (let i = 0; i < nodeList.length; i++) {
if (nodeList[i].id + '' === node.id + '') {
index = i
break
}
}
if (index > -1) {
nodeList.splice(index, 1)
}
return {
code: 200
}
}
}