<template>
	<view>
		<view
			style="box-shadow: 0px 0px 8px 0px rgba(165, 189, 251, 0.4);width: 96%;border-top-right-radius: 10rpx;margin: 10rpx auto;padding-top: 10rpx;">
			<span
				style="width: 10rpx;height: 40rpx;background-color: #2979ff;display: block;float: left;margin-top: 20rpx;"></span>
			<!-- <h4 style="width: 140rpx;border-radius: 200rpx;text-align: center;color: #2979ff;border: 2rpx solid #1785FF;float: right;margin-right: 10rpx;margin-top: 10rpx;">2222222</h4> -->
			<view style="width: 92%;margin: 0 auto;margin: 0 auto;">
				<view
					style="display: flex;justify-content: space-between;height: 80rpx;line-height: 80rpx;border-bottom: 1rpx solid #eff4ff;">
					<h3>添加监控信息</h3>
				</view>
				<view>
					<u-field v-model="form.deviceName" label="监控名称:" label-width="150" required placeholder="请填写监控名称" />
					<u-field v-model="form.deviceSerial" label="设备序列号:" label-width="150" required
						placeholder="请填写设备序列号" />
					<u-field v-model="form.fWarehouseName" label="绑定仓库:" label-width="150" required disabled @click="show = !show" placeholder="请填写仓库" />
					<u-field v-model="dataForm.devices[0].connection.validateCode" label="萤石验证码:" label-width="150" required
						placeholder="请填写萤石验证码" />
				</view>
			</view>
		</view>
		<view
			style="width: 100%;position:fixed; bottom:44rpx;background-color: #FFFFFF;padding-left: 20px;padding-right: 20px;">
			<u-button type="primary" @click="appCheckCode">确认添加</u-button>
		</view>
		<!-- <u-action-sheet :list="listData" @click="click" v-model="show" :mask-close-able="false"></u-action-sheet> -->
		<u-select v-model="show" :list="listData" @confirm="click" value-name="fId" label-name="text"></u-select>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					deviceSerial: "",
					fWarehouseId:"",
					fWarehouseName:"",
					projectId: ""
				},
				show:false,
				listData:[],
				dataForm: {
					devices: [{
						deviceTypeCode: "IPCamera", //设备二级分类
						deviceSerial: "G26011245", //设备序列号
						deviceCategory: "Video", //设备大类
						// deviceRelatedInfo: {
						// 	deviceOrgId: "1320208694555696" //组织ID
						// },
						connection: {
							validateCode: "" //验证码mkdirmd5A
						},
						projectId: "1390317392767280", //项目ID
						deviceName: "", //设备名称
						treatyType: "ezviz_net" //传输协议
					}]
				}
			}
		},
		created() {
			this.$u.get('/basicdata/warehouse/appList').then(res=>{
				console.log(res)
				for(let item in res.rows){
					this.listData.push({
						text:res.rows[item].fName,
						fId:res.rows[item].fId
					})
				}
				console.log(this.listData)
			})
		},
		methods: {
			//选择仓库
			click(item){
				this.form.fWarehouseId = item[0].value
				this.form.fWarehouseName = item[0].label
			},
			// 确认添加监控
			appCheckCode() {
				if(!this.form.deviceSerial){
					this.$refs.uToast.show({
						title: '请填写设备序列号',
						position:'bottom'
					})
				}
				if(!this.form.fWarehouseId){
					this.$refs.uToast.show({
						title: '请选择仓库',
						position:'bottom'
					})
				}
				if(!this.form.deviceName){
					this.$refs.uToast.show({
						title: '请填写监控名称',
						position:'bottom'
					})
				}
				if(!this.dataForm.devices[0].connection.validateCode){
					this.$refs.uToast.show({
						title: '请填写萤石验证码',
						position:'bottom'
					})
				}
				this.haikangInterfaceAdd()
			},
			haikangInterfaceAdd() {
				this.dataForm.devices[0].deviceName = this.form.deviceName
				this.dataForm.devices[0].deviceSerial = this.form.deviceSerial
				uni.request({
				    url: 'https://open.hikyun.com/artemis/api/eits/v2/global/device/ezviz/save', //添加设备到第三方平台
				    data: this.dataForm,
				    header: {
				        'access_token': uni.getStorageSync('access_token') //自定义请求头信息
				    },
					method:'POST',
				    success: (res) => {
						if(res.data.code == 200){
							this.form.projectId = '1390317392767280'
							this.$u.post('/warehouse/webcam/', this.form).then(res => {
								this.$refs.uToast.show({
									title: '添加成功',
									position:'bottom'
								})
							})
						}else{
							this.$refs.uToast.show({
								title: res.data.msg,
								position:'bottom'
							})
						}
				    }
				});
			},
		}
	}
</script>

<style>
</style>
