KKbes
2023-06-06 2291a36fcb66026690656554143dcdc8b0e72ea0
产品配套搜索  lwc重写
5个文件已添加
477 ■■■■■ 已修改文件
force-app/main/default/classes/LexSearchSetProductController.cls 149 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/LexSearchSetProductController.cls-meta.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/lwc/lexSearchSetProduct/lexSearchSetProduct.html 82 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/lwc/lexSearchSetProduct/lexSearchSetProduct.js 230 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/lwc/lexSearchSetProduct/lexSearchSetProduct.js-meta.xml 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/LexSearchSetProductController.cls
New file
@@ -0,0 +1,149 @@
// author:kkbes
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;
  }
}
force-app/main/default/classes/LexSearchSetProductController.cls-meta.xml
New file
@@ -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>
force-app/main/default/lwc/lexSearchSetProduct/lexSearchSetProduct.html
New file
@@ -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>
force-app/main/default/lwc/lexSearchSetProduct/lexSearchSetProduct.js
New file
@@ -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);
                })
    }
}
force-app/main/default/lwc/lexSearchSetProduct/lexSearchSetProduct.js-meta.xml
New file
@@ -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>