<template>
  <basic-container>
    <!--搜索栏-->
    <avue-form :option="option" v-model="search" @submit="handleSearch" @reset-change="handleClear"></avue-form>
    <!--/搜索栏-->
    <waiting-mission ref="waiting" v-if="search.status === 1" @refresh="handleClear"></waiting-mission>
    <ongoing-mission ref="onging" v-if="search.status === 2" @refresh="handleClear"></ongoing-mission>
    <finished-mission ref="finished" v-if="search.status === 3" @refresh="handleClear"></finished-mission>
    <expired-mission ref="expired" v-if="search.status === 4" @refresh="handleClear"></expired-mission>
  </basic-container>
</template>

<script>
import WaitingMission from './Table/WaitingMission'
import OngoingMission from './Table/OngoingMission'
import FinishedMission from './Table/FinishedMission'
import ExpiredMission from './Table/ExpiredMission'
import {companyMissionState, educationState, recruitStatus} from '@/common/dic'
import {getDeptMyTree} from "@/api/tenant/talents";

const searchData = {
  status: 1
}
export default {
  comments: {},
  name: "tenant_mission",
  data() {
    return {
      recruitStatus,
      educationState,
      missionTypes: companyMissionState,
      timeValue: "",
      endDateRange: "",//报名截止日期筛选
      beginTimeValue: "",//开始时间筛选
      successTimeValue: "",//完成时间筛选
      page: {
        pageSize: 20,
        currentPage: 1,
        total: 0,
      },
      search: Object.assign({}, searchData),
      depTree: [],
      timeScreenTerm: [
        {
          value: 2,
          label: '开始日期',
        },
        {
          value: 3,
          label: '结束日期',
        }, {
          value: 1,
          label: '报名截止日期',
        }],
    }
  },
  components: {
    WaitingMission,
    OngoingMission,
    FinishedMission,
    ExpiredMission
  },
  computed: {
    option() {
      return {
        menuSpan: 6,
        column: [
          {
            label: "所属机构",
            prop: "deptId",
            type: "tree",
            multiple: false,
            dicData: this.depTree,
            props: {
              label: "title",
              value: 'value'
            },
            span: 6,
          },
          {
            label: '岗位名称',
            prop: 'missionTitle',
            span: 6,
          },
          {
            label: '地址',
            prop: 'address',
            placeholder: "请输入地址",
            span: 6,
          }, {
            label: '零工工种',
            prop: 'worktypeNames',
            span: 6,
          },
          {
            label: '审核状态',
            prop: 'reviewState',
            type: 'select',
            dicData: recruitStatus,
            span: 6,
          }, {
            label: '学历',
            prop: 'education',
            type: 'select',
            dicData: educationState,
            span: 6,
          },
        ]
      }
    }
  },
  watch: {},
  created() {
    this.getDept()
  },
  methods: {

    handleSearch(form, done) {
      if (this.search.status === 1) {
        this.$refs.waiting.onLoad(this.page, this.$api.filterObject(this.search));
      } else if (this.search.status === 2) {
        this.$refs.onging.onLoad(this.page, this.$api.filterObject(this.search));
      } else if (this.search.status === 3) {
        this.$refs.finished.onLoad(this.page, this.$api.filterObject(this.search));
      } else if (this.search.status === 4) {
        this.$refs.expired.onLoad(this.page, this.$api.filterObject(this.search));
      }
      done && done()
    },
    async getDept() {
      let params = {
        tenantId: '000000'
      }
      let resData = await getDeptMyTree(params)
      if (resData.data.code === 200) {
        this.depTree = resData.data.data
      }
    },
    date() {
      this.dateChange(this.timeValue)
    },
    dateChange(val) {
      // if (val) {
      //   this.search.stime = val[0] + " 00:00:00";
      //   this.search.etime = val[1] + " 23:59:59";
      // } else {
      //   this.search.stime = '';
      //   this.search.etime = '';
      // }
      switch (this.search.state) {
        case 1:
          return this.endDateChange(val)
        case 2:
          return this.beginDateChange(val);
        case 3:
          return this.successDateChange(val);
      }

    },
    handleClear() {
      this.$nextTick(() => {
        this.search = Object.assign({}, searchData)
        this.handleSearch()
      })
    },
    // 开始时间
    beginDateChange(val) {
      if (val) {
        this.clearDateTime()
        this.search.stimeBeginTime = val[0] + " 00:00:00";
        this.search.stimeEndTime = val[1] + " 23:59:59";
      } else {
        this.search.stimeBeginTime = '';
        this.search.stimeEndTime = '';
      }
    },
    // 完成时间
    successDateChange(val) {
      if (val) {
        this.clearDateTime()
        this.search.etimeBeninTime = val[0] + " 00:00:00";
        this.search.etimeEndTime = val[1] + " 23:59:59";
      } else {
        this.search.etimeBeninTime = '';
        this.search.etimeEndTime = '';
      }
    },
    // 报名截止时间
    endDateChange(val) {
      if (val) {
        this.clearDateTime()
        this.search.etimePubBeginTime = val[0] + " 00:00:00";
        this.search.etimePubEndTime = val[1] + " 23:59:59";
      } else {
        this.search.etimePubBeginTime = '';
        this.search.etimePubEndTime = '';
      }
    },
    // 清楚多余时间参数
    clearDateTime() {
      this.search.etimePubBeginTime = '';
      this.search.etimePubEndTime = '';
      this.search.etimeBeninTime = '';
      this.search.etimeEndTime = '';
      this.search.stimeBeginTime = '';
      this.search.stimeEndTime = '';
    }
  }
};
</script>
<style scoped>
.el-form-item {
  margin-bottom: 18px !important;
  margin-right: 10px !important;
  padding: 0 10px;
}

.searchBtn {
  display: inline-block;
  margin-bottom: 18px;
}
</style>
