<template>
	<view>
		<view class="vtitle">借用人信息</view>
		<view class="form_group">
			<view class="lable">扫码</view>
			<view class="tag" @click="qr()">
				<text class="span"></text>
				<text class="icon code">&#xe60e;</text>
			</view>
		</view>
		<view class="form_group">
			<view class="lable">设备所属部门</view>
			<view class="tag" @click="qr()">
				<text class="span">智能技术研究所</text>
				<text class="icon more">&#xe631;</text>
			</view>
		</view>
		<view class="form_group">
			<view class="lable">借用人</view>
			<view class="tag" @click="qr()">
				<text class="span"></text>
				<text class="icon more">&#xe631;</text>
			</view>
		</view>
		<view class="form_group">
			<view class="lable">手机号</view>
			<view class="tag" @click="qr()">
				<text class="span"></text>
				<text class="icon more">&#xe631;</text>
			</view>
		</view>
		<view class="vtitle">借用设备信息</view>
		<view class="form_group">
			<view class="lable">手机号</view>
			<view class="tag" @click="qr()"><text class="span">PMQ133701437</text></view>
		</view>
		<view class="form_group">
			<view class="lable">设备名称</view>
			<view class="tag" @click="qr()"><text class="span">压力传感器</text></view>
		</view>
		<view class="form_group">
			<view class="lable">计量编号</view>
			<view class="tag" @click="qr()"><text class="span">压力传感器</text></view>
		</view>
		<view class="form_group">
			<view class="lable">设备名称</view>
			<view class="tag" @click="qr()"><text class="span">PMQ137700009</text></view>
		</view>
		<view class="form_group">
			<view class="lable">三向加速度计</view>
			<view class="tag" @click="qr()"><text class="span">三向加速度计</text></view>
		</view>
		<button class="btn">提交</button>
	</view>
</template>

<script>
let qrcode = require('@/common/code.js');
export default {
	data() {
		return {
			item: {},
			op: '设备归还',
			current: 0
		};
	},
	onLoad(e) {
		this.op = e.op;
		//选中审批人员监听函数,其它类型的参考这个
		uni.$on('select', res => {
			console.log('asd:' + JSON.stringify(res));
		});
	},
	onReady() {
		uni.setNavigationBarTitle({
			title: this.op
		});
	},
	methods: {
		qr() {
			// 调用uni提供的调用相机api
			uni.chooseImage({
				sizeType: ['original'],
				sourceType: ['camera'],
				count: 1,
				success: res => {
					const tempFilePaths = res.tempFilePaths[0]; // 获取到二维码图片的链接
					qrcode.decode(tempFilePaths); // 解析二维码图片
					qrcode.callback = r => {
						this.item.code = r;
						console.log('asd:' + r);
						this.$forceUpdate();
					};
				}
			});
		},
		//选择结果形式
		change(e) {
			this.current = e;
			console.log('aa:' + this.radio[this.current].name);
		},
		//选择审批人员
		select() {
			uni.navigateTo({
				url: '/pages/index/select'
			});
		},
		//提交
		add() {
			this.http.request({
				url: this.http.urls.user_task_add,
				data: this.item,
				method: 'POST',
				success: res => {
					uni.showModal({
						title: '提示',
						content: '提交成功',
						showCancel: false,
						success: res => {
							if (res.confirm) {
								uni.navigateBack();
							}
						}
					});
				}
			});
		}
	}
};
</script>

<style lang="scss">
.btn {
	width: 80%;
	margin-top: 20px;
	margin-bottom: 20px;
}
</style>
