changeAdmin.vue 3.12 KB
<script setup lang="ts">
import { reactive, onMounted, ref, getCurrentInstance, defineProps } from "vue";
import { getTableList } from "@/api/housekeeper/buildinMganager.ts";
import { addOrUpBuildingHouseKeeper } from "@/api/community/housekeeper.ts";
import Pagination from "@/components/Pagination/index.vue";

let instance: ComponentInternalInstance | null = getCurrentInstance(); //获取app实例
// 声明props
const props = defineProps({
  buildingId: {
    type: Number,
    default: null,
  },
  originalIds: {
    type: Number,
    default: null,
  },
});

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

/**
 * 列表查询
 */
const search = (): void => {
  data.loading = true;
  getTableList(searchData)
    .then((res) => {
      console.log(res);
      data.tableList = res.data.data;
      data.total = res.data.data.length;
      data.loading = false;
    })
    .catch((err) => {
      console.log(err);
      data.loading = false;
    });
};
/**
 * 表格选择回调
 */
const handleSelectionChange = (val:Array) => {
  data.selectList=val.map((val: any) =>{
    return val.id
  })
}

const submit=()=>{
  console.log(data.selectList.length)
  if(data.selectList.length==0){
    instance?.proxy?.$message.error('请选择新的楼管')
  }else{
    addOrUpBuildingHouseKeeper({buildingId:props.buildingId,houseKeeperIds:data.selectList[0],originalIds:props.originalIds}).then((res)=>{
      console.log(res)
    })
  }
}

onMounted(() => {
  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">
    <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-column label="身份证号" prop="idcard"></el-table-column>
      <el-table-column label="类型">
        <template #default="scope">
          <span>{{ scope.row.type == 0 ? "选举" : "派驻" }}</span></template
        >
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <Pagination
      v-if="data.total > 0"
      :total="data.total"
      :currentPage="searchData.pageNum"
      :pageSize="searchData.pageSize"
      @pageChange="search"
    ></Pagination>
  </div>
</template>

<style></style>