• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
可樂_Thompson
博客园    首页    新随笔    联系   管理    订阅  订阅
如何通过watch监听单选框动态的显示选中和取消选中时对应的金额?

这是之前的一个需求:

 当全部选中时,退保金额为主险和附加险的总和

 当取消主险的时候只显示附险的退保金额

 当全部取消的时候,退保金额是0元

思路:

首先是对单选框的checked进行watch监听。

 代码:

checked(val){
       if(this.checked){
            this.surrenderAmount = this.newAmount
        }else{
           this.surrenderAmount = (Number(this.surrenderAmount).toFixed(2)-Number(this.list[0].polPrem).toFixed(2)).toFixed(2)
        }
    }

然后,对附加险选中和取消选中的时候:

 代码:

 checkItem(show, index) {
      if (show) {
        this.list[index].show = false
        this.surrenderAmount = (Number(this.surrenderAmount).toFixed(2) - Number(this.list[index].polPrem).toFixed(2)).toFixed(2)
      } else {
        this.list[index].show = true
        this.surrenderAmount += this.list[index].polPrem
      }
    }

这样就能实现动态改变金额的效果了。

posted on 2020-06-04 14:44  可樂_Thompson  阅读(416)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3