import { screenList, meetingList } from "../compontents/contactsColums";
import { customInterence } from "@/api/api.js";

var moment = require("moment");
moment().format();
export const mutualMixin = {
  data() {
    return {
      tableLoading: false,
      activeName: 1,
      tableColums: [],
      total: 0,
      page_no: 1,
      pageSize: 10,
      publicHaveMove: true,
      list: [],
      chartList: [],
      userForm: {},
      checkActiveList: [1, 2], //活动的方式
      checkMeetingList: [1, 2], //是否到会
      monthLabel: [
        {
          label: "近1个月",
        },
        {
          label: "近3个月",
        },
      ],
      /* 筛选条件 */
      filterObj: {
        month: "",
        date: [],
      },
      searchVal: "", //
      start_date: "",
      end_date: "",
      sales: [],
      salesArr: [], //销售
      defaultSalesProps: {
        multiple: true,
        label: "RealName",
        children: "ChildrenList",
        value: "AdminId",
      }, //销售级联配置
      dialogVisibleActivity: false, //专项调研
      specialDetailId: null,
      dialogTitle: "",
      typeList: [
        { label: "权益", value: 1 },
        { label: "研选", value: 2 },
      ],
      activeTypeName: 1,
    };
  },
  computed: {
    screenList() {
      return screenList;
    },
    meetingList() {
      return meetingList;
    },
    showSelectBox() {
      return this.activeName === 1 || this.activeName === 2 || this.activeName === 11;
    },
    tableColumsList() {
      let arr = this.activeTypeName === 2 ? this.tableColums.filter((_) => _.key != "PermissionName") : this.tableColums;
      return arr;
    },
  },
  methods: {
    /* 获取销售 */
    getSale() {
      customInterence.getSale().then((res) => {
        if (res.Ret === 200) {
          this.salesArr = res.Data.List;
        }
      });
    },
    /* 选择服务日期 */
    dateChange(e) {
      if (e[0]) {
        this.start_date = e[0];
        this.end_date = e[1];
      } else {
        this.start_date = "";
        this.end_date = "";
      }
      this.filterObj.month = "";
      this.page_no = 1;
      this.searchVal = "";
      this.getTableData();
    },
    /* 切换月份 */
    toggleMonth(label) {
      this.filterObj.month = label;
      let days = label == "近1个月" ? -1 : label == "近3个月" ? -3 : 0;
      this.filterDate(days);
    },
    /* 获取未来几个月的日期范围 */
    filterDate(month) {
      if (month) {
        let date_now = moment().add(month, "M").format("YYYY-MM-DD");
        let date_after = moment().format("YYYY-MM-DD");
        let date = [date_now, date_after];
        this.start_date = date_now;
        this.end_date = date_after;
        this.filterObj.date = date;
        this.page_no = 1;
        this.searchVal = "";
        this.getTableData();
      }
    },
    /* 表格行的样式 */
    handleRowStyle(key) {
      const style = {
        Title: "color: #409eff; cursor: pointer",
        ActivityName: this.activeName == 1 || this.activeName == 8 ? "color: #409eff; cursor: pointer" : "",
      };
      return style[key] ? style[key] : "";
    },
    /* 表格行的点击事件 */
    handleRowClick(row, key) {
      if (key === "Title") {
        window.open(row.HttpUrl, "_blank");
      } else if (key === "ActivityName" && this.activeName === 8) {
        this.themeDetails(row.ActivityId);
      }
    },
    /* 表格行的数据处理 */
    handleRowContent(row, key) {
      // if (["IsMeeting"].includes(key)) {
      //   return row[key] == 1 ? "已到会" : "未到会";
      // } else {
      //   return row[key];
      // }
      if (key == "IsMeeting") {
        return row[key] == 1 ? "已到会" : "未到会";
      } else if (key == "Source") {
        return row[key] == 1 ? "纪要" : row[key] == 2 ? "图表" : row[key] == 3 ? "纪要/图表" : row[key] == 4 ? "产业资源包" : row[key] == 5 ? "报告" : "活动";
      } else if (key == "ActivityType") {
        return row[key] == 1 ? "线上" : row["City"] ? `线下(${row["City"]})` : "线下";
      } else if (key == "SpecialType") {
        return row[key] == 1 ? "笔记" : row[key] == 2 ? "观点" : "";
      } else {
        return row[key];
      }
    },
    // 调研主题的点击事件
    themeDetails(id) {
      this.dialogTitle = "活动详情";
      this.specialDetailId = id;
      this.dialogVisibleActivity = true;
    },
    // 搜索
    handleSearch() {
      this.page_no = 1;
      this.getTableData();
    },
    // 页码改变事件
    handleCurrentChange(page, index) {
      this.page_no = page;
      this.getTableData();
    },
    /* 加载更多 */
    loadMorePublicChart: _.throttle(function (e) {
      let scrollTop = this.$refs.listChartPage.scrollTop;
      let clientHeight = this.$refs.listChartPage.clientHeight;
      let scrollHeight = this.$refs.listChartPage.scrollHeight;
      if (scrollTop + clientHeight >= scrollHeight - 10 && this.publicHaveMove) {
        this.page_no++;
        this.getChartData();
      }
    }, 300),
    // 选择后的事件
    dataChangeHandler() {
      this.page_no = 1;
      this.getTableData();
    },
  },
};
