UNPKG

ttk-app-core

Version:
83 lines (78 loc) 4.21 kB
import React from 'react' import { Menu, Checkbox, DataGrid,Icon, TableSort } from 'edf-component' let //centerArr = ['seq', 'buyDate', 'beginDeprPeriod','createTime', 'isHasInitName','isDraftName'], //rightArr = ['deprMonth', 'salvageRateStr', 'accuDepreciationStr','depreciationStr','yearPeriodDepreciationStr','queryPeriodDepreciationStr', 'salvageRate', 'hasDeprMonths','quantity', 'inputTaxRate','origValueStr', 'initAccuDepreciation','accuDepreciation','netWorthStr','inputTax'], percentage = ['salvageRate', 'salvageRateStr'] export default function renderGridColumns(columnNameList, list, other, fun, sortChange, showOption) { const arr = [] const res = columnNameList.map((element,index) => { return ( element.isVisible ? <DataGrid.Column name = {element.fieldName} columnKey={element.fieldName} isResizable={true} header={<DataGrid.Cell>{element.caption}</DataGrid.Cell>} header={(element.isOrderMode && !showOption.includeSum) ? <DataGrid.Cell>{element.caption}<TableSort sortOrder={other.sort.userOrderField == element.fieldName ? other.sort.order : null} handleClick={(e) => {sortChange(element.fieldName, e)}}></TableSort></DataGrid.Cell> : <DataGrid.Cell>{element.caption}</DataGrid.Cell>} cell={({rowIndex, ...props}) => { return <DataGrid.Cell {...props} tip={true} className={getClassName(list[rowIndex], element.idAlignType)} style={{fontWeight:(list[rowIndex].seq == '合计' ? 'bold': '')}}> {list[rowIndex] && list[rowIndex][element.fieldName] ? ((percentage.indexOf(element.fieldName)>-1 && list[rowIndex][element.fieldName] && Number(list[rowIndex].seq)) ? list[rowIndex][element.fieldName]+'%' : ((element.idFieldType == '1000040002' && Number(list[rowIndex][element.fieldName])) ? (addThousandsPosition(list[rowIndex][element.fieldName])) : list[rowIndex][element.fieldName])) : ''} </DataGrid.Cell> }} width={element.width} /> : null )}) res.push(<DataGrid.Column name = 'option' columnKey='option' fixedRight= {true} header={<DataGrid.Cell style = {{position: 'relative'}}> <Icon style = {{position: 'absolute', left: 0}} type='youcezhankailanmushezhi' fontFamily='edficon' onClick={() => fun({value:true})}/> </DataGrid.Cell>} cell={({rowIndex, ...props}) => { return <DataGrid.Cell {...props} className={rowIndex == list.length - 1 ? 'total rightName' : ''}> </DataGrid.Cell> }} width={30} />) res.push(<DataGrid.Column name = 'option' columnKey='option' flexGrow={1} header={<DataGrid.Cell></DataGrid.Cell>} cell={({rowIndex, ...props}) => { return <DataGrid.Cell {...props} className={rowIndex == list.length - 1 ? 'total rightName' : ''}> </DataGrid.Cell>}} width={0} />) return res } function getClassName(option, idAlignType){ let leftName = 'mk-datagrid-cellContent-left', rightName = 'mk-datagrid-cellContent-right' if(idAlignType == '1000050002'){ return option.seq != '小计' && !Number(option.seq) ? 'total':'' }else if(idAlignType == '1000050003'){ return option.seq != '小计' && !Number(option.seq) ? `total ${rightName}`:rightName }else{ return option.seq != '小计' && !Number(option.seq) ? `total ${leftName}`:leftName } } function addThousandsPosition(value){ let num if(value == 0){ return parseFloat(0).toFixed(2) } if (value != '') { num = parseFloat(value).toFixed(2) }else{ num = value.toString() } let regex = /(\d{1,3})(?=(\d{3})+(?:\.))/g return num.replace(regex, "$1,") }