InfoPromotions.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <!-- promotions.vue -->
  2. <template>
  3. <view class="div">
  4. <view
  5. class="div ui-promotions-wrapper ui-detail-common"
  6. v-if="mansong_info"
  7. >
  8. <!-- 展示促销信息 -->
  9. <view class="div promotions-body" :style="'background-image:url('+ovalbg+')'">
  10. <view
  11. class="div body-list"
  12. v-for="(item, index) in mansong_info.rules"
  13. :key="index"
  14. >
  15. <text class="span">满{{ item.mansongrule_price }}立减现金{{ item.mansongrule_discount }}</text>
  16. <text class="span" v-if="item.goods_id && item.goods_storage" @click="goNavigate('/pages/home/goodsdetail/Goodsdetail',{ 'goods_id': item.goods_id })">,送礼品 {{item.mansong_goods_name}}</text>
  17. </view>
  18. </view>
  19. <view class="div time-body">
  20. <view class="div pt-10 pb-10">还剩<text class="span day" v-if="day">{{ day }}天</text></view>
  21. <view class="div time-wrapper">
  22. <text class="span time" style="margin-left:0">{{ hours }}</text
  23. >&nbsp;时&nbsp;<text class="span time">{{ minute }}</text
  24. >&nbsp;分&nbsp;<text class="span time">{{ second }}</text
  25. >&nbsp;秒
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import { urlencode } from '@/util/common'
  33. import { mapState, mapMutations } from 'vuex'
  34. import { env } from '../../../../static/config'
  35. export default {
  36. data () {
  37. return {
  38. flag: false,
  39. day: '',
  40. hours: '',
  41. minute: '',
  42. second: '',
  43. time: '',
  44. ovalbg: env.SITE_URL+'/uploads/home/h5/home/oval.png'
  45. }
  46. },
  47. mounted () {
  48. this.time = setInterval(() => {
  49. if (this.flag == true) {
  50. clearInterval(this.time)
  51. } else {
  52. this.timeDown()
  53. }
  54. }, 1000)
  55. },
  56. computed: {
  57. ...mapState({
  58. mansong_info: state => state.goodsdetail.mansongInfo
  59. })
  60. },
  61. methods:{
  62. goNavigate(path,query=false){
  63. uni.navigateTo({url:path+(query?('?'+urlencode(query)):'')})
  64. },
  65. /*
  66. * timeDown: 倒计时
  67. */
  68. timeDown () {
  69. if (
  70. this.mansong_info
  71. ) {
  72. const endTime = new Date(this.mansong_info.mansong_endtime * 1000)
  73. const nowTime = new Date()
  74. let leftTime = parseInt((endTime.getTime() - nowTime.getTime()) / 1000)
  75. this.day = parseInt(leftTime / (24 * 60 * 60))
  76. this.hours = this.formate(parseInt((leftTime / (60 * 60)) % 24))
  77. this.minute = this.formate(parseInt((leftTime / 60) % 60))
  78. this.second = this.formate(parseInt(leftTime % 60))
  79. if (leftTime <= 0) {
  80. this.flag = true
  81. this.$emit('time-end')
  82. }
  83. }
  84. },
  85. /*
  86. * 格式化时间
  87. */
  88. formate (time) {
  89. if (time >= 10) {
  90. return time
  91. } else {
  92. return `0${time}`
  93. }
  94. }
  95. }
  96. }
  97. </script>
  98. <style lang="scss" scoped>
  99. .ui-promotions-wrapper{margin-bottom:$modelSpace;display: flex;height:7.5rem;background-color: #fff;margin-top:$modelSpace;
  100. .promotions-body{width:6rem;background-size:6rem;background-repeat:no-repeat;background-position:left top;font-size:$fontSize;padding-top:3rem;padding-left:$pageSpace;
  101. .body-list{padding-top:.5rem;color:$descTextColor;white-space: nowrap;
  102. overflow: hidden;
  103. text-overflow: ellipsis;}
  104. }
  105. .time-body{flex:1;font-size:$subFontSize;padding-left:.5rem;
  106. .day{color:$primaryColor;margin-left:.2rem;}
  107. .time-wrapper{display: flex;align-items: center;
  108. .time{width:1.5rem;height:1.5rem;margin:0 .1rem;font-size:1rem;line-height:1.5rem;background:$subColor;border:1px solid $primaryColor;border-radius:.2rem;color:$primaryColor;text-align:center;}
  109. }
  110. }
  111. }
  112. </style>