Newer
Older
KaiFengPC / src / views / floodSys / floodSet / spongeLand.vue
@zhangdeliang zhangdeliang on 23 May 7 KB 初始化项目
<template>
  <!-- 排水防涝子系统 配置管理  海绵地块轮换配置-->
  <div class="publicContainer">
    <!-- 搜索区域 -->
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
      <el-form-item label="轮换频次" prop="changeFrequency">
        <el-input v-model="queryParams.changeFrequency" 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" v-hasPermi="['floodSys:jing:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete" v-hasPermi="['floodSys:jing:remove']">
          删除
        </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="600" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" />
      <el-table-column label="轮换频次" prop="changeFrequency" />
      <el-table-column label="轮换时间" prop="changeTime" />
      <el-table-column label="关联海绵地块" prop="stNameList"> </el-table-column>
      <el-table-column label="更新时间" prop="updateTime" />
      <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="['floodSys:jing:edit']">修改</el-button>
          <el-button link type="danger" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['floodSys:jing:remove']">
            删除
          </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="500px" append-to-body>
      <el-form ref="formRef" :model="formData" :rules="rulesForm" label-width="120px" class="publicForm">
        <el-form-item label="轮换频次" prop="changeFrequency">
          <el-input v-model="formData.changeFrequency" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="轮换时间" prop="changeTime">
          <el-date-picker type="datetime" v-model="formData.changeTime" placeholder="请选择日期"> </el-date-picker>
        </el-form-item>
        <el-form-item label="关联地块" prop="stCodeList">
          <el-select v-model="formData.stCodeList" placeholder="请选择" multiple>
            <el-option v-for="item in landList" :key="item.stCode" :label="item.label" :value="item.stCode" />
          </el-select>
        </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>
  </div>
</template>

<script setup name="海绵地块轮换配置">
import { configSpongePage, configSpongeAdd, configSpongeDel, configSpongeDetail, configSpongeEdit } from '@/api/floodSys/floodStation';
import { formateDate } from '@/utils/validate';
import { rtuSiteInfolist } from '@/api/cameraResource/siteCameraRelation';
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 formRef = ref(null);
const landList = ref([
  // { value: '1', label: '地块1' },
  // { value: '0', label: '地块2' },
]);

const allData = reactive({
  formData: {
    // stCodeList: ["2109600026"]
  },
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    changeFrequency: undefined,
  },
  rulesForm: {
    changeFrequency: [{ required: true, message: '请输入', trigger: 'blur' }],
    changeTime: [{ required: true, message: '请输入', trigger: 'change' }],
    stCodeList: [{ required: true, message: '请输入', trigger: 'change' }],
  },
});
const { queryParams, formData, rulesForm } = toRefs(allData);

/** 获取查询数据列表 */
function getDataList() {
  tableLoading.value = true;
  configSpongePage(queryParams.value).then(response => {
    tableData.value = response.data;
    total.value = response.total;
    tableLoading.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;
  configSpongeDetail(postId).then(response => {
    dialogShow.value = true;
    dialogTitle.value = '修改海绵地块轮换';

    nextTick(() => {
      formData.value = { ...formData.value, ...response.data };
    });
  });
}

/** 取消按钮 */
function cancelForm() {
  dialogShow.value = false;
}
/** 提交按钮 */
function submitForm() {
  proxy.$refs['formRef'].validate(valid => {
    if (valid) {
      let params = { ...formData.value };
      params.changeTime = formateDate(params.changeTime);
      if (dialogTitle.value == '修改海绵地块轮换') {
        configSpongeEdit(params).then(response => {
          proxy.$modal.msgSuccess('修改成功');
          dialogShow.value = false;
          getDataList();
        });
      } else {
        if (params.id) delete params.id;
        configSpongeAdd(params).then(response => {
          proxy.$modal.msgSuccess('新增成功');
          dialogShow.value = false;
          getDataList();
        });
      }
    }
  });
}
/** 删除按钮操作 */
function handleDelete(row) {
  const postIds = row.id || checkedIds.value;
  proxy.$modal
    .confirm('是否确认删除该数据项?')
    .then(function () {
      return configSpongeDel(postIds);
    })
    .then(() => {
      getDataList();
      proxy.$modal.msgSuccess('删除成功');
    })
    .catch(() => {});
}

function getList() {
  let params = {
    monitorTargetType: 'typical_land',
  };
  rtuSiteInfolist(params).then(response => {
    response.data.map(item => {
      landList.value.push({
        value: item.id,
        label: item.stName,
        stCode: item.stCode,
      });
      // console.log(landList.value, 'landList.value');
    });
  });
}

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