<template>
  <basic-container style="position: relative">
    <avue-crud
      :data="infoData"
      :option="options"
      :table-loading="visible"
      :search.sync="search"
      :page.sync="infoPages"
      @search-change="searchChange"
      @search-reset="resetChange"
      @size-change="sizeChange"
      @current-change="currentChange"
    >
    </avue-crud>
  </basic-container>
</template>

<script>
import {missionCount} from '@/api/report/report'
import CustomLoading from "@/components/Custom-Loading/index.vue";
import {dateFormat} from "@/util/date";
import {getDeptMyTree} from "@/api/tenant/talents";

const pages = {total: 0, size: 10, currentPage: 1}
const baseOptions = {
  dateBtn: false,
  addBtn: false,
  editBtn: false,
  delBtn: false,
  height: "auto",
  reserveSelection: false,
  border: true,
  columnBtn: false,
  refreshBtn: false,
  menu: false,
  tip: false,
  searchMenuSpan: 6,
  selection: false,
  headerAlign: 'center',
  align: 'center',
}
export default {
  components: {CustomLoading},
  data() {
    return {
      infoPages: Object.assign({}, pages),
      infoData: [],
      visible: false,
      search: {},
      depTree: []
    }
  },
  created() {
    this.getDept()
    this.getList()
  },
  computed: {
    options() {
      return {
        ...baseOptions,
        column: [
          {
            label: "所属机构",
            prop: "deptId",
            type: "tree",
            multiple: false,
            dicData: this.depTree,
            props: {
              label: "title",
              value: 'value'
            },
            checkStrictly: true,
            search: true,
            span: 20,
            hide: true,
            searchLabelWidth: 80,
            searchSpan: 8,
          },
          {
            label: '机构名称',
            prop: 'name',
            search: false,
          },
          {
            label: '发布零工岗位数',
            prop: 'data1',
          },
          {
            label: '招聘中零工岗位数',
            prop: 'data2',
          },
          {
            label: '关闭零工岗位数',
            prop: 'data3'
          },
          {
            label: '待审核零工岗位数',
            prop: 'data4'
          },
          {
            label: '审核通过零工岗位数',
            prop: 'data5'
          },
          {
            label: '推送成功零工岗位数',
            prop: 'data6'
          },
          {
            label: '日期',
            prop: 'date',
            hide: true,
            display: false,
            type: 'month',
            format: "yyyy-MM",
            valueFormat: "yyyy-MM",
            searchSpan: 8,
            searchRange: true,
            search: true,
          }]
      }
    }
  },
  methods: {
    async getDept() {
      let params = {
        tenantId: '000000'
      }
      let resData = await getDeptMyTree(params)
      if (resData.data.code === 200) {
        this.depTree = resData.data.data
      }
    },
    sizeChange(size) {
      this.infoPages.size = size
      this.getList()
    },
    currentChange(page) {
      this.infoPages.page = page
      this.getList()
    },
    searchChange(values, done) {
      this.getList().then(() => {
        done()
      })
    },
    resetChange() {
      this.search = {}
      let params = {size: 10, current: 1}
      this.getList()
    },
    getList(values) {
      return new Promise(async (resolve, reject) => {
        this.visible = true
        let params = {
          size: this.infoPages.size,
          current: this.infoPages.currentPage,
          ...this.search,
        }
        // if (Array.isArray(this.search.date) && this.search.date.length) {
        //   const [stime, etime] = this.search.date
        //   params.stime = dateFormat(stime, "yyyy-MM-dd")
        //   params.etime = dateFormat(etime, "yyyy-MM-dd")
        //   delete params.date
        // }
        console.log(123123, params)
        let resData = await missionCount(params)
        if (resData.data.code === 200) {
          const {records, current, total, size} = resData.data.data
          this.infoData = records
          this.infoPages = {...this.infoPages, currentPage: current, total, size}
          this.visible = false;
          resolve(true)
        } else {
          reject()
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">

</style>

