<template>
	<view>
		<!--mine/footprint/footprint.wxml-->
		<view v-if="pageList.length > 0">
			<block v-for="(item, index) in pageList" :key="index">
				<view class="date">{{item.times}}</view>
				<view class="list">
					<navigator v-for="(item, index2) in item.nodes" :key="index2"
						:url="'/product/detail/detail?id=' + item.id" hover-class="none" class="li">
						<image :src="item.pic" mode="aspectFit" class="cimg"></image>
						<view class="zhinfo">
							<view class="zhtit">{{item.title}}</view>
							<!-- <view class="guige">规格：15g</view> -->
							<view class="jiage">
								<view class="zhjia">￥<text>{{item.salePrice}}</text></view>
							</view>
						</view>
					</navigator>
				</view>
			</block>
		</view>
		<view class="nodata" v-if="ishow">
			<image :src="picUrlss+'empty.png'"></image>
			<text>暂无记录~</text>
		</view>
	</view>
</template>

<script>
	const req = require("../../utils/request.js");
	const app = getApp();

	export default {
		data() {
			return {
				picUrlss: req.public.picUrls,
				form: {
					page: 1,
					limit: 10
				},
				pageList: [],
				isLoad: true,
				ishow: false
			};
		},

		components: {},
		props: {},
		onLoad: function(options) {
			this.loadFootprint();
		},

		onReachBottom() {
			this.form.page++;
			this.loadFootprint();
		},

		methods: {
			loadFootprint() {
				let isShowLoading = false;

				if (this.form.page == 1 && !isShowLoading) {
					req.loadIng('加载中');
					isShowLoading = true;
				}

				if (!this.isLoad) return false;
				this.isLoad = false;
				let that = this;
				req.getRequest('/api/footprint/product', this.form, data => {
					if (data && data.length == 10) this.isLoad = true;
					let pageList = that.pageList;

					if (data && data.length > 0) {
						data = data.map(it => {
							const t = it.createDate.split('-');
							it.times = t[1] + '-' + t[2];
							return it;
						});
						data.forEach(it => {
							let isExist = pageList.filter(pg => pg.createDate === it.createDate).length >
							0;
							let nodes = [];

							if (isExist) {
								pageList[pageList.length - 1].nodes.push(it);
							} else {
								let map = {
									times: it.times,
									createDate: it.createDate
								};
								nodes.push(it);
								map.nodes = nodes;
								pageList.push(map);
							}
						});
						that.setData({
							pageList: pageList
						});
						that.setData({
							ishow: false
						});
						// console.log(pageList);
					} else {
						that.setData({
							ishow: true
						});
					}

					if (isShowLoading) {
						uni.hideLoading();
						isShowLoading = false;
					}
				});
			}

		}
	};
</script>
<style>
	@import "./footprint.css";
</style>
