<template>
	<view class="content">
		<view class="title-box">
			<view class="title">
				<view class="title">价格采集</view>
				<view class="icon-add" @click="add"/>
			</view>
		</view>
		<view class="container-box">
			<u-list v-if="datas.length > 0">
				<u-list-item v-for="(item, index) in datas" :key="index">
					<info-item :name="item.monitorName" :date="item.userCollectDate" :address="item.address"/>
				</u-list-item>
			</u-list>
			<view v-if="datas.length <= 0" class="center">
				暂无数据
			</view>
		</view>
	</view>
</template>

<script>
	import infoItem from './components/infoItem.vue'
	import { findAppPage } from '@/api/collect'
	export default {
		components: {
			infoItem
		},
		data() {
			return {
				page: {
					current: 1,
					size: 10,
				},
				datas: [],
			}
		},
		onNavigationBarButtonTap(e) {
			if (e.index === 0) {
				this.add()
			}
		},
		mounted() {
			this.init()
		},
		methods: {
			init() {
				this.getList()
			},
			add() {
				findAppPage({
					current: 1,
					size: 1,
					sortField: 'userCollectDate',
					sortOrder: 'DESCEND',
				}).then(resp => {
					const list = resp?.data?.records || []
					if(list.length > 0) {
						this.gotoAdd()
					}else {
						this.gotoAdd()
					}
				})
				
			},
			gotoAdd() {
				uni.navigateTo({
					url: '/pages/collectionDetail/index'
				})
			},
			getList() {
				return findAppPage({
					... this.page, 
					sortField: 'userCollectDate', 
					sortOrder: 'DESCEND',
					isApp: 1,
				}).then((resp) => {
					console.log('resp', resp);
					this.datas = resp?.data?.records || []
				})
			}
		}
	}
</script>

<style lang="scss">
	.center {
		text-align: center;
	}
	.bg-w {
		background-color: white;
	}
</style>