"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.getFileDetail = exports.getChildList = exports.downloadImage = exports.delImage = void 0;
exports.saveImage = saveImage;
var _message = _interopRequireDefault(require("@alifd/next/lib/message"));
var _request = _interopRequireDefault(require("../../utils/request"));
// 上传文件
function saveImage(data) {
  return new Promise(function (resolve, reject) {
    (0, _request["default"])({
      url: '/api/gzmpc-lowcode/file/upload',
      method: 'post',
      data: data,
      headers: {
        'Content-Type': 'multipart/form-data;'
      }
    }).then(function (res) {
      resolve(res.data);
      _message["default"].success('上传成功');
    })["catch"](function (err) {
      reject(err);
    });
  });
}

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

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

// 获取图片附件详情
exports.delImage = delImage;
var getFileDetail = function getFileDetail(fileId) {
  return new Promise(function (resolve, reject) {
    (0, _request["default"])({
      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([]);
    });
  });
};

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