<template>
	<view class="wrap">
	
		<view class="content content1" v-for="(item,index) in dataList" :key="index">
			<view class="top">
				<view>{{item.warehouseName}}</view>
				<view>25日0时前有效</view>
			</view>
			<view>{{item.name}}</view>
			<view class="car-list">
				<view v-for="(item1,index) in item.carList">
					{{item1.carNumber}}
				</view>
			</view>
			<u-button @click='del(item)'>删除</u-button>
		</view>
		<u-modal v-model="isShowAlert1" :title-style="{fontSize: '18px',fontWeight:'500'}"
			:content-style="{fontSize: '14px',fontWeight:'400'}" confirm-color='#22C572' confirm-text='确定' title='登录提示'
			showCancelButton='false' :content="content1" @confirm="alertBtn" @cancel="cancelClick"></u-modal>
		<u-modal v-model="isShowAlert" :title-style="{fontSize: '18px',fontWeight:'500'}"
			:content-style="{fontSize: '14px',fontWeight:'400'}" confirm-color='#22C572' confirm-text='确定' title='登录提示'
			showCancelButton='false' :content="content" @confirm="alertBtn" @cancel="cancelClick"></u-modal>
	</view>
</template>
<script>
	import {
		mapState
	} from 'vuex';

	export default {
		components: {

		},
		data() {
			return {
				id:'',
				warehouseName:'',
				isShowAlert: false,
				isShowAlert1:false,
				content: '当前登入信息验证失败，是否重新登录？',
					content1: '确定删除送粮记录？',
				dataList:[
					{
						warehouseName:"鲅鱼圈1号库",
						id:1,
						name:'张三',
						carList:[{carNumber:'123123'},{carNumber:'123123'},{carNumber:'123123'}
						]
					},
					{
						warehouseName:"鲅鱼圈2号库",
						id:2,
						name:'张三1',
						carList:[{carNumber:'123123'},{carNumber:'123123'},{carNumber:'123123'}
						]
					}
				]
			}
		},

		onLoad() {

		},
		// #ifndef MP
		onNavigationBarButtonTap(e) {
			const index = e.index;
			if (index === 0) {
				this.navTo('/pages/set/set');
			} else if (index === 1) {
				// #ifdef APP-PLUS
				const pages = getCurrentPages();
				const page = pages[pages.length - 1];
				const currentWebview = page.$getAppWebview();
				currentWebview.hideTitleNViewButtonRedDot({
					index
				});
				// #endif
				uni.navigateTo({
					url: '/pages/notice/notice'
				})
			}
		},
		// #endif
		computed: {
			...mapState(['hasLogin', 'userInfo']),
		},
		onShow() {
			this.$api.doRequest('get', '/commonUser/api/checkSession').then(res => {
				console.log("checkSession", res)
				if (res.data.data == "INVALID") {
					this.isShowAlert = true;
				}
				let _obj = {
					commonId:uni.getStorageSync("userInfo").id,
					pageSize:1,
					currentPage:10
					
				}
			this.$api.doRequest('get', '/grainDeliveryRegistration/selectGrainDeliveryRegistration',_obj ).then(res => {
				if (res.data.code == 200) {
			
				}
			})
				
			})
			console.log("hasLogin", this.hasLogin)
		},
		methods: {
			del(row){
				this.isShowAlert1=true
				this.id = row.id
				// 删除成功后删除页面当前行
				
				
				
				},
				
			navTo(url) {
				if (!this.hasLogin) {
					url = '/pages/public/login';
				}
				uni.navigateTo({
					url
				})
			},
			alertBtn() {debugger
				this.$api.doRequest('post', '//grainDeliveryRegistration/api/deleteInfo',{
					id:this.id
				}).then(res => {
					if (res.data.code == 200) {
				for(let i=0;i<this.dataList.length;i++){
					if(this.id==this.dataList[i].id){
						this.dataList.splice(i,1)
					}
				}
					}
				})
			
			},
			cancelClick() {
				this.isShowAlert = false
			}
		}
	}
</script>
<style lang='scss' scoped>
	page {
		background: #F5F6FA;
	}

	.wrap {
		background: #fff;
		margin: 10px;
		border-radius: 10px;
		padding: 10px;
	}
	.top{
		display: flex;
		justify-content: space-between;
	}
</style>
