nationalStandard.vue 4.18 KB
<template>
  <div class="innnerBox">
	  <div class="title">sip视频设置</div>
		<el-form :model="sipSetting" ref="form" :rules="rules" label-width="100px" class="demo-ruleForm"  inline-message hide-required-asterisk>
			  <el-form-item
				label="用户名"
				prop="sip_username">
				<div style="width: 30%;">
					<el-input  v-model="sipSetting.sip_username" autocomplete="off"></el-input>
				</div>
			  </el-form-item>
			  <el-form-item label="密码" prop="sip_password">
				 <div style="width: 30%;">
					<el-input type="password" v-model="sipSetting.sip_password" autocomplete="off"></el-input>
				</div>
			  </el-form-item>
			  <el-form-item>
				<el-button type="primary" @click="addSip('form')" v-if="!isGetted">提交</el-button>
				<el-button type="primary" @click="editSip('form')" v-if="isGetted">编辑</el-button>
				<el-button type="primary" @click="delFun()" v-if="isGetted">删除</el-button>
			  </el-form-item>
		</el-form>
  </div>
</template>
<script>
	export default {
		data(){
			var validateUser = (rule, value, callback) => {
				if (value === '') {
				callback(new Error('请输入用户名'));
				} else {
				callback();
				}
			};
			var validatePass = (rule, value, callback) => {
				if (value === '') {
				  callback(new Error('请输入密码'));
				} else {
				  callback();
				}
			  };
			return{
				rules: {
					sip_username:[
						{ validator: validateUser, trigger: 'change' }
					],
					sip_password: [
						{ validator: validatePass, trigger: 'change' }
					],
				},
				user_unid:sessionStorage.getItem('user_unid'),
				dev_unid:sessionStorage.getItem('dev_unid'),
				isGetted:false,
				sipSetting:{
					sip_username: '',    // string
					sip_password: ''  
				},
				sip_unid:''
			}
		},
		watch:{},
		components:{},
		mounted(){
			this.getSipParam();
		},
		methods:{
			 addSip(formName) {
				this.$refs[formName].validate((valid) => {
				  if (valid) {
					this.$api.resource.addSip(this.sipSetting,this.dev_unid,this.user_unid).then(res=>{
							// console.log(res.data);
							if(res.ecode == 200) {
								this.isGetted = true;
								this.$message({
									type: 'success',
									message: res.enote
								})
							} else {
								this.isGetted = false;
								this.$message({
									type: 'error',
									message: res.enote
								})
							}
						
					})
				  } else {
					return false;
				  }
				});
			},
			editSip(formName){
				this.$refs[formName].validate((valid) => {
				if (valid) {
					this.$api.resource.editSip(this.sipSetting,this.dev_unid,this.user_unid,this.sip_unid).then(res=>{
						// console.log(res.data);
						if(res.ecode == 200) {
							this.$message({
								type: 'success',
								message: '修改成功!'
							})
						} else {
							this.$message({
								type: 'error',
								message: res.enote
							})
						}
					})
				} else {
					return false;
				}
				});
			},
			delFun(){
				this.$confirm('此操作将永久删除, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$api.resource.delSip(this.sipSetting,this.dev_unid,this.user_unid,this.sip_unid).then(res=>{
						if(res.ecode == 200) {
							this.$message({
								type: 'success',
								message: '删除成功!'
							})
							for(let j in this.sipSetting) {
								this.sipSetting[j] = '';
							}
							this.isGetted = false;
						} else {
							this.$message({
								type: 'error',
								message: res.enote
							})
						}
					})
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '已取消'
					});          
				});
			},
			getSipParam() {
				this.$api.resource.getsip({},this.dev_unid,this.user_unid).then(res=>{
						if(res.ecode) {
							this.isGetted = false;
						} else {
							this.isGetted = true;
							this.sipSetting.sip_username = res.sip_username;
							this.sipSetting.sip_password = res.sip_password;
							this.sip_unid = res.sip_unid;
						}
					
				})
			}
		},
	}
</script>
<style lang="scss" scoped>
	.title{
		height: 30px;
    line-height: 30px;
    padding-left: 30px;
    font-size: 14px;
    background: #3bb7ff;
	color: #FFFFFF;
	margin-bottom: 20px;
	}
</style>