import request from '@/utils/request';

/**
 * 分页查询活动
 * @param params 查询条件
 */
export async function pageActivity(params) {
  const res = await request.get('/sylive/activity/page', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 获取活动信息
 * @param params 查询条件
 */
export async function getActivityInfo(params) {
  const res = await request.get('/sylive/activity/info', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 根据id查询活动
 * @param id 活动id
 */
export async function getActivity(id) {
  return getActivityInfo({ activityId: id });
}

/**
 * 查询活动列表
 * @param params 查询条件
 */
export async function listActivity(params) {
  const res = await request.get('/sylive/activity', {
    params
  });
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加活动
 * @param data 活动信息
 */
export async function addActivity(data) {
  const res = await request.post('/sylive/activity', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改活动
 * @param data 活动信息
 */
export async function updateActivity(data) {
  const res = await request.put('/sylive/activity', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 复制活动
 * @param id 活动id
 */
export async function copyActivity(id) {
  const res = await request.get('/sylive/activity/copy/' + id);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改活动商品
 * @param data 活动信息
 */
export async function updateActivityItem(data) {
  const res = await request.put('/sylive/activity/item', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改活动券
 * @param data 活动信息
 */
export async function updateActivityCoupon(data) {
  const res = await request.put('/sylive/activity/coupon', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除活动
 * @param id 活动id
 */
export async function removeActivity(id) {
  return removeActivitys([id]);
}

/**
 * 批量删除活动
 * @param ids 活动id集合
 */
export async function removeActivitys(ids) {
  const res = await request.delete('/sylive/activity/batch', {
    data: { ids }
  });
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改活动状态
 * @param userId 活动id
 * @param status 状态
 */
export async function updateActivityStatus(activityId, status) {
  const res = await request.put('/sylive/activity/status', {
    activityId,
    status
  });
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 根据id查询活动机构数据统计
 * @param id 活动id
 */
export async function getActivityStatistics(id) {
  const res = await request.get('/sylive/statistics/biz/' + id);
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 根据id查询活动团队数据统计
 * @param id 活动id
 */
export async function getActivityStatisticsTeam(id) {
  const res = await request.get('/sylive/statistics/team/' + id);
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 分页查询门店统计
 * @param params 查询条件
 */
export async function pageStatisticsArea(params) {
  const res = await request.get('/sylive/statistics/page_area', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 区域统计折线图
 * @param params 查询条件
 */
export async function getStatisticsStackedArea(params) {
  const res = await request.get('/sylive/statistics/stacked_area', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 分页查询门店统计
 * @param params 查询条件
 */
export async function pageStatisticsBiz(params) {
  const res = await request.get('/sylive/statistics/page_biz', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 分页查询顾问统计
 * @param params 查询条件
 */
export async function pageStatisticsConsultant(params) {
  const res = await request.get('/sylive/statistics/page_consultant', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 分页查询门店统计
 * @param params 查询条件
 */
export async function pageTeamStatisticsBiz(params) {
  const res = await request.get('/sylive/statistics/page_team_biz', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 分页查询团员统计
 * @param params 查询条件
 */
export async function pageTeamStatisticsConsultant(params) {
  const res = await request.get('/sylive/statistics/page_team_consultant', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 获取区域饼状数据
 * @param params 查询条件
 */
export async function getActivityPiechart(params) {
  const res = await request.get('/sylive/statistics/piechart', {
    params
  });
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 获取门店柱状数据
 * @param params 查询条件
 */
export async function getActivityBarchart(params) {
  const res = await request.get('/sylive/statistics/barchart', {
    params
  });
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 获取顾问柱状数据
 * @param params 查询条件
 */
export async function getActivitystoreBarchart(params) {
  const res = await request.get('/sylive/statistics/storebarchart', {
    params
  });
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 获取排名数据
 * @param params 查询条件
 */
export async function getStatisticsRanking(params) {
  const res = await request.get('/sylive/statistics/ranking', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 获取漏头数据
 * @param params 查询条件
 */
export async function getStatisticsFunnel(params) {
  const res = await request.get('/sylive/statistics/funnel', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 观看下单统计折线图
 * @param params 查询条件
 */
export async function getStatisticsStackedWatchOrder(params) {
  const res = await request.get('/sylive/statistics/stacked_watchOrder', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改抽奖配置
 * @param data 信息
 */
export async function updateActivityDraw(data) {
  const res = await request.put('/sylive/activity/draw', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改回访标签
 * @param data 信息
 */
export async function updateActivityVisitTag(data) {
  const res = await request.put('/sylive/activity/visit_tag', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改黑名单
 * @param data 信息
 */
export async function updateActivityBlacklist(data) {
  const res = await request.put('/sylive/activity/blacklist', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 导入黑名单
 * @param file excel文件
 */
export async function importActivityBlacklist(file, activityId) {
  const formData = new FormData();
  formData.append('file', file);
  formData.append('activityId', activityId);
  const res = await request.post('/sylive/activity/blacklist_import', formData);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
