/*
 * @Author: cclu lkrnchocolateaaron@gmail.com
 * @Date: 2022-03-25 16:09:05
 * @LastEditors: zzy 411037547@qq.com
 * @LastEditTime: 2022-07-18 00:16:45
 * @FilePath: \cloud-platform\src\services\picture.ts
 * @Description: 系统内图片增删改查接口
 */
import request from '@/utils/request';
import requestAHYD from '@/utils/requestAHYD';
import { tableList } from '@/utils/format';

// 上传图片的公共方法
// 上传图片信息（文件格式传输） 入参数据： TableId【数据表内码】 TableName【数据表名称】 ImageName【图片名称】
export async function uploadPicture(uploadFilds?: any) {
    return await request(`/Picture/UploadPicture`, {
        method: 'POST',
        data: uploadFilds
    })
}


export async function uploadAHYDPicture(uploadFilds?: any) {
    return await requestAHYD(`/Picture/UploadPicture`, {
        method: 'POST',
        data: uploadFilds
    })
}

export async function SavePicture(uploadFilds?: any) {

    return await request(`/Picture/SaveImgFile`, {
        method: 'POST',
        data: uploadFilds
    })

}

//  获取附件图片
export async function getPictureList(id: number, TableType?: string) {
    const data = await request(`/Picture/GetPictureList?TableId=${id}&TableType=${TableType || ''}`, {
        method: 'GET'
    })

    if (data.Result_Code !== 100) {
        return {
            data: [],
            current: 1,
            pageSize: 10,
            total: 0,
            success: false
        }
    }
    return tableList(data.Result_Data);
}

//  删除图片
export async function deleteAHYDPicture(imagepath: string, id: number, TableName?: string, TableType?: string) {

    const data = await requestAHYD(`/Picture/DeletePicture?imagepath=${imagepath}&imageid=${id}&TableName=${TableName || ''}&TableType=${TableType || ''}`, {
        method: 'POST'
    })

    if (data.Result_Code !== 100) {
        return false
    }

    return true
}

//  删除图片
export async function deletePicture(imagepath: string, id: number, TableName?: string, TableType?: string) {

    const data = await request(`/Picture/DeletePicture?imagepath=${imagepath}&imageid=${id}&TableName=${TableName || ''}&TableType=${TableType || ''}`, {
        method: 'POST'
    })

    if (data.Result_Code !== 100) {
        return false
    }

    return true
}
//  删除多张图片
export async function deleteMultiPicture(params: { imagepath: string, id: number, TableName?: string, TableType?: string }[]) {

    const data = await request(`/Picture/DeleteMultiPicture`, {
        method: 'POST',
        data: params
    })

    if (data.Result_Code !== 100) {
        return false
    }

    return true
}
