adddev.vue 6.69 KB
<template>
  <div>
    <el-dialog title="添加设备" :visible.sync="addvdialog" :before-close="closeaddvdialog" width="50%">
      <div class="" style="overflow:hidden">
        <el-form ref="vforms" :model="vform" label-width="120px">
          <el-col :span="12">
            <el-form-item label="分析终端编号" prop="vchan_refid" :rules="[
                   { required: true, message: '分析终端编号不能为空', trigger: 'blur' }]">
              <el-input v-model="vform.vchan_refid"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item prop="vchan_name" label="分析终端名称">
              <el-input v-model="vform.vchan_name"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item prop="vchan_prop.type" label="相机属性">
              <el-select v-model="vform.vchan_prop.is_dome" placeholder="请选区域">
                <el-option  label="球机" :value="true"></el-option>
                <el-option  label="枪机" :value="false"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item prop="vchan_prop.ip" label="IP地址" :rules="[
                   { required: true, message: '相机IP不能为空', trigger: 'blur' }]">
              <el-input v-model="vform.vchan_prop.ip"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item prop="vchan_prop.port" label="端口号">
              <el-input v-model="vform.vchan_prop.port"></el-input>
            </el-form-item>
          </el-col>
           <el-col :span="12">
             <el-form-item prop="vchan_prop.type" label="协议类型">
                <el-select v-model="vform.vchan_prop.video_protocol_id" placeholder="请选协议类型">
                  <el-option  label="RTSP" value="1"></el-option>
                  <el-option  label="枪机" value="2"></el-option>
                </el-select>
              </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item prop="vchan_prop.video_source_url" label="推流地址">
              <el-input v-model="vform.vchan_prop.video_source_url"></el-input>
            </el-form-item>
          </el-col>
           <el-col :span="12">
            <el-form-item prop="vchan_prop.ent_prop" label="相机属性">
              <el-select v-model="vform.vchan_prop.ent_prop" placeholder="请选区域">
                <el-option  label="入口" :value="1"></el-option>
                <el-option  label="出口" :value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用户名" prop="vchan_prop.user_name" :rules="[
                   { required: true, message: '相机用户名不能为空', trigger: 'blur' }]">
              <el-input v-model="vform.vchan_prop.user_name"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="密码" prop="vchan_prop.password" :rules="[
                   { required: true, message: '密码不能为空', trigger: 'blur' }]">
              <el-input v-model="vform.vchan_prop.password" type="password"></el-input>
            </el-form-item>
          </el-col>
           <el-col :span="12">
            <el-form-item label="挂在地址" prop="org_unid" :rules="[
                   { required: true, message: '挂载点不能为空', trigger: 'blur' }]">
              <el-select v-model="vform.org_unid" placeholder="请选区域">
                <el-option v-for="(item,index) in address" :key="index" :label="item.org_name" :value="item.unid"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="closeaddvdialog">关闭</el-button>
        <el-button type="primary" @click="submitvchan">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        vform: {
          vchan_refid:'',
          org_pid: '',
          org_unid:'',
          vchan_name: "",
          vchan_type:'vchan',
          vchan_prop: {
            ent_prop:1,
            is_dome: false,
            ip: null,
            port: "",
            user_name: "",
            password: "",
            video_protocol_id: "",
            video_source_url: ""
          }
        }
      }
    },
    props: ["addvdialog","editData","state"],

    methods: {
      closeaddvdialog(state) {
        this.state = "add";
        this.$emit("closedialog",state);
      },
      resetForm(formName) {
        this.$refs['vforms'].resetFields();
      },
      editvchan(){
      },
      submitvchan() {
      let url = this.API.org.getvchan,
      data = this.vform;
      if(this.state == 'edit'){
        url = this.API.org.editvchan(data.id)
         data=  {
          vchan_refid:this.vform.vchan_refid,
          org_pid: this.vform.org_pid,
          org_unid:this.vform.org_unid,
          vchan_name:this.vform.vchan_name,
          vchan_type:'vchan',
          vchan_prop: {
            ent_prop:this.vform.vchan_prop.ent_prop,
            is_dome: this.vform.vchan_prop.is_dome,
            ip: this.vform.vchan_prop.ip,
            port: this.vform.vchan_prop.post,
            user_name: this.vform.vchan_prop.user_name,
            password:this.vform.vchan_prop.password,
            video_protocol_id: this.vform.vchan_prop.video_protocol_id,
            video_source_url: this.vform.vchan_prop.video_source_url
          }
        }
      }
       this.$refs['vforms'].validate((valid) => {
          if (valid) {
           this.axios.post(url,data,{
              headers:{
                "authorization": localStorage.getItem("atoken"),
              }}).then(response => {
              this.resetForm();
              this.closeaddvdialog(1);
              this.state = "add";
           });
          } else {
            return false;
          }
        });
      },
     deepCopy (data) {
       let result = ''
        result = JSON.parse(JSON.stringify(data));
        return result;
      }
    },
    created(){
      debugger
      this.faceapi.getAddress().then(res => {
        this.address = res.list_data;
      })
    },
    watch:{
      editData(val){
        console.log(val)
        if(val) {
          val.org_unid = Number(val.org_unid)
        }
         this.vform = this.deepCopy(val);
      },
      state(val){
        if(val == 'add'){
          this.resetForm();
        }
      }
    }
  };

</script>
<style lang="stylus" scoped>


</style>