<template>
	<view class="list-body">
		<uni-nav-bar @clickLeft="goBack()" class="nav-bar" height="110rpx" leftWidth="200rpx" leftText="人员选择"
			leftIcon="left" border backgroundColor="#2cade8" color="#fff" fixed statusBar shadow></uni-nav-bar>
		<view class="apply-info">
			<view class="row" v-for="(row,index) in vpeopleList" :key="index" @tap="select(row)">
				<view class="center">
					<view class="name-tel">
						<view class="name">姓名：{{row.text}}</view>
						<view class="tel">手机号：{{row.visitor_.phone}}</view>
						<view class="tel">身份证号：{{row.visitor_.id_number}}</view>
					</view>
				</view>
				<view class="right">
					<view class="icon bianji" @tap.stop="edit(row)">
					</view>
				</view>
			</view>
			<button type="primary" class="select" @click="checkPeople">选择人员</button>
		</view>
		<button type="primary" class="addNew" @click="add">新增人员</button>
		<view class="dialogWrap" v-if="limitedPeople">
			<view class="dialogCont">
				<view class="dialogTitle">
					<view>选择来访人员</view>
					<view class="dialogCloseImg" @click="closeDialog"></view>
				</view>
				<form @submit="formSubmit">
					<view class="uni-form-item uni-column">
						<view class="title">访客</view>
						<uni-data-select name="visitor" :localdata="userRange" v-model="formData.visitor">
						</uni-data-select>
					</view>
					<view class="uni-form-item uni-column">
						<view class="title">是否主访客</view>
						<view>
							<switch name="is_main" v-model="formData.is_main" />
						</view>
					</view>
					<view class="uni-btn-v">
						<button class="mini-btn" type="primary" size="mini" form-type="submit">确定</button>
					</view>
				</form>
			</view>
		</view>
		<view class="apply-info" style="min-height: fit-content;display: flex;">
			<button v-for=" item in initform.transitions" :key="item.id" @click="submitticket(item.id)" type="primary" style="width: 25%;">{{item.name}}
			</button>
			<button type="warn"  style="width: 25%;">退出</button>
		</view>
		
	</view>
</template>

<script>
	export default {
		name: "vpeopleList",
		data() {
			return {
				limitedPeople: false,
				formData: {
					visit: '',
					visitor: '',
					is_main: true,
				},
				initform: {},
				vpeopleList: [],
				userRange: [],
			}
		},
		onLoad(params) {
			this.visitId = params.visit;
		},
		onShow() {
			this.getUserRange();
			this.getVpeopleList();
			this.getInit();
		},
		methods: {
			formSubmit(val) {
				let that = this;
				that.formData.visit = that.visitId;
				that.$u.api.vpeopleCreate(that.formData).then(res => {
					if (res.err_msg) {} else {
						that.getVpeopleList();
						this.limitedPeople = false;
					}
				})
			},
			//获取所有已注册游客
			getUserRange() {
				let that = this;
				that.$u.api.vmVisitor({
					page: 0
				}).then(res => {
					that.userRange = [];
					let user = [];
					let obj = {};
					res.forEach(item => {
						obj = item;
						obj.value = item.id;
						obj.text = item.name;
						user.push(obj);
					})
					that.userRange = user
				})
			},
			//获取已有游客
			getVpeopleList() {
				let that = this;
				that.$u.api.vmVpeople({
					page: 0,
					visit: '1554721956950052864'
				}).then(res => {
					that.vpeopleList = [];
					let user = [];
					let obj = {};
					res.forEach(item => {
						obj = item;
						obj.value = item.id;
						obj.text = item.visitor_.name;
						user.push(obj);
					})
					that.vpeopleList = user
				})
			},
			checkPeople() {
				this.limitedPeople = true;
			},
			closeDialog() {
				this.limitedPeople = false;
			},
			select(row) {},
			goBack() {
				uni.navigateBack({
					delta: 1
				})
			},

			add() {
				uni.navigateTo({
					url: '/pages/workSpace/newWork/addUser'
				})
			},
			edit(row) {},
			getInit() {
				this.$u.api.workflowInit('visit').then((res) => {
					this.initform = res;

				});
			},
			//提交工单
			submitticket(id) {
				let ticket = {};
				ticket.workflow = this.initform.workflow;
				ticket.ticket_data = {
					visit: this.visitId
				};
				ticket.transition = id;
				this.$u.api.ticketCreate(ticket).then((res) => {
					if(res.err_msg){}else{
						uni.reLaunch({
							url: '/pages/workSpace/workSpace'
						})
					}
				});

			}
		}
	}
</script>

<style>
	>>>.uni-navbar__header,
	>>>.uni-status-bar {
		background-image: linear-gradient(90deg, #164cc3 0%, #2c6fd9 100%), linear-gradient(#e60012, #e60012) !important;
	}

	.list-body {
		background-color: #f3fbff;
		padding-bottom: 113px;
	}

	.apply-info {
		min-height: 70vh;
		width: 710upx;
		margin: 0 auto;
		background-color: #FFFFFF;
		border-radius: 5px;
		padding: 12px 16px;
		box-sizing: border-box;
		margin-top: 12px;
	}

	.row {
		padding: 10upx;
		margin-bottom: 20upx;
		border-bottom: 1upx solid #eeeeee;
	}

	.uni-list-cell {
		display: flex;
		padding: 10upx;
		margin-bottom: 20upx;
		border-bottom: 1upx solid #eeeeee;
	}

	.addNew {
		width: 50px;
		height: 50px;
		border-radius: 25px;
		line-height: 50px;
		box-shadow: 0 0 6px 2px rgba(0, 0, 0, .3);
		z-index: 100;
		position: fixed;
		bottom: 20px;
		right: 20px;
	}

	.select {
		margin: auto;
		box-shadow: 0upx 5upx 10upx rgba(0, 0, 0, 0.4);
		width: 400rpx;
		height: 80rpx;
		line-height: 80rpx;
		font-size: 30rpx;
	}

	.save-btn {
		height: 80rpx;
		color: #fff;
		font-size: 30upx;
		justify-content: center;
		align-items: center;
	}

	.dialogWrap {
		position: fixed;
		width: 100vw;
		height: 100vh;
		background-color: rgba(0, 0, 0, .3);
		top: 0;
		left: 0;
		z-index: 110;
	}

	.dialogCont {
		width: 80vw;
		position: absolute;
		top: 50%;
		margin: auto;
		background-color: #ffffff;
		left: 10vw;
		transform: translateY(-50%);
		padding: 20rpx;
		border-radius: 20rpx;
	}

	.dialogTitle {
		font-size: 36rpx;
		padding-bottom: 20rpx;
		border-bottom: 1px solid #eeeeee;
		display: flex;
		justify-content: space-between;
	}

	.uni-form-item {
		height: 160rpx;
	}

	.uni-form-item>.title {
		height: 80rpx;
		line-height: 80rpx;
		font-size: 32rpx;
	}

	.uni-btn-v {
		text-align: center;
	}

	.dialogCloseImg {
		width: 52rpx;
		height: 52rpx;
		background-image: url('../../../static/my/my_apply/zuofei.png');
		background-repeat: no-repeat;
		background-size: cover;
	}
</style>
