import request from '../axios';

export const getList = (current=1, size=20, params={}) => {
  return request({
    url: '/api/bigdata/visual/list',
    method: 'get',
    params: {
      ...params,
      current,
      size,
    }
  })
}

export const getDetail = (id) => {
  return request({
    url: '/api/bigdata/visual/detail',
    method: 'get',
    params: {
      id
    }
  })
}

export const remove = (ids) => {
  return request({
    url: '/api/bigdata/visual/remove',
    method: 'post',
    params: {
      ids,
    }
  })
}

export const add = (data) => {
  return request({
    url: '/api/bigdata/visual/save',
    method: 'post',
    data: {
      visual: {
        password: data.password,
        category: data.category,
        status: data.status,
        title: data.title,
      },
      config: {
        detail: JSON.stringify({
          name: data.title,
          width: data.width,
          height: data.height,
          scale: 1,
          backgroundImage: '',
          backgroundColor:"rgba(255, 255, 255, 1)",
          url: '',
          mark: {},
          gradeShow: false,
          gradeLen: 30,
        }),
        component: '[]'
      },
    }
  })
}

export const copy = (data) => {
  return request({
    url: '/api/bigdata/visual/save',
    method: 'post',
    data: {
      visual: {
        password: data.visual.password,
        category: data.visual.category,
        status: data.visual.status,
        title: data.visual.title,
        orderIndex: data.visual.orderIndex,
        backgroundUrl: data.visual.backgroundUrl,
      },
      config: {
        detail: data.config.detail,
        component: data.config.component
      },
    }
  })
}

export const copyObj = (id) => {
  return request({
    url: '/api/bigdata/visual/copy',
    method: 'post',
    params: {
      id,
    }
  })
}

export const update = (data) => {
  return request({
    url: '/api/bigdata/visual/submit',
    method: 'post',
    data: {
      "id": data.id,
      "password": data.password,
      "category": data.category,
      "status": data.status,
      "title": data.title,
      "orderIndex": data.orderIndex,
    }
  })
}
export const getObj = (id) => request({
  url: '/api/bigdata/visual/detail',
  method: 'get',
  params: {
    id
  }
});
export const updateComponent = (data) => request({
  url: '/api/bigdata/visual/updateVisual',
  method: 'post',
  data: data
});

export const uploadImg = (file) => {
  return request({
    url: '/api/file/uploadFile',
    method: 'post',
    data: file,
    headers: { "Content-Type": "multipart/form-data" }
  })
}
export const videlUploadImg = (file) => {
  console.log(file)
  return request({
    url: 'http://video-api.a.tiandunyun.com/upload/image',
    method: 'post',
    data: file,
    headers: { "Content-Type": "multipart/form-data" }
  })
}
export  const  updateHistoryComponent= (data) => request({
  url: '/api/historyreportinfo/updateVisualBackgroudUrl',
  method: 'post',
  data: data
});

export const objkey = (url,method,params) => request({
  url: url,
  method: method,
  params: params
});

