<template>
  <el-form label-width="50px" inline>
    <el-form-item label="应用">
      <el-select
        v-model="conditions.pkg"
        filterable
        clearable
        placeholder="请选择"
        @change="handleAppChange"
      >
        <el-option
          v-for="item in appsArr"
          :key="item.id"
          :value="item.value"
          :label="item.label"
        />
      </el-select>
    </el-form-item>

    <el-form-item label="开始日期" label-width="100px">
      <el-date-picker
        v-model="conditions.startDate"
        align="right"
        type="date"
        placeholder="选择日期"
        :picker-options="pickerOptions"
        value-format="yyyy-MM-dd"
        @change="handleDateChange"
      >
      </el-date-picker>
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="handleQuery">查询</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { menuSelectApps } from "@/api/report";
import { pickerOptions } from "./pickerOptions";
import { getTime } from "@/utils/utils";

export default {
  data() {
    return {
      appsArr: [],
      pickerOptions: pickerOptions,
      conditions: {
        pkg: "",
        startDate: "",
      },
    };
  },

  created() {
    this.conditions.startDate = getTime();
    this._fetchApps();
  },

  methods: {
    _fetchApps() {
      let params = {
        platformId: 5,
        menuCode: "game.Overview",
      };
      menuSelectApps(params).then((res) => {
        this.appsArr = res.result.data;
      });
    },

    handleAppChange() {
      this.$emit("pkgChange", this.conditions.pkg);
    },

    handleDateChange() {
      this.$emit("dateChange", this.conditions.startDate);
    },

    handleQuery() {
      this.$emit("handleQuery");
    },
  },
};
</script>

<style>
</style>