<!--
  @description: 报表统计-采购计划统计-搜索条件
  @Modifier：肖文龙
  @routerPath:
  @date：  2021/02/07
-->
<template>
  <div>
    <el-form ref="searchForm" :model="searchForm" inline>
      <el-form-item v-if="roleFlag()" label="采购单位">
        <el-input v-model="searchForm.orgName" @focus="organSelect" />
      </el-form-item>
      <el-form-item label="统计年度">
        <el-date-picker
          v-model="searchForm.statisticalYear"
          value-format="yyyy"
          popper-class="el-date-picker-year"
          type="year"
          placeholder="请选择年度"
        />
      </el-form-item>
      <el-form-item label="统计月份">
        <el-select v-model="searchForm.statisticalMonth" placeholder="请选择月份" popper-class="el-select-reportChart">
          <el-option
            v-for="item in monthList"
            :key="item.typecode"
            :label="item.typename"
            :value="item.typecode"
          />
        </el-select>
      </el-form-item>
      <el-form-item class="fr">
        <el-button type="primary" round @click="search">
          统计
        </el-button>
        <el-button type="primary" round @click="resetForm('searchForm')">
          重置
        </el-button>
      </el-form-item>
    </el-form>
    <!-- 所属机构弹框 -->
    <organTree-dialog ref="organTree" :btn-round="true" :single-choice="true" @call-back="organTree" />
  </div>
</template>
<script>
/* 混入 */
import { timeDateGroupMixin } from './../../mixins/reportChartGroup.js'
import { reportChartSearch } from './../../mixins/reportChartSearch.js'// 搜索公共方法
/* 组件 */
import organTreeDialog from '@/views/common/user/organizationTree/organTree-dialog' // 采购单位选择
export default {
  name: 'PlanStatisticsSearch',
  components: {
    'organTree-dialog': organTreeDialog // 采购单位选择
  },
  mixins: [reportChartSearch],
  data() {
    return {
      /* 字典信息-start */
      ...timeDateGroupMixin,
      /* 字典信息-end */
      // 查询条件
      searchForm: {
        statisticalYear: '', // 统计年度
        statisticalMonth: '', // 统计月份
        orgName: '', // 采购单位名称
        orgId: '', // 采购单位ID
        orgCode: ''// 采购单位编码
      }
    }
  },
  methods: {
    // 选择机构
    organSelect() {
      this.$refs.organTree.open({
        title: '选择机构', // 弹框标题
        dialog: true, // 弹窗状态
        selectCodes: this.searchForm.orgCode && this.searchForm.orgCode.split(',')// 当前选中的供货范围Code
      })
    },
    // 选择机构
    organTree(data) {
      // 选择
      this.$set(this.searchForm, 'orgName', data.labels)
      this.$set(this.searchForm, 'orgCode', data.codes)
      this.$set(this.searchForm, 'orgId', data.keys)
    },
    /**
     * 搜索
     *  @param {searchForm} Object 查询条件
    */
    search() {
      const data = { ...this.searchForm }
      // 删除不需要的内容
      delete data.timeDate
      delete data.orgName
      // 获取父组件实例
      this.parentVm('', data)
    }
  }
}
</script>
<style lang="less" scoped>
</style>
