Newer
Older
toilet / src / views / rule / components / editMonitor.vue
yangqianqian on 8 Mar 2021 7 KB 自测修改
<template>
  <div class="app-container">
    <el-dialog :title="title" :visible.sync="dialogFormVisible" append-to-body @close="closeDialog">
      <el-form ref="dataForm" :rules="rules" :model="monitorForm" label-well-code="right" label-width="100px">
        <el-row type="flex" justify="center">
          <el-col :span="12">
            <el-form-item label="监控点名称" prop="monitorName">
              <el-input v-model.trim="monitorForm.monitorName" 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="stationId">
              <el-select v-model="monitorForm.stationId" placeholder="请选择所属场站">
                <el-option
                  v-for="item in stationList"
                  :key="item.stationId"
                  :label="item.stationName"
                  :value="item.stationId"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex" justify="center">
          <el-col :span="12">
            <el-form-item label="安装位置" prop="location">
              <el-input v-model.trim="monitorForm.location" 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="deviceCode">
              <el-input v-model.trim="monitorForm.deviceCode" 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="setupDate">
              <el-date-picker
                v-model.trim="monitorForm.setupDate"
                type="date"
                value-format="yyyy-MM-dd"
                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 { addMonitor, editMonitor, getMonitorList } from '@/api/station'

export default {
  name: 'EditMonitor',
  data() {
    const validateOtherReason = (rule, value, callback) => {
      const reg = /[:;:;]/im
      if (value !== '' && value.length > 0) {
        if (reg.test(value)) {
          callback(new Error('不能含有冒号或分号'))
        } else {
          if (value.indexOf('哺乳假') !== -1 || value.indexOf('年假') !== -1 || value.indexOf('事假') !== -1 || value.indexOf('病假') !== -1 ||
            value.indexOf('婚假') !== -1 || value.indexOf('丧假') !== -1 || value.indexOf('工伤') !== -1 || value.indexOf('探亲假') !== -1 ||
            value.indexOf('生育假') !== -1) {
            callback(new Error('请在“备注信息”下拉框里选择请假类型'))
          } else {
            callback()
          }
        }
      } else {
        callback(new Error('其他原因不能为空'))
      }
    }
    return {
      listLoading: true,
      dialogFormVisible: false, // 对话框是否显示
      stationList: [],
      monitorForm: {
        id: '',
        monitorName: '',
        stationId: '',
        location: '',
        deviceCode: '',
        setupDate: ''
      }, // 表单
      title: '', // 表头显示标题
      rules: {
        monitorName: [{ required: true, message: '监控点名称不能为空', trigger: ['blur'] }],
        stationId: [{ required: true, message: '所属场站必选', trigger: ['change'] }],
        deviceCode: [{ required: true, message: '设备编号不能为空', trigger: ['blur'] }]
      } // 前端校验规则
    }
  },
  watch: { },
  mounted() {
    this.fetchStationList()
  },
  methods: {
    closeDialog() {
      this.list = []
      this.listLoading = true
      if (this.edited) {
        this.edited = false
        this.$parent.fetchData(true)
      }
    },
    // 初始化对话框
    initDialog: function(dialogFormVisible, info) {
      this.dialogFormVisible = dialogFormVisible
      this.fetchStationList()
      this.resetForm()
      if(info === null){
        this.title = '新增监控点'
      } else {
        debugger
        this.title = '编辑监控点'
        this.monitorForm.id = info.monitorPointId
        this.monitorForm.monitorName = info.monitorPointName
        this.monitorForm.stationId = info.stationId
        this.monitorForm.location = info.location
        this.monitorForm.deviceCode = info.devcode
        this.monitorForm.setupDate = info.setupDate
      }
    },
    // 重置表单
    resetForm() {
      this.monitorForm = {
        id: '',
        monitorName: '',
        stationId: '',
        location: '',
        deviceCode: '',
        setupDate: ''
      } // 表单
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    // 保存数据
    saveData: function() {
      // 表单校验
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          if(this.title === '编辑监控点'){
            editMonitor(this.monitorForm).then(response => {
              if (response.code === 200) {
                this.$message.success('修改成功')
                this.$emit('watchChild')
                this.dialogFormVisible = false
              }
            })
          } else {
            addMonitor(this.monitorForm).then(response => {
              if (response.code === 200) {
                this.$confirm('新增成功,是否继续新增?', '提示', {
                  confirmButtonText: '是',
                  cancelButtonText: '否',
                  type: 'info'
                }).then(() => {
                  this.resetForm()
                  this.$nextTick(() => {
                    this.$refs['dataForm'].clearValidate()
                  })
                }).catch(() => {
                  this.$emit('watchChild')
                  this.dialogFormVisible = false
                })
              }
            })
          }
        }
      })
    },
    // 删除备注
    fetchStationList() {
      this.listLoading = true
      const listQuery = {
        keyword: ''
      }
      getMonitorList(listQuery).then(response => {
        this.stationList = response.data
      })
    },
    // 获取已添加的备注信息列表
    fetchData() {
      var params = {}
      params.personId = this.remarksForm.personId
      params.date = this.curDate
      getRemarksList(params).then(response => {
        if (response.code === 200) {
          this.list = response.data
        }
        this.listLoading = false
      })
    },
    // 获取可添加的备注类型列表
    fetchRemarksType() {
      var params = {}
      params.personId = this.remarksForm.personId
      params.date = this.curDate
      params.reportId = this.remarksForm.reportId
      getEnabledTypeList(params).then(response => {
        if (response.code === 200) {
          this.remarksTypeList = response.data
        }
      })
    },
    cancel: function() {
      this.dialogFormVisible = false
      this.$emit('watchChild')
    }
  }
}
</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>