<!--  -->
<template>
  <div>
    <div class="staff-archives-title">条件筛选</div>
    <el-form :inline="true" :model="formInline" class="demo-form-inline staff-archives-form">
      <el-form-item label="选择部门">
        <el-input
          placeholder="请选择部门"
          @focus="isChoose=true"
          readonly
          :value="formInline.departmentName"
        ></el-input>
      </el-form-item>

      <el-form-item :label="`选择月份`">
        <el-date-picker
          type="month"
          placeholder="选择月份"
          v-model="selectMonthTime"
          value-format="yyyy-MM"
          @change="changeApplyMonth"
        >
        </el-date-picker>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="primary" @click="restValue">重置</el-button>
      </el-form-item>
    </el-form>

    <el-dialog title="选择部门" :visible.sync="isChoose" width="30%">
      <el-tree :data="menuList" :props="defaultProps" @node-click="handleNodeClick">
        <span class="custom-tree-node" slot-scope="{ node, data }">
          <span>{{ data.departmentName }}</span>
          <span>({{ data.memberCount }})人</span>
        </span>
      </el-tree>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="isChoose = false">取 消</el-button>
        <el-button type="primary" size="mini" @click="onsumbit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import { apiOrganizationList } from '@/api/api_staff'
  export default {
    props: {
      monthTime: {
        type: String,
        default: ''
      }
    },
    data () {
      return {
        selectMonthTime: this.nowDate(),
        isChooseObj: {},
        isChoose: false,
        menuList: [],
        defaultProps: {
          children: 'list',
          label: 'name'
        },
        formInline: {
          value: []
        }
      }
    },
    computed: {},
    beforeMount () { },
    created () {
      this.handleGetMenuList()
      this.handleChangeData()
    },
    mounted () {},
    beforeUpdate () {
      // this.selectMonthTime = this.monthTime
    },
    methods: {
      async  handleChangeData () {
        this.onSubmit()
      },
      // 获取侧边架构列表
      async handleGetMenuList () {
        let result = await apiOrganizationList()
        this.menuList = result
      },
      // 修改月份
      changeApplyMonth (val) {
        this.selectMonthTime = val
        console.log(val)
      },
      onSubmit () {
        let obj = {
          departmentId: this.formInline.departmentId,
          selectMonthTime: this.selectMonthTime
        }
        this.$emit('submit', obj)
      },
      restValue () {
        this.formInline = {}
        this.selectMonthTime = ''
      },
      onsumbit () {
        this.formInline = Object.assign({}, this.formInline, this.isChooseObj)
        this.isChoose = false
      },
      handleNodeClick (a, b) {
        this.isChooseObj = {
          departmentId: a.departmentId,
          departmentName: a.departmentName
        }
      },
      nowDate () {
        var data = new Date()
        var month = data.getMonth() < 9 ? '0' + (data.getMonth() + 1) : data.getMonth() + 1
        return data.getFullYear() + '-' + month
      }
    },
    watch: {}

  }
</script>

<style lang='scss'>
  .el-range-separator {
    width: 7% !important;
  }
  .el-input__icon {
    transition: all 0.5s;
  }
  .staff-archives-choose {
    margin: 2px;
    height: 200px;
    overflow: auto;
    transition: all 0.3s;
    position: relative;
    border: 1px solid #dcdfe6;
  }
  .staff-archives-choose1 {
    height: 0px;
    opacity: 0;
    overflow: hidden;
  }
</style>




<!--
&lt;!&ndash;  &ndash;&gt;
<template>
  <div>
    <div class="staff-archives-title">条件筛选</div>
    <el-form :inline="true"  class="demo-form-inline staff-archives-form">
      <el-form-item :label="`选择月份`">
        <el-date-picker
          type="month"
          placeholder="选择月份"
          v-model="applyMonth"
          @change="changeApplyMonth"
        >
        </el-date-picker>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="primary" @click="restValue">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getDataForMonth } from '@/utils'
export default {
  data () {
    return {
      applyMonth: '',
      defaultVal: '',
      defaultValYear: '',
      defaultValMon: '',
      value2: [],
      isChooseObj: {},
      isChoose: false,
      menuList: [],
      defaultProps: {
        children: 'list',
        label: 'name'
      },
      formInline: {
        value: []
      }
    }
  },
  computed: {},
  beforeMount () { },
  created () {
    this.handleChangeData({
      Month: 3,
      title: '近三个月'
    })
  },
  mounted () { },
  methods: {
    async  handleChangeData (data) {
      this.index = data.Month
      this.title = data.title
      let dataList = getDataForMonth(data.Month)
      this.formInline.value = dataList
      this.formInline.beginDate = dataList[0]
      this.formInline.endDate = dataList[1]
      this.onSubmit()
    },
    changeData (data) {
      this.index = null
      this.title = null
      this.formInline.beginDate = data[0]
      this.formInline.endDate = data[1]
    },
    // 修改月份
    changeApplyMonth (val) {
      this.defaultVal = val.getFullYear() + '-' + (val.getMonth() + 1) + '-' + '1'
      this.defaultValYear = val.getFullYear()
      this.defaultValMon = val.getMonth() + 1
      console.log(this.defaultVal)
    },
    onSubmit () {
      let obj = {
        departmentId: this.formInline.departmentId,
        beginDate: this.formInline.beginDate,
        endDate: this.formInline.endDate
      }
      let monthLetter = {
        index: this.index,
        title: this.title
      }
      this.$emit('submit', obj, monthLetter)
    },
    restValue () {
      this.formInline = {}
      this.index = null
      this.title = null
    },
    onsumbit () {
      this.formInline = Object.assign({}, this.formInline, this.isChooseObj)
      this.isChoose = false
    }
  },
  watch: {}

}
</script>

<style lang='scss'>
.el-range-separator {
  width: 7% !important;
}
.el-input__icon {
  transition: all 0.5s;
}
.staff-archives-choose {
  margin: 2px;
  height: 200px;
  overflow: auto;
  transition: all 0.3s;
  position: relative;
  border: 1px solid #dcdfe6;
}
.staff-archives-choose1 {
  height: 0px;
  opacity: 0;
  overflow: hidden;
}
</style>
-->
