Newer
Older
baseResourceFront / src / views / rule / components / setThresh.vue
yangqianqian on 23 Mar 2021 4 KB 修改UI
<template>
  <div class="app-container">
    <el-dialog :title="title" :visible.sync="dialogFormVisible" append-to-body @close="cancel">
      <el-form ref="dataForm" :rules="rules" :model="monitorForm" label-well-code="right" label-width="140px">
        <el-row type="flex" justify="center">
          <el-col :span="12">
            <el-form-item label="监控点名称" prop="monitorName">
              <el-input v-model.trim="monitorForm.monitorName" disabled type="text" placeholder="必填"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex" justify="center">
          <el-col :span="12">
            <el-form-item label="所属场站" prop="stationName">
              <el-input v-model="monitorForm.stationName" disabled placeholder=""/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex" justify="center">
          <el-col :span="12">
            <el-form-item label="燃气浓度报警阈值" prop="high">
              <el-input v-model.trim="monitorForm.high" type="number" :min="0" placeholder="燃气浓度报警阈值"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="saveData">保存</el-button>
        <el-button @click="cancel">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { setThresh } from '@/api/system/alarm'

export default {
  name: 'SetThresh',
  data() {
    const validateHigh = (rule, value, callback) => {
      if (value !== '') {
        if ((/^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/).test(value) === false) {
          callback(new Error('请填写大于0的数字'))
        } else {
          callback()
        }
      } else {
        callback(new Error('消警持续时间不能为空'))
      }
    }
    return {
      listLoading: true,
      dialogFormVisible: false, // 对话框是否显示
      monitorForm: {
        stationName: '',
        monitorId: '',
        monitorName: '',
        high: '' // 报警阈值
      },
      title: '', // 表头显示标题
      rules: {
        high: [{ required: true, validator: validateHigh, trigger: ['change', 'blur'] }]
      } // 前端校验规则
    }
  },
  watch: { },
  mounted() { },
  methods: {
    // 初始化对话框
    initDialog: function(dialogFormVisible, monitorInfo) {
      debugger
      this.dialogFormVisible = dialogFormVisible
      this.title = '设置监控点报警阈值'
      this.monitorForm.stationName = monitorInfo.stationName
      this.monitorForm.monitorName = monitorInfo.monitorPointName
      this.monitorForm.monitorId = monitorInfo.monitorPointId
      this.monitorForm.high = monitorInfo.high
    },
    // 重置表单
    resetForm() {
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    // 保存数据
    saveData: function() {
      // 表单校验
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          setThresh(this.monitorForm).then(response => {
            if (response.code === 200) {
              this.$message.success('设置成功')
              this.$emit('watchChild')
              this.dialogFormVisible = false
            }
          })
        }
      })
    },
    cancel: function() {
      this.dialogFormVisible = false
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  $tableTitleHeight:46px;
  .el-select{
    width: 100%;
  }
  .el-date-editor{
    width: 100%;
  }
  .table-title{
    background-color:rgba(243, 243, 243, 1);
    height: $tableTitleHeight;
    .title-header{
      line-height:$tableTitleHeight;
      color: #606266;
      font-size: 15px;
      i{
        margin-left: 5px;
        margin-right: 5px;
      }
    }
  }
  .edit_btns{
    .edit_btn{
      float:right;
      margin:7px 3px;//为了需要居中显示margin-top和bottom要用$tableTitleHeight减去按钮原高度除以2
    }
  }
  .dialog-footer{
    text-align: right;
    margin-top: 10px;
  }
</style>