147 lines
3.9 KiB
Vue
147 lines
3.9 KiB
Vue
<template>
|
|
<view>
|
|
<view class="v12-justify-around v12-pa-2 v12-white">
|
|
<view v-for="(day, i) in currentWeek" :key="i" class="v12-font-26">
|
|
<view style="color:#BCBCBC" class="day-wrap">{{ getDate(day) }}</view>
|
|
<view class="v12-dark-text day-wrap" :class="{'active': actived === i}">{{ getDay(day) }}</view>
|
|
</view>
|
|
</view>
|
|
<view class="v12-mt-3 v12-px-3 " v-for="(item, index) in items" :key="index">
|
|
<view>
|
|
<text class="v12-font-bold v12-font-32">{{ item.historyDate }}</text>
|
|
<view class="wrapper">
|
|
<view @click="goodsDetail(ite)" v-for="(ite, key) in item.histories" :key="key" class="v12-white v12-radius-20 v12-pa-2 history-card">
|
|
<view>
|
|
<image class="goods-img" :src="ite.image" mode="scaleToFill"></image>
|
|
</view>
|
|
<view :style="{opacity: !ite.couponName ? 0 : 1}" class="v12-align-center v12-mt-2">
|
|
<view class="v12-primary-text v12-primary-border v12-radius-6 v12-font-22 v12-px-1">券</view>
|
|
<view class="v12-primary-text v12-primary-border v12-radius-6 v12-font-22 v12-px-1">{{ ite.couponName }}</view>
|
|
</view>
|
|
<view class="v12-justify-between v12-mt-2">
|
|
<view class="v12-font-bold v12-primary-text">
|
|
<text class="v12-font-16">¥</text>
|
|
<text class="v12-font-24">{{ ite.price }}</text>
|
|
</view>
|
|
<view class="">
|
|
<image class="logo" :src="webUrl+'/orderIcon/组 355.png'" mode="" style="margin-right:0; width: 28rpx; height:28rpx"/>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import { getHistory } from '@/api/user'
|
|
export default {
|
|
data() {
|
|
return {
|
|
currentWeek: [],
|
|
actived: 0,
|
|
webUrl: this.$VUE_APP_RESOURCES_URL,
|
|
items: []
|
|
}
|
|
},
|
|
onLoad() {
|
|
this.queryHistory()
|
|
},
|
|
mounted() {
|
|
this.currentWeek = this.getWeek()
|
|
this.getActived()
|
|
},
|
|
methods: {
|
|
getActived() {
|
|
const weekMap = this.currentWeek.map(e => new Date(e).getDay())
|
|
const today = new Date().getDay()
|
|
return weekMap.indexOf(today)
|
|
},
|
|
getWeek() {
|
|
let dates = [];
|
|
let now = new Date();
|
|
let dayOfWeek = now.getDay(); // 0-6, 0是周日
|
|
let numDate = now.getDate(); // 当前日
|
|
let numDaysToMonday = dayOfWeek ? dayOfWeek - 1 : 6;
|
|
|
|
// 得到本周周一的日期
|
|
let monday = new Date(now);
|
|
monday.setDate(numDate - numDaysToMonday);
|
|
|
|
// 生成本周剩余的日期
|
|
for (let i = 0; i < 7; i++) {
|
|
dates.push(new Date(monday).toISOString().slice(0, 10));
|
|
monday.setDate(monday.getDate() + 1);
|
|
}
|
|
|
|
return dates;
|
|
},
|
|
getDay(date) {
|
|
return new Date(date).getDate()
|
|
},
|
|
getDate(date) {
|
|
const dateMap = {
|
|
1: '一',
|
|
2: '二',
|
|
3: '三',
|
|
4: '四',
|
|
5: '五',
|
|
6: '六',
|
|
0: '日'
|
|
}
|
|
const d = new Date(date).getDay()
|
|
return dateMap[d]
|
|
},
|
|
handle(day, i) {
|
|
this.actived = i
|
|
|
|
},
|
|
goodsDetail (item) {
|
|
this.$yrouter.push({
|
|
path: '/pages/shop/GoodsCon/index',
|
|
query: {
|
|
id: item.productId
|
|
}
|
|
})
|
|
},
|
|
queryHistory() {
|
|
getHistory().then(res => {
|
|
this.items = res.data
|
|
})
|
|
}
|
|
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="less" scoped>
|
|
.wrapper{
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
align-content: space-around !important;
|
|
}
|
|
.goods-img{
|
|
width: 168rpx;
|
|
height: 168rpx;
|
|
border-radius: 8rpx;
|
|
margin-right: 8rpx;
|
|
}
|
|
.history-card{
|
|
width: 178rpx;
|
|
margin-top: 16rpx;
|
|
margin-right: 16rpx;
|
|
}
|
|
.active{
|
|
background: #C52733;
|
|
color: #fff !important;
|
|
}
|
|
.day-wrap{
|
|
width: 40rpx;
|
|
height: 40rpx;
|
|
line-height: 40rpx;
|
|
text-align: center;
|
|
border-radius: 50%;
|
|
}
|
|
|
|
</style> |