<template>
  <div class="app-container">
    <Com-search :search="searchObj" @handleSearch="handleSearch">
      <template #selectTree>
        <treeselect
          v-model="orgNo"
          :options="deptOptions"
          :show-count="true"
          placeholder="请选择所属单位"
          :normalizer="unitNamenormalizer"
        />
      </template>
      <template #btn>
        <el-button type="primary" @click="handleExport">导出</el-button>
      </template>
    </Com-search>
    <Com-table
      :tableFormat="tableFormat"
      :tableData="tableData"
      :loading="loading"
    >
    </Com-table>
  </div>
</template>

<script>
import { deptTreeSelect } from "@/api/system/user";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { poiseList } from "@/api/home";
import { tableFormat, searchObj } from "./utils/index.json";
export default {
  components: { Treeselect },
  data() {
    return {
      tableFormat: tableFormat,
      tableData: [],
      loading: false,
      orgNo: undefined,
      deptOptions: [],
      searchObj: searchObj,
      searchData: {
        orgNo: "",
        mtrlNo: "",
        mtrlDes: "",
      },
    };
  },
  mounted() {
    this.getPageData();
    this.getDeptTree();
  },
  methods: {
    // 导出
    handleExport() {
      this.searchData.orgNo = this.orgNo;
      this.download(
        "adsHyxtMatMtrlForeD/exportPoiseList",
        {
          ...this.searchData,
        },
        `${new Date().getTime()}.xlsx`
      );
    },
    handleSearch(obj) {
      this.searchData = obj;
      this.getPageData();
    },
    unitNamenormalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.orgNo,
        label: node.label,
      };
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then((response) => {
        this.deptOptions = response.data;
      });
    },
    getPageData() {
      this.searchData.orgNo = this.orgNo;
      let params = {
        ...this.searchData,
      };
      poiseList(params).then((res) => {
        if (res && res.code == 200) {
          this.tableData = res.data || [];
        }
        console.log(res, "ddddddddddddd");
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.app-container {
  position: absolute;
  width: 100%;
  height: calc(100% - 60px - 60px);
}
</style>
