|
@@ -66,7 +66,7 @@
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
|
-import { transDecimalPlace,isNumberVal,getDecimalPlaces,transNumPercentType } from '../common/customTable';
|
|
|
+import { isNumberValue,getDecimalPlaces,transNumPercentType } from '../common/customTable';
|
|
|
export default {
|
|
|
props: {
|
|
|
cell: {
|
|
@@ -94,15 +94,13 @@ export default {
|
|
|
if(nval) {
|
|
|
console.log(nval)
|
|
|
this.cellArray = Array.isArray(nval)?nval:[nval]
|
|
|
- this.option = this.cellArray.length?this.cellArray[0].ShowStyle?{
|
|
|
+ this.option = this.cellArray.length&&this.cellArray[0].ShowStyle?{
|
|
|
...JSON.parse(this.cellArray[0].ShowStyle)
|
|
|
}:{
|
|
|
nt: "",//numberType
|
|
|
pn: 0,//ponitNum
|
|
|
- }:{
|
|
|
- nt: "",//numberType
|
|
|
- pn: 0,//ponitNum,
|
|
|
}
|
|
|
+ this.option.decimal=!isNaN(parseFloat(this.option.decimal)) && isFinite(this.option.decimal)?this.option.decimal:undefined
|
|
|
}else{
|
|
|
this.cellArray=[]
|
|
|
this.option ={
|
|
@@ -334,6 +332,7 @@ export default {
|
|
|
this.cellArray.map(item =>{
|
|
|
if(!item.merData || item.merData.type=='merge'){
|
|
|
if(key==='decimal'){
|
|
|
+ console.log(222)
|
|
|
this.changeCellDecimal(item)
|
|
|
}else{
|
|
|
this.changeCellPoint(key,item)
|
|
@@ -344,26 +343,14 @@ export default {
|
|
|
/* 处理小数点位数 */
|
|
|
changeCellPoint(key,cell) {
|
|
|
//单元格不是数字就不用转了
|
|
|
- if( !isNumberVal(cell.ShowValue)) return
|
|
|
+ if( !isNumberValue(cell.ShowValue)) return
|
|
|
let cellValueStyle = cell.ShowStyle?JSON.parse(cell.ShowStyle):{
|
|
|
nt: "",//numberType
|
|
|
pn: 0,//ponitNum
|
|
|
}
|
|
|
- key==='add-point' ? cellValueStyle.pn++ : cellValueStyle.pn--;
|
|
|
-
|
|
|
- //判断小数点后尾数 整数最小pn为0 小数最小为负位数
|
|
|
- if(cellValueStyle.pn <= parseInt(`-${getDecimalPlaces(cell.ShowValue)}`)) {
|
|
|
- cellValueStyle.pn = parseInt(`-${getDecimalPlaces(cell.ShowValue)}`)
|
|
|
- }
|
|
|
-
|
|
|
- //百分比格式的话 pn最小为位数-2
|
|
|
- if(cellValueStyle.nt==='percent' && cellValueStyle.pn <= parseInt(`-${getDecimalPlaces(cell.ShowValue)-2}`)) {
|
|
|
- cellValueStyle.pn = parseInt(`-${getDecimalPlaces(cell.ShowValue)-2}`)
|
|
|
- }
|
|
|
-
|
|
|
- cell.ShowFormatValue = transDecimalPlace(cell.ShowValue,{...cellValueStyle,pn:cellValueStyle.pn})
|
|
|
- cell.ShowStyle = JSON.stringify({...cellValueStyle,pn:cellValueStyle.pn})
|
|
|
-
|
|
|
+ let xsNum=!isNaN(parseFloat(cellValueStyle.decimal)) && isFinite(cellValueStyle.decimal)?cellValueStyle.decimal:getDecimalPlaces(cell.ShowValue)
|
|
|
+ // console.log(xsNum)
|
|
|
+ cell.ShowStyle = JSON.stringify({...cellValueStyle,pn:0,decimal:key==='add-point'?xsNum+1:xsNum-1<0?0:xsNum-1})
|
|
|
},
|
|
|
changeCellsType(){
|
|
|
this.cellArray.map(item =>{
|
|
@@ -373,19 +360,30 @@ export default {
|
|
|
})
|
|
|
},
|
|
|
changeCellDecimal(item) {
|
|
|
- if(!isNumberVal(item.ShowValue)) return
|
|
|
+ if(!isNumberValue(item.ShowValue)) return
|
|
|
+ console.log(this.option,getDecimalPlaces(item.ShowFormatValue))
|
|
|
+ if(this.option.nt=='percent'&& this.option.decimal==undefined){
|
|
|
+ this.$set(this.option,'decimal',getDecimalPlaces(item.ShowFormatValue)+'')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if(this.option.nt!='percent'&&this.option.decimal==undefined){
|
|
|
+ item.ShowFormatValue=''
|
|
|
+ }
|
|
|
+ // console.log(this.option)
|
|
|
+ this.option.pn = 0
|
|
|
const styleCss = item.ShowStyle ? JSON.parse(item.ShowStyle) : {};
|
|
|
item.ShowStyle = JSON.stringify({...this.option,last:!isNaN(parseFloat(this.option.decimal)) && isFinite(this.option.decimal)?styleCss.last?styleCss.last:'decimal':styleCss.last=='decimal'?this.option.nt=='percent'?'nt':'':styleCss.last})
|
|
|
},
|
|
|
/* 处理百分位或数字格式 */
|
|
|
changeCellType(item) {
|
|
|
- if(!isNumberVal(item.ShowValue)) return
|
|
|
+ if(!isNumberValue(item.ShowValue)) return
|
|
|
this.option.pn = 0
|
|
|
|
|
|
item.ShowFormatValue = transNumPercentType(item.ShowValue,this.option.nt)
|
|
|
+ const num = getDecimalPlaces(item.ShowFormatValue?item.ShowFormatValue:item.ShowValue)
|
|
|
const styleCss = item.ShowStyle ? JSON.parse(item.ShowStyle) : {};
|
|
|
- item.ShowStyle = JSON.stringify({...this.option,last:this.option.nt!='percent'?styleCss.last=='nt'?!isNaN(parseFloat(this.option.decimal)) && isFinite(this.option.decimal)?'decimal':'':styleCss.last:styleCss.last?styleCss.last:'nt'})
|
|
|
-
|
|
|
+ //last 记录最先操作方式
|
|
|
+ item.ShowStyle = JSON.stringify({...this.option,last:'nt',decimal:num})
|
|
|
},
|
|
|
cellMergeHandle(){
|
|
|
this.$emit('cellMerge')
|