relieve.vue 3.38 KB
<script setup lang="ts">
import {
  reactive,
  ref,
  getCurrentInstance,
  defineProps,
  defineEmits,
  watchEffect,
} from "vue";
import {
  deleteHouseResident,
  membersByHouseId,
} from "@/api/community/houses.ts";
import { addOrUpBuildingHouseKeeper } from "@/api/community/housekeeper.ts";
import Pagination from "@/components/Pagination/index.vue";

let instance: ComponentInternalInstance | null = getCurrentInstance(); //获取app实例
const multipleTableRef = ref<InstanceType<typeof ElTable>>();
// 声明props
const props = defineProps({
  houseId: {
    type: Number,
    default: null,
  },
});

// 数据筛选
const searchData = reactive({
  condition: "",
  page: 1,
  pageSize: 10,
});
// 展示
const data = reactive({
  total: 0,
  tableList: [],
  loading: false,
  selectList: [],
});

/**
 * 列表查询
 */
const search = (): void => {
  data.loading = true;
  searchData.houseId = props.houseId;
  membersByHouseId(searchData)
    .then((res) => {
      data.tableList = res.data.data;
      data.tableList.map((item) => {
        item.houseId = props.houseId;
        item.residentId = item.id;
      });
      data.total = res.data.data.length;
      data.loading = false;
      data.selectList = [];
    })
    .catch((err) => {
      console.log(err);
      data.loading = false;
    });
};

const emit = defineEmits<{
  (e: "success"): void;
}>();

const handleSelectionChange = (val) => {
  data.selectList = val.map((val: any) => {
    return val.id;
  });
};
/**
 * 数据提交
 */
const submit = () => {
  if (data.selectList.length == 0) {
    instance?.proxy?.$message.error("请选择业主");
  } else {
    instance?.proxy?.$messageBox
      .confirm("确认要进行此操作?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      })
      .then(() => {
        deleteHouseResident({houseId:props.houseId,residentIds:data.selectList.toString()}).then((res) => {
          multipleTableRef.value!.clearSelection();
          data.selectList = [];
          emit("success");
        });
      })
      .catch((err) => {});
  }
};
watchEffect(() => {
  if (props.houseId) {
    search();
  }
});
</script>
<template>
  <div>
    <!-- 搜索 -->
    <el-form :inline="true" :model="searchData" v-loading="data.loading">
      <el-form-item>
        <el-input
          style="width: 280px"
          placeholder="请输入姓名/手机号/身份证号"
          v-model="searchData.condition"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item
        ><el-button type="primary" @click="search"
          >查询</el-button
        ></el-form-item
      >
      <el-form-item
        ><el-button type="primary" @click="submit"
          >确认选择</el-button
        ></el-form-item
      >
    </el-form>

    <!-- 表格 -->
    <el-table
      border
      :data="data.tableList"
      @selection-change="handleSelectionChange"
      ref="multipleTableRef"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column label="姓名" prop="name"></el-table-column>
      <el-table-column label="手机号" prop="mobile"></el-table-column>
    </el-table>
    <!-- 分页 -->
    <Pagination
      v-if="data.total > 0"
      :total="data.total"
      v-model:currentPage="searchData.page"
      v-model:pageSize="searchData.pageSize"
      @pageChange="search"
    ></Pagination>
  </div>
</template>

<style></style>