小程序 通过计算属性 改变状态

<!-- 工期剩余 -->
<!-- 还剩下3天的时候变成红色 -->
<template>
  <div class="day-residue-tag">
    <span>{{stateTitle}}</span>
    <span>{{residueTime}}</span>
  </div>
</template>
<script>
export default {
  props: {
    // 为10的时候,是完工
    state: {
      name: '订单状态',
      type: Number
    },
    expect_at: {
      name: '工期剩余',
      type: String
    },
    finish_at: {
      name: '完工时间',
      type: String
    }
  },
  computed: {
    stateTitle() {
      if (this.state == 10) {
        return '完成时间'
      }
      return '工期剩余'
    },
    // 剩余时间
    residueTime() {
      if (this.state > 6) {
        if (this.finish_at) {
          return this.timeF(this.finish_at)
        }
        else return '--'
      }
      // 计算剩余时间差
      const diff = new Date(this.expect_at).getTime() - new Date().getTime();
      return this.countDownText(diff)
    }
  },
  methods: {
    // 倒计时时间显示处理
    countDownText(diff) {
      const d = Math.floor(diff / (60 * 1000 * 60 * 24));
      const ddiff = diff % (60 * 1000 * 60);
      const h = Math.floor(ddiff / (60 * 1000 * 60 * 24));
      const hdiff = diff % (60 * 1000 * 60);
      const m = Math.floor(hdiff / (60 * 1000));
      const mdiff = hdiff % (60 * 1000);
      const s = mdiff / (1000);
      const sCeil = Math.ceil(s);
      const sFloor = Math.floor(s);
      return `${d}天`
    },
  }
}
</script>
<style lang="less" scoped>
  .day-residue-tag {
  }
</style>



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值