UNPKG

ttk-app-core

Version:
84 lines (77 loc) 3.81 kB
import React from 'react' function initColumn(columns, ...cellArr) { let resColumn = [], className = '' let leftArr = ['propertyName', 'inventoryCode', 'inventoryName', 'specification'] let centerArr = ['businessTypeName', 'businessDate', 'code', 'unitName'] // 先插入一级节点 columns.forEach(item => { if (!item.fieldParentName) { let width = '100px' if(leftArr.indexOf(item.fieldName)>-1) className = 'detail_left' if(centerArr.indexOf(item.fieldName)>-1) className = 'detail_center' switch (item.fieldName){ case 'unitName': width = '78px' break; case 'specification': width = '78px' break; case 'propertyName': width = '78px' break; case 'inventoryCode': width = '78px' break; } let data = { 'title': item.fieldTitle, 'name': item.fieldName, 'dataIndex': item.fieldName, 'key': item.fieldName, 'className': className, 'render': item.fieldName == 'code' ? cellArr[1] : cellArr[0], 'width': width } resColumn.push(data) } }) resColumn.forEach(item => { let childData = [], isAmount = false columns.forEach(x => { if (x.fieldParentName && x.fieldParentName === item.name) { if(x.fieldName == 'receiveAmount' || x.fieldName == 'dispatchAmount') isAmount = true let data = { 'title': x.fieldTitle, 'name': x.fieldName, 'dataIndex': x.fieldName, 'key': x.fieldName, 'render': isAmount ? cellArr[2] : cellArr[3] } childData.push(data) } }) if (childData && childData.length > 0) item.children = childData }) return resColumn } export default function renderColumns(...cellArr) { const columns = [ { fieldName: 'businessTypeName', fieldTitle: '业务类型', fieldParentName: null }, { fieldName: 'businessDate', fieldTitle: '单据日期', fieldParentName: null }, { fieldName: 'code', fieldTitle: '单据编号', fieldParentName: null }, { fieldName: 'propertyName', fieldTitle: '存货分类', fieldParentName: null }, { fieldName: 'inventoryCode', fieldTitle: '存货编码', fieldParentName: null }, { fieldName: 'inventoryName', fieldTitle: '存货名称', fieldParentName: null }, { fieldName: 'unitName', fieldTitle: '计量单位', fieldParentName: null }, { fieldName: 'specification', fieldTitle: '规格型号', fieldParentName: null }, { fieldName: 'inTreasury', fieldTitle: '入库', fieldParentName: null }, { fieldName: 'outTreasury', fieldTitle: '出库', fieldParentName: null }, { fieldName: 'receiveQuantity', fieldTitle: '数量', fieldParentName: 'inTreasury' }, { fieldName: 'receivePrice', fieldTitle: '单价', fieldParentName: 'inTreasury' }, { fieldName: 'receiveAmount', fieldTitle: '金额', fieldParentName: 'inTreasury' }, { fieldName: 'dispatchQuantity', fieldTitle: '数量', fieldParentName: 'outTreasury' }, { fieldName: 'dispatchPrice', fieldTitle: '单价', fieldParentName: 'outTreasury' }, { fieldName: 'dispatchAmount', fieldTitle: '金额', fieldParentName: 'outTreasury' }, ] return initColumn(columns, ...cellArr) }