瀏覽代碼

fix: 优惠券时间显示问题

cuiyalong 3 年之前
父節點
當前提交
67939e59fd
共有 2 個文件被更改,包括 4 次插入2 次删除
  1. 2 2
      src/components/coupon/CouponCardList.vue
  2. 2 0
      src/utils/globalFunctions.js

+ 2 - 2
src/components/coupon/CouponCardList.vue

@@ -26,9 +26,9 @@
       </div>
       <div class="spec-footer">
         <span class="spec-time">
-          <span class="spec-start">{{ dateFormatter(coupon.lotteryBeginDate.replace(/-/g, '/'), 'yyyy.MM.dd') }}</span>
+          <span class="spec-start">{{ dateFormatter(coupon.lotteryBeginDate, 'yyyy.MM.dd') }}</span>
           <span class="spec-split">-</span>
-          <span class="spec-end">{{ dateFormatter(coupon.lotteryEndDate.replace(/-/g, '/'), 'yyyy.MM.dd') }}</span>
+          <span class="spec-end">{{ dateFormatter(coupon.lotteryEndDate, 'yyyy.MM.dd') }}</span>
         </span>
         <span class="spec-right spec-available" v-if="!coupon.available">暂不可用</span>
         <span class="spec-right spec-expire" v-else-if="coupon.expireTime">{{ coupon.expireTime }}</span>

+ 2 - 0
src/utils/globalFunctions.js

@@ -1,3 +1,4 @@
+import moment from 'moment'
 // 字符串处理相关函数
 // 手机号中间4位加* ------------>
 export function addConfusionForTel (tel) {
@@ -151,6 +152,7 @@ export function formatPrice (s, n = -1, comma = false) {
 export function dateFormatter (date, fmt = 'yyyy-MM-dd HH:mm:ss') {
   // 将传入的date转为时间对象
   if (!date) return ''
+  date = moment(date).valueOf()
   date = new Date(date)
   const o = {
     'y+': date.getFullYear(),