Newer
Older
KaiFengPC / src / views / floodSys / assetManage / EasyToFlood.vue
@鲁yixuan 鲁yixuan on 27 Aug 9 KB updata
<template>
  <div class="publicContainer">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
      <el-form-item label="道路名称:" prop="road">
        <el-input v-model="queryParams.road" placeholder="请输入道路名称" clearable style="width: 180px" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>

        <el-button 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>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <!-- 表格 -->
    <el-table :data="dataList" v-loading="loading" stripe :max-height="580">
      <el-table-column type="index" width="55" label="序号" />
      <el-table-column label="道路名称" prop="road" />
      <el-table-column label="应急处置措施" prop="emergencyMeasure" width="300" />
      <el-table-column label="点位值守人" prop="onDutyPeople" />
      <el-table-column label="点位值守人联系电话" prop="onDutyPhone" />

      <el-table-column label="街道负责人" prop="streetHeadPeople" />
      <el-table-column label="街道负责人联系电话" prop="streetHeadPhone" />

      <el-table-column label="区级负责人" prop="areaHeadPeople" />
      <el-table-column label="区级负责人联系电话" prop="areaHeadPhone" />
      <el-table-column label="操作" width="280">
        <template #default="scope">
          <el-button link icon="View" type="primary" @click="handleDetail(scope.row, 'view')">详情</el-button>
          <el-button link type="warning" icon="Edit" @click="handleUpdate(scope.row, 'view')">修改</el-button>
          <el-button link type="danger" icon="Delete" @click="handleDelete(scope.row, 'view')">删除</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="getList"
    />
    <!-- 新增弹窗 -->
    <el-dialog :title="title" v-model="open" width="1000px" append-to-body :close-on-click-modal="false">
      <el-form ref="roleRef" :model="form" :rules="rules" label-width="180px" :disabled="multiple">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="道路名称:" prop="road">
              <el-input v-model="form.road" placeholder="请输道路名称" clearable style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="应急处置措施:" prop="emergencyMeasure">
              <el-input type="textarea" v-model="form.emergencyMeasure" placeholder="请输入应急处置措施" clearable style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="点位值守人:" prop="onDutyPeople">
              <el-input v-model="form.onDutyPeople" placeholder="请输入点位值守人" clearable style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="点位值守人联系电话:" prop="onDutyPhone">
              <el-input v-model="form.onDutyPhone" placeholder="请输入点位值守人联系电话" clearable style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="街道负责人:" prop="streetHeadPeople">
              <el-input v-model="form.streetHeadPeople" placeholder="请输入街道负责人" clearable style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="街道负责人联系电话:" prop="streetHeadPhone">
              <el-input v-model="form.streetHeadPhone" placeholder="请输入街道负责人联系电话" clearable style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="区级负责人:" prop="areaHeadPeople">
              <el-input v-model="form.areaHeadPeople" placeholder="请输入区级负责人" clearable style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="区级负责人联系电话:" prop="areaHeadPhone">
              <el-input v-model="form.areaHeadPhone" placeholder="请输入区级负责人联系电话" clearable style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
<script setup name="EasyToFlood">
import {
  waterloggedCommunitiespage,
  waterloggedCommunitiesadd,
  waterloggedCommunitiesedit,
  waterloggedCommunitiesdelete,
} from '@/api/floodSys/EasyToFlood';
const { proxy } = getCurrentInstance();
import { validPhone } from '@/utils/validate';

const open = ref(false);
const multiple = ref(false);
const showSearch = ref(true);
const loading = ref(true);
const total = ref(0);
const title = ref('');
const dataList = ref([]);
const AllData = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,

    road: '',
  },
  rules: {
    road: [{ required: true, message: '请输道路名称', trigger: 'blur' }],
    emergencyMeasure: [{ required: true, message: '请输入应急处置措施', trigger: 'blur' }],
    streetHeadPeople: [{ required: true, message: '请输入街道负责人', trigger: 'blur' }],
    streetHeadPhone: [
      { required: true, message: '手机号不能为空', trigger: 'blur' },
      {
        validator: (rule, value) => {
          return new Promise((resolve, reject) => {
            if (!validPhone(value)) {
              reject(Error('手机号格式错误'));
            } else {
              resolve();
            }
          });
        },
        trigger: 'blur',
      },
    ],
    onDutyPeople: [{ required: true, message: '请输入点位值守人', trigger: 'blur' }],
    onDutyPhone: [
      { required: true, message: '手机号不能为空', trigger: 'blur' },
      {
        validator: (rule, value) => {
          return new Promise((resolve, reject) => {
            if (!validPhone(value)) {
              reject(Error('手机号格式错误'));
            } else {
              resolve();
            }
          });
        },
        trigger: 'blur',
      },
    ],
    areaHeadPeople: [{ required: true, message: '请输入区级负责人', trigger: 'blur' }],
    areaHeadPhone: [
      { required: true, message: '手机号不能为空', trigger: 'blur' },
      {
        validator: (rule, value) => {
          return new Promise((resolve, reject) => {
            if (!validPhone(value)) {
              reject(Error('手机号格式错误'));
            } else {
              resolve();
            }
          });
        },
        trigger: 'blur',
      },
    ],
  },
});
const { queryParams, form, rules } = toRefs(AllData);

//搜索
function handleQuery() {
  getList();
}
//重置
function resetQuery() {
  proxy.resetForm('queryRef');
  handleQuery();
}
// 新增
function handleAdd() {
  title.value = '新增易涝小区';
  open.value = true;
  form.value = {};
  multiple.value = false;
}
// 新增中取消事件
function cancel() {
  open.value = false;
  proxy.resetForm('roleRef');
}

//查看详情操作
function handleDetail(row) {
  open.value = true;
  multiple.value = true;
  title.value = '查看易涝小区';
  form.value = { ...row };
}
// 修改按钮操作
function handleUpdate(row) {
  open.value = true;
  title.value = '修改易涝小区';
  multiple.value = false;
  form.value = { ...row };
}

/** 搜索列表 */
const getList = async () => {
  loading.value = true;
  let res = await waterloggedCommunitiespage(queryParams.value);
  dataList.value = res.data;
  total.value = res.total;
  loading.value = false;
};

/** 新增弹框 修改弹框 提交按钮 */
async function submitForm() {
  proxy.$refs['roleRef'].validate(valid => {
    if (valid) {
      if (form.value.id != undefined) {
        waterloggedCommunitiesedit(form.value).then(() => {
          proxy.$modal.msgSuccess('修改成功');
          open.value = false;
          getList();
        });
      } else {
        waterloggedCommunitiesadd(form.value).then(() => {
          proxy.$modal.msgSuccess('新增成功');
          open.value = false;
          getList();
        });
      }
    }
  });
}
// 表格删除
function handleDelete(row) {
  proxy.$modal
    .confirm('是否确认删除?')
    .then(async () => {
      const res = await waterloggedCommunitiesdelete(row.id);
      if (res?.code !== 200) return;
      proxy.$modal.msgSuccess('操作成功!');
      getList();
    })
    .catch(() => {});
}

onMounted(() => {
  getList();
});
</script>
<style scoped lang="scss">
.dituclass {
  width: 100%;
  height: 300px;
  // background: red;
  margin-bottom: 10px;
  border: 1px solid #004565;
}
</style>