<template>
	<view>
		<view class="content">

			<view class="info_inner">
				<view class="input_box">
					<view class="label"><text> * </text>姓名：</view>
					<view class="box">
						{{user.name}}
					</view>
				</view>
				<view class="input_box">
					<view class="label"><text> * </text>单位：</view>
					<view class="box">

					</view>
				</view>
				<view class="input_box">
					<view class="label"><text> * </text>用车日期：</view>
					<view class="box">
						<uni-datetime-picker v-model="datetimerange" type="datetimerange" rangeSeparator="至" />
					</view>
				</view>
			</view>

			<view class="info_list">
				<view class="info_item" v-for="(item,index) in list" :key="index">
					<view class="del" v-if="index > 0" @click="del_item(index)">
						<uni-icons type="clear" size="24" color="#666"></uni-icons>
					</view>
					<view class="input_box">
						<view class="label"><text> * </text>用车明细（单选）：</view>
						<view class="box" @click="change_mingxi(index)">
							{{item.array_text_mingxi}}
						</view>
					</view>
					<view class="input_box">
						<view class="label"><text> * </text>用车数量：</view>
						<view class="box">
							<input type="number" v-model="item.num" />
						</view>
					</view>
					<view class="input_box">
						<view class="label">申请事由：</view>
						<view class="box">
							<textarea v-model="item.inner" auto-height placeholder="请输入申请事由" />
						</view>
					</view>
				</view>
				<view class="add_item" @click="add_item()">
					+
				</view>
			</view>


			<view class="btn" @click="tijiao()">提交</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {},
				// 时间范围
				datetimerange: [],

				// 用车单数组
				list: [{
					array_text_mingxi: "",
					num: 1,
					inner: ""
				}],


				array_mingxi: ['下方', '回收', '转运'],
				array_text_mingxi: ""
			};
		},
		onLoad() {
			this.user = uni.getStorageSync('user')
		},
		watch: {
			datetimerange(newval) {
				console.log("范围选:", this.datetimerange);
			},
		},
		methods: {
			change_mingxi(index) {
				uni.showActionSheet({
					itemList: this.array_mingxi,
					success: (res) => {
						console.log(res)

						// 当前显示的名称
						this.list[index].array_text_mingxi = this.array_mingxi[res.tapIndex]
					},
				})
			},

			add_item() {
				console.log('+++')

				this.list.push({
					array_text_mingxi: "",
					num: 1,
					inner: ""
				})
			},
			
			del_item(index){
				this.list.splice(index,1)
			},
			
			tijiao(){
				console.log(this.list)
			}
		}
	}
</script>

<style lang="scss">
	.content {
		background-color: #F2FAF7;
		padding-bottom: 80rpx;

		.info_inner {
			background-color: #FFFFFF;
			box-sizing: border-box;
			padding: 25rpx;
		}

		.info_list {
			.info_item {
				margin-top: 20rpx;
				background-color: #FFFFFF;
				box-sizing: border-box;
				padding: 25rpx;
				
				position: relative;
				
				.del{
					position: absolute;
					top: 20rpx;
					right: 20rpx;
				}
			}

			.add_item {

				margin: 0 auto;
				margin-top: 50rpx;
				width: 80rpx;
				height: 80rpx;
				border-radius: 50%;
				border: 4rpx solid #009fe8;

				color: #009fe8;
				font-size: 80rpx;
				text-align: center;
				line-height: 70rpx;
			}

		}

		.input_box {
			margin-bottom: 20rpx;
			font-size: 32rpx;

			.label {
				min-height: 80rpx;
				line-height: 80rpx;
				color: #6C6F74;

				text {
					color: red;
				}
			}

			.box {
				width: 700rpx;
				min-height: 90rpx;
				line-height: 90rpx;
				background: #FFFFFF;
				border-radius: 8rpx;
				border: 2rpx solid #E9EBF2;

				box-sizing: border-box;
				padding: 0 25rpx;

				input {
					height: 90rpx;
				}

				textarea {
					min-height: 160rpx;
					width: 650rpx;
					box-sizing: border-box;
					padding: 20rpx 0;
				}

				/deep/.uni-date-editor--x {
					.uniui-clear {
						display: none;
					}

					.uniui-calendar {
						display: none;
					}
				}

				/deep/.uni-date-x--border {
					box-sizing: border-box;
					border-radius: 4px;
					border: none;
				}

				/deep/.uni-date-x {
					padding: 0;
				}
			}
		}

	}


	.btn {
		width: 700rpx;
		margin: 0 auto;
		margin-top: 80rpx;
		background-color: #009FE8;
		box-sizing: border-box;
		padding: 25rpx 0;
		color: #FFFFFF;
		text-align: center;
	}
</style>
