From 2291a36fcb66026690656554143dcdc8b0e72ea0 Mon Sep 17 00:00:00 2001
From: KKbes <1620284052@qq.com>
Date: 星期二, 06 六月 2023 11:08:10 +0800
Subject: [PATCH] 产品配套搜索  lwc重写

---
 force-app/main/default/lwc/lexSearchSetProduct/lexSearchSetProduct.html        |   82 ++++++++++
 force-app/main/default/lwc/lexSearchSetProduct/lexSearchSetProduct.js          |  230 ++++++++++++++++++++++++++++
 force-app/main/default/lwc/lexSearchSetProduct/lexSearchSetProduct.js-meta.xml |   11 +
 force-app/main/default/classes/LexSearchSetProductController.cls-meta.xml      |    5 
 force-app/main/default/classes/LexSearchSetProductController.cls               |  149 ++++++++++++++++++
 5 files changed, 477 insertions(+), 0 deletions(-)

diff --git a/force-app/main/default/classes/LexSearchSetProductController.cls b/force-app/main/default/classes/LexSearchSetProductController.cls
new file mode 100644
index 0000000..3b4148e
--- /dev/null
+++ b/force-app/main/default/classes/LexSearchSetProductController.cls
@@ -0,0 +1,149 @@
+// author锛歬kbes
+
+public with sharing class LexSearchSetProductController {
+  
+  // public class  InitData{
+
+  //   @AuraEnabled
+  //   public Boolean isSelected;
+  //   @AuraEnabled
+  //   public String Name;
+  //   @AuraEnabled
+  //   public String Product_Set_CD;
+  //   @AuraEnabled
+  //   public Decimal Quantity;
+  //   @AuraEnabled
+  //   public String Quote_Select_Info;
+  //   @AuraEnabled
+  //   public Boolean Valid;
+
+
+
+  //   public InitData()
+
+  // }
+
+
+
+    public class SSPLine {
+        @AuraEnabled
+        public Boolean isSelected;
+        @AuraEnabled
+        public String setProductid ;
+        @AuraEnabled
+        public String setProductidFull;
+        @AuraEnabled
+        public Decimal Quantity;
+        @AuraEnabled
+        public Product_Set__c theObject;
+        @AuraEnabled
+        public String Name;      
+        @AuraEnabled
+        public String Product_Set_CD;
+        @AuraEnabled
+        public String Quote_Select_Info;
+        @AuraEnabled
+        public Boolean Valid;
+        @AuraEnabled
+        public String Report;
+
+
+        public SSPLine(Product_Set__c psl) {
+          isSelected = false;
+          setProductid = psl.id;
+            setProductid = setProductid.substring(0,15);
+            setProductidFull = psl.id;
+            Name = psl.Name;
+            Product_Set_CD= psl.Product_Set_CD__c;
+            Quantity = psl.Quantity__c;
+            Quote_Select_Info = psl.Quote_Select_Info__c;
+            Valid = psl.Valid_Status__c;
+            Report='鈼�';
+        }
+    }
+
+
+  //   @AuraEnabled
+  //   public static void SelectDone(List<SSPLine>  activities){
+  //       setPFString = '';
+  //       setProductidFullList = New List<String>();
+  //       if(activities.size()==1){
+  //         setPFString = activities[0].setProductidFull;
+  //       }else{
+  //         for(SSPLine arc : activities){
+  //           if(arc.isSelected==true){
+  //             if(String.isblank(setPFString)||setPFString==null){
+  //               setPFString = arc.setProductidFull;
+  //             }else{
+  //               setPFString = setPFString+','+arc.setProductidFull;
+  //             }
+              
+  //           }
+  //         }
+  //       }
+  //       DataStatus = 'Fin';
+  // }
+
+
+
+    @AuraEnabled
+    public static String getNeedParm1(){
+        String baseUrl = URL.getSalesforceBaseUrl().toExternalForm();
+        return baseUrl;
+    }
+
+    @AuraEnabled
+    public static String init(){
+        String reportid;
+        Report r = new Report();
+        List<Report> rs = new List<Report>();
+        rs=[Select id,DeveloperName,Name,NamespacePrefix from Report Where DeveloperName='Set_Product_Detail'];
+        if (rs.size()>0){
+            //system.debug('DeveloperName=' + rs[0].DeveloperName);
+            //system.debug('Name=' + rs[0].Name);
+            //system.debug('NamespacePrefix=' + rs[0].NamespacePrefix);
+            reportid = rs[0].id;
+            reportid = reportid.substring(0,15);
+        }
+        return reportid;
+  }
+
+  @AuraEnabled
+  public static List<SSPLine> getData(String SearchName , String filterName , String SearchCode){
+    String searchSql = 'Select id, name, Price__c, Product_Set_CD__c, Quantity__c,Valid_Status__c,Quote_Select_Info__c From Product_Set__c ';
+    String whereStr = 'Where Valid_Status__c = true ';
+    String whereSql = '';
+
+    if(SearchName != null && SearchName != ''){
+      whereSql += 'and name Like ' + '\'%' + SearchName + '%\' ';
+    }
+
+    if(filterName != null && filterName != ''){
+      whereSql += 'and Applicable_Department__c =\'' + filterName + '\'';
+    }
+
+    if(SearchCode != null && SearchCode != ''){
+      whereSql += 'and Product_Set_CD__c like ' + '\'%' + SearchCode + '%\' ';
+    }
+    searchSql = searchSql + whereStr + whereSql;
+
+    searchSql += ' order by Product_Set_CD__c limit 500';
+
+    List<Product_Set__c> cl = new List<Product_Set__c>();
+
+    cl = Database.query(searchSql);
+    List<SSPLine> activities = New List<SSPLine>();
+
+    for(Product_Set__c psl : cl){
+        SSPLine a = new SSPLine(psl);
+        activities.add(a);
+        
+    }
+    return activities;
+  }
+
+
+
+
+
+}
\ No newline at end of file
diff --git a/force-app/main/default/classes/LexSearchSetProductController.cls-meta.xml b/force-app/main/default/classes/LexSearchSetProductController.cls-meta.xml
new file mode 100644
index 0000000..d75b058
--- /dev/null
+++ b/force-app/main/default/classes/LexSearchSetProductController.cls-meta.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
+    <apiVersion>51.0</apiVersion>
+    <status>Active</status>
+</ApexClass>
diff --git a/force-app/main/default/lwc/lexSearchSetProduct/lexSearchSetProduct.html b/force-app/main/default/lwc/lexSearchSetProduct/lexSearchSetProduct.html
new file mode 100644
index 0000000..980c4ba
--- /dev/null
+++ b/force-app/main/default/lwc/lexSearchSetProduct/lexSearchSetProduct.html
@@ -0,0 +1,82 @@
+<template  >
+
+    <apex:outputPanel id="all">
+        <form id="mainForm">
+            <apex:pageBlock id="idSearchSetProduct" title={Label.Set_Search}>
+                <table width="900" border="0" style="background-color:#DCDCDC">
+                    <colgroup>
+                        <col width="12" />
+                        <col width="20" />
+                        <col width="20" />
+                        <col width="200" />
+                        <col width="200" />
+                        <col width="200" />
+                        <col width="100" />  
+                        <col width="128" />
+                    </colgroup>
+                    
+                    <tr>
+                        <td>&nbsp;</td>
+                        <th>{Label.Search_Condition}</th>
+                        <td>&nbsp;</td>
+                        <th>{Label.Set_Name}</th>
+                        <th>{Label.Set_Code}</th>
+                        <th>閫傜敤绉戝</th>
+                        <td>&nbsp;</td>
+                        <td>&nbsp;</td>
+                    </tr>
+                    <tr>
+                        <td>&nbsp;</td>
+                        <td>&nbsp;</td>
+                        <td>&nbsp;</td>
+                        <td><lightning-input value={SearchName}  onchange={getInput1} ></lightning-input>
+                        </td>
+                        <td><lightning-input value={SearchCode} onchange={getInput2}></lightning-input>
+                        </td>
+                        <td><lightning-combobox
+					            name="progress"
+					            value={value}
+					            placeholder="Select Progress"
+					            options={options}
+					            onchange={handleChange} >    
+					        </lightning-combobox></td>
+                        <td><div><lightning-button label={Label.Search} onclick={serContact}></lightning-button></div>
+                        </td>
+                        <td><div><lightning-button label="娣诲姞" onclick={SelectDone}></lightning-button></div>
+                        </td>
+                    </tr>
+                    <tr>
+                        <td style="border-bottom: 1px solid #888;" colspan="15">&nbsp;</td>
+                    </tr>
+                </table>
+                <table width="900" border="0" style="background-color:#DCDCDC">
+                    <tr>
+                        <td width="12">&nbsp;</td>
+                        <th valign="top">{Label.Search_Result}</th>
+                        <td width="20">&nbsp;</td>
+                        <td>
+                            <table border="0">
+                                <tr>
+                                    <td>
+                                    <div style="height: 300px;">
+                                    <lightning-datatable 
+                                            key-field="id"
+                                            data={data}
+                                            columns={columns}
+                                            onrowaction={handleRowAction}>
+                                            >
+
+                                    </lightning-datatable>
+
+                                    </div>
+                                    </td>
+                                </tr>
+                            </table>
+                        </td>
+                    </tr>
+                </table>
+            </apex:pageBlock>
+        </form>
+    </apex:outputPanel>
+
+</template>
diff --git a/force-app/main/default/lwc/lexSearchSetProduct/lexSearchSetProduct.js b/force-app/main/default/lwc/lexSearchSetProduct/lexSearchSetProduct.js
new file mode 100644
index 0000000..e9b52a1
--- /dev/null
+++ b/force-app/main/default/lwc/lexSearchSetProduct/lexSearchSetProduct.js
@@ -0,0 +1,230 @@
+import { LightningElement, track, wire ,api} from 'lwc';
+
+
+import LightningConfirm from 'lightning/confirm';
+
+
+import jquery183minjs from '@salesforce/resourceUrl/jquery183minjs';
+import PleaseWaitDialog from '@salesforce/resourceUrl/PleaseWaitDialog';
+
+import Selected from '@salesforce/label/c.Selected';
+import Set_Search from '@salesforce/label/c.Set_Search';
+import Search_Condition from '@salesforce/label/c.Search_Condition';
+import Set_Name  from '@salesforce/label/c.Set_Name';
+import Set_Code  from '@salesforce/label/c.Set_Code';
+import Search  from '@salesforce/label/c.Search';
+import Search_Result  from '@salesforce/label/c.Search_Result';
+import Quantity  from '@salesforce/label/c.Quantity';
+import valid  from '@salesforce/label/c.valid';
+    
+import getNeedParm1  from "@salesforce/apex/LexSearchSetProductController.getNeedParm1";
+import init  from "@salesforce/apex/LexSearchSetProductController.init";
+import getData  from "@salesforce/apex/LexSearchSetProductController.getData";
+
+
+    const columns = [
+    { label: '閫夋嫨', fieldName: 'Selected'  },
+    { label: 'Report', fieldName: 'ReportUrl' , type : 'url' ,
+    typeAttributes:{
+                label:{
+                    fieldName:'Report'
+                },
+                target:'_balank'
+            }
+    },
+    { label: '浜у搧閰嶅鍚�', fieldName: 'Name' },
+    { label: '浜у搧閰嶅缂栫爜', fieldName: 'Product_Set_CD' },
+    { label: '鏁伴噺', fieldName: 'Quantity' },
+    { label: '琛ヨ冻淇℃伅', fieldName: 'Quote_Select_Info' },
+    { label: '鏈夊姽', fieldName: 'Valid', },
+     {
+            type: 'action',
+            typeAttributes: {
+                rowActions: [
+                    { label: '鐐瑰嚮娣诲姞', name: '鐐瑰嚮娣诲姞' }
+                ]
+            }
+        }
+    ];
+
+
+
+//author : kkbes 
+
+export default class lexSearchSetProduct extends LightningElement {
+
+
+
+
+    Label = {
+        Set_Search,
+        Search_Condition,
+        Set_Name,
+        Set_Code,
+        Search,
+        Search_Result,
+        Selected,
+        Quantity,
+        valid
+    }
+
+
+
+    @api recordId;
+    IsLoading=true;
+    data = [];
+    columns = columns;
+    SSPLine;
+    
+    //鎼滅储闇�瑕佺殑鏁版嵁
+    inputData1;
+    inputData2;
+    //閫夋嫨妗嗗垵濮嬪��
+    value = '--鏃�--';
+
+    //鎼滅储鍑虹殑鏁版嵁 report onclick鎷兼帴闇�瑕佺殑鍙傛暟     
+    needParm2;
+
+
+
+    get options() {
+        return [
+            { label: '--鏃�--', value: '--鏃�--' },
+            { label: '娑堝寲绉�', value: '娑堝寲绉�' },
+            { label: '鍛煎惛绉�', value: '鍛煎惛绉�' },
+            { label: '鏅绉�', value: '鏅绉�' },
+            { label: '娉屽翱绉�', value: '娉屽翱绉�' },
+            { label: '濡囩', value: '濡囩' },
+            { label: '鑰抽蓟鍠夌', value: '鑰抽蓟鍠夌' },
+            { label: '鑳介噺', value: '鑳介噺' },
+            { label: 'SI', value: 'SI' },
+            { label: '澶栫閫氱敤', value: '澶栫閫氱敤' },
+        ];
+    }
+
+    handleChange(event) {
+        this.value = event.detail.value;
+    }
+
+    getInput1(event){
+        this.inputData1=event.detail.value;
+
+    }
+
+    getInput2(event){
+        this.inputData2=event.detail.value;
+
+    }
+
+
+
+    handleRowAction(event) {
+        const action = event.detail.action;
+        const row = event.detail.row;
+            switch (action.name) {
+                case '鐐瑰嚮娣诲姞':
+                    this.handleAdd(row);
+                    break;
+                default:
+                    break;
+            }
+    }
+
+    handleAdd(row) {
+        // Implement edit logic here
+        console.log('Editing row' + JSON.stringify(row));
+        this.SetProductId(row.setProductidFull);
+    }
+
+    SetProductId(str) {
+        console.log(str);
+        top.window.opener.setProductEntryGateway(str);
+        top.window.close();
+        }
+
+
+
+    connectedCallback(){
+        init().then(res=>{
+            if(res!=null){
+                this.needParm2=res;
+                console.log('needParm2='+res); 
+            }
+        }).catch(error=>{
+            console.log('error2');
+        });
+      
+    }
+
+
+
+
+    async SelectDone(){
+        var selectedRecords =  this.template.querySelector("lightning-datatable").getSelectedRows();
+            if(selectedRecords.length>0){
+                var Str;
+                for(var e=0;e<selectedRecords.length;e++){
+                    Str=Str+','+selectedRecords[e].setProductidFull;
+                }
+                top.window.opener.setProductEntryGateway(Str);
+                top.window.close();
+            }
+            else{
+                const result = await LightningConfirm.open({
+                message: '鎮ㄥ皻鏈�夊彇浠讳綍浜у搧閰嶅锛岀‘璁ゅ畬鎴愪箞锛�',
+                variant: 'headerless',
+                label: 'this is the aria-label value',
+                });
+                if(result){
+                    top.window.close();
+                }
+                else{
+                }
+            }
+    }
+
+
+    async serContact(){
+        console.log('into serContact')
+        var SearchName = this.inputData1;
+        var SearchCode = this.inputData2;
+        var filterName = this.value;
+            if(filterName == '--鏃�--'){
+                filterName='';
+            }
+            if(SearchName == undefined){
+                SearchName='';
+            }
+            if(SearchCode == undefined){
+                SearchCode = '';
+            }
+            await getData({SearchName : SearchName , SearchCode : SearchCode , filterName : filterName}).then(res=>{
+                if(res!=null){
+                    this.IsLoading=false;
+                    for(var i=0;i<res.length;i++){
+                        if(this.needParm2!=null){
+                            res[i].ReportUrl='/'+this.needParm2+res[i].setProductidFull;
+                        }
+                        else{
+                            res[i].ReportUrl='/';
+                        }
+                        if(res[i].Valid){
+                            res[i].Valid = '鏄�';
+                        }
+                        else{
+                            res[i].Valid = '鍚�';
+                        }
+                    }
+                    this.data=res;
+                }
+                }).catch(error=>{
+                    console.log(error);
+                })
+
+    }
+
+}
+
+
+
+
diff --git a/force-app/main/default/lwc/lexSearchSetProduct/lexSearchSetProduct.js-meta.xml b/force-app/main/default/lwc/lexSearchSetProduct/lexSearchSetProduct.js-meta.xml
new file mode 100644
index 0000000..e022317
--- /dev/null
+++ b/force-app/main/default/lwc/lexSearchSetProduct/lexSearchSetProduct.js-meta.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="lexSearchSetProduct">
+    <apiVersion>51.0</apiVersion>
+    <isExposed>true</isExposed>
+        <targets>
+        <target>lightning__RecordPage</target>
+        <target>lightning__AppPage</target>
+        <target>lightning__HomePage</target>
+        <target>lightning__RecordAction</target>
+    </targets>
+</LightningComponentBundle>
\ No newline at end of file

--
Gitblit v1.9.1