<template>
  <section class="list">
    <ai-list>
      <ai-title slot="title" title="签到管理" isShowBottomBorder>
        <template #rightBtn>
          <el-button type="primary">设置</el-button>
        </template>
      </ai-title>
      <template #left>
        <ai-tree-menu title="组织部门" @search="handleSearchTree">
          <el-tree ref="DeptTree" :data="treeData" :props="{label:'name'}" :filter-node-method="(v,data)=>data.label.indexOf(v)>-1"/>
        </ai-tree-menu>
      </template>
      <template #content>
        <ai-search-bar>
          <template #left>
            <ai-download url="/app/appwechatsigninfo/export" :params="{...search,ids}" :instance="instance" fileName="签到管理导出文件"/>
          </template>
          <template #right>
            <el-input size="small" placeholder="搜索" v-model="search.name" clearable @change="page.current=1,getTableData()"/>
          </template>
        </ai-search-bar>
        <ai-table :tableData="tableData" :total="page.total" :current.sync="page.current" :size.sync="page.size"
                  @getList="getTableData" :col-configs="colConfigs" :dict="dict">
          <el-table-column slot="options" label="操作" fixed="right" align="center" width="300">
            <template slot-scope="{row}">

            </template>
          </el-table-column>
        </ai-table>
      </template>
    </ai-list>
  </section>
</template>

<script>
import AiTreeMenu from "dui/packages/layout/AiTreeMenu";

export default {
  name: "list",
  components: {AiTreeMenu},
  props: {
    instance: Function,
    dict: Object,
    permissions: Function
  },
  data() {
    return {
      search: {name: ""},
      page: {current: 1, size: 10, total: 0},
      tableData: [],
      colConfigs: [
        {prop: "createDate", label: "签到时间"},
        {prop: "departmentName", label: "部门"},
        {prop: "status", label: "状态", dict: "wxSignStatus"},
        {prop: "wxUserName", label: "用户"}
      ],
      treeData: []
    }
  },
  methods: {
    getTableData() {
      this.instance.post("/app/appwechatsigninfo/list", null, {
        params: {...this.page, ...this.search}
      }).then(res => {
        if (res?.data) {
          this.tableData = res.data.records
          this.page.total = res.data.total
        }
      })
    },
    handleAdd(id) {
      this.$router.push({hash: "#add", query: {id}})
    },
    getDepartments() {
      this.instance.post("/app/wxcp/wxdepartment/listAll").then(res => {
        if (res?.data) {
          this.treeData = this.$arr2tree(res.data, {parent: 'parentid'})
        }
      })
    },
    handleSearchTree(name) {
      this.$refs.DeptTree.filter(name)
    }
  },
  created() {
    this.getTableData()
    this.getDepartments()
  }
}
</script>

<style lang="scss" scoped>
.list {
  height: 100%;
}
</style>
