<template>
  <div class="d-flex flex-wrap pb-3 align-center">
    <!-- 活动类型 0路演 1讲座 2沙龙 不传参数则查询全部 -->
    <div class="mb-3">
      <span class="font-bold-14">活动类型：</span>
      <a-checkbox-group :options="items" @change="onChange" />
    </div>
    <!-- 发布平台 -->
    <div class="mb-3">
      <span class="font-bold-14 ml-8">发布平台：</span>
      <a-radio-group @change="getPlatform" v-model="publishPlatform">
        <a-radio :value="0">绿谷</a-radio>
        <a-radio :value="1">创时代</a-radio>
      </a-radio-group>
    </div>
    <!-- 活动标题 -->
    <a-input class="ml-3 mb-3" placeholder="标题" style="width: 150px" v-model="titleKey" />
    <!-- 发布时间 -->
    <a-range-picker
      @change="onChangeTime"
      class="ml-3 mb-3"
      format="YYYY-MM-DD HH:mm:ss"
      show-time
    />
    <a-button @click="handleTableChange" class="ml-3 mb-3" type="primary">搜索</a-button>
    <div class="flex-1"></div>
    <a-button @click="showModal" class="editable-add-btn mb-3" type="primary">增加</a-button>
    <!-- 添加 -->
    <activity-add :visible="visible" @closeModal="closeModal" />
  </div>
</template>

<script>
import ActivityAdd from 'components/Activity/ActivityAdd.vue';
// import { selLikeTeam } from 'config/api';

export default {
  name: 'ActivitySearch',
  components: {
    ActivityAdd,
  },
  data() {
    return {
      visible: false,
      titleKey: '',
      items: ['路演', '讲座', '沙龙'],
      activityType: [],
      checkedValues: [],
      publishPlatform: '', // 发布平台
      startTime: '',
      endTime: '',
    };
  },

  methods: {
    // 发布平台
    getPlatform(value) {
      console.log('value: ', value);
      this.publishPlatform = value;
    },

    // 发布时间
    onChangeTime(dates, dateStrings) {
      this.startTime = dateStrings[0];
      this.endTime = dateStrings[1];
    },

    showModal() {
      this.visible = true;
    },

    closeModal() {
      this.visible = false;
    },

    onChange(checkedValues) {
      this.checkedValues = checkedValues;
    },

    async handleTableChange() {
      const { activityType, titleKey, checkedValues, publishPlatform, startTime, endTime } = this;
      for (let i = 0; i < checkedValues.length; i++) {
        const item = checkedValues[i];
        const currentIndex = this.items.indexOf(item);
        const a = this.items.findIndex(a => a === item);
        const index = this.activityType.findIndex(c => c === a.label);
        if (index === -1) {
          this.activityType.push(currentIndex);
        }
      }
      // 传参
      const condition = {
        activityType,
        titleKey,
        publishPlatform,
        startTime,
        endTime,
      };
      await this.$emit('getSelectTeam', condition);
      this.activityType = [];
    },
  },
};
</script>

<style scoped lang="stylus"></style>
