cameraDialog.vue 7.32 KB
<template>
	<div>
		<!-- 添加相机 -->
		<el-dialog
		  title="添加相机"
		  :visible.sync="cameraAddVisible"
		  width="450px">
		  <div>
			  <el-form label-position="left" label-width="120px" :model="addVideoParam" :rules="rules" ref="cameraDialog" inline-message hide-required-asterisk>
				<el-form-item label="组织编号">
				  <el-input v-model="initParam.orgId" disabled></el-input>
				</el-form-item>
				<el-form-item label="组织名称">
				  <el-input v-model="initParam.orgName" disabled></el-input>
				</el-form-item>
				<el-form-item label="地点编号">
				  <el-input v-model="initParam.addr_code" disabled></el-input>
				</el-form-item>
				<el-form-item label="地点名称">
				  <el-input v-model="initParam.addr_name" disabled></el-input>
				</el-form-item>
				<el-form-item label="设备编号"   prop="vchan_refid">
				  <el-input v-model="addVideoParam.vchan_refid" :disabled="type=='edit'"></el-input>
				</el-form-item>
				<el-form-item label="设备名称" prop="name">
				  <el-input v-model="addVideoParam.name"></el-input>
				</el-form-item>
				<el-form-item label="方向">
				  <el-select v-model="addVideoParam.dir_code" placeholder="请选择方向" :popper-append-to-body=false>
				    <el-option :key="item.code" :label="item.name" :value="item.code" v-for="item in  dirCodeList"></el-option>
				   </el-select>
				</el-form-item>
				<el-form-item label="IP地址">
				  <el-input v-model="addVideoParam.ip"></el-input>
				</el-form-item>
				<el-form-item label="端口"  prop="port">
				  <el-input v-model="addVideoParam.port"></el-input>
				</el-form-item>
				<el-form-item label="协议">
				  <el-select v-model="addVideoParam.video_protocol_id" placeholder="请选择协议" :popper-append-to-body=false>
				    <el-option label="rtsp" value="rtsp"></el-option>
				    <el-option label="onvif" value="onvif"></el-option>
				   </el-select>
				</el-form-item>
				<el-form-item label="取流地址"  prop="video_source_url">
				  <el-input v-model="addVideoParam.video_source_url"></el-input>
				</el-form-item>
				<el-form-item label="用户名">
				  <el-input v-model="addVideoParam.user_name"></el-input>
				</el-form-item>
				<el-form-item label="密码">
				  <el-input v-model="addVideoParam.password"></el-input>
				</el-form-item>
				<el-form-item label="扩展字段1">
				  <el-input v-model="addVideoParam.extend_1"></el-input>
				</el-form-item>
				<el-form-item label="扩展字段2">
				  <el-input v-model="addVideoParam.extend_2"></el-input>
				</el-form-item>
			  </el-form>
		  </div>
		  <span slot="footer" class="dialog-footer">
		    <el-button @click="cameraAddVisible=false">取 消</el-button>
		    <el-button type="primary" @click="save" v-if="type!='detail'">确 定</el-button>
		  </span>
		</el-dialog>
	</div>
</template>

<script>
	export default{
		data(){
			return{
				addVideoParam:{
					vchan_refid:'',
					name:'',
					port:'',
					video_source_url:'',
					addr_unid:'',
					dir_code:'',
					ip:'',
					video_protocol_id:'',
					user_name:'',
					password:'',
					extend_1:'',
					extend_2:'',
					is_dome:false,
					vchan_type:'camera'
				},
				initParam:{
				},
				cameraAddVisible:false,
				dirCodeList:JSON.parse(localStorage.getItem('卡口方向')),
				type:'',
				devsId:'',
				rules: {
					  vchan_refid: [
						{ required: true, message: '设备编号不能为空', trigger: 'change' }
					  ],
					  name:[
						  { required: true, message: '设备名称不能为空', trigger: 'change' }
					  ],
					  port:[
						  { required: true, message: '端口不能为空', trigger: 'change' }
					  ],
					  video_source_url:[
						  { required: true, message: '取流地址不能为空', trigger: 'change' }
					  ]
				}
			}
		},
		methods:{
			initDialog(node,type,devsId){
				this.cameraAddVisible=true;
				this.devsId=devsId;
				if(type == 'add'){
					this.type='add'
					this.addVideoParam.addr_unid=node.data.unid;
					
					this.initParam.addr_name = node.data.org_name;
					this.initParam.addr_code = node.data.org_code;
					
					this.initParam.orgName = node.parent.data.org_name;
					this.initParam.orgId = node.parent.data.org_code;
				}else if(type == 'edit'){
					this.type = 'edit';
					this.addVideoParam.addr_unid = node.addrNode.unid;
					
					this.initParam.addr_name = node.addrNode.org_name;
					this.initParam.addr_code = node.addrNode.org_code;
					
					this.initParam.orgName = node.orgNode.org_name;
					this.initParam.orgId = node.orgNode.org_code;
					
					this.addVideoParam.vchan_refid = node.id;
					this.addVideoParam.name = node.label;
					this.addVideoParam.dir_code=node.dir_code;
					this.addVideoParam.ip=node.ip;
					this.addVideoParam.port=node.port;
					this.addVideoParam.video_protocol_id=node.video_proto;
					this.addVideoParam.video_source_url=node.url;
					this.addVideoParam.user_name=node.username;
					this.addVideoParam.password=node.password;
					this.addVideoParam.extend_1=node.extend_1;
					this.addVideoParam.extend_2=node.extend_2;
				}else if(type == 'detail'){
					this.type = 'detail';
					this.addVideoParam.addr_unid = node.addrNode.unid;
					
					this.initParam.addr_name = node.addrNode.org_name;
					this.initParam.addr_code = node.addrNode.org_code;
					
					this.initParam.orgName = node.orgNode.org_name;
					this.initParam.orgId = node.orgNode.org_code;
					
					this.addVideoParam.vchan_refid = node.id;
					this.addVideoParam.name = node.label;
					this.addVideoParam.dir_code=node.dir_code;
					this.addVideoParam.ip=node.ip;
					this.addVideoParam.port=node.port;
					this.addVideoParam.video_protocol_id=node.video_proto;
					this.addVideoParam.video_source_url=node.url;
					this.addVideoParam.user_name=node.username;
					this.addVideoParam.password=node.password;
					this.addVideoParam.extend_1=node.extend_1;
					this.addVideoParam.extend_2=node.extend_2;
				}
			},
			save(){
				if(this.type == 'add'){
					this.$refs['cameraDialog'].validate((valid) => {
					  if (valid) {
						this.$api.resource.addCamera(this.addVideoParam,localStorage.getItem('dev_unid')).then(res=>{
							if(res.ecode==200){
								 this.$message({
								  message: res.enote,
								  type: 'success'
								});
								let data={
									org_type:"address",
									unid:this.addVideoParam.addr_unid
								}
								 this.$emit('getAllData',data)
								// this.$parent.$parent.$parent.submitLaterGet(data)
								this.cameraAddVisible=false;
							}else{
								 this.$message.error(res.enote);
							}
							
						})
					  } else {
						console.log('error submit!!');
						return false;
					  }
					});
				}else if(this.type == 'edit'){
					this.addVideoParam.is_dome=false;
					this.$refs['cameraDialog'].validate((valid) => {
					  if (valid) {
						this.$api.resource.editCamera(this.addVideoParam,this.devsId,this.addVideoParam.vchan_refid).then(res=>{
							if(res.ecode==200){
								 this.$message({
								  message: res.enote,
								  type: 'success'
								});
								let data={
									org_type:"address",
									unid:this.addVideoParam.addr_unid
								}
								this.$emit('getData',data)
								this.cameraAddVisible=false;
							}else{
								 this.$message.error(res.enote);
							}
							
						})
					  } else {
						console.log('error submit!!');
						return false;
					  }
					});
					
				}
			}
		}
	}
</script>

<style>
</style>