UNPKG

ttk-app-core

Version:
246 lines (235 loc) 12.1 kB
/** * mock.js 提供应用截获ajax请求,为脱离后台测试使用 * 模拟查询更改内存中mockData,并返回数据 */ import { fetch } from 'edf-utils' import {queryAccountList, queryBaseArchives, getDocVoucherDate, advanceSearchSAData2,advanceSearchNAData2, queryRptListSAccount,queryRptListSType1,advanceSearchNAData,advanceSearchSAData} from './mockData/db' const mockData = fetch.mockData fetch.mock('/v1/gl/report/balanceauxrpt/query', (option) => {//获取列表数据 if (option.auxInfo.length != 1 || option.accountCodeList.length != 0) { switch(option.searchType) { case 0: if (option.includeSum) { const auxInfo = option.auxInfo const queryRptList = JSON.parse(JSON.stringify(advanceSearchSAData)) let content = null, searchKey = null, details = queryRptList.value.details, parmas const accountCodeList = option.accountCodeList const auxTypeList = ["customerId", "supplierId", "projectId", "departmentId", "personId", "inventoryId", "accountId"] const auxType = advanceSearchSAData.value.auxType auxInfo.forEach(element => { const nameLastStr = element.split(':')[1] if (nameLastStr == '1') { content = true } else { if (nameLastStr) { searchKey = nameLastStr parmas = element.split(':')[0] parmas = parmas.replace(/Id/g,'') } } }); if (content) { return {"result":true,"value":{}} } queryRptList.value.details = details.filter(item => item.accountName == '合计' || item[`${parmas}Id`] == searchKey) let newDataList = [] const total = details.filter(item => item.accountName == '合计') let itemObj = null if (accountCodeList.length != 0) { // queryRptList.value.details.forEach((item) => { // accountCodeList.forEach((key) => { // if (item.accountCode == key) { // newDataList.push(item) // itemObj = item // } // // if (itemObj.customerId == item.customerId && key != item.accountCode) { // // newDataList.push(item) // // } // }) // }) // newDataList = newDataList.concat(total) // queryRptList.value.details = newDataList } auxTypeList.forEach((item) => { item = `${item}:` if (!auxInfo.includes(item)) { const parmas = item.replace(/Id:/g,'') let list = queryRptList.value.details if (parmas != 'account') { list = list.filter(ele => ele[`${parmas}Name`] !== '小计') } queryRptList.value.details = list queryRptList.value.style = '' } }) // console.log(queryRptList.value.details, 'queryRptList.value.details') if (queryRptList.value.details && queryRptList.value.details[0].accountName == '合计') { return {"result":true,"value":{}} } return queryRptList } else { const auxInfo = option.auxInfo const queryRptList = JSON.parse(JSON.stringify(advanceSearchNAData)) let content = null, searchKey = null, details = queryRptList.value.details, parmas const accountCodeList = option.accountCodeList auxInfo.forEach(element => { const nameLastStr = element.split(':')[1] if (nameLastStr == '1') { content = true } else { if (nameLastStr) { searchKey = nameLastStr parmas = element.split(':')[0] parmas = parmas.replace(/Id/g,'') } } }); if (content) { return {"result":true,"value":{}} } queryRptList.value.details = details.filter(item => item[`${parmas}Name`] != '小计' && (item.accountName == '合计' || item[`${parmas}Id`] == searchKey)) let newDataList = [] const total = details.filter(item => item.accountName == '合计') if (accountCodeList.length != 0) { queryRptList.value.details.forEach((item) => { accountCodeList.forEach((key) => { if (item.accountCode == key) { newDataList.push(item) } }) }) newDataList = newDataList.concat(total) queryRptList.value.details = newDataList } if (queryRptList.value.details && queryRptList.value.details[0].accountName == '合计') { return {"result":true,"value":{}} } return queryRptList } case 1: if (option.includeSum) { return advanceSearchSAData2 } else { return advanceSearchNAData2 } } } else { const includeSum = option.includeSum let parmas, filesId if (option.auxInfo) { //档案筛选 let files = option.auxInfo[0], filesName = files.split(':')[0] filesId = files.split(':')[1] switch (filesName) { case 'customerId': parmas = 'customer' break; case 'supplierId': parmas = 'supplier' break; case 'projectId': parmas = 'project' break; case 'departmentId': parmas = 'department' break; case 'personId': parmas = 'person' break; case 'inventoryId': parmas = 'inventory' break; default: parmas = 'customer' } } switch(option.searchType) { case 0 : if (queryRptListSAccount[parmas]) { if (includeSum) { // return queryRptListSAccount[parmas] const queryRptList = JSON.parse(JSON.stringify(queryRptListSAccount[parmas])) let details = queryRptList.value.details if (filesId) { if (filesId == 1) return {"result":true,"value":{}} queryRptList.value.details = details.filter(item => item.accountName == '合计' || item[`${parmas}Id`] == filesId) } return queryRptList } else { const queryRptList = JSON.parse(JSON.stringify(queryRptListSAccount[parmas])) let details = queryRptList.value.details if (filesId) { if (filesId == 1) return {"result":true,"value":{}} queryRptList.value.details = details.filter(item => item[`${parmas}Name`] != '小计' && (item.accountName == '合计' || item[`${parmas}Id`] == filesId)) } else { queryRptList.value.details = details.filter(item => item[`${parmas}Name`] != '小计') } return queryRptList } } else { return {"result":true,"value":{}} } case 1: if (queryRptListSType1[parmas]) { if (includeSum) { const queryRptList = JSON.parse(JSON.stringify(queryRptListSType1[parmas])) const details = queryRptList.value.details if(option.sigleAccountCode) { queryRptList.value.details = details.filter(element => (element.accountCode == option.sigleAccountCode || element.accountName == '合计')) if (queryRptList.value.details && queryRptList.value.details[0].accountName == '合计') { return {"result":true,"value":{}} } // return queryRptList } if (filesId) { if (filesId == 1) return {"result":true,"value":{}} queryRptList.value.details = details.filter(item => item.accountName == '合计'|| item.accountName == '小计' || item[`${parmas}Id`] == filesId) } return queryRptList } else { const queryRptList = JSON.parse(JSON.stringify(queryRptListSType1[parmas])) let details = queryRptList.value.details details = details.filter(item => item.accountName != '小计') if(option.sigleAccountCode) { //科目筛选 queryRptList.value.details = details.filter(element => (element.accountCode == option.sigleAccountCode || element.accountName == '合计')) // return queryRptList } else { queryRptList.value.details = details } if (filesId) { if (filesId == 1) return {"result":true,"value":{}} queryRptList.value.details = details.filter(item => item[`${parmas}Name`] != '小计' && (item.accountName == '合计' || item[`${parmas}Id`] == filesId)) } if (queryRptList.value.details && queryRptList.value.details[0].accountName == '合计') { return {"result":true,"value":{}} } return queryRptList } } else { return {"result":true,"value":{}} } } } }) fetch.mock('/v1/gl/account/query', (option) => {//获取档案列表 return queryAccountList }) fetch.mock('/v1/gl/report/balanceauxrpt/export', (option) => {//导出 return }) fetch.mock('/v1/gl/report/balanceauxrpt/print', (option) => {//打印 return }) fetch.mock('/v1/gl/report/glauxsumrpt/query', (option) => { return }) fetch.mock('/v1/gl/doc/findMaxDocVoucherDate', (option) => {//获取年月 return getDocVoucherDate }) fetch.mock('/v1/ba/basearchive/queryBaseArchives', (option) => {//获取不同档案下的数据列表 return queryBaseArchives }) fetch.mock('/v1/gl/report/balanceauxrpt/share', (option) => { return })