buli
2023-07-14 5b5c1e16deaa3a9d6d0ed1ffca390655ed103df7
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import { LightningElement,wire,track } from 'lwc';
import { CurrentPageReference } from 'lightning/navigation';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { NavigationMixin } from 'lightning/navigation';
import init from '@salesforce/apex/LexArriveGsDetailsController.init';
import proSale from '@salesforce/apex/LexArriveGsDetailsController.proSale';
import helpText from '@salesforce/label/c.LexArrivegsDetailsPageHelpText';
//table css 
import { loadStyle } from "lightning/platformResourceLoader";
import WrappedHeaderTable from "@salesforce/resourceUrl/lexdatatable";
 
export default class LexArriveGsDetails extends NavigationMixin(LightningElement) {
 
    @track eSetId;
    @track showSpinner = true;
    @track showPage = false;
    @track accountid;
    @track orderallcount;
    @track consumableorderdetailsCount;
    @track arrivetoorder = false;
    @track coc;
    @track consumableorderdetailsRecords = [];
    stylesLoaded = false;
    //是否一直显示提示
    @track isNoteStay = true;
    @track colms = [
        {label:'消耗品名称' , fieldName:'prodName', hideDefaultActions: true,wrapText:true},
        {label:'规格' , fieldName:'packing_list', hideDefaultActions: true,wrapText:true,initialWidth:50,cellAttributes: { alignment: "right" }},
        {label:'CFDA状态' , fieldName:'statusCFDA', hideDefaultActions: true,wrapText:true,initialWidth:100},
        {label:'注册证编码号' , fieldName:'approbation_No', hideDefaultActions: true,wrapText:true,initialWidth:125},
        {label:'注册证效期' , fieldName:'expiration_DateStr', hideDefaultActions: true,wrapText:true,initialWidth:115},
        {label:'使用期限' , fieldName:'Sterilization_limitStr', hideDefaultActions: true,wrapText:true,initialWidth:115},
        {label:'BarCode' , fieldName:'barCode', hideDefaultActions: true,initialWidth:250,wrapText:true},
        {label:'采购单价' ,type:'number',fieldName:'intraTradeList', hideDefaultActions: true,wrapText:true,initialWidth:120,typeAttributes:{minimumFractionDigits: 2},cellAttributes: { alignment: "right" }}
    ];
    label = {helpText};
 
    // 获取参数
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
        if (currentPageReference) {
            this.eSetId = currentPageReference.state?.EsetId;
        }
        console.log('CurrentPageReference:'+this.eSetId);
    }
 
    renderedCallback(){ 
        if (!this.stylesLoaded) {
            Promise.all([loadStyle(this, WrappedHeaderTable)])
                .then(() => {
                    console.log("Custom styles loaded");
                    this.stylesLoaded = true;
                })
                .catch((error) => {
                    console.error("Error loading custom styles");
                });
        }
    }
 
    //初始化
    connectedCallback(){
        init({eSetIdStr : this.eSetId})
        .then(result=>{
            this.showPage = true;
            this.isNoteStay = result.isNoteStay;
            if(result.result == 'Success'){
                this.coc = result.coc;
                if(this.coc.Arrive_Order__c != null && this.coc.Arrive_Order__c != ''){
                    this.coc['arriveOrder'] = this.coc.Arrive_Order__r.Name;
                }
                console.log('this.coc:'+JSON.stringify(this.coc));
                this.accountid = result.accountid;
                this.orderallcount = result.orderallcount;
                this.arrivetoorder = result.arrivetoorder;
                this.consumableorderdetailsCount = result.consumableorderdetailsCount;
                this.consumableorderdetailsRecords = result.consumableorderdetailsRecords;
                for(var i in this.consumableorderdetailsRecords){
                    if(this.consumableorderdetailsRecords[i].esd != null){
                        this.consumableorderdetailsRecords[i]['recordId'] = this.consumableorderdetailsRecords[i].esd.Id;
                        if(this.consumableorderdetailsRecords[i].esd.Consumable_Product__c != null && this.consumableorderdetailsRecords[i].esd.Consumable_Product__c != ''){
                            this.consumableorderdetailsRecords[i]['prodName'] = this.consumableorderdetailsRecords[i].esd.Consumable_Product__r.Name__c;
                        }
                        // this.consumableorderdetailsRecords[i]['prodName'] = this.consumableorderdetailsRecords[i].prodName;
                        this.consumableorderdetailsRecords[i]['barCode'] = this.consumableorderdetailsRecords[i].esd.Bar_Code__c;
                        this.consumableorderdetailsRecords[i]['intraTradeList'] = this.consumableorderdetailsRecords[i].esd.Intra_Trade_List_RMB__c;
                        console.log("Intra_Trade_List_RMB__c:"+this.consumableorderdetailsRecords[i].esd.Intra_Trade_List_RMB__c);
                    }
                    if(this.consumableorderdetailsRecords[i].Prod != null){
                        this.consumableorderdetailsRecords[i]['statusCFDA'] = this.consumableorderdetailsRecords[i].Prod.SFDA_Status__c;
                    }
                }
                this.showSpinner = false;
            }else {
                this.showSpinner = false;
                console.log("error:"+result.errorMsg);
                this.showMyToast('初始化失败',result.errorMsg,'error');
            }
        })
        .catch(error=>{
            this.showSpinner = false;
            this.showPage = true;
            console.log("error:"+error);
            this.showMyToast('初始化失败',error,'error');
        })
    }
 
    proSale(){
        this.showSpinner = true;
        proSale({
            cocStr : JSON.stringify(this.coc),
            orderallcountParm : this.orderallcount,
            consumableorderdetailsCountParm : this.consumableorderdetailsCount,
            eSetIdStr : this.eSetId
        })
        .then(result=>{
            if(result.result == 'Success'){
                var url = result.url;
                const config = {
                    type: 'standard__webPage',
                    attributes: {
                       url: url
                    }
                };
                this[NavigationMixin.Navigate](config);
            }else {
                this.showSpinner = false;
                console.log("error:"+result.errorMsg);
                this.showMyToast('出库失败',result.errorMsg,'error');
            }
        })
        .catch(error=>{
            this.showPage = true;
            this.showSpinner = false;
            console.log("error:"+error);
            this.showMyToast('出库失败',error,'error');
        })
    }
 
    clickOrder(){
        if(this.coc.Arrive_Order__c != null && this.coc.Arrive_Order__c != ''){
            const config = {
                type: 'standard__webPage',
                attributes: {
                   url: '/detail/'+this.coc.Arrive_Order__c
                }
            };
            this[NavigationMixin.Navigate](config);
        }
    }
 
    showMyToast(title, message, variant) {
        console.log('show custom message');
        var iconName = '';
        var content = '';
        if(variant == 'success'){
           iconName = 'utility:check';
        }else{
           iconName = 'utility:error';
        }
        if(message != ''){
           content = '<h2><strong>'+title+'<strong/></h2><h5>'+message+'</h5>';
        }else{
           content = '<h2><strong>'+title+'<strong/></h2>';
        }
        this.template.querySelector('c-common-toast').
        showToast(variant,content,iconName,10000);
        // var mode;
        // if(this.isNoteStay){
        //     mode ='sticky';
        // }else{
        //     mode = 'dismissable';
        // }
        // const evt = new ShowToastEvent({
        //     title: title,
        //     message: message,
        //     variant: variant,
        //     mode: mode
        // });
        // this.dispatchEvent(evt);
     }
}