Vue 计算合同总额

计算总额的触发事件,必须满足四个计算值的条件,必须全部填写,才可计算,否则不会触发计算事件
在这里插入图片描述
以一个月30天未计算标准

  stcv() {
      let form = JSON.parse(JSON.stringify(this.form))
      // this.resultDate 计租日期差值 
      // form.unitPrice  合同首年总额
      // form.growthRate 租金年增长率 
      // form.rentGrowthCycle 租金增长周期
      if (form.Dates != null && form.unitPrice != null && form.growthRate != null && form.rentGrowthCycle != null) {
        // this.resultDate.split('.')[0] //得到计租期的年数
        // this.resultDate.split('.')[1] //得到计租期的月数
        // this.resultDate.split('.')[2] //得到计租期的天数
        // form.growthRate = form.growthRate / 100 //将增长率转换成小数

        //总计合同总额
        this.contractMoney = 0
        if (form.rentGrowthCycle >= this.resultDate.split('.')[0]) {
          //当增长周期大于计租年时:总计租金=首年总额X计租年
          this.contractMoney = this.resultDate.split('.')[0] * form.unitPrice;
          form.contractMoney = this.contractMoney
        } else {
          this.contractMoney = form.unitPrice * form.rentGrowthCycle
          //第N轮周期年租金
          var f = form.unitPrice;
          //一共需要的周期
          var g = 0;
          // if (this.resultDate.split('.')[0] % form.rentGrowthCycle == 0) {
          //   g = Number(this.resultDate.split('.')[0] / form.rentGrowthCycle) - 1
          //   g = parseInt(g)
          // } else {
          g = Number(this.resultDate.split('.')[0] / form.rentGrowthCycle) - 1
          g = parseInt(g)
          // }
          // console.log(g)
          // this.lastf = []
          for (var i = 0; i < g; i++) {
            //f是循环增长之后的每一年合同总额
            f = f * (1 + form.growthRate / 100)
            // console.log(f)
            // this.lastf.push(f)
            //这时候的this.contractMoney等于整数年的合同金额,不包括,余数那年的金额
            this.contractMoney = this.contractMoney + f * form.rentGrowthCycle;
          }
          // console.log(f)
          // console.log(this.lastf)
          //再计算存在计租年%增长周期年 > 0 部分租金 先判断是否有余数
          this.count = (this.resultDate.split('.')[0] / form.rentGrowthCycle).toString()
          //余数年
          if (this.count.split('.')[1] != undefined) {
            // this.contractMoney = this.contractMoney + this.lastf[this.lastf.length - 1] * (1 + form.growthRate / 100) *  this.resultDate.split('.')[0] % form.rentGrowthCycle
            // console.log(this.resultDate.split('.')[0] % form.rentGrowthCycle) //算出余数余几年
            this.contractMoney = this.contractMoney + f * (1 + form.growthRate / 100) * this.resultDate.split('.')[0] % form.rentGrowthCycle
            //当月份和天数都为0的时候,按照第一种方式计算,整年的,如果有多出的月份和天数按下面方式计算,先算月最后算天依次计算
            if (this.resultDate.split('.')[1] == 0 && this.resultDate.split('.')[2] == 0) {
              form.contractMoney = (this.contractMoney).toFixed(2)
              // console.log('月份和天数都为0')
            } else {
              // this.contractMoney //此时的已经是算出所有年的金额(包括余数年),算月和日直接加上
              form.contractMoney = (this.contractMoney + this.resultDate.split('.')[1] * (f * (1 + form.growthRate / 100) / 12) +
                this.resultDate.split('.')[2] * (f * (1 + form.growthRate / 100) / 12 / 30)).toFixed(2)
            }
            //整数年
          } else {
            //当月份和天数都为0的时候,按照第一种方式计算,整年的,如果有多出的月份和天数按下面方式计算,先算月最后算天依次计算
            if (this.resultDate.split('.')[1] == 0 && this.resultDate.split('.')[2] == 0) {
              form.contractMoney = (this.contractMoney).toFixed(2)
              // console.log('月份和天数都为0')
            } else {
              // this.contractMoney //此时的已经是算出所有年的金额,算月和日直接加上
              form.contractMoney = (this.contractMoney + this.resultDate.split('.')[1] * (f * (1 + form.growthRate / 100) / 12) +
                this.resultDate.split('.')[2] * (f * (1 + form.growthRate / 100) / 12 / 30)).toFixed(2)
            }
            // console.log('我是整数年')
          }
        }
        this.form = form
      } else {
        form.contractMoney = ''
        this.form = form
        this.$message.error('请将计租期、合同首年总额、租金年增长率、租金增长周期填写完整!');
      }
    },
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值