binxie
2024-01-18 b1d36ea3e6653e59bd767aa192c688ee0d9d4c58
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
 * @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 ,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';
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
    @api url;
    status;//状态
    profileId;//profileId id
    systemProfileId;
    TwoS1_Sales_Hospital;
    TwoS4_Sales_Manager;
    IsLoading = true;
    @track
    flag = false;
    
    @wire(CurrentPageReference)
     getStateParameters(currentPageReference) {
         if (currentPageReference) {
            this.url = currentPageReference.state.backgroundContext;
            const urlValue = currentPageReference.state.recordId;
           if (urlValue) {
             let str = `${urlValue}`;
             this.recordId = str;
           }
         }
     }
    
 
    connectedCallback(){
        Promise.all([
            loadStyle(this, lwcCSS)
        ]);
        init({
            recordId: this.recordId
        }).then(result => {
                this.IsLoading = false;
                this.status = result.status;
                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();
        })        
    }
 
    //招标项目 失单
    LoseButton(){
        console.log(this.url,'xxx')
        sqlResult({id: this.recordId}).then(result=>{
            //简档权限 2S1_销售医院担当 2S4_销售管理者 系统管理员
            if (this.profileId != this.TwoS1_Sales_Hospital  && this.profileId != this.TwoS4_Sales_Manager && this.profileId != this.systemProfileId) {
                this.showToast("您没有权限,无法创建询价提交失单。","error");
                return;
            }
            // 判断内部确认状态
            if(this.status == '01.待确认'|| this.status == '02.不相关'){ 
                this.showToast("状态为待确认或不相关,不可以做失单。","error");
                return;
            }
            // 判断是否需要新建询价
            if(this.status == '05.询价中'|| this.status == '06.成交' || this.status == '07.部分成交' || this.status == '08.失单' || result.length > 0){
                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;
                        }                 
                    });
            }
            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) {
        const event = new ShowToastEvent({
            message: msg,
            variant: type
        });
        this.dispatchEvent(event);
        this.dispatchEvent(new CloseActionScreenEvent());
    }
}