binxie
2024-01-16 1b08402678deb31bba4a347bfd388eba8360cbc1
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
import { LightningElement ,api, wire, track} from 'lwc';
import {CurrentPageReference} from 'lightning/navigation';
import { CloseActionScreenEvent } from 'lightning/actions';
//备品智能化 2023-11-15 Add by dzk Start 同步报价产品方法引用
import initGetQuoteProLine  from '@salesforce/apex/LexOPDPlanProdController.initGetQuoteProLine';
import createQuotePREData  from '@salesforce/apex/LexOPDPlanProdController.createQuotePREData';
//备品智能化 2023-11-15 Add by dzk End
import init  from '@salesforce/apex/LexOPDPlanProdController.initOriginal';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
 
//备品智能化 2023-11-20 Add by dzk Start 同步报价产品时,状态验证
const event = new ShowToastEvent({
                    message:
                    "只有草案中才可以进行同步报价产品。",
                    variant : "error" 
});
//备品智能化 同步报价产品页面,按钮验证
const event1 = new ShowToastEvent({
                    message:
                    "请至少选择一个报价产品,进行同步。",
                    variant : "error" 
});
//备品智能化 同步报价产品时,验证是否有询价
const event2 = new ShowToastEvent({
                    message:
                    "无询价的OPD计划无需同步报价产品。",
                    variant : "error" 
});
//备品智能化 2023-11-20 Add by dzk End 
export default class lexSynchronousQuoteProduct extends LightningElement {
    @api recordId;
         OPDPlan;
    //备品智能化 2023-11-20 Add by dzk Start 报价产品页面显示
    @track data;      
    @track selectCreateProductLine = [];
    @track showquotefalg = false;
    @track columns = [{
            label: '产品名称',
            fieldName: 'Name',
            type: 'text',
            cellAttributes: {
                alignment: 'left'
            },
            hideDefaultActions: true,
        },
        {
            label: '报价编码',
            fieldName: 'QuoteNo',
            type: 'text',
            cellAttributes: {
                alignment: 'left'
            },
            hideDefaultActions: true,
        },
        {
            label: '产品代码',
            fieldName: 'ProductCode',
            type: 'text',
            cellAttributes: {
                alignment: 'left'
            },
            hideDefaultActions: true,
        },
        {
            label: '产品型号',
            fieldName: 'ProductModel',
            type: 'text',
            cellAttributes: {
                alignment: 'left'
            },
            hideDefaultActions: true,
        },
   
    ];
    //备品智能化 2023-11-20 Add by dzk End
 
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
        if (currentPageReference) {
            const urlValue = currentPageReference.state.recordId;
            if (urlValue) {
                let str = `${urlValue}`;
                this.recordId = str;
            }
        }
    }
 
    connectedCallback(){
        init({recordId:this.recordId}).then(res=>{
            if (res!=null) {
                console.log(res);
                this.OPDPlan=res;
                this.SynchronousQuoteProduct().then(res=>{
          
                }); 
            }
            else{
                const eventInItError = new dispatchEvent({
                    message : '页面初始化错误,请联系管理员',
                    variant : 'error'
                });
                this.dispatchEvent(eventInItError);
                return;
            }
 
        });
    }
    
    //备品智能化 2023-11-20 Add by dzk Start 显示OPD——询价——报价——报价行项目数据
    @wire(initGetQuoteProLine, { recordId: '$recordId' })
    wiredQuoteItems({error,data}) {
        if (data) {
            this.data = data;
        } else if (error) {
            console.log('页面初始化错误------' + JSON.stringify(error));
        }
    }
    // 取消关闭按钮
    CancelProduct(){
        this.showquotefalg = false;
        this.dispatchEvent(new CloseActionScreenEvent());
    }
 
    // 计划备品复选框勾选
    handleRowData(event) {
        const selectedRows = event.detail.selectedRows;
        this.selectCreateProductLine = selectedRows;
        console.log('选中的数据---------' + JSON.stringify(selectedRows));
    }
 
    // 保存按钮
    SynchronousProducts(){
        if(this.selectCreateProductLine.length == 0){
            this.dispatchEvent(event1);
            return;
        } 
        createQuotePREData({ records: JSON.stringify(this.selectCreateProductLine),recordId:this.recordId }).then(result => {
            console.error('处理结果:', result);
            // 处理 Apex 方法的返回结果
        }).catch(error => {
           // 处理错误
            console.error('发生错误:', error);
        });
                this.showquotefalg = false;
        this.dispatchEvent(new CloseActionScreenEvent());
        setTimeout(function () {
            //1秒后执行刷新
            window.location.reload();
        }, 1000);
        
    }
    //备品智能化 2023-11-20 Add by dzk End
    async SynchronousQuoteProduct(){
        var opdstagename = this.OPDPlan.Status__c;
        var oppId = this.OPDPlan.Related_Opportunity1_ID__c;
        if(opdstagename !== '草案中' ){
            this.dispatchEvent(event);
            this.dispatchEvent(new CloseActionScreenEvent());
            this.showquotefalg = false;
            return;
        } 
        if(oppId === '' || oppId === null || oppId === undefined){
            this.dispatchEvent(event2);
            this.dispatchEvent(new CloseActionScreenEvent());
            this.showquotefalg = false;
            return;
        }   
        this.showquotefalg = true;
    }
 
}