ttk-app-core
Version:
enterprise develop framework
96 lines (82 loc) • 3.95 kB
JavaScript
import React from 'react'
import { DataGrid, Checkbox, Icon, TableSort } from 'edf-component'
//let centerArr = ['seq'],
//rightArr = ['netWorthStr','origValueStr','origValue', 'depreciation','accuDepreciation', 'netWorth']
export default function renderColumns(columns, list, other, _this){
let { Column, Cell } = DataGrid
let cols = [
<Column name='operation' columnKey='operation' width={30}
fixedRight={true}
header={<Cell name='cb' style = {{position: 'relative'}}>
<Icon style = {{position: 'absolute', left: 0}} type="youcezhankailanmushezhi" fontFamily='edficon' onClick = { function(data){_this.showTableSetting({value: true})} } />
</Cell>}
cell={(ps) => {
if(!Number(list[ps.rowIndex].seq)) return <Cell name='cell' className={!Number(list[ps.rowIndex].seq) ? 'total':''}></Cell>
return (<Cell name='cell' className={!Number(list[ps.rowIndex].seq) ? 'total':''}></Cell>)
}}
/>
]
columns.forEach(op => {
if(op.isVisible){
let col = <Column name={op.id} columnKey={op.fieldName} isResizable={true} width={op.width}
header={op.isOrderMode ? <Cell name='header'>{op.caption}<TableSort sortOrder={other.sort.userOrderField == op.fieldName ? other.sort.order : null} handleClick={(e) => {_this.sortChange(op.fieldName, e)}}></TableSort></Cell> : <Cell name='header'>{op.caption}</Cell>}
cell={(ps) => {
return <Cell tip={(op.fieldName!='code' && op.fieldName!='docCode') ? true : false} className={getClassName(list[ps.rowIndex], op.idAlignType)}>
{
(op.fieldName=='code' || op.fieldName=='docCode') ?
(op.fieldName=='docCode' ? getDocCodeDom(list[ps.rowIndex], _this, other) :
<a title={list[ps.rowIndex][op.fieldName]} onClick={_this.query(list[ps.rowIndex].id)}>{list[ps.rowIndex][op.fieldName]}</a>) :
(
(op.idFieldType == '1000040002' && Number(list[ps.rowIndex][op.fieldName])) ?
(addThousandsPosition(list[ps.rowIndex][op.fieldName])) :
list[ps.rowIndex][op.fieldName]
)
}
</Cell>
}}
/>
cols.push(col)
}
})
cols.push(<Column name='right' columnKey='right' flexGrow={1} width={0}
header={<Cell name='cb'></Cell>}
cell={(ps) => {
return <Cell name='cell' className={!Number(list[ps.rowIndex].seq) ? 'total':''}></Cell>
}}/>)
return cols
}
//渲染凭证号
function getDocCodeDom(option, _this, other){
if(!Number(option.seq)) return <p></p>
if(!option.docCodes || !option.docIds){
if(other.isTasking) {
return <p style={{textAlign: 'center'}}>生成中</p>
}
return <p></p>
}
return <p>{_this.getDocCodes(option.docCodes, option.docIds)}</p>
}
function getClassName(option, idAlignType){
let leftName = 'mk-datagrid-cellContent-left',
rightName = 'mk-datagrid-cellContent-right'
if(idAlignType == '1000050002'){
return !Number(option.seq) ? 'total':''
}else if(idAlignType == '1000050003'){
return !Number(option.seq) ? `total ${rightName}`:rightName
}else{
return !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,")
}