Newer
Older
KaiFengPC / src / views / floodSys / scada / gateStation / index.vue
@zhangdeliang zhangdeliang on 23 May 9 KB 初始化项目
<template>
  <!-- 排水防涝子系统 配置管理  闸站基础信息管理-->
  <div class="publicContainer">
    <!-- 搜索区域 -->
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
      <el-form-item label="闸站名称" prop="gateName">
        <el-input v-model="queryParams.gateName" placeholder="请输入" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button type="success" icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 按钮区域 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="Plus" @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete"> 删除 </el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getDataList"></right-toolbar>
    </el-row>
    <!-- 表格 -->
    <el-table v-loading="tableLoading" :data="tableData" max-height="650" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" />
      <el-table-column label="闸站名称" prop="gateName" />
      <el-table-column label="闸站编号" prop="gateCode" />
      <el-table-column label="性能" prop="performance" />
      <el-table-column label="所属乡镇" prop="township" />
      <el-table-column label="堤别" prop="dibei" />
      <el-table-column label="桩号" prop="pileNumber" />
      <el-table-column label="型式" prop="patternType" />
      <el-table-column label="孔数" prop="holesNumber" />
      <el-table-column label="孔(宽*高)" prop="holesSize" />
      <el-table-column label="闸底高程" prop="bottomElevation" />
      <el-table-column label="闸站类型" prop="gateType" />
      <el-table-column label="启闭能力" prop="openClosingAbility" />
      <el-table-column label="建设年份" prop="constructionYear" />
      <el-table-column label="规模(m³/s)" prop="designScale" />
      <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)">修改</el-button>
          <el-button link type="danger" icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getDataList"
    />

    <!-- 添加或修改弹窗 -->
    <el-dialog :title="dialogTitle" v-model="dialogShow" width="800px" append-to-body>
      <el-form ref="formRef" :model="formData" :rules="rulesForm" label-width="120px" class="publicForm flex50">
        <el-form-item label="闸站名称" prop="gateName">
          <el-input v-model="formData.gateName" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="闸站编号" prop="gateCode">
          <el-input v-model="formData.gateCode" controls-position="right" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="闸站性能" prop="performance">
          <el-input v-model="formData.performance" controls-position="right" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="所属乡镇" prop="township">
          <el-input v-model="formData.township" controls-position="right" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="堤别" prop="dibei">
          <el-input v-model="formData.dibei" controls-position="right" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="桩号" prop="pileNumber">
          <el-input v-model="formData.pileNumber" controls-position="right" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="型式" prop="patternType">
          <el-input v-model="formData.patternType" controls-position="right" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="孔数" prop="holesNumber">
          <el-input v-model="formData.holesNumber" controls-position="right" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="孔(宽*高)" prop="holesSize">
          <el-input v-model="formData.holesSize" controls-position="right" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="闸底高程" prop="bottomElevation">
          <el-input v-model="formData.bottomElevation" controls-position="right" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="闸站类型" prop="gateType">
          <el-input v-model="formData.gateType" controls-position="right" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="启闭能力" prop="openClosingAbility">
          <el-input v-model="formData.openClosingAbility" controls-position="right" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="建设年份" prop="constructionYear">
          <el-date-picker v-model="formData.constructionYear" type="year" value-format="YYYY" placeholder="请选择" />
        </el-form-item>
        <el-form-item label="设计规模(m³/s)" prop="designScale">
          <el-input v-model="formData.designScale" controls-position="right" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="GIS坐标" prop="position" style="width: 100%">
          <el-input v-model="formData.position" controls-position="right" placeholder="请输入">
            <template #append>
              <el-button type="primary" @click="showMap = true">获取经纬度</el-button>
            </template>
          </el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="info" @click="cancelForm">取 消</el-button>
          <el-button type="primary" @click="submitForm">确 定</el-button>
        </div>
      </template>
    </el-dialog>
    <!-- 地图选取位置 -->
    <el-dialog title="地图选取位置(可搜索可直接点击获取)" v-model="showMap" width="800px" append-to-body>
      <MapPosition v-if="showMap" :isShowSearch="true" :isShowTool="false" :isSelectAddress="true" @getPlace="getAddress"></MapPosition>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="showMap = false">确 定</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="闸站基础信息管理">
import { facilityGatePage, facilityGateAdd, facilityGateDel, facilityGateDetail, facilityGateEdit } from '@/api/floodSys/floodStation';
import MapPosition from '@/components/Map/index.vue'; //地图选点获取经纬度位置组件

const { proxy } = getCurrentInstance();

const tableData = ref([]);
const tableLoading = ref(true);
const total = ref(0);
const dialogShow = ref(false);
const dialogTitle = ref('');
const showSearch = ref(true);
const checkedIds = ref([]);
const multiple = ref(true);
const showMap = ref(false);

const allData = reactive({
  formData: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    gateName: undefined,
  },
  rulesForm: {
    gateName: [{ required: true, message: '请输入', trigger: 'blur' }],
    gateCode: [{ required: true, message: '请输入', trigger: 'blur' }],
  },
});
const { queryParams, formData, rulesForm } = toRefs(allData);

// 获取位置
function getAddress(val) {
  formData.value.position = val.lonLat[0] + ',' + val.lonLat[1];
  formData.value.lon = val.lonLat[0];
  formData.value.lat = val.lonLat[1];
}

/** 获取查询数据列表 */
function getDataList() {
  tableLoading.value = true;
  facilityGatePage(queryParams.value).then(response => {
    tableData.value = response.data;
    total.value = response.total;
    tableLoading.value = false;
  });
}
/** 取消按钮 */
function cancelForm() {
  dialogShow.value = false;
}
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getDataList();
}
/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm('queryRef');
  handleQuery();
}
/** 多选框选中数据 */
function handleSelectionChange(selection) {
  checkedIds.value = selection.map(item => item.id);
  multiple.value = !selection.length;
}
/** 新增按钮操作 */
function handleAdd() {
  proxy.resetForm('formRef'); //清空表单
  dialogShow.value = true;
  dialogTitle.value = '添加闸站基础信息';
}
/** 修改按钮操作 */
function handleUpdate(row) {
  const postId = row.id || checkedIds.value;
  facilityGateDetail(postId).then(response => {
    dialogShow.value = true;
    dialogTitle.value = '修改闸站基础信息';
    nextTick(() => {
      formData.value = response.data;
      formData.value.position = response.data.lon + ',' + response.data.lat;
    });
  });
}
/** 提交按钮 */
function submitForm() {
  proxy.$refs['formRef'].validate(valid => {
    if (valid) {
      if (dialogTitle.value == '修改闸站基础信息') {
        facilityGateEdit(formData.value).then(response => {
          proxy.$modal.msgSuccess('修改成功');
          dialogShow.value = false;
          getDataList();
        });
      } else {
        if (formData.value.id) delete formData.value.id;
        facilityGateAdd(formData.value).then(response => {
          proxy.$modal.msgSuccess('新增成功');
          dialogShow.value = false;
          getDataList();
        });
      }
    }
  });
}
/** 删除按钮操作 */
function handleDelete(row) {
  const postIds = row.id || checkedIds.value;
  proxy.$modal
    .confirm('是否确认删除该数据项?')
    .then(function () {
      return facilityGateDel(postIds);
    })
    .then(() => {
      getDataList();
      proxy.$modal.msgSuccess('删除成功');
    })
    .catch(() => {});
}

onMounted(() => {
  getDataList();
});
</script>