<template>
	<uni-row class="main" v-bind:style="{ 'min-height': client.win_height + 'px' }">
		<view class="one_1">
			<button type="info" size="mini" @click="toOpen()">扫一扫</button>
		</view>
		<view class="one_2">
			<view class="img">
				<image class="img" :src="coverImg" v-if="coverImg"></image>
				<span v-else>暂无图片</span>
			</view>
			<view class="info">
				<form>
					<view class="content">
						<view class="title">姓名：</view>
						<input :value="info.name" disabled />
					</view>
					<view class="content">
						<view class="title">职业等级：</view>
						<input :value="info.exam_grade" disabled />
					</view>
					<view class="content">
						<view class="title">发证日期：</view>
						<input :value="info.cert_date" disabled />
					</view>
					<view class="content">
						<view class="title">证件状态：</view>
						<input :value="info.cert_status" disabled />
					</view>
					<view class="content">
						<view class="title">保安员编号：</view>
						<input :value="info.baoan_num" disabled />
					</view>
					<view class="content">
						<view class="title">出生日期：</view>
						<input :value="info.birth" disabled />
					</view>
					<view class="content">
						<view class="title">身份证号：</view>
						<input :value="info.card" disabled />
					</view>
					<view class="content">
						<view class="title">住址：</view>
						<input :value="info.house_onaddress" disabled />
					</view>
					<view class="content">
						<view class="title">发证公安机关：</view>
						<input :value="info.cert_police" disabled />
					</view>
					<view class="content">
						<view class="title">所在企业：</view>
						<input :value="info.is_company" disabled />
					</view>
					<view class="content">
						<view class="title">服务单位：</view>
						<input :value="info.service_company" disabled />
					</view>
				</form>
			</view>
			<view class="btn">
				<button type="primary" size="mini" @click="toAccord('身份信息吻合',info)">符合</button>
				<button type="warn" size="mini" @click="toAccord('身份信息不吻合',info)">不符合</button>
			</view>
		</view>
	</uni-row>
</template>

<script>
	import {
		mapState,
		mapGetters,
		createNamespacedHelpers
	} from "vuex";
	import helper from "../../common/base.js";
	const {
		mapActions: certBase
	} = createNamespacedHelpers("certificates_base");
	const {
		mapActions: collect
	} = createNamespacedHelpers(
		"security_guard_collect"
	);
	const {
		mapActions: companywork
	} = createNamespacedHelpers(
		"company_baoan_work"
	);
	const {
		mapActions: companydispatch
	} = createNamespacedHelpers(
		"company_baoan_dispatch"
	);
	const {
		mapActions: daily
	} = createNamespacedHelpers(
		"daily_inspection"
	);

	import moment from 'moment'

	export default {
		name: "index",
		props: {},
		components: {},
		data: function() {
			return {
				client: {},
				// 头像
				coverImg: '',
				// 详细信息
				info: {},
			};
		},
		created() {},
		methods: {
			...certBase(["fetch"]),
			...collect(["query"]),
			...companywork({
				companyworkQuery: 'query'
			}),
			...companydispatch({
				companydispatchQuery: 'query'
			}),
			...daily({
				dailyCreate: 'create'
			}),
			// 打开摄像头
			toOpen() {
				uni.scanCode({
					onlyFromCamera: true,
					success: (res) => {
						if (res.result) {
							this.search(res.result);
						} else {
							uni.showToast({
								title: '二维码识别失败',
								duration: 2000,
								icon: "error",
							});
						}
					}
				});
			},
			// 查询详细信息,头像1
			async search(id) {
				// 查询信息
				let data = {}
				let res = await this.fetch({
					security_guard_id: id
				});
				if (res.errcode == '0' && res.data) {
					res.data.cert_status = res.data.cert_status == '0' ? '正常' : '注销';
					data = res.data;
				} else {
					uni.showToast({
						title: "查无此人",
						duration: 2000,
						icon: "error",
					});
				}
				// 查询所在企业
				let arr = await this.companyworkQuery({
					security_guard_id: id
				})
				if (arr.errcode == '0' && arr.data) {
					data.is_company = arr.data[0].company_name;
				} else {
					uni.showToast({
						title: "暂无信息",
						duration: 2000,
						icon: "error",
					});
				}
				// 查询所服务的单位
				let aee = await this.companydispatchQuery({
					security_guard_id: id
				})
				if (aee.errcode == '0' && aee.data) {
					data.service_company = aee.data[0].service_target;
				} else {
					uni.showToast({
						title: "暂无信息",
						duration: 2000,
						icon: "error",
					});
				}
				this.$set(this, `info`, data);
				// 查詢头像
				res = await this.query({
					security_guard_id: id,
					type: "人像"
				});
				if (res.errcode == '0' && res.total > 0) {
					let data = res.data[0];
					let url = helper.webfilesUrl + data.data;
					this.$set(this, `coverImg`, url);
				} else {
					this.$set(this, `coverImg`, '');
					uni.showToast({
						title: '暂无头像',
						duration: 2000,
						icon: "error",
					});
				}

			},
			async toAccord(type, row) {
				let data = {
					industry_type: '保安监管',
					company_name: row.is_company,
					inspect_type: '日常检查',
					inspect_time: moment().format('YYYY-MM-DD HH:mm:ss'),
					inspect_name: this.user.name,
					inspect_matter: type,
				}
				let res = await this.dailyCreate(data);
				if (res.errcode == '0') {
					uni.showToast({
						title: '提交成功',
						duration: 2000,
						icon: "success",
					});
				} else {
					uni.showToast({
						title: res.errmsg,
						duration: 2000,
						icon: "error",
					});
				}
			}
		},
		computed: {
			...mapState(["user"]),
		},
		onLoad() {
			// this.search('61df86d187810eea5488beb4');
			// 获取设备信息
			uni.getSystemInfo({
				success: (res) => {
					this.client = {
						win_top: res.windowTop,
						win_width: res.windowWidth,
						win_height: res.windowHeight,
						scr_width: res.screenWidth,
						scr_height: res.screenHeight,
					};
				},
			});
		},
	};
</script>

<style lang="scss">
	.main {
		background-color: #409eff;
		overflow-y: auto;

		.one_1 {
			text-align: center;
			margin: 8px 0;
		}

		.one_2 {
			width: 97%;
			padding: 0 5px;

			.img {
				text-align: center;

				image {
					width: 100px;
					height: 100px;
					overflow: hidden;
					border: 1px solid #f9f9f9;
				}

				span {
					display: inline-block;
					width: 100px;
					height: 100px;
					overflow: hidden;
					text-align: center;
					line-height: 100px;
					border: 1px solid #f9f9f9;
				}
			}

			.info {
				.content {
					padding: 0 10px;
					margin: 10px 0;

					.title {
						font-size: 16px;
						margin: 0 0 8px 0;
						color: #000000;
					}

					input {
						border: 1px solid #ccc;
						border-radius: 5px;
						padding: 5px;
					}
				}
			}

			.btn {
				text-align: center;
				margin: 10px 0;

				button {
					margin: 0 10px;
				}
			}
		}
	}
</style>
