页面中的人民币价格和美元价格该如何表示,无数据的时候显示N/C,有数据的时候显示
html文件
<el-table :data="data" border stripe>
<el-table-column prop="componentPn" label="PN" align="center"/>
<el-table-column prop="componentFc" label="FC" align="center"/>
<el-table-column prop="description" label="描述" align="center"/>
<el-table-column prop="listpriceOnshore" label="人民币价格" align="center">
<template slot-scope="scope">{{scope.row.listpriceOnshore |listpriceOnshoreFilters }}</template>
</el-table-column>
<el-table-column prop="listpriceOffshore" label="美元价格" align="center">
<template slot-scope="scope">{{scope.row.listpriceOffshore |listpriceOffshoreFilters }}</template>
</el-table-column>
<el-table-column prop="operation" label="操作" align="center">
<template slot-scope="scope">
<el-button size="mini" type="primary" icon="el-icon-edit" @click="priceEditClick(scope.row)"/>
</template>
</el-table-column>
</el-table>
JS文件
filters : {
// 人民币过滤器
listpriceOnshoreFilters:function (value) {
if (value>0) {
return ' ¥ ' +Number(value).toFixed(2).replace(/\d{1,3}(?=(\d{3})+\b)/g,'$&,')
}else {
return 'N/C'
}
},
// 美元过滤器
listpriceOffshoreFilters:function (value) {
if (value >0 ) {
return ' $ ' +Number(value).toFixed(2).replace(/\d{1,3}(?=(\d{3})+\b)/g,'$&,')
}else {
return 'N/C'
}
},
// 编辑中人民币过滤器
},
点击编辑,弹出编辑价格对话框,是否有价,有价的话,如下图,显示人民币价格和美元价格,
<!--编辑-->
<el-dialog :visible.sync="dialogedit" :modal-append-to-body="false" title="编辑价格" width="25%" center>
<el-form :model="formPrice" label-width="90px" >
<el-form-item label="PN">
<el-input v-model="formPrice.PN" placeholder="FUH-9009000-EM66"/>
</el-form-item>
<el-form-item label="中文描述">
<el-input v-model="formPrice.chinaDesc" type="textarea"/>
</el-form-item>
<el-form-item label="是否计价" >
<el-select v-model="formPrice.valuation" placeholder="请选择" class="date_input" @change="priceChange()">
<el-option
v-for="iteminoptionsPrice"
:key="item.id"
:label="item.label"
:value="item.value"/>
</el-select>
</el-form-item>
<el-form-item v-if="formPrice.valuation== 0" label="人民币价格" class="date_input">
<el-input v-model="formPrice.RMB" @focus="priceRmbFocus(formPrice.RMB)" @blur="priceRMB(formPrice.RMB)" placeholder="¥888888"/>
</el-form-item>
<el-form-item v-if="formPrice.valuation== 0" label="美元价格">
<el-input v-model="formPrice.US" @focus="priceUSFocus(formPrice.US)" @blur="priceUS(formPrice.US)" placeholder="$8888888"/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="priceAmendClick()">确 定</el-button>
<el-button @click="dialogedit= false">取 消</el-button>
</div>
</el-dialog>
方法:
methods: {
// 失焦人民币价格
priceRMB(num) {
this.formPrice.RMB =Number(num).toFixed(2).replace(/\d{1,3}(?=(\d{3})+\b)/g,'$&,')
},
// 获得焦点人民币价格
priceRmbFocus(num) {
this.formPrice.RMB = num.replace(/,/g,"")
},
// 失焦美元价格
priceUS(num) {
this.formPrice.US =Number(num).toFixed(2).replace(/\d{1,3}(?=(\d{3})+\b)/g,'$&,')
},
// 获得焦点美元价格
priceUSFocus(num) {
this.formPrice.US = num.replace(/,/g,"")
},
priceChange() {
this.formPrice.RMB =''
this.formPrice.US =''
},
}
filters : {
// 人民币过滤器
listpriceOnshoreFilters:function (value) {
if (value>0) {
return ' ¥ ' +Number(value).toFixed(2).replace(/\d{1,3}(?=(\d{3})+\b)/g,'$&,') //分隔符,保留两位小数,三位三位分开
}else {
return 'N/C'
}
},
// 美元过滤器
listpriceOffshoreFilters:function (value) {
if (value >0 ) {
return ' $ ' +Number(value).toFixed(2).replace(/\d{1,3}(?=(\d{3})+\b)/g,'$&,')
}else {
return 'N/C'
}
},
// 编辑中人民币过滤器
},