286 lines
7.4 KiB
Vue
286 lines
7.4 KiB
Vue
<template>
|
|
<view class="v12-pb-10">
|
|
<view class="v12-justify-around v12-pa-2 v12-white data-nav">
|
|
<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, 'disabled': disabled(day)}" @click="handle(day, i)">{{ getDay(day) }}</view>
|
|
</view>
|
|
</view>
|
|
<view v-if="isLoad" class="history-wrap">
|
|
<view
|
|
v-for="(item, index) in items"
|
|
:key="index"
|
|
class="v12-mt-3"
|
|
:id="`history-${item.historyDate}`"
|
|
>
|
|
<view class="" style="height: 56px; width: 100%" v-if="isSrcoll"></view>
|
|
<view >
|
|
<text class="v12-font-bold v12-font-32">{{ item.historyDate }}</text>
|
|
<view class="wrapper">
|
|
<view
|
|
v-for="(historyItem, historyKey) in item.histories"
|
|
:key="historyKey"
|
|
class="v12-white v12-radius-20 history-card"
|
|
@click="goodsDetail(historyItem)"
|
|
>
|
|
<image
|
|
class="goods-img"
|
|
:src="historyItem.image"
|
|
mode="scaleToFill"
|
|
/>
|
|
<view class="good-info">
|
|
<view
|
|
v-if="historyItem.couponName"
|
|
:style="{
|
|
opacity: !historyItem.couponName ? 0 : 1
|
|
}"
|
|
class="v12-align-center v12-mt-2"
|
|
>
|
|
<view class="v12-primary-text v12-primary-border v12-radius-6 v12-font-18 v12-px-1">券</view>
|
|
<view class="v12-primary-text v12-primary-border v12-radius-6 v12-font-18 v12-px-1">{{ historyItem.couponName }}</view>
|
|
</view>
|
|
<view class="more-t v12-font-20 v12-mt-2">{{ historyItem.storeName }}</view>
|
|
<view class="v12-justify-between v12-mt-2 price">
|
|
<view v-if="!historyItem.isNegotiable" class="v12-font-bold v12-primary-text" :class="{'v12-align-center': (historyItem.price).toString().length < 5 && (historyItem.otPrice).toString().length < 5 }">
|
|
<text class="v12-font-16">¥</text>
|
|
<text class="v12-font-24 v12-mr-1">{{ historyItem.price }}</text>
|
|
<view class="ot-price v12-font-weight-400">
|
|
<text class="v12-font-22">¥</text>
|
|
<text class="v12-font-22">{{ historyItem.otPrice }}</text>
|
|
<view class="under-line"></view>
|
|
</view>
|
|
</view>
|
|
<view v-else class="v12-font-26 v12-primary-text v12-font-bold">价格面议</view>
|
|
<image
|
|
:src="webUrl+'/orderIcon/组 355.png'"
|
|
class="icon"
|
|
/>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
<view class="v12-px-6" v-if="items.length > 0">
|
|
<u-divider text=" · 已经到底啦 · " textPosition="center"></u-divider>
|
|
</view>
|
|
<image
|
|
v-if="items.length === 0"
|
|
:src="webUrl + '/orderIcon/nohistory.png'"
|
|
class="img-nodata v12-mt-16"
|
|
mode="widthFix"
|
|
/>
|
|
</view>
|
|
<goo-skeleton
|
|
v-else
|
|
:show-avatar="false"
|
|
/>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import { getHistory } from '@/api/user'
|
|
export default {
|
|
data() {
|
|
return {
|
|
currentWeek: [],
|
|
actived: 0,
|
|
webUrl: this.$VUE_APP_RESOURCES_URL,
|
|
isLoad: false,
|
|
items: [],
|
|
isSrcoll: false
|
|
}
|
|
},
|
|
onLoad() {
|
|
this.queryHistory()
|
|
},
|
|
onShow() {
|
|
this.$nextTick(() => {
|
|
this.currentWeek = this.getWeek()
|
|
this.actived = this.getActived()
|
|
})
|
|
},
|
|
methods: {
|
|
disabled(day) {
|
|
const dayItems = this.items.filter(item => {
|
|
return item.historyDate === day
|
|
}).map(e => {
|
|
return e.histories
|
|
}).flat()
|
|
return dayItems.length === 0
|
|
},
|
|
getActived() {
|
|
const weekMap = this.currentWeek.map(e => new Date(e).getDay())
|
|
const today = new Date().getDay()
|
|
return weekMap.indexOf(today)
|
|
},
|
|
getWeek() {
|
|
const dates = []
|
|
const now = new Date();
|
|
// 0-6, 0是周日
|
|
const dayOfWeek = now.getDay()
|
|
// 当前日
|
|
const numDate = now.getDate()
|
|
const numDaysToMonday = dayOfWeek - 1 > -1 ? dayOfWeek : 0
|
|
|
|
// 得到本周周一的日期
|
|
const 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) {
|
|
if(this.disabled(day)) return
|
|
this.actived = i
|
|
this.isSrcoll = true
|
|
uni.pageScrollTo({
|
|
selector:`#history-${day}`,
|
|
duration:200,
|
|
success:(success)=>{
|
|
this.isSrcoll = false
|
|
},
|
|
})
|
|
},
|
|
formatStr(str) {
|
|
const regx = /-/g
|
|
return str.replace(regx, '')
|
|
},
|
|
goodsDetail (item) {
|
|
this.$yrouter.push({
|
|
path: '/pages/shop/GoodsCon/index',
|
|
query: {
|
|
id: item.productId
|
|
}
|
|
})
|
|
},
|
|
queryHistory() {
|
|
this.items = []
|
|
this.isLoad = false
|
|
getHistory().then(res => {
|
|
const { data = [] } = res
|
|
if (data.length > 0) {
|
|
this.items = data.filter(e => e.histories && e.histories.length > 0).reverse()
|
|
// data.map(item => {
|
|
// if (item.histories) {
|
|
// if (item.histories.length > 0) {
|
|
// this.items.push(item)
|
|
// }
|
|
// }
|
|
// })
|
|
}
|
|
}).finally(() => {
|
|
this.isLoad = true
|
|
})
|
|
}
|
|
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="less" scoped>
|
|
.data-nav{
|
|
position: sticky;
|
|
width: 100%;
|
|
top: 0;
|
|
z-index: 9;
|
|
box-sizing: border-box;
|
|
}
|
|
.disabled{
|
|
color: #CBCBCB !important;
|
|
}
|
|
.history-wrap {
|
|
padding: 0 20rpx;
|
|
.img-nodata {
|
|
width: 100%;
|
|
}
|
|
}
|
|
.under-line{
|
|
width: 100%;
|
|
height: 3rpx;
|
|
background-color: #CBCBCB;
|
|
position: absolute;
|
|
top: 4rpx;
|
|
bottom: 0;
|
|
left: 0;
|
|
right: 0;
|
|
margin: auto;
|
|
|
|
}
|
|
.wrapper{
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
width: 710rpx;
|
|
margin: 0 auto;
|
|
}
|
|
.history-card{
|
|
width: 226rpx;
|
|
box-sizing: border-box;
|
|
margin-top: 16rpx;
|
|
margin-right: 16rpx;
|
|
border-radius: 20rpx;
|
|
overflow: hidden;
|
|
&:nth-child(3n) {
|
|
margin-right: 0;
|
|
}
|
|
.goods-img {
|
|
display: block;
|
|
width: 226rpx;
|
|
height: 226rpx;
|
|
}
|
|
.good-info {
|
|
padding: 12rpx 12rpx 20rpx 12rpx;
|
|
.price {
|
|
line-height: 34rpx;
|
|
align-items: flex-end;
|
|
.ot-price {
|
|
// margin: 0 0 0 10rpx;
|
|
color: #CBCBCB;
|
|
position: relative;
|
|
}
|
|
}
|
|
.icon {
|
|
display: block;
|
|
width: 34rpx;
|
|
height: 34rpx;
|
|
}
|
|
}
|
|
}
|
|
.active{
|
|
background: #C52733;
|
|
color: #fff !important;
|
|
}
|
|
.day-wrap{
|
|
width: 40rpx;
|
|
height: 40rpx;
|
|
line-height: 40rpx;
|
|
text-align: center;
|
|
border-radius: 50%;
|
|
}
|
|
|
|
</style> |