<template>
	<view>
		<view class="search-box">
			<view class="search ddflex">
				<image src="../static/images/ssico.png"></image>
				<input v-model="search" placeholder="输入核销码" placeholder-class="placeholder" class="fflex" @confirm="confirmSearch" />
			</view>
		</view>
		<view class="list" v-if="pageList&&pageList.length>0">
			<navigator :url="'/write/detail/detail?orderId=' + item.id" hover-class="none" class="li" v-for="(item,index) in pageList" :key="index">
				<view class="li-t ddflex">
					<view class="fflex">{{item.useTime}}</view>
					<view class="sta">已核销</view>
				</view>
				<view class="lis">核销码<text>{{item.code}}</text></view>
				<view class="info ddflex">
					<image :src="item.productPic" mode="aspectFill"></image>
					<view class="fflex">
						<view class="pro-tit">{{item.proudctName}}</view>
						<text class="pro-count">×{{item.quantity}}</text>
					</view>
				</view>
			</navigator>
		</view>
		<view class="nodata" v-else>
			<image :src="picUrlss+'empty_dd.png'"></image>
			<text>没有记录</text>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	const req = require("../../utils/request.js");
	export default {
		data() {
			return {
				picUrlss: req.public.picUrls,
				search: '',
				form:{
					page: 1,
					limit: 10
				},
				pageList: [],
				isLoad: true
			};
		},
		onLoad(options) {
			this.getList();
		},
		onReachBottom() {
			this.form.page++;
			this.getList();
		},
		methods: {
			confirmSearch(){
				this.isLoad = true;
				this.form.page = 1;
				this.getList();
			},
			getList(){
				if (!this.isLoad) return false;
				this.isLoad = false;
				let form = this.form;
				if (this.search) {
					form.search = this.search;
				} else {
					delete form.search
				}
				req.getRequest('/api/v3/secondary/card/writeRecord',form,data=>{
					if (data.list && data.list.length == 10) this.isLoad = true;
					if (this.form.page > 1) data.list = this.pageList.concat(data.list);
					this.pageList = data.list;
				})
			}
		}
	};
</script>

<style>
	@import "./index.css";
</style>
