ttk-app-core
Version:
enterprise develop framework
149 lines (136 loc) • 8.05 kB
JavaScript
import React from 'react'
import { DataGrid, Checkbox, Icon, TableSort } from 'edf-component'
let //centerArr = ['isDraftName','unitName','seq', 'buyDate', 'beginDeprPeriod','createTime', 'isHasInitName'],
//rightArr = ['quantityStr','salvageRateStr','initDeprMonths','deprMonth', 'salvageRate', 'hasDeprMonths','quantity', 'inputTaxRate', 'origValue', 'origValueStr', 'initAccuDepreciation','accuDepreciation','netWorthStr','inputTax'],
percentage = ['salvageRate', 'salvageRateStr', 'inputTaxRate']
export default function renderColumns(columns, list, other, _this){
let { Column, Cell } = DataGrid
let cols = [
<Column name='select' columnKey='select' width={34}
header={<Cell name='cb'>
<Checkbox checked={_this.extendAction.gridAction.isSelectAll("dataGrid")}
onChange={_this.extendAction.gridAction.selectAll("dataGrid")}>
</Checkbox>
</Cell>}
cell={(ps) => {
return <Cell name='cell' className={!Number(list[ps.rowIndex].seq) ? 'total':''}>
{!Number(list[ps.rowIndex].seq) ? null : <Checkbox onChange={_this.selectRow(ps.rowIndex)} checked={list[ps.rowIndex].selected}></Checkbox>}
</Cell>
}}
/>,
<Column name='operation' columnKey='operation' width={105}
fixedRight={true}
header={<Cell name='cb'>
<Icon 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 app-oprate':'app-oprate'}>
<Icon type={list[ps.rowIndex].act == "change" ? "biandong" : "bianji"}
fontFamily='edficon'
disabled={list[ps.rowIndex].changeTypeId == 5100060004}
title={list[ps.rowIndex].act == "change" ? "变动" : "编辑"}
style={{fontSize: 23, cursor: 'pointer'}}
onClick={list[ps.rowIndex].changeTypeId != 5100060004 ? _this.modifyDetail(list[ps.rowIndex]) : ""} />
<Icon type="shanchu"
fontFamily='edficon'
disabled={(list[ps.rowIndex].act == "change" || list[ps.rowIndex].changeTypeId == 5100060004) ? true : false}
title='删除'
style={{fontSize: 23, cursor: 'pointer'}}
onClick={(list[ps.rowIndex].act == "change" || list[ps.rowIndex].changeTypeId == 5100060004) ? "" : _this.delClick(list[ps.rowIndex])} />
<Icon type="chuzhi"
fontFamily='edficon'
disabled={list[ps.rowIndex].assetPropertyId == 5100010003 ? true : (list[ps.rowIndex].changeTypeId == 5100060004 || list[ps.rowIndex].isDraftName=="草稿" ? true : false)}
title='处置'
style={{fontSize: 23, cursor: 'pointer'}}
onClick={list[ps.rowIndex].assetPropertyId == 5100010003 ? /*_this.disposeTip*/null : (list[ps.rowIndex].changeTypeId == 5100060004 || list[ps.rowIndex].isDraftName=="草稿" ? "" : _this.managementClick(list[ps.rowIndex]))}/>
<Icon type="jilu"
fontFamily='edficon'
title='记录'
style={{fontSize: 23, cursor: 'pointer'}}
onClick = {_this.recordClick(list[ps.rowIndex])} />
</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) => {
if(list[ps.rowIndex].isDraftName=="草稿" && op.fieldName=='name'){
return <Cell className='asset-name'>
<span title = {list[ps.rowIndex][op.fieldName]}>{list[ps.rowIndex][op.fieldName]}</span>
<Icon type="caogao"
fontFamily='edficon'
title='草稿'
style={{fontSize: 22, color: '#E39200'}}/>
</Cell>
}
return <Cell tip={op.fieldName!='code' ? true : false} className={getClassName(list[ps.rowIndex], op.idAlignType)}>
{
op.fieldName=='code' ?
<a title={list[ps.rowIndex][op.fieldName]}
onClick={list[ps.rowIndex].changeTypeId != 5100060004 ? _this.modifyDetail(list[ps.rowIndex]) : _this.query(list[ps.rowIndex].id)}>{list[ps.rowIndex][op.fieldName]}</a> :
(
((op.idFieldType == '1000040002' && Number(list[ps.rowIndex][op.fieldName]) !== NaN) || op.fieldName == 'initAdjust') ?
getNumberOption(list[ps.rowIndex], op) :
((percentage.indexOf(op.fieldName)>-1 && list[ps.rowIndex][op.fieldName] && Number(list[ps.rowIndex].seq)) ? 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 getNumberOption(option, op){
//if(op.fieldName == 'initAdjust' && (!Number(option.seq) || !option.origAccuDepreciation)) return ''
if(op.fieldName == 'initAccuDepreciation' && option.origAccuDepreciation !== undefined && option.origAccuDepreciation !== null){
if(option.origAccuDepreciation){
return addThousandsPosition(option.origAccuDepreciation)
}
return ''
}/*else if(Number(option.origAccuDepreciation) !== NaN && op.fieldName == 'initAdjust'){
if(option.initAccuDepreciation-option.origAccuDepreciation){
return addThousandsPosition(option.initAccuDepreciation-option.origAccuDepreciation)
}
return ''
}*/else{
if(option[op.fieldName]){
return addThousandsPosition(option[op.fieldName])
}
return ''
}
}
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,")
}