import { Http,Util } from '@/utils';
import EntityService from '../entity-service';
import LostLogic from '@/service/opportunity/lost-logic';
import WinLogic from '@/service/opportunity/win-logic';



/**
 * 商机服务对象基类
 *
 * @export
 * @class OpportunityServiceBase
 * @extends {EntityServie}
 */
export default class OpportunityServiceBase extends EntityService {

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

    /**
     * 初始化基础数据
     *
     * @memberof OpportunityServiceBase
     */
    public initBasicData(){
        this.APPLYDEKEY ='opportunity';
        this.APPDEKEY = 'opportunityid';
        this.APPDENAME = 'opportunities';
        this.APPDETEXT = 'opportunityname';
        this.APPNAME = 'crm';
        this.SYSTEMNAME = 'ibizbusinesscentral';
    }

// 实体接口

    /**
     * Select接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof OpportunityServiceBase
     */
    public async Select(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.account && context.contact && context.opportunity){
            return Http.getInstance().get(`/accounts/${context.account}/contacts/${context.contact}/opportunities/${context.opportunity}/select`,isloading);
        }
        if(context.contact && context.opportunity){
            return Http.getInstance().get(`/contacts/${context.contact}/opportunities/${context.opportunity}/select`,isloading);
        }
        if(context.account && context.opportunity){
            return Http.getInstance().get(`/accounts/${context.account}/opportunities/${context.opportunity}/select`,isloading);
        }
            return Http.getInstance().get(`/opportunities/${context.opportunity}/select`,isloading);
    }

    /**
     * Create接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof OpportunityServiceBase
     */
    public async Create(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.account && context.contact && true){
            let masterData:any = {};
        let quotesData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_quotes'),'undefined')){
            quotesData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_quotes') as any);
            if(quotesData && quotesData.length && quotesData.length > 0){
                quotesData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.quoteid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.quotes = quotesData;
        let opportunitycompetitorsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors'),'undefined')){
            opportunitycompetitorsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors') as any);
            if(opportunitycompetitorsData && opportunitycompetitorsData.length && opportunitycompetitorsData.length > 0){
                opportunitycompetitorsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.relationshipsid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunitycompetitors = opportunitycompetitorsData;
        let opportunityproductsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts'),'undefined')){
            opportunityproductsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts') as any);
            if(opportunityproductsData && opportunityproductsData.length && opportunityproductsData.length > 0){
                opportunityproductsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.opportunityproductid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunityproducts = opportunityproductsData;
            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(`/accounts/${context.account}/contacts/${context.contact}/opportunities`,data,isloading);
            this.tempStorage.setItem(tempContext.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(tempContext.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(tempContext.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
        }
        if(context.contact && true){
            let masterData:any = {};
        let quotesData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_quotes'),'undefined')){
            quotesData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_quotes') as any);
            if(quotesData && quotesData.length && quotesData.length > 0){
                quotesData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.quoteid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.quotes = quotesData;
        let opportunitycompetitorsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors'),'undefined')){
            opportunitycompetitorsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors') as any);
            if(opportunitycompetitorsData && opportunitycompetitorsData.length && opportunitycompetitorsData.length > 0){
                opportunitycompetitorsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.relationshipsid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunitycompetitors = opportunitycompetitorsData;
        let opportunityproductsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts'),'undefined')){
            opportunityproductsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts') as any);
            if(opportunityproductsData && opportunityproductsData.length && opportunityproductsData.length > 0){
                opportunityproductsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.opportunityproductid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunityproducts = opportunityproductsData;
            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(`/contacts/${context.contact}/opportunities`,data,isloading);
            this.tempStorage.setItem(tempContext.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(tempContext.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(tempContext.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
        }
        if(context.account && true){
            let masterData:any = {};
        let quotesData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_quotes'),'undefined')){
            quotesData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_quotes') as any);
            if(quotesData && quotesData.length && quotesData.length > 0){
                quotesData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.quoteid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.quotes = quotesData;
        let opportunitycompetitorsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors'),'undefined')){
            opportunitycompetitorsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors') as any);
            if(opportunitycompetitorsData && opportunitycompetitorsData.length && opportunitycompetitorsData.length > 0){
                opportunitycompetitorsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.relationshipsid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunitycompetitors = opportunitycompetitorsData;
        let opportunityproductsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts'),'undefined')){
            opportunityproductsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts') as any);
            if(opportunityproductsData && opportunityproductsData.length && opportunityproductsData.length > 0){
                opportunityproductsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.opportunityproductid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunityproducts = opportunityproductsData;
            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(`/accounts/${context.account}/opportunities`,data,isloading);
            this.tempStorage.setItem(tempContext.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(tempContext.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(tempContext.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
        }
        let masterData:any = {};
        let quotesData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_quotes'),'undefined')){
            quotesData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_quotes') as any);
            if(quotesData && quotesData.length && quotesData.length > 0){
                quotesData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.quoteid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.quotes = quotesData;
        let opportunitycompetitorsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors'),'undefined')){
            opportunitycompetitorsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors') as any);
            if(opportunitycompetitorsData && opportunitycompetitorsData.length && opportunitycompetitorsData.length > 0){
                opportunitycompetitorsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.relationshipsid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunitycompetitors = opportunitycompetitorsData;
        let opportunityproductsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts'),'undefined')){
            opportunityproductsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts') as any);
            if(opportunityproductsData && opportunityproductsData.length && opportunityproductsData.length > 0){
                opportunityproductsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.opportunityproductid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunityproducts = opportunityproductsData;
        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(`/opportunities`,data,isloading);
        this.tempStorage.setItem(tempContext.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
        this.tempStorage.setItem(tempContext.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
        this.tempStorage.setItem(tempContext.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
        return res;
    }

    /**
     * Update接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof OpportunityServiceBase
     */
    public async Update(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.account && context.contact && context.opportunity){
            let masterData:any = {};
        let quotesData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_quotes'),'undefined')){
            quotesData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_quotes') as any);
            if(quotesData && quotesData.length && quotesData.length > 0){
                quotesData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.quoteid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.quotes = quotesData;
        let opportunitycompetitorsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors'),'undefined')){
            opportunitycompetitorsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors') as any);
            if(opportunitycompetitorsData && opportunitycompetitorsData.length && opportunitycompetitorsData.length > 0){
                opportunitycompetitorsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.relationshipsid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunitycompetitors = opportunitycompetitorsData;
        let opportunityproductsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts'),'undefined')){
            opportunityproductsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts') as any);
            if(opportunityproductsData && opportunityproductsData.length && opportunityproductsData.length > 0){
                opportunityproductsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.opportunityproductid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunityproducts = opportunityproductsData;
            Object.assign(data,masterData);
            let res:any = await Http.getInstance().put(`/accounts/${context.account}/contacts/${context.contact}/opportunities/${context.opportunity}`,data,isloading);
            this.tempStorage.setItem(context.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
        }
        if(context.contact && context.opportunity){
            let masterData:any = {};
        let quotesData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_quotes'),'undefined')){
            quotesData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_quotes') as any);
            if(quotesData && quotesData.length && quotesData.length > 0){
                quotesData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.quoteid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.quotes = quotesData;
        let opportunitycompetitorsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors'),'undefined')){
            opportunitycompetitorsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors') as any);
            if(opportunitycompetitorsData && opportunitycompetitorsData.length && opportunitycompetitorsData.length > 0){
                opportunitycompetitorsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.relationshipsid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunitycompetitors = opportunitycompetitorsData;
        let opportunityproductsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts'),'undefined')){
            opportunityproductsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts') as any);
            if(opportunityproductsData && opportunityproductsData.length && opportunityproductsData.length > 0){
                opportunityproductsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.opportunityproductid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunityproducts = opportunityproductsData;
            Object.assign(data,masterData);
            let res:any = await Http.getInstance().put(`/contacts/${context.contact}/opportunities/${context.opportunity}`,data,isloading);
            this.tempStorage.setItem(context.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
        }
        if(context.account && context.opportunity){
            let masterData:any = {};
        let quotesData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_quotes'),'undefined')){
            quotesData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_quotes') as any);
            if(quotesData && quotesData.length && quotesData.length > 0){
                quotesData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.quoteid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.quotes = quotesData;
        let opportunitycompetitorsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors'),'undefined')){
            opportunitycompetitorsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors') as any);
            if(opportunitycompetitorsData && opportunitycompetitorsData.length && opportunitycompetitorsData.length > 0){
                opportunitycompetitorsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.relationshipsid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunitycompetitors = opportunitycompetitorsData;
        let opportunityproductsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts'),'undefined')){
            opportunityproductsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts') as any);
            if(opportunityproductsData && opportunityproductsData.length && opportunityproductsData.length > 0){
                opportunityproductsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.opportunityproductid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunityproducts = opportunityproductsData;
            Object.assign(data,masterData);
            let res:any = await Http.getInstance().put(`/accounts/${context.account}/opportunities/${context.opportunity}`,data,isloading);
            this.tempStorage.setItem(context.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
        }
        let masterData:any = {};
        let quotesData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_quotes'),'undefined')){
            quotesData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_quotes') as any);
            if(quotesData && quotesData.length && quotesData.length > 0){
                quotesData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.quoteid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.quotes = quotesData;
        let opportunitycompetitorsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors'),'undefined')){
            opportunitycompetitorsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors') as any);
            if(opportunitycompetitorsData && opportunitycompetitorsData.length && opportunitycompetitorsData.length > 0){
                opportunitycompetitorsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.relationshipsid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunitycompetitors = opportunitycompetitorsData;
        let opportunityproductsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts'),'undefined')){
            opportunityproductsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts') as any);
            if(opportunityproductsData && opportunityproductsData.length && opportunityproductsData.length > 0){
                opportunityproductsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.opportunityproductid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunityproducts = opportunityproductsData;
        Object.assign(data,masterData);
            let res:any = await  Http.getInstance().put(`/opportunities/${context.opportunity}`,data,isloading);
            this.tempStorage.setItem(context.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
    }

    /**
     * Remove接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof OpportunityServiceBase
     */
    public async Remove(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.account && context.contact && context.opportunity){
            return Http.getInstance().delete(`/accounts/${context.account}/contacts/${context.contact}/opportunities/${context.opportunity}`,isloading);
        }
        if(context.contact && context.opportunity){
            return Http.getInstance().delete(`/contacts/${context.contact}/opportunities/${context.opportunity}`,isloading);
        }
        if(context.account && context.opportunity){
            return Http.getInstance().delete(`/accounts/${context.account}/opportunities/${context.opportunity}`,isloading);
        }
            return Http.getInstance().delete(`/opportunities/${context.opportunity}`,isloading);
    }

    /**
     * Get接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof OpportunityServiceBase
     */
    public async Get(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.account && context.contact && context.opportunity){
            let res:any = await Http.getInstance().get(`/accounts/${context.account}/contacts/${context.contact}/opportunities/${context.opportunity}`,isloading);
            this.tempStorage.setItem(context.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
        }
        if(context.contact && context.opportunity){
            let res:any = await Http.getInstance().get(`/contacts/${context.contact}/opportunities/${context.opportunity}`,isloading);
            this.tempStorage.setItem(context.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
        }
        if(context.account && context.opportunity){
            let res:any = await Http.getInstance().get(`/accounts/${context.account}/opportunities/${context.opportunity}`,isloading);
            this.tempStorage.setItem(context.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
        }
            let res:any = await Http.getInstance().get(`/opportunities/${context.opportunity}`,isloading);
            this.tempStorage.setItem(context.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
    }

    /**
     * GetDraft接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof OpportunityServiceBase
     */
    public async GetDraft(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.account && context.contact && true){
            let res:any = await Http.getInstance().get(`/accounts/${context.account}/contacts/${context.contact}/opportunities/getdraft`,isloading);
            res.data.opportunity = data.opportunity;
            this.tempStorage.setItem(context.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
        }
        if(context.contact && true){
            let res:any = await Http.getInstance().get(`/contacts/${context.contact}/opportunities/getdraft`,isloading);
            res.data.opportunity = data.opportunity;
            this.tempStorage.setItem(context.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
        }
        if(context.account && true){
            let res:any = await Http.getInstance().get(`/accounts/${context.account}/opportunities/getdraft`,isloading);
            res.data.opportunity = data.opportunity;
            this.tempStorage.setItem(context.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
        }
        let res:any = await  Http.getInstance().get(`/opportunities/getdraft`,isloading);
        res.data.opportunity = data.opportunity;
            this.tempStorage.setItem(context.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
        return res;
    }

    /**
     * Active接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof OpportunityServiceBase
     */
    public async Active(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.account && context.contact && context.opportunity){
            let masterData:any = {};
        let quotesData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_quotes'),'undefined')){
            quotesData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_quotes') as any);
            if(quotesData && quotesData.length && quotesData.length > 0){
                quotesData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.quoteid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.quotes = quotesData;
        let opportunitycompetitorsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors'),'undefined')){
            opportunitycompetitorsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors') as any);
            if(opportunitycompetitorsData && opportunitycompetitorsData.length && opportunitycompetitorsData.length > 0){
                opportunitycompetitorsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.relationshipsid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunitycompetitors = opportunitycompetitorsData;
        let opportunityproductsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts'),'undefined')){
            opportunityproductsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts') as any);
            if(opportunityproductsData && opportunityproductsData.length && opportunityproductsData.length > 0){
                opportunityproductsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.opportunityproductid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunityproducts = opportunityproductsData;
            Object.assign(data,masterData);
            let res:any = await Http.getInstance().post(`/accounts/${context.account}/contacts/${context.contact}/opportunities/${context.opportunity}/active`,data,isloading);
            this.tempStorage.setItem(context.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
        }
        if(context.contact && context.opportunity){
            let masterData:any = {};
        let quotesData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_quotes'),'undefined')){
            quotesData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_quotes') as any);
            if(quotesData && quotesData.length && quotesData.length > 0){
                quotesData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.quoteid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.quotes = quotesData;
        let opportunitycompetitorsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors'),'undefined')){
            opportunitycompetitorsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors') as any);
            if(opportunitycompetitorsData && opportunitycompetitorsData.length && opportunitycompetitorsData.length > 0){
                opportunitycompetitorsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.relationshipsid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunitycompetitors = opportunitycompetitorsData;
        let opportunityproductsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts'),'undefined')){
            opportunityproductsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts') as any);
            if(opportunityproductsData && opportunityproductsData.length && opportunityproductsData.length > 0){
                opportunityproductsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.opportunityproductid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunityproducts = opportunityproductsData;
            Object.assign(data,masterData);
            let res:any = await Http.getInstance().post(`/contacts/${context.contact}/opportunities/${context.opportunity}/active`,data,isloading);
            this.tempStorage.setItem(context.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
        }
        if(context.account && context.opportunity){
            let masterData:any = {};
        let quotesData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_quotes'),'undefined')){
            quotesData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_quotes') as any);
            if(quotesData && quotesData.length && quotesData.length > 0){
                quotesData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.quoteid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.quotes = quotesData;
        let opportunitycompetitorsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors'),'undefined')){
            opportunitycompetitorsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors') as any);
            if(opportunitycompetitorsData && opportunitycompetitorsData.length && opportunitycompetitorsData.length > 0){
                opportunitycompetitorsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.relationshipsid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunitycompetitors = opportunitycompetitorsData;
        let opportunityproductsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts'),'undefined')){
            opportunityproductsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts') as any);
            if(opportunityproductsData && opportunityproductsData.length && opportunityproductsData.length > 0){
                opportunityproductsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.opportunityproductid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunityproducts = opportunityproductsData;
            Object.assign(data,masterData);
            let res:any = await Http.getInstance().post(`/accounts/${context.account}/opportunities/${context.opportunity}/active`,data,isloading);
            this.tempStorage.setItem(context.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
        }
            return Http.getInstance().post(`/opportunities/${context.opportunity}/active`,data,isloading);
    }

    /**
     * CheckKey接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof OpportunityServiceBase
     */
    public async CheckKey(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.account && context.contact && context.opportunity){
            let masterData:any = {};
        let quotesData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_quotes'),'undefined')){
            quotesData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_quotes') as any);
            if(quotesData && quotesData.length && quotesData.length > 0){
                quotesData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.quoteid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.quotes = quotesData;
        let opportunitycompetitorsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors'),'undefined')){
            opportunitycompetitorsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors') as any);
            if(opportunitycompetitorsData && opportunitycompetitorsData.length && opportunitycompetitorsData.length > 0){
                opportunitycompetitorsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.relationshipsid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunitycompetitors = opportunitycompetitorsData;
        let opportunityproductsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts'),'undefined')){
            opportunityproductsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts') as any);
            if(opportunityproductsData && opportunityproductsData.length && opportunityproductsData.length > 0){
                opportunityproductsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.opportunityproductid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunityproducts = opportunityproductsData;
            Object.assign(data,masterData);
            let res:any = await Http.getInstance().post(`/accounts/${context.account}/contacts/${context.contact}/opportunities/${context.opportunity}/checkkey`,data,isloading);
            this.tempStorage.setItem(context.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
        }
        if(context.contact && context.opportunity){
            let masterData:any = {};
        let quotesData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_quotes'),'undefined')){
            quotesData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_quotes') as any);
            if(quotesData && quotesData.length && quotesData.length > 0){
                quotesData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.quoteid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.quotes = quotesData;
        let opportunitycompetitorsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors'),'undefined')){
            opportunitycompetitorsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors') as any);
            if(opportunitycompetitorsData && opportunitycompetitorsData.length && opportunitycompetitorsData.length > 0){
                opportunitycompetitorsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.relationshipsid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunitycompetitors = opportunitycompetitorsData;
        let opportunityproductsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts'),'undefined')){
            opportunityproductsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts') as any);
            if(opportunityproductsData && opportunityproductsData.length && opportunityproductsData.length > 0){
                opportunityproductsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.opportunityproductid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunityproducts = opportunityproductsData;
            Object.assign(data,masterData);
            let res:any = await Http.getInstance().post(`/contacts/${context.contact}/opportunities/${context.opportunity}/checkkey`,data,isloading);
            this.tempStorage.setItem(context.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
        }
        if(context.account && context.opportunity){
            let masterData:any = {};
        let quotesData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_quotes'),'undefined')){
            quotesData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_quotes') as any);
            if(quotesData && quotesData.length && quotesData.length > 0){
                quotesData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.quoteid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.quotes = quotesData;
        let opportunitycompetitorsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors'),'undefined')){
            opportunitycompetitorsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors') as any);
            if(opportunitycompetitorsData && opportunitycompetitorsData.length && opportunitycompetitorsData.length > 0){
                opportunitycompetitorsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.relationshipsid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunitycompetitors = opportunitycompetitorsData;
        let opportunityproductsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts'),'undefined')){
            opportunityproductsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts') as any);
            if(opportunityproductsData && opportunityproductsData.length && opportunityproductsData.length > 0){
                opportunityproductsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.opportunityproductid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunityproducts = opportunityproductsData;
            Object.assign(data,masterData);
            let res:any = await Http.getInstance().post(`/accounts/${context.account}/opportunities/${context.opportunity}/checkkey`,data,isloading);
            this.tempStorage.setItem(context.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
        }
            return Http.getInstance().post(`/opportunities/${context.opportunity}/checkkey`,data,isloading);
    }

    /**
     * Lose接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof OpportunityServiceBase
     */
    public async Lose(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        let appLogic:LostLogic = new LostLogic({context:JSON.parse(JSON.stringify(context)),data:JSON.parse(JSON.stringify(data))});
        const result = await appLogic.onExecute(context,data,isloading?true:false);
        return {status:200,data:result};
    }

    /**
     * Save接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof OpportunityServiceBase
     */
    public async Save(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.account && context.contact && context.opportunity){
            let masterData:any = {};
        let quotesData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_quotes'),'undefined')){
            quotesData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_quotes') as any);
            if(quotesData && quotesData.length && quotesData.length > 0){
                quotesData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.quoteid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.quotes = quotesData;
        let opportunitycompetitorsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors'),'undefined')){
            opportunitycompetitorsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors') as any);
            if(opportunitycompetitorsData && opportunitycompetitorsData.length && opportunitycompetitorsData.length > 0){
                opportunitycompetitorsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.relationshipsid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunitycompetitors = opportunitycompetitorsData;
        let opportunityproductsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts'),'undefined')){
            opportunityproductsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts') as any);
            if(opportunityproductsData && opportunityproductsData.length && opportunityproductsData.length > 0){
                opportunityproductsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.opportunityproductid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunityproducts = opportunityproductsData;
            Object.assign(data,masterData);
            let res:any = await Http.getInstance().post(`/accounts/${context.account}/contacts/${context.contact}/opportunities/${context.opportunity}/save`,data,isloading);
            this.tempStorage.setItem(context.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
        }
        if(context.contact && context.opportunity){
            let masterData:any = {};
        let quotesData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_quotes'),'undefined')){
            quotesData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_quotes') as any);
            if(quotesData && quotesData.length && quotesData.length > 0){
                quotesData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.quoteid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.quotes = quotesData;
        let opportunitycompetitorsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors'),'undefined')){
            opportunitycompetitorsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors') as any);
            if(opportunitycompetitorsData && opportunitycompetitorsData.length && opportunitycompetitorsData.length > 0){
                opportunitycompetitorsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.relationshipsid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunitycompetitors = opportunitycompetitorsData;
        let opportunityproductsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts'),'undefined')){
            opportunityproductsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts') as any);
            if(opportunityproductsData && opportunityproductsData.length && opportunityproductsData.length > 0){
                opportunityproductsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.opportunityproductid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunityproducts = opportunityproductsData;
            Object.assign(data,masterData);
            let res:any = await Http.getInstance().post(`/contacts/${context.contact}/opportunities/${context.opportunity}/save`,data,isloading);
            this.tempStorage.setItem(context.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
        }
        if(context.account && context.opportunity){
            let masterData:any = {};
        let quotesData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_quotes'),'undefined')){
            quotesData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_quotes') as any);
            if(quotesData && quotesData.length && quotesData.length > 0){
                quotesData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.quoteid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.quotes = quotesData;
        let opportunitycompetitorsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors'),'undefined')){
            opportunitycompetitorsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors') as any);
            if(opportunitycompetitorsData && opportunitycompetitorsData.length && opportunitycompetitorsData.length > 0){
                opportunitycompetitorsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.relationshipsid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunitycompetitors = opportunitycompetitorsData;
        let opportunityproductsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts'),'undefined')){
            opportunityproductsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts') as any);
            if(opportunityproductsData && opportunityproductsData.length && opportunityproductsData.length > 0){
                opportunityproductsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.opportunityproductid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunityproducts = opportunityproductsData;
            Object.assign(data,masterData);
            let res:any = await Http.getInstance().post(`/accounts/${context.account}/opportunities/${context.opportunity}/save`,data,isloading);
            this.tempStorage.setItem(context.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
        }
        let masterData:any = {};
        let quotesData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_quotes'),'undefined')){
            quotesData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_quotes') as any);
            if(quotesData && quotesData.length && quotesData.length > 0){
                quotesData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.quoteid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.quotes = quotesData;
        let opportunitycompetitorsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors'),'undefined')){
            opportunitycompetitorsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunitycompetitors') as any);
            if(opportunitycompetitorsData && opportunitycompetitorsData.length && opportunitycompetitorsData.length > 0){
                opportunitycompetitorsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.relationshipsid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunitycompetitors = opportunitycompetitorsData;
        let opportunityproductsData:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts'),'undefined')){
            opportunityproductsData = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_opportunityproducts') as any);
            if(opportunityproductsData && opportunityproductsData.length && opportunityproductsData.length > 0){
                opportunityproductsData.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.opportunityproductid = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.opportunityproducts = opportunityproductsData;
        Object.assign(data,masterData);
            let res:any = await  Http.getInstance().post(`/opportunities/${context.opportunity}/save`,data,isloading);
            this.tempStorage.setItem(context.srfsessionkey+'_quotes',JSON.stringify(res.data.quotes ? res.data.quotes : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunitycompetitors',JSON.stringify(res.data.opportunitycompetitors ? res.data.opportunitycompetitors : []));
            this.tempStorage.setItem(context.srfsessionkey+'_opportunityproducts',JSON.stringify(res.data.opportunityproducts ? res.data.opportunityproducts : []));
            return res;
    }

    /**
     * Win接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof OpportunityServiceBase
     */
    public async Win(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        let appLogic:WinLogic = new WinLogic({context:JSON.parse(JSON.stringify(context)),data:JSON.parse(JSON.stringify(data))});
        const result = await appLogic.onExecute(context,data,isloading?true:false);
        return {status:200,data:result};
    }

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

    /**
     * FetchLost接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof OpportunityServiceBase
     */
    public async FetchLost(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.account && context.contact && true){
            let tempData:any = JSON.parse(JSON.stringify(data));
            return Http.getInstance().get(`/accounts/${context.account}/contacts/${context.contact}/opportunities/fetchlost`,tempData,isloading);
        }
        if(context.contact && true){
            let tempData:any = JSON.parse(JSON.stringify(data));
            return Http.getInstance().get(`/contacts/${context.contact}/opportunities/fetchlost`,tempData,isloading);
        }
        if(context.account && true){
            let tempData:any = JSON.parse(JSON.stringify(data));
            return Http.getInstance().get(`/accounts/${context.account}/opportunities/fetchlost`,tempData,isloading);
        }
        let tempData:any = JSON.parse(JSON.stringify(data));
        return Http.getInstance().get(`/opportunities/fetchlost`,tempData,isloading);
    }

    /**
     * FetchTop5接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof OpportunityServiceBase
     */
    public async FetchTop5(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.account && context.contact && true){
            let tempData:any = JSON.parse(JSON.stringify(data));
            return Http.getInstance().get(`/accounts/${context.account}/contacts/${context.contact}/opportunities/fetchtop5`,tempData,isloading);
        }
        if(context.contact && true){
            let tempData:any = JSON.parse(JSON.stringify(data));
            return Http.getInstance().get(`/contacts/${context.contact}/opportunities/fetchtop5`,tempData,isloading);
        }
        if(context.account && true){
            let tempData:any = JSON.parse(JSON.stringify(data));
            return Http.getInstance().get(`/accounts/${context.account}/opportunities/fetchtop5`,tempData,isloading);
        }
        let tempData:any = JSON.parse(JSON.stringify(data));
        return Http.getInstance().get(`/opportunities/fetchtop5`,tempData,isloading);
    }

    /**
     * FetchWin接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof OpportunityServiceBase
     */
    public async FetchWin(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.account && context.contact && true){
            let tempData:any = JSON.parse(JSON.stringify(data));
            return Http.getInstance().get(`/accounts/${context.account}/contacts/${context.contact}/opportunities/fetchwin`,tempData,isloading);
        }
        if(context.contact && true){
            let tempData:any = JSON.parse(JSON.stringify(data));
            return Http.getInstance().get(`/contacts/${context.contact}/opportunities/fetchwin`,tempData,isloading);
        }
        if(context.account && true){
            let tempData:any = JSON.parse(JSON.stringify(data));
            return Http.getInstance().get(`/accounts/${context.account}/opportunities/fetchwin`,tempData,isloading);
        }
        let tempData:any = JSON.parse(JSON.stringify(data));
        return Http.getInstance().get(`/opportunities/fetchwin`,tempData,isloading);
    }
}