<script setup>
import { Switch } from '@element-plus/icons-vue'
import { apiCustomerUser } from '@/api/customer'
import LineChart from './components/LineChart.vue'
import PieChart from './components/PieChart.vue'


const emits = defineEmits(['change'])

const filterState = reactive({
  type: '',
  keyword: ''
})

const userId = ref('')
const options = ref([])
const searchLoading = ref(false)
async function handleSearch(query) {
  if (query) {
    searchLoading.value = true
    const res = await apiCustomerUser.userList({
      PageSize: 100,
      CurrentIndex: 1,
      KeyWord: query
    })
    searchLoading.value = false
    if (res.Ret === 200) {
      const arr = res.Data.List || []
      options.value = arr
    } else {
      options.value = []
    }
  }
}



</script>

<template>
  <div class="user-report-statistic-chart-page">
    <div class="flex filter-wrap">
      <el-button
        type="primary"
        :icon="Switch"
        link
        @click="emits('change', 'chart')"
        >数据表</el-button
      >
      <el-select
        v-model="userId"
        filterable
        remote
        placeholder="姓名/手机号/邮箱"
        :remote-method="handleSearch"
        :loading="searchLoading"
        style="max-width: 359px; margin-left: auto"
        clearable
      >
        <template #prefix>
          <el-icon><i-ep-Search /></el-icon>
        </template>

        <el-option
          v-for="item in options"
          :key="item.UserId"
          :label="item.RealName"
          :value="item.UserId"
        />
      </el-select>
    </div>
    <div class="content-wrap">
      <div class="bg-white item-wrap">
        <LineChart :userId="userId"/>
      </div>
      <div class="bg-white item-wrap">
        <PieChart :userId="userId"/>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.filter-wrap {
  gap: 10px;
}
.content-wrap {
  display: flex;
  gap: 0 30px;
  .item-wrap {
    margin-top: 20px;
    flex: 1;
  }
}
</style>