Newer
Older
KaiFengPC / src / views / dataAnalysis / rtuSiteInfo / monitorList.vue
@zhangdeliang zhangdeliang on 23 May 7 KB 初始化项目
<template>
  <!-- 监测项列表 -->
  <div>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="Plus" @click="handleAddMonitor">新增</el-button>
      </el-col>
    </el-row>
    <el-table v-loading="monitorLoading" :data="monitorList" border :max-height="500">
      <el-table-column label="序号" type="index" width="55" />
      <el-table-column label="站点编号" prop="stCode" width="120" />
      <el-table-column label="站点名称" prop="stName" show-overflow-tooltip />
      <el-table-column label="监测项名称" prop="monitorName" show-overflow-tooltip />
      <el-table-column label="监测项编号" prop="monitorCode" width="110" />
      <el-table-column label="监测范围" width="110">
        <template #default="scope">
          <span>{{ scope.row.minValue }}--{{ scope.row.maxValue }}</span>
        </template>
      </el-table-column>
      <el-table-column label="异常值" prop="exceptionValue" width="90" />
      <el-table-column label="操作" width="160" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['dataAnalysis:rtuSiteInfo:edit']">
            修改
          </el-button>
          <el-button link type="warning" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['dataAnalysis:rtuSiteInfo:remove']">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="monitorTotal > 0"
      :total="monitorTotal"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改RTU站点对话框 -->
    <el-dialog :title="title" v-model="dialogShow" width="900px" append-to-body>
      <el-form ref="rtuSiteMonitorInfoRef" :model="form" :rules="rules" label-width="150px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="监测对象类型" prop="monitorCode">
              <el-select v-model="form.monitorCode" placeholder="请选择" filterable style="width: 100%">
                <el-option
                  v-for="dict in monitorCodeList"
                  :key="dict.monitorCode"
                  :label="dict.monitorName"
                  :value="dict.monitorCode"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="最小值" prop="minValue">
              <el-input v-model="form.minValue" placeholder="请输入最小值" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="最大值" prop="maxValue"> <el-input v-model="form.maxValue" placeholder="请输入最大值" /> </el-form-item
          ></el-col>
          <el-col :span="12">
            <el-form-item label="异常值" prop="exceptionValue">
              <el-input v-model="form.exceptionValue" placeholder="请输入异常值" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input type="textarea" v-model="form.remark" placeholder="请输入备注" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="info" @click="cancel">取 消</el-button>
          <el-button type="primary" @click="submitForm">确 定</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
<script setup>
import {
  pageRtuSiteMonitor,
  getRtuSiteMonitor,
  addRtuSiteMonitor,
  updateRtuSiteMonitor,
  delRtuSiteMonitor,
} from '@/api/dataAnalysis/rtuSiteMonitor';
import { listRtuMonitorProperty } from '@/api/dataAnalysis/rtuMonitorProperty';
import { findDictObj } from '@/utils/ruoyi.js';
const { proxy } = getCurrentInstance();
const loading = ref(false);
const dialogShow = ref(false);
const title = ref('');
const monitorLoading = ref(false);
const monitorCodeList = ref([]); //监测因子列表
const monitorList = ref([]); //站点配置的监测项列表
const monitorTotal = ref(0);
const data = reactive({
  form: {
    monitorCode: null,
    minValue: '',
    maxValue: '',
    exceptionValue: '',
    remark: null,
  },
  rules: {
    siteType: [{ required: true, message: '站点类型不能为空', trigger: 'change' }],
    monitorTargetType: [{ required: true, message: '监测对象类型不能为空', trigger: 'change' }],
    buildType: [{ required: true, message: '建设方式不能为空', trigger: 'change' }],
    stName: [{ required: true, message: '站点不能为空', trigger: 'blur' }],
    stCode: [{ required: true, message: '站点编号不能为空', trigger: 'blur' }],
  },
  queryParams: {
    pageNum: 1,
    pageSize: 10,
  },
});
const { queryParams, form, rules, monitorQueryParams } = toRefs(data);
const props = defineProps({
  //刷新标志
  refresh: {
    type: [String, Number],
    default: 1,
  },
  //行数据
  row: {
    type: Object,
    default: {},
  },
});
watch(
  () => props.refresh,
  () => {
    queryParams.value = {
      pageNum: 1,
      pageSize: 10,
    };
    getList();
    getListRtuMonitorProperty();
  },
  {
    deep: true,
    immediate: true,
  }
);
function getList() {
  queryParams.value.stCode = props.row.stCode;
  loading.value = true;
  pageRtuSiteMonitor(queryParams.value).then(res => {
    monitorList.value = res.data;
    monitorTotal.value = res.total;
    monitorLoading.value = false;
  });
}

//获取监测项
function getListRtuMonitorProperty() {
  listRtuMonitorProperty().then(res => {
    monitorCodeList.value = res.data;
  });
}

function handleAddMonitor() {
  proxy.resetForm('formRef'); //清空表单
  dialogShow.value = true;
  title.value = '新增监测项';
}

// 取消按钮
function cancel() {
  dialogShow.value = false;
}
/** 修改按钮操作 */
function handleUpdate(row) {
  const _id = row.id || ids.value;
  getRtuSiteMonitor(_id).then(response => {
    form.value = response.data;
    dialogShow.value = true;
    title.value = '修改监测项';
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs['rtuSiteMonitorInfoRef'].validate(valid => {
    if (valid) {
      form.value.stCode = props.row.stCode;
      form.value.monitorValue = findDictObj(form.value.monitorCode, 'code', monitorCodeList.value).name;
      if (form.value.id != null) {
        updateRtuSiteMonitor(form.value).then(response => {
          proxy.$modal.msgSuccess('修改成功');
          dialogShow.value = false;
          getList();
        });
      } else {
        addRtuSiteMonitor(form.value).then(response => {
          proxy.$modal.msgSuccess('新增成功');
          dialogShow.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal
    .confirm('是否确认删除?')
    .then(function () {
      return delRtuSiteMonitor(_ids);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess('删除成功');
    })
    .catch(() => {});
}
</script>