<template>
  <div>
    <div class="titleBox">
      <page-title title="单位信息" />
    </div>

    <!-- 表格 -->
    <div class="tabBox">
      <MyTable :tableData="pageData.tableData" :tableColumn="pageData.tableColumn" :tableHeight="pageData.tableHeight"
        :key="pageData.keyCount" :tableConfiger="pageData.tableConfiger" :controlsWidth="pageData.controlsWidth">
        <template #bxxLx="{ row }">
          <DictTag :value="row.bxxLx" :tag="false" :options="D_BZ_BXDLX" />
        </template>
        <template #bxds="{ row }">
          <div>{{ row.bxds?.length }}</div>
        </template>
        <!-- 操作 -->
        <template #controls="{ row }">
          <el-link type="primary" @click="addEdit('view', row)">详情</el-link>
        </template>
      </MyTable>

      <Pages @changeNo="changeNo" @changeSize="changeSize" :tableHeight="pageData.tableHeight" :pageConfiger="{
        ...pageData.pageConfiger,
        total: pageData.total
      }"></Pages>

      <ViewDetailsDialog ref="detailsRef" v-model="visible" />
    </div>
  </div>
</template>

<script setup>
import { onMounted, reactive, ref } from "vue";
import MyTable from '@/components/aboutTable/MyTable.vue';
import Pages from '@/components/aboutTable/Pages.vue';
import PageTitle from '@/components/aboutTable/PageTitle.vue';
import ViewDetailsDialog from "./components/viewDetailsDialog.vue";
import { qcckGet, qcckPost, qcckDelete } from "@/api/qcckApi.js";

const visible = ref(false);
const searchBox = ref(null);
const detailsRef = ref(null);
const D_BZ_BXDLX = ref([]);

const pageData = reactive({
  tableData: [],
  keyCount: 0,
  tableConfiger: {
    rowHieght: 61,
    showSelectType: "null",
    loading: false
  },
  total: 0,
  pageConfiger: {
    pageSize: 20,
    pageCurrent: 1
  },
  controlsWidth: 180,
  tableColumn: [
    { label: "单位名称", prop: "dwmc" },
    { label: "信用代码", prop: "xydm" },
    { label: "场所名称", prop: "csmc" },
    { label: "场所电话", prop: "csLxdh" }
  ]
});

// 表格高度计算
const tabHeightFn = () => {
  pageData.tableHeight =
    window.innerHeight - 240;
  window.onresize = function () {
    tabHeightFn();
  };
};


const getList = async () => {
  try {
    pageData.tableConfiger.loading = true;
    const res = await qcckPost({
    ...pageData.pageConfiger,
    }, `/bagl/mosty-base/baxx/dwgl/page`)

    if(res) {
      pageData.tableData = res.records || [];
      pageData.total = res.total;
    }
  } finally {
    pageData.tableConfiger.loading = false;
  }
};

const addEdit = (type, row) => {
  detailsRef.value.open(row, type);
}

const changeNo = (val) => {
  pageData.pageConfiger.pageNum = val;
  getList();
};
const changeSize = (val) => {
  pageData.pageConfiger.pageSize = val;
  getList();
};

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

<style scoped lang="scss">

</style>
