<template>
  <div class="app-container">
    <el-input
      class="w260 mb10"
      clearable
      v-model="queryParams.videoName"
      placeholder="请输入直播名称"
    />
    <el-button type="primary" @click="queryList(1)">查询</el-button>
    <div class="mb10">
      <el-button
        v-for="(item, index) in buttonText"
        :key="index"
        :class="{ selected: selectedButton === index }"
        plain
        @click="selected(index)"
        >{{ item }}</el-button
      >
      <el-date-picker
        v-if="selectedButton === 5"
        style="margin-left:20px"
        v-model="valueTime"
        type="daterange"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
      >
      </el-date-picker>
      <el-button v-if="selectedButton === 5" type="primary" @click="queryList()"
        >查询</el-button
      >
    </div>
    <div class="mb10">
      <el-button
        v-for="(item, index) in buttonTextTwo"
        :key="index"
        :class="{ selected: selectedButtonTwo === index }"
        plain
        @click="selectedTwo(index)"
        >{{ item }}</el-button
      >
    </div>
    <div class="mb10">
      <el-table :data="data" v-loading="loading" border style="width: 100%">
        <el-table-column label="序号" type="index" fixed width="180">
        </el-table-column>
        <el-table-column prop="userName" label="昵称" width="180">
        </el-table-column>
        <el-table-column
          prop="phone"
          :label="settingToC ? '客户账号' : '客户手机号'"
          width="180"
        >
        </el-table-column>
        <el-table-column prop="notifyTime" label="提醒时间" width="180">
        </el-table-column>
        <el-table-column prop="description" label="事件描述"> </el-table-column>
      </el-table>
    </div>
    <!--分页组件-->
    <el-pagination
      :total="total"
      :current-page="queryParams.current"
      :page-size="queryParams.size"
      layout="total, sizes, prev, pager, next, jumper"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>
<script>
import { notifyList } from "@/api/videoLive";
import { mapGetters, mapState } from "vuex";
import dayjs from "dayjs";
export default {
  data() {
    return {
      queryParams: {
        current: 1,
        size: 10,
        videoName: ""
      },
      startTime: "",
      endTime: "",
      total: 1,
      loading: false,
      data: [],
      selectedButton: 0,
      selectedButtonTwo: 0,
      buttonText: ["今日", "昨日", "近一周", "近一月", "近一年", "自定义"],
      buttonTextTwo: [
        "全部",
        "领取优惠券",
        "完成问卷任务",
        "参与投票",
        "点击产品",
        "提交订单未付款",
        "订阅产品",
        "发生退款",
        "预约未观看",
        "预约"
      ],
      valueTime: ""
    };
  },
  computed: {
    ...mapGetters(["user"]),
    ...mapState({
      settingToC: state => state.settings.settingToC
    })
  },
  mounted() {
    this.queryList();
  },
  watch: {
    timeType(value) {
      this.time = this.startTime = this.endTime = "";
    }
  },
  methods: {
    selected(index) {
      this.queryParams.current = 1;
      this.selectedButton = index;
      if (index !== 5) {
        this.queryList();
      }
    },
    selectedTwo(index) {
      this.queryParams.current = 1;
      this.selectedButtonTwo = index;
      this.queryList();
    },
    queryList(val) {
      if (val) {
        this.queryParams.current = 1;
      }
      this.loading = true;
      if (this.selectedButton === 5) {
        if (!this.valueTime) {
          return this.$message.error("请选择自定义时间!");
        } else {
          this.startTime = dayjs(this.valueTime[0]).format(
            "YYYY-MM-DD HH:mm:ss"
          );
          this.endTime = dayjs(this.valueTime[1])
            .add(1, "day")
            .format("YYYY-MM-DD HH:mm:ss");
        }
      } else if (this.selectedButton === 1) {
        this.endTime = dayjs().format("YYYY-MM-DD");
        this.startTime = dayjs()
          .subtract(1, "day")
          .format("YYYY-MM-DD");
      } else if (this.selectedButton === 0) {
        this.startTime = dayjs().format("YYYY-MM-DD");
        this.endTime = dayjs()
          .add(1, "day")
          .format("YYYY-MM-DD");
      } else if (this.selectedButton === 2) {
        this.endTime = dayjs()
          .add(1, "day")
          .format("YYYY-MM-DD");
        this.startTime = dayjs()
          .subtract(7, "day")
          .format("YYYY-MM-DD");
      } else if (this.selectedButton === 3) {
        this.endTime = dayjs()
          .add(1, "day")
          .format("YYYY-MM-DD");
        this.startTime = dayjs()
          .subtract(1, "month")
          .format("YYYY-MM-DD");
      } else if (this.selectedButton === 4) {
        this.endTime = dayjs()
          .add(1, "day")
          .format("YYYY-MM-DD");
        this.startTime = dayjs()
          .subtract(1, "year")
          .format("YYYY-MM-DD");
      }

      if (this.selectedButtonTwo) {
        this.queryParams.type = this.selectedButtonTwo;
      } else {
        this.queryParams.type = null;
      }
      this.queryParams.startTime = this.startTime;
      this.queryParams.endTime = this.endTime;
      notifyList(this.queryParams).then(data => {
        this.data = data.data.list;
        this.total = data.data.total;
        this.loading = false;
      });
    },
    searchList() {
      this.queryParams.size = 10;
      this.queryParams.current = 1;
      this.queryList();
    },
    handleSizeChange(val) {
      this.$set(this.queryParams, "size", val);
      this.$set(this.queryParams, "current", 1);
      this.queryList();
    },
    handleCurrentChange(val) {
      this.$set(this.queryParams, "current", val || 1);
      this.queryList();
    },

    toDetail(val) {}
  }
};
</script>

<style scoped lang="scss">
.mb10 {
  margin-bottom: 20px;
}
.w260 {
  width: 260px;
}

.selected {
  background-color: #409eff !important;
  color: #ffffff !important;
}
</style>
