import _Message from "@alifd/next/es/message";
import request from "../../utils/request";
// 上传文件
export function saveImage(data) {
  return new Promise(function (resolve, reject) {
    request({
      url: '/api/gzmpc-lowcode/file/upload',
      method: 'post',
      data: data,
      headers: {
        'Content-Type': 'multipart/form-data;'
      }
    }).then(function (res) {
      resolve(res.data);
      _Message.success('上传成功');
    })["catch"](function (err) {
      reject(err);
    });
  });
}

// 下载文件
export var downloadImage = function downloadImage(id) {
  return new Promise(function (resolve, reject) {
    request({
      url: "/api/gzmpc-lowcode/file/download?id=" + id,
      method: 'get',
      headers: {
        'Content-Type': 'multipart/form-data;'
      }
    }).then(function (res) {
      resolve(res);
      _Message.success('下载成功');
    })["catch"](function (err) {
      reject(err);
    });
  });
};

// 删除文件
export var delImage = function delImage(data) {
  return new Promise(function (resolve, reject) {
    request({
      url: '/api/gzmpc-lowcode/file/delete',
      method: 'POST',
      data: data,
      headers: {
        'Content-Type': 'multipart/form-data;'
      }
    }).then(function (res) {
      _Message.success('删除成功');
      resolve(res);
    })["catch"](function (err) {
      reject(err);
    });
  });
};

// 获取图片附件详情
export var getFileDetail = function getFileDetail(fileId) {
  return new Promise(function (resolve, reject) {
    request({
      url: "/api/gzmpc-lowcode/file/list?fileId=" + fileId,
      method: "get"
    }).then(function (res) {
      var _data$records;
      var data = res.data;
      var fileData = data === null || data === void 0 ? void 0 : (_data$records = data.records) === null || _data$records === void 0 ? void 0 : _data$records.map(function (item) {
        return {
          "uid": item.id,
          "id": item.id,
          "fileId": item.fileId,
          "name": item.fileName,
          "url": item.fileUrl,
          "downloadURL": item.fileUrl,
          "imgURL": item.thumbnailUrl ? item.thumbnailUrl : item.fileUrl,
          "state": "done",
          "fileExtension": item.fileExtension,
          "size": 100
        };
      });
      resolve(fileData);
    })["catch"](function (err) {
      reject([]);
    });
  });
};

// 获取枚举值列表-子
export var getChildList = function getChildList(parentId) {
  return new Promise(function (resolve, reject) {
    request({
      url: "/api/gzmpc-lowcode/enum/child-list?parentId=" + parentId,
      method: "GET"
    }).then(function (res) {
      resolve(res.data);
    });
  });
};