<template>
	<view class="containers">
		<view class="db">
			<view class="dblist">
				<view>
					<view class="dbitem">
						<text class="dbtype">{{info.type_text}}</text>
						<view class="dbstatus bm">
							<view>{{info.audit_status_text}}</view>
							<view>
								<text style="margin-right:10px">访问时间：{{info.date}}</text>
								<text>{{info.visit_time.start_time}}至{{info.visit_time.end_time}}</text>
							</view>
							<view v-if="info.type=='2'">施工时段：{{info.work_start_time}}至{{info.work_end_time}}</view>
						</view>
						<view class="dbinfo justify-left">
							<view>
								<view>被访人：<text>{{info.accept_admin.name}}</text></view>
								<view>部门：<text>{{info.accept_admin.department.name}}</text></view>
								<view>访问区域：<text>{{info.visit_area.name}}</text></view>
							</view>
							<view>
								<view>拜访人：<text>{{info.name}}</text></view>
								<view>电话：{{info.mobile}}</view>
								<view v-if="info.type=='1'">事由：<text>{{info.reason}}</text></view>
								<view v-else-if="info.type=='3'">车牌：<text>{{info.plate}}</text></view>
							</view>
						</view>
						<view class="dblong">
							<view>长期访客申请：<text>{{info.long_time==0?'否':'是'}}</text></view>
							<view v-if="info.long_time==1">长期访问时间：{{info.start_date}} 至 {{info.end_date}}</view>
						</view>

					</view>
				</view>
				<template v-if="info.type!='3'">
					<view class="dbtext">随访人员</view>
					<view class="dbitem sfyritem">
						<template v-if="info.follw_people">
							<view class="dbinfo justify-left" v-for="people in info.follw_people">
								<view>
									<view>
										随访人：<text>{{people.name}}</text>
									</view>
									<view>证件类型：<text>{{people.credent_name}}</text></view>
									<view>证件号：<text>{{people.idcard}}</text></view>
								</view>
								<view>
									电话：<text>{{people.mobile}}</text>
								</view>
							</view>
						</template>
						<template v-else>
							<view class="dbinfo justify-left">
								无
							</view>
						</template>
					</view>
				</template>

				<template v-if="info.type!='3'">
					<view class="dbtext">到访车辆</view>
					<view class="dbitem sfyritem">
						<view class="dbinfo">
							<view class="onechild">
								车牌：<text>{{info.cars}}</text>
							</view>
						</view>
					</view>
				</template>

				<template v-if="info.type=='3'">
					<view class="dbtext">收货人</view>
					<view class="dbitem sfyritem">
						<view class="dbinfo justify-left">
							<view>
								部门：<text>{{info.accept_goods_admin.department.name}}</text>
							</view>
							<view>
								人员：<text>{{info.accept_goods_admin.name}}</text>
							</view>
						</view>
					</view>
				</template>
				<view class="dbtext">被访人员</view>
				<view class="dbitem sfyritem">
					<view class="dbinfo justify-left">
						<view>
							部门：<text>{{info.accept_admin.department.name}}</text>
						</view>
						<view>
							人员：<text>{{info.accept_admin.name}}</text>
						</view>
					</view>
				</view>

				<!-- 审核 -->
				<view class="checkforms dbitem" v-if="info.audit_status==0" style="padding-top:30rpx">
					<uni-forms ref="formdata" :model="checkForm" :rules="rules" labelWidth="100px">
						<uni-forms-item label="状态" required name="status">
							<uni-data-select v-model="checkForm.status" :localdata="statusList">
							</uni-data-select>
						</uni-forms-item>
						<uni-forms-item label="审核" required name="level">
							<uni-data-select v-model="checkForm.level" :localdata="levelList" @change="setLevel">
							</uni-data-select>
							<view>{{check_admin_name}}</view>
						</uni-forms-item>
						<uni-forms-item label="备注">
							<uni-easyinput type="textarea" v-model="checkForm.reason" placeholder="请输入备注" />
						</uni-forms-item>

					</uni-forms>
					<button type="primary" style="background-color: #044ed7;" @click="checkSubmit">审核</button>

				</view>

			</view>

		</view>

	</view>
</template>

<script>
	import '@/static/css/bd.css'
	export default {
		data() {
			return {
				id: "",
				info: {},
				checkForm: {
					level: "",
					status: "",
					audit_admin_id: "",
					visit_id:"",
					reason:""
				},
				rules: {
					status: {
						rules: [{
							required: true,
							errorMessage: '请选择状态'
						}]
					},
					level: {
						rules: [{
							required: true,
							errorMessage: '请选择审核级别'
						}]
					},
				},
				statusList: [{
						value: 0,
						text: "待审核"
					},
					{
						value: 1,
						text: "通过"
					},
					{
						value: 2,
						text: "驳回"
					},
				],
				levelList: [],
				check_admin_name: ""
			}
		},
		onReady() {

		},
		onLoad(options) {
			this.id = options.id
			this.checkForm.visit_id = parseInt(options.id)
			this.loadDetail()
		},
		methods: {
			setLevel(val) {
				let that = this
				console.log(val)
				this.levelList.map(item => {
					if (item.value == val) {
						that.checkForm.level = item.value
						that.checkForm.audit_admin_id = item.admin_id
						that.check_admin_name = item.admin_name ? item.admin_name : ''
					}
				})
			},
			checkSubmit() {
				let that = this
				console.log(that.checkForm)
				this.util.request({
					api: '/api/admin/visit_audit/save',
					method: "POST",
					requestType:'bd',
					data: that.checkForm,
					utilSuccess: function(res) {
						uni.showToast({
							title: res.msg,
							duration: 2000,
							icon: 'none'
						})
						// uni.removeStorageSync('formData')
						uni.navigateTo({
							url:'/pages/bd/record?type=mycheck'
						})
					},
					utilFail: function(res) {
						uni.showToast({
							title: res.errmsg,
							duration: 2000,
							icon: 'none'
						})
					}
				})
			},
			loadDetail() {
				let that = this
				this.util.request({
					api: '/api/admin/visit/show',
					method: "get",
					requestType: 'bd',
					data: {
						id: that.id
					},
					utilSuccess: function(res) {
						for (let k of res.visit_area.audit_admin) {
							that.levelList.push({
								text: k.type_name,
								value: k.level,
								admin_id: k.admin_id,
								admin_name: k.admin_name
							})
						}

						that.info = res
					},
					utilFail: function(res) {
						uni.showToast({
							title: res.errmsg,
							duration: 2000,
							icon: 'none'
						})
					}
				})
			},
			isnull(p) {
				if (p == '' || p == undefined || p == null || p == 'undefined' || p == 'null') {
					return ""
				} else {
					return p
				}
			}
		}


	}
</script>

<style scoped>
	.containers {
		background-color: #eceefe;
		min-height: 100vh;
		padding-top: 20rpx;
	}

	.dbtext {
		padding-top: 10rpx;
		margin-bottom: 30rpx;
		color: #303639;
		font-size: 40rpx;
		padding-left: 30rpx
	}

	.sfyritem {
		padding-bottom: 10rpx
	}

	.dbinfo>view text {
		color: #8f9596;
	}
</style>
