<template>
	<view class="wrap">
		<view class="content1">
			<view>{{dataList.warehouseName}}</view>
			<view class="row2">
				<view class='locationwrap'>
					<image class='location' src="../../../static/img/liangmai/icon_ditu@2x.png" mode=""></image>
					{{warehouseNameAddress}}
				</view>
			</view>
			<view class="row3">
				<view>{{startDate}}创建（有效期{{dataList.validityDate}}）</view>
			</view>
		</view>
		<view class="content2">
			<view class="title">送货信息</view>
			<view class="wrap wrap1" v-for="(item,index) in dataList.shippingInformationList" :key='index'>
				<view class="row1">
					<view class="left">
						<view>货主{{index+1}}-{{item.shipperName}}</view>
						<view @click="reduceBtn(index)">--</view>
					</view>
					<view class="right" @click='show=true'>
						<view>{{shipperName}}</view>
						<u-icon name="arrow-right" color=""></u-icon>
						<u-picker @confirm="nameConfirm" range-key='name' mode="selector" v-model="show"
							:range="nameList"></u-picker>
					</view>
				</view>
				<view class="row2">
					<view class="left">
						供应商（送粮人）
					</view>
					<view class="right">{{item.supplier}}</view>
				</view>
				<view class="row2" v-for="(item1,index1) in item.carNumberList" :key='index1'>
					<view class="left">
						车牌号-{{index1+1}}
					</view>
					<u-input v-model="item1.carNo" placeholder="输入7为车牌号" />
					<view>
						<view @click="addCarNumber(item.carNumberList)">+</view>
						<view @click="delCarNumber(item.carNumberList,index1)">-</view>
					</view>
				</view>


			</view>
			<u-button @click='addGoodPeople'>增加货主</u-button>
		</view>
		<u-button @click='submit'>提交</u-button>
		<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>
		<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>

	</view>
</template>
<script>
	import {
		mapState
	} from 'vuex';

	export default {
		components: {

		},
		data() {
			return {
				isShowAlert: false,
				isShowAlert1: false,
				content: '当前登入信息验证失败，是否重新登录？',
				content1: '确定提交送粮信息？',
				show: false,
				show1: false,
				cargoOwner: [{
					name: '123'
				}],
				shipperName: "王五",
				nameList: [{
						name: '1'
					},
					{
						name: '2'
					}
				],
				warehouseNameAddress: '辽宁省营口市龙港花园',
				startDate: "2021-11-20",
				dataList: {
					warehouseName: "鲅鱼圈1号库",
					validityDate: '2021-11-23',
					shippingInformationList: [{
						shipperName: '张三',
						supplier: '供应商姓名',
						carNo: '123456,123456,1234456',
						carNumberList: [{
							carNo: '123'
						}]
					}]

				}
			}
		},

		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;
				}
			})
			console.log("hasLogin", this.hasLogin)
		},
		methods: {
			reduceBtn(index) {
				debugger
				if (this.dataList.shippingInformationList.length > 1) {
					this.dataList.shippingInformationList.splice(index, 1)
					this.$forceUpdate()
				}
			},
			submit() {
				this.isShowAlert1 = true
			},
			nameConfirm() {},
			/**
			 * 统一跳转接口,拦截未登录路由
			 * navigator标签现在默认没有转场动画，所以用view
			 */
			navTo(url) {
				if (!this.hasLogin) {
					url = '/pages/public/login';
				}
				uni.navigateTo({
					url
				})
			},
			alertBtn() {
				this.$api.doRequest('post', '/grainDeliveryRegistration/api/insertInfo', this.submitData).then(res => {
					if (res.data.code == 200) {

					}
				})
			},
			cancelClick() {
				this.isShowAlert = false
				this.isShowAlert1 = false
			},
			addGoodPeople() {
				this.dataList.shippingInformationList.push({
					shipperName: '张三1',
					supplier: '供应商姓名1',
					carNo: '123456,123456,1234456',
					carNumberList: [{
						carNo: '222'
					}]
				})
			},
			addCarNumber(val) {
				val.push({
					carNo: '456'
				})
			},
			delCarNumber(val, index) {
				debugger
				if (val.length > 1) {
					val.splice(index, 1)
					this.$forceUpdate()
				}
			}
		}
	}
</script>
<style lang='scss' scoped>
	page {
		background: #F5F6FA;
	}

	.wrap {
		background: #fff;
		margin: 10px;
		border-radius: 10px;
		padding: 10px;
	}

	.location {
		width: 32rpx;
		height: 32rpx;
		margin-right: 10rpx;
	}

	.locationwrap {
		font-size: 16px;
		display: flex;
		align-items: center;
	}
</style>
