import { Http,Util } from '@/utils';
import EntityService from '../entity-service';



/**
 * 文档服务对象基类
 *
 * @export
 * @class EMDRWGServiceBase
 * @extends {EntityServie}
 */
export default class EMDRWGServiceBase extends EntityService {

    /**
     * Creates an instance of  EMDRWGServiceBase.
     * 
     * @param {*} [opts={}]
     * @memberof  EMDRWGServiceBase
     */
    constructor(opts: any = {}) {
        super(opts);
    }

    /**
     * 初始化基础数据
     *
     * @memberof EMDRWGServiceBase
     */
    public initBasicData(){
        this.APPLYDEKEY ='emdrwg';
        this.APPDEKEY = 'emdrwgid';
        this.APPDENAME = 'emdrwgs';
        this.APPDETEXT = 'emdrwgname';
        this.APPNAME = 'eamweb';
        this.SYSTEMNAME = 'eam_practice05';
    }

// 实体接口

    /**
     * Select接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof EMDRWGServiceBase
     */
    public async Select(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.pfemp && context.emdrwg){
            return Http.getInstance().get(`/pfemps/${context.pfemp}/emdrwgs/${context.emdrwg}/select`,isloading);
        }
            return Http.getInstance().get(`/emdrwgs/${context.emdrwg}/select`,isloading);
    }

    /**
     * Update接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof EMDRWGServiceBase
     */
    public async Update(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.pfemp && context.emdrwg){
            return Http.getInstance().put(`/pfemps/${context.pfemp}/emdrwgs/${context.emdrwg}`,data,isloading);
        }
        let masterData:any = {};
        Object.assign(data,masterData);
            let res:any = await  Http.getInstance().put(`/emdrwgs/${context.emdrwg}`,data,isloading);
            return res;
    }

    /**
     * GetDraft接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof EMDRWGServiceBase
     */
    public async GetDraft(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.pfemp && true){
            return Http.getInstance().get(`/pfemps/${context.pfemp}/emdrwgs/getdraft`,isloading);
        }
        let res:any = await  Http.getInstance().get(`/emdrwgs/getdraft`,isloading);
        res.data.emdrwg = data.emdrwg;
        return res;
    }

    /**
     * Save接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof EMDRWGServiceBase
     */
    public async Save(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.pfemp && context.emdrwg){
            return Http.getInstance().post(`/pfemps/${context.pfemp}/emdrwgs/${context.emdrwg}/save`,data,isloading);
        }
        let masterData:any = {};
        Object.assign(data,masterData);
            let res:any = await  Http.getInstance().post(`/emdrwgs/${context.emdrwg}/save`,data,isloading);
            return res;
    }

    /**
     * CheckKey接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof EMDRWGServiceBase
     */
    public async CheckKey(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.pfemp && context.emdrwg){
            return Http.getInstance().post(`/pfemps/${context.pfemp}/emdrwgs/${context.emdrwg}/checkkey`,data,isloading);
        }
            return Http.getInstance().post(`/emdrwgs/${context.emdrwg}/checkkey`,data,isloading);
    }

    /**
     * Remove接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof EMDRWGServiceBase
     */
    public async Remove(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.pfemp && context.emdrwg){
            return Http.getInstance().delete(`/pfemps/${context.pfemp}/emdrwgs/${context.emdrwg}`,isloading);
        }
            return Http.getInstance().delete(`/emdrwgs/${context.emdrwg}`,isloading);

    }

    /**
     * Create接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof EMDRWGServiceBase
     */
    public async Create(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.pfemp && true){
            if(!data.srffrontuf || data.srffrontuf !== "1"){
                data[this.APPDEKEY] = null;
            }
            if(data.srffrontuf){
                delete data.srffrontuf;
            }
            return Http.getInstance().post(`/pfemps/${context.pfemp}/emdrwgs`,data,isloading);
        }
        let masterData:any = {};
        Object.assign(data,masterData);
        if(!data.srffrontuf || data.srffrontuf !== "1"){
            data[this.APPDEKEY] = null;
        }
        if(data.srffrontuf){
            delete data.srffrontuf;
        }
        let tempContext:any = JSON.parse(JSON.stringify(context));
        let res:any = await Http.getInstance().post(`/emdrwgs`,data,isloading);
        return res;
    }

    /**
     * Get接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof EMDRWGServiceBase
     */
    public async Get(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.pfemp && context.emdrwg){
            return Http.getInstance().get(`/pfemps/${context.pfemp}/emdrwgs/${context.emdrwg}`,isloading);
        }
            let res:any = await Http.getInstance().get(`/emdrwgs/${context.emdrwg}`,isloading);
            return res;

    }

    /**
     * FetchDefault接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof EMDRWGServiceBase
     */
    public async FetchDefault(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.pfemp && true){
            let tempData:any = JSON.parse(JSON.stringify(data));
            return Http.getInstance().get(`/pfemps/${context.pfemp}/emdrwgs/fetchdefault`,tempData,isloading);
        }
        let tempData:any = JSON.parse(JSON.stringify(data));
        return Http.getInstance().get(`/emdrwgs/fetchdefault`,tempData,isloading);
    }
}