<template>
  <div>
    <!-- 查询 -->
    <div class='tabox'>
      <div class="headBox3">
        <el-button type="primary" @click="addUserHander" v-if='props.obj.saveBtnShow'>
          <el-icon>
            <CirclePlus />
          </el-icon>
          <span>新增</span>
        </el-button>
      </div>
      <MOSTY.Table :table-columns="pageData.tableColumns" :tableData="pageData.tableData" :tableloading="tableloading"
        tableHeight="300px">
        <template #actions="{ row }">
          <span class="operedit" @click="handlexg(row)" v-if='props.obj.saveBtnShow'>
            <el-icon>
              <EditPen />
            </el-icon>修改</span>
          <el-popconfirm v-if='props.obj.saveBtnShow' confirm-button-text="是" cancel-button-text="否" icon-color="red"
            title="确定要删除?" @confirm="handledelete(row)">
            <template #reference>
              <span class="operdel" size="small">
                <el-icon>
                  <Delete />
                </el-icon>
                删除</span>
            </template>
          </el-popconfirm>
          <span class="operesee" @click="handleSee(row)">
            <el-icon>
              <Compass />
            </el-icon>查看</span>
        </template>
      </MOSTY.Table>
      <div class="fenye">
        <MOSTY.Pages :pageConfiger="pageData.pageConfiger" @changeNo="handleCurrentChange"
          @changeSize="handleSizeChange" />
      </div>
    </div>
  </div>
  <!-- 办公区域 -->
  <div v-if="showdialogjzw" class="dialog-box">
    <Addbgquindex :formData="formData" @saveSuccess="saveSuccess" :type="props.obj.type" />
  </div>
</template>
<script setup>
import * as MOSTY from "@/components/MyComponents/index";
import Addbgquindex from "@/components/dialog/Addbgquindex.vue";
import { getApi } from "@/api/tobAcco_api.js";
import { ElMessage } from "element-plus";
import { reactive, ref, onMounted, getCurrentInstance } from "vue"
const emits = defineEmits(["handleChange", 'searchChange']);
const tableloading = ref(false);
const showdialogjzw = ref(false);
const formData = ref({
  title: ""
});
const total = ref(0)
const props = defineProps({
  obj: {
    default: null,
    type: Object
  }
});
const pageData = reactive({
  listQuery: {
    pageCurrent: 1,
    pageSize: 10
  },
  tableColumns: [
    {
      title: "区域名称",
      prop: "regionname"
    },
    {
      title: "责任人姓名",
      prop: "liableperson"
    },
    {
      title: "操作",
      prop: "actions",
      slot: true
    }
  ],
  pageConfiger: {
    pageSize: 10,
    pageCurrent: 1,
    total: 0
  },
  tableData: []
})
onMounted(() => {
  //判断是重点部位还是非重点部位
  pageData.listQuery.id = props.obj.id
  gettablist()
})
//查询 根据部位ID查询办公区域
const gettablist = () => {
  tableloading.value = true
  getApi(pageData.listQuery, '/mosty-jcgl/region/queryPartidList').then((res) => {
    if (res) {
      tableloading.value = false
      pageData.tableData = res.records
      pageData.pageConfiger.total = res.total
    }
  })
}

//关闭
const saveSuccess = async (val, obj) => {
  formData.value = {}
  showdialogjzw.value = false
  emits("searchChange", 'bgqy');
  //修改不追加，直接刷新
  gettablist()
}
//新增
function addUserHander() {
  if (props.obj.type == 'cq') {
    formData.value.sfcq = '1'
    formData.value.publicarea = '1'
  } else {
    if (props.obj.sfcq && props.obj.sfcq == '1') {
      formData.value.sfcq = '1'
      formData.value.publicarea = '1'
    } else {
      formData.value.sfcq = '2'
      formData.value.publicarea = '2'
    }

  }
  formData.value.siteid = props.obj.siteid
  formData.value.sitename = props.obj.sitename
  formData.value.buildingid = props.obj.buildingid
  formData.value.buildingname = props.obj.buildingname
  formData.value.floorid = props.obj.floorid
  formData.value.floorname = props.obj.floorname
  formData.value.partname = props.obj.partname
  formData.value.partid = props.obj.id
  formData.value.qtmc = props.obj.qtmc ? props.obj.qtmc : null
  formData.value.title = '办公区域新增';
  formData.value.saveBtnShow = true;
  showdialogjzw.value = true
}
//修改
function handlexg(row) {
  if (props.obj.type == 'cq') {
    formData.value.sfcq = '1'
    formData.value.publicarea = '1'
  }
  formData.value.sfcq = props.obj.sfcq ? props.obj.sfcq : null
  formData.value.publicarea = props.obj.publicarea ? props.obj.publicarea : null
  formData.value.siteid = props.obj.siteid
  formData.value.sitename = props.obj.sitename
  formData.value.buildingid = props.obj.buildingid
  formData.value.buildingname = props.obj.buildingname
  formData.value.floorid = props.obj.floorid
  formData.value.floorname = props.obj.floorname
  formData.value.partname = props.obj.partname
  formData.value.partid = props.obj.id
  formData.value.qtmc = props.obj.qtmc ? props.obj.qtmc : null
  formData.value.id = row.id
  formData.value.title = '办公区域修改';
  formData.value.saveBtnShow = true;
  showdialogjzw.value = true
}
//查看
function handleSee(row) {
  if (props.obj.type == 'cq') {
    formData.value.sfcq = '1'
    formData.value.publicarea = '1'
  } formData.value.sfcq = props.obj.sfcq ? props.obj.sfcq : null
  formData.value.publicarea = props.obj.publicarea ? props.obj.publicarea : null
  formData.value.siteid = props.obj.siteid
  formData.value.sitename = props.obj.sitename
  formData.value.buildingid = props.obj.buildingid
  formData.value.buildingname = props.obj.buildingname
  formData.value.floorid = props.obj.floorid
  formData.value.floorname = props.obj.floorname
  formData.value.partname = props.obj.partname
  formData.value.partid = props.obj.id
  formData.value.qtmc = props.obj.qtmc ? props.obj.qtmc : null
  formData.value.id = row.id
  formData.value.title = '办公区域详情';
  formData.value.saveBtnShow = false;
  showdialogjzw.value = true
}
//注销
function handledelete(row) {
  getApi({ id: row.id }, `/mosty-jcgl/region/deleteRegionOne`).then(res => {
    ElMessage.success("删除成功");
    emits("searchChange", 'bgqy');
    gettablist()
  })
}

//查询
function Searchdata() {
  gettablist()
}
//页码发生变化
const handleCurrentChange = (val) => {
  pageData.listQuery.pageCurrent = val;
  gettablist()
};
//查询条数发生变化
const handleSizeChange = (val) => {
  pageData.listQuery.pageSize = val;
  gettablist()
};
</script>

<style lang="scss" scoped>
.headBox3 {
  display: flex;
  justify-content: end;
  width: 100%;
  margin-bottom: 10px;
}

.top_ul {
  display: flex;
  justify-content: start;
  flex-wrap: wrap;

  >li {
    width: 15%;
    height: 83px;
    margin: 6px 32px;
  }
}
</style>
