<template>
    <div class="seller-calendar">
      <el-card class="seller-calendar-context">
        <!-- 日程组件 -->
        <calendar
          ref="calendarRef"
          :eventList="eventList"
          @eventClick="eventClick"
          @cellClick="cellClick"
          @weekChange="getEventList"
        >
          <template #left>
            <el-cascader
              v-model="selectSeller"
              :options="sellerList"
              :show-all-levels="false"
              :props="{
                expandTrigger: 'hover',
                children: 'Child',
                emitPath: false,
                label:'AdminName',
                value:'AdminId',
              }"
              filterable
              clearable
              placeholder="请选择销售"
              @change="getEventList"
            />
          </template>
          <!-- <template #right>
            <el-button
              type="primary"
              @click="addMatterBtn"
              >添加事项</el-button
            >
          </template> -->
        </calendar>
      </el-card>
      <!-- 事项弹窗  -->
      <addMatterDia 
        :isShow.sync="isAddMatterDiaShow" 
        :edit_matter_id="edit_matter_id" 
        :matter_form="matter_form"
        @ensureCallback="addCallback"
      />
    </div>
  </template>
  
  <script>
  import { roadshowInterence,customInterence } from "@/api/api.js";
  import calendar from "@/components/calendar.vue";
  import addMatterDia from "./compononts/addMatterDia.vue";
  export default {
    components: {
      calendar,
      addMatterDia
    },
    data() {
      return {
        // 活动列表
        eventList: [],
        // 销售员列表
        sellerList: [],
        // 选择的销售
        selectSeller: "",
        activityStartDate:new Date(),
        // 点击单元格对应日期时间
        cellDate: null,
        // 子组件默认数据
        sonData: null,
        edit_id:0,
        edit_rs_id: 0,
  
        // 删除弹窗显示
        isDeleteDiaShow: false,
        // 删除原因
        deleteReason: "",
        rowInfo:'',
  
        edit_matter_id: 0,
        isAddMatterDiaShow: false,
        matter_form: {}
        
      };
    },
    methods: {
      //获取销售列表
      async getSellerList(){
        const res = await roadshowInterence.getSellerList();
        if(res.Ret!==200) return 
        this.sellerList = res.Data.List||[]
        this.sellerList = this.sellerList.map(i=>{
            if(!i.AdminName){
                i.AdminName = i.GroupName
            }
            if(!i.AdminId){
                i.AdminId = i.GroupId
            }
            return i
        })

      },
      
      // 获取活动列表
      async getEventList() {
  
        //当前的起始日期
        const { currentStart,currentEnd } = this.$refs.calendarRef.calendarApi.view;
  
        const { formateDate } = this.$refs.calendarRef;
  
        // 获取本周日程
        const res = await roadshowInterence.getSellerCalendarDetail({
          StartDate: formateDate(currentStart),
          EndDate: formateDate(new Date(currentEnd.getTime()- 24*60*60*1000)),
          SellerId: Number(this.selectSeller) || -1
        });
  
        this.eventList = [
          ...(res.Data.CalendarList || []),
          ...(res.Data.RsMattersList || []),
        ].map((item, index) => {
          return { ...item, id: index };
        });
      },
  
      // 添加说明弹窗
      addMatterBtn() {
        //当前的起始日期
        const { currentStart } = this.$refs.calendarRef.calendarApi.view;
        this.edit_id = 0;
        this.edit_rs_id = 0;
        this.activityStartDate = currentStart
        this.isAddMatterDiaShow = true;
      },
      
      // 单元格添加说明事件
      /* cellClick(startDate) {
        if (!this.selectSeller)
          return this.$message.warning("请先选择销售");
        const endDate = new Date(startDate.getTime() + 1000 * 60 * 60);
        this.sonData = {
          selectResearchers: [
            {
              researcherId: '',
              startDate: startDate,
              startTime: startDate,
              endDate: endDate,
              endTime: endDate,
            },
          ],
        };
        this.edit_id = 0;
        this.edit_rs_id = 0;
        this.isActivityCellDiaShow = true;
      }, */
  
      // 添加活动后刷新
      addCallback() {
        this.getEventList();
      },
    },
    computed: {},
    mounted() {
      this.getSellerList();
    }
  };
  </script>
  
  <style>
  </style>