项目中的价格,人民币,美元

页面中的人民币价格和美元价格该如何表示,无数据的时候显示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'

    }

},

// 编辑中人民币过滤器

},

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 9,504评论 0 13
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,438评论 0 10
  • ORACLE自学教程 --create tabletestone ( id number, --序号usernam...
    落叶寂聊阅读 1,121评论 0 0
  • 下午就出去培训,出去拓展。行程是下午培训,晚上打牌、乒乓球、台球、卡拉OK,第二天上午爬古山寨,下午漂流,傍晚回程...
    OO碰到OO阅读 516评论 0 0
  • 世间事飘忽不定者多,万事随心,随不了心便随缘,随不了缘便随时势。
    蚂蚁心阅读 277评论 0 0