123
chenjingwu
2024-04-15 5d4f265aab8e9813eaa2a9d6eb6247955218f8ef
force-app/main/default/lwc/lexTenderingLostButton/lexTenderingLostButton.js
@@ -1,20 +1,37 @@
/*
 * @Author: zhangchunxu
 * @Date: 2023-08-13 18:57:20
 * @LastEditors: zhangchunxu
 * @LastEditTime: 2023-09-14 10:58:50
 *
 */
import { LightningElement,wire,track,api} from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import { CurrentPageReference ,NavigationMixin} from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import  init  from '@salesforce/apex/TenderingButtonController.initTenderingController';
import  sqlResult  from '@salesforce/apex/TenderingButtonController.sqlResult';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
export default class lexTenderingLostButton extends LightningElement {
import LightningConfirm from 'lightning/confirm';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader'
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
export default class lexTenderingLostButton extends NavigationMixin(LightningElement) {
    @api recordId;//当前这条数据的id
    id;//返回值的id  Tender_information__c招标项目的id
    @api url;
    status;//状态
    profileId;//profileId id
    systemProfileId;
    TwoS1_Sales_Hospital;
    TwoS4_Sales_Manager;
    IsLoading = true;
    @track
    flag = false;
    @wire(CurrentPageReference)
     getStateParameters(currentPageReference) {
         if (currentPageReference) {
           const urlValue = currentPageReference.state.recordId;
            this.url = currentPageReference.state.backgroundContext;
            const urlValue = currentPageReference.state.recordId;
           if (urlValue) {
             let str = `${urlValue}`;
             this.recordId = str;
@@ -24,25 +41,28 @@
    
    connectedCallback(){
        Promise.all([
            loadStyle(this, lwcCSS)
        ]);
        init({
            recordId: this.recordId
        }).then(result => {
                this.IsLoading = false;
                this.id = result.Id;
                this.status = result.status;
                this.profileId = result.profileId.slice(0,15);
                this.profileId = result.profileId;
                this.systemProfileId = result.systemProfileId;
                this.TwoS1_Sales_Hospital = result.TwoS1_Sales_Hospital;
                this.TwoS4_Sales_Manager = result.TwoS4_Sales_Manager;
                this.LoseButton();
                this.dispatchEvent(new CloseActionScreenEvent());
        }).catch(() => {
        }).finally(() => {
        });
        })
    }
    //失单
    //招标项目 失单
    LoseButton(){
        sqlResult({id: this.id}).then(result=>{
        console.log(this.url,'xxx')
        sqlResult({id: this.recordId}).then(result=>{
            //简档权限 2S1_销售医院担当 2S4_销售管理者 系统管理员
            if (this.profileId != '00e10000000xnp2' && this.profileId != '00e10000000xnpH' && this.profileId != '00e10000000Y3o5') {
            if (this.profileId != this.TwoS1_Sales_Hospital  && this.profileId != this.TwoS4_Sales_Manager && this.profileId != this.systemProfileId) {
                this.showToast("您没有权限,无法创建询价提交失单。","error");
                return;
            }
@@ -53,13 +73,58 @@
            }
            // 判断是否需要新建询价
            if(this.status == '05.询价中'|| this.status == '06.成交' || this.status == '07.部分成交' || this.status == '08.失单' || result.length > 0){
                if(confirm('此项目已关联询价,请确实是否新建询价提交失单。')) {
                }else{
                    return;
                }
                LightningConfirm.open({
                    message: '此项目已关联询价,请确实是否新建询价提交失单。',
                    variant: 'headerless',
                    label: 'this is the aria-label value',
                    }).then(res=>{
                        if(res) {
                            this.flag = true
                            // window.open(`/apex/TenderLostPage?id=${this.recordId}`,'','height=500,width=800,top=200,left=250,location=no');
                            // const defaultValues = encodeDefaultFieldValues({
                            //     oppId :this.id,
                            //     pageStatus:'',
                            //     lostType :"",
                            // });
                            // this[NavigationMixin.Navigate]({
                            //     type: 'standard__objectPage',
                            //     attributes: {
                            //         objectApiName: 'Tender_information__c',
                            //         actionName: 'new'
                            //     },
                            //     state:{
                            //         defaultFieldValues: defaultValues
                            //     }
                            // });
                            // this.dispatchEvent(new CloseActionScreenEvent());
                        }else{
                            this.dispatchEvent(new CloseActionScreenEvent());
                            return;
                        }
                    });
            }
            window.open(`/apex/TenderLostPage?id=${this.id}`,'','height=500,width=800,top=200,left=250,location=no');
            if(this.status == "04.待关联询价" || this.status == "03.不应标" || this.status == "09.终止"){
                this.flag = true
                // window.open(`/apex/TenderLostPage?id=${this.recordId}`,'','height=500,width=800,top=200,left=250,location=no');
                // const defaultValues = encodeDefaultFieldValues({
                //     oppId :this.id,
                //     pageStatus:'',
                //     lostType :"",
                // });
                // this[NavigationMixin.Navigate]({
                //     type: 'standard__objectPage',
                //     attributes: {
                //         objectApiName: 'Tender_information__c',
                //         actionName: 'new'
                //     },
                //     state:{
                //         defaultFieldValues: defaultValues
                //     }
                // });
                // this.dispatchEvent(new CloseActionScreenEvent());
            }
        })
    }
    showToast(msg,type) {
@@ -68,5 +133,6 @@
            variant: type
        });
        this.dispatchEvent(event);
        this.dispatchEvent(new CloseActionScreenEvent());
    }
}