import request from '@/utils/request';
import CryptoJS from 'crypto-js';
import { nanoid } from 'nanoid';

// 二维码
export const getMapProduct = (data) => {
  const nonce = nanoid();
  const timestampHeader = (Date.now() / 1000).toFixed();
  const token = 'dsfsdfsdfsf';
  const signatureHeader = CryptoJS.SHA256(timestampHeader + token + nonce + timestampHeader).toString(CryptoJS.enc.Hex);
  return request({
    url: 'https://yzh.gdgov.cn/yzm-generator/generateCode',
    method: 'POST',
    headers: {
      'x-yzm-nonce': nonce,
      'x-yzm-signature': signatureHeader,
      'x-yzm-paasid': token,
      'x-yzm-timestamp': timestampHeader,
      'Content-Type': 'application/json;charset=utf-8'
    },
    data: {
      id: data.id,
      name: data.name,
      areaCode: data.areaCode,
      ext: data.ext
    }
  });
};

// 获取签名列表
export function getCheckinList(eventId: string) {
  return request({
    url: '/api/event_management/checkin/list',
    method: 'get',
    params: {
      event_id: eventId
    }
  });
}

// 更新事发地点 (用于将表单数据发送到服务器以更新某个事件的位置信息)
export function updateEventLocation(eventId: string, address: string, longitude: string, latitude: string) {
  return request({
    url: '/api/event_management/event/save_address',
    method: 'post',
    params: {
      eventId: eventId,
      address: address,
      longitude: longitude,
      latitude: latitude
    }
  });
}

// 新建事件
export function addEvent(data) {
  return request({
    url: '/api/event_management/event/create',
    method: 'post',
    data: data
  });
}
// 任务新增
export function addTask(data) {
  return request({
    url: '/api/taskRegistration/create',
    method: 'post',
    data: data
  });
}
// 任务查询
export function selectTask(params) {
  return request({
    url: '/api/taskRegistration/select',
    method: 'get',
    params: params
  });
}
// 任务更新
export function updateTaskRegistration(data) {
  return request({
    url: '/api/taskRegistration/update',
    method: 'put',
    data: data
  });
}

// 查看事业单位
export function getUnits(params) {
  return request({
    url: '/api/taskRegistration/selectUnit',
    method: 'get',
    params: params
  });
}

// 任务删除
export function deleteTask(data) {
  return request({
    url: '/api/taskRegistration/delete',
    method: 'post',
    data: data
  });
}
