19626
2023-05-15 f6a201e215d929bda9815e1689907d166a603519
force-app/main/default/lwc/lexPCLLostReportPage/lexPCLLostReportPage.js
@@ -4,7 +4,7 @@
 * @Author: chen jing wu
 * @Date: 2023-04-20 15:04:03
 * @LastEditors: chen jing wu
 * @LastEditTime: 2023-04-20 18:01:37
 * @LastEditTime: 2023-04-26 11:45:00
 */
/*
 * @Description: 
@@ -14,33 +14,265 @@
 * @LastEditors: chen jing wu
 * @LastEditTime: 2023-04-20 17:11:01
 */
import { LightningElement } from 'lwc';
const columns = [
    {
      label: '失单品牌',
      fieldName: 'LostBrandName__c',
      type: 'list',
      editable: true
    },
    {
      label: '失单对手型号',
      fieldName: 'LostProductName__c',
      type: 'text',
      editable: true
    },
    {
        label: '失单数量',
        fieldName: 'Quantity__c',
        type: 'number',
        editable: true
    },
    {
    label: '失单对手型号(手动)',
    fieldName: 'LostProductMannual__c',
    type: 'text',
    editable: true
    },
    {
    label: '失单产品类别',
    fieldName: 'ProductClass__c',
    type: 'list',
    editable: true
    },
    {
    label: '失单产品区分',
    fieldName: 'ProductCategory__c',
    type: 'list',
    editable: true
    }
    // ...
  ];
import { api, wire,track,LightningElement } from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import save from '@salesforce/apex/lexPCLLostReportLwcController.save';
import jquery from '@salesforce/resourceUrl/jquery183minjs';
import blockUIcss from '@salesforce/resourceUrl/blockUIcss';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { loadStyle, loadScript } from 'lightning/platformResourceLoader';
import setBrand from '@salesforce/apex/lexPCLLostReportLwcController.setBrand';
import setbrand from '@salesforce/apex/lexPCLLostReportLwcController.setBrand';
import init from '@salesforce/apex/lexPCLLostReportLwcController.init';
import initForApex from '@salesforce/apex/lexPCLLostReportLwcController.initForApex';
import multiSelectCombobox from 'c/multiSelectCombobox'
import searchBrands from '@salesforce/apex/lexPCLLostReportLwcController.searchBrands';
export default class LexPCLLostReportPage extends LightningElement {
    connectedCallback(){
        Promise.all([
           loadScript(this,jquery),
           loadStyle(this,blockUIcss)
        ]).then(() =>{
            save().then(result=>{
                if(result){
                    this.showToast(result,"success");
                    window.unblockUI();
                    this.clearBrandMannualName();
                }
            setBrand({
            }).then({
            });
            })
    @api oppId = '0061000001R2xjWAAR';
    @api lostReportId;
    @api pageStatus = 'Create';
    @api lostType = '失单';
    @api submitFlag;
    searchResult;
    LostReport;
    brandCount;
    brandOptions = [];
    connectedCallback() {
        this.initAll();
        searchBrands().then(result=>{
            this.brandOptions = JSON.parse(result);
            console.log(this.brandOptions);
            const multiCombobox = this.template.querySelector('c-multi-select-combobox');
            multiCombobox.refreshOptions(this.brandOptions);
        }).catch(error=>{
            console.log("error");
            console.log(error);
        });
    }
    //失单类型
    RecordTypeOptions = [{ label: '--无--', value: '' },
                    { label: '失单', value: '失单' },
                    { label: '部分失单', value: '部分失单' }];
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
            console.log(111);
            console.log(currentPageReference);
        if (currentPageReference) {
            const urlValue = currentPageReference.state.recordId;
            if (urlValue) {
            let str = `${urlValue}`;
            console.log("str");
            console.log(str);
            this.oppId = str;
            }
        }
    }
    // connectedCallback(){
    //     this.initAll();
    // }
    // connectedCallback(){
    //     console.log("1");
    //     initForApex({
    //         oppId1: this.oppId,
    //         lostReportId1: this.lostReportId,
    //         pageStatus1: this.pageStatus,
    //         lostType1: this.lostType,
    //         submitFlag1: this.submitFlag
    //     }).then(()=>{
    //         console.log("2");
    //         init().then(result=>{
    //             console.log("3");
    //             console.log(result);
    //             if(result.message == '提交成功!'){
    //                 this.showToast(result.message,"success");
    //                 this.LostReport = result.LostReport;
    //             }else{
    //                 console.log("211");
    //                 this.showToast(result.message,"error");
    //                 console.log("985");
    //             }
    //         });
    //     });
    // }
    initAll(){
        console.log(this.oppId);
        console.log(this.lostReportId);
        console.log(this.pageStatus);
        console.log(this.lostType);
        console.log(this.submitFlag);
        initForApex({
                    oppId1: this.oppId,
                    lostReportId1: this.lostReportId,
                    pageStatus1: this.pageStatus,
                    lostType1: this.lostType,
                    submitFlag1: this.submitFlag
                }).then(()=>{
                    console.log("2");
                    init().then(result=>{
                        console.log("3");
                        console.log(result);
                        if(result.message == '提交成功!'){
                            this.showToast(result.message,"success");
                            this.LostReport = result.LostReport;
                        }else{
                            console.log("211");
                            //this.showToast(result.message,"error");
                            console.log("985");
                        }
                    });
                });
    }
    getParamValue(paramName) {
        // Use the URLSearchParams API to get the value of a query parameter
        const params = new URLSearchParams(window.location.search);
        return params.get(paramName);
    }
    saveJs() {
        save().then(result=>{
            if(result){
                this.showToast(result,"success");
                this.clearBrandMannualName();
            }
        })
    }
    addBrandJs() {
        addBrand().then(()=>{
        });
    }
    submitJS() {
        submit().then(result=>{
            if(result.get('error')){
                this.showToast(result.get('error'),"error");
            }else{
                this[NavigationMixin.Navigate]({
                    type: 'standard__recordPage',
                    attributes: {
                        uri: result.get('uri'),
                        Id: result.get('Id'),
                        pageStatus: result.get('pageStatus'),
                        submitFlag: result.get('submitFlag')
                    }
                });
            }
        });
    }
    addProductJs(number) {
        addProduct().then(()=>{
        });
    }
    RemoveJs(number) {
        Remove().then(()=>{
        });
    }
    // add tcm 20211118 start
    searchJs(topNum, secondNum) {
        search().then(()=>{
        });
    }
    get pageStatusIsCreateOrEdit() {
        return this.pageStatus === 'Create' || this.pageStatus === 'Edit';
    }
    // add tcm 20211118 end
    setLostTotalAmount() {
        //console.log('setLostTotalAmount start:');
        var totalAmount = this.template.querySelector('[data-id="LostTotalAmount"]');
        var totalAmountHidden = this.template.querySelector('[data-id="LostTotalAmountHidden"]');
        var brandAmountObjects = this.template.querySelectorAll('[data-id^="BrandContent:LostPriceOut"]');
        var brandCompanyObjects = this.template.querySelectorAll('[data-id^="BrandContent:Lost_By_CompanyOut"]');
        if (!!totalAmount && !!totalAmountHidden) {
            var tempLostAmount = 0.0;
            var brandCount = parseInt(this.brandCount);
            //console.log(brandCount);
            for (var i = 0; i < brandCount; i++) {
                var brandAmountObject = brandAmountObjects[i];
                var brandCompanyObject = brandCompanyObjects[i];
                if (!!brandAmountObject && !!brandCompanyObject) {
                    var brandCompanyText = brandCompanyObject.innerText;
                    var brandCompanyValue = brandCompanyObject.value;
                    if (!!brandCompanyText && brandCompanyText !== '--无--' && !!brandCompanyValue) {
                        var brandAmount = parseFloat(brandAmountObject.value);
                        tempLostAmount = tempLostAmount + brandAmount;
                    }
                }
            }
            totalAmount.innerHTML = toNumComma(tempLostAmount);
            totalAmountHidden.value = tempLostAmount;
        }
        //console.log('setLostTotalAmount end');
    }
    setBrandName(brandNumber) {
        setbrand().then(()=>{
            this.clearBrandMannualName();
        });
    }
    setBrandMannualName(brandNumber) {
        setbrandmannual().then(()=>{
        });
    }
    // 失单品牌不等于其他时,失单品牌(手动)清空并且不允许填写,失单品牌等于其他时,失单对手型号不可用  thh 2022-01-13 start
    clearBrandMannualName(){
        if (this.template.querySelector('[id$="Lost_By_CompanyOut"]').value === '其他') {
            this.template.querySelector('[id$="LostProduct"]').setAttribute('disabled', true);
        } else {
            this.template.querySelector('[id$="Lost_By_Company_MannualOut:Lost_By_Company_Mannual"]').value = '';
            this.template.querySelector('[id$="Lost_By_Company_MannualOut:Lost_By_Company_Mannual"]').setAttribute('disabled', true);
        }
    }
    cancel() {
        // Navigate to the specified opportunity page using the NavigationMixin
        this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                recordId: this.oppId,
                actionName: 'view'
            }
        });
    }
    showToast(msg,type) {
@@ -52,84 +284,5 @@
        this.dispatchEvent(event);
        this.dispatchEvent(new CloseActionScreenEvent());
    }
    saveJs() {
        blockme();
        save();
    }
    addBrandJs() {
        blockme();
        addBrand();
    }
    submitJS() {
        blockme();
        submit();
    }
    addProductJs(number) {
        blockme();
        addProduct(number);
    }
    RemoveJs(number) {
        blockme();
        Remove(number);
    }
    // add tcm 20211118 start
    searchJs(topNum, secondNum) {
        blockme();
        search(topNum, secondNum);
    }
    // add tcm 20211118 end
    setLostTotalAmount() {
        //console.log('setLostTotalAmount start:');
        var totalAmount = document.getElementById("allPage:allForm:allBlock:EditPage:LostReport:lstReport:LostTotalAmountOut:LostTotalAmount");
        var totalAmountHidden = document.getElementById("allPage:allForm:allBlock:LostTotalAmount");
        if (!!totalAmount && !!totalAmountHidden) {
            var tempLostAmount = 0.0;
            var i = 0;
            var brandCount = parseInt("{!brandCount}");
            //console.log(brandCount);
            for (var i = 0; i < brandCount; i++) {
                var brandAmountObject =
                    document.getElementById("allPage:allForm:allBlock:EditPage:LostBrands:" +
                        i + ":LostBrand:BrandContent:LostPriceOut:LostPrice");
                var brandCompanyObject =
                    document.getElementById("allPage:allForm:allBlock:EditPage:LostBrands:" +
                        i + ":LostBrand:BrandContent:Lost_By_CompanyOut:Lost_By_Company");
                if (!!brandAmountObject && !!brandCompanyObject) {
                    var brandCompanyText = brandCompanyObject.innerText;
                    var brandCompanyValue = brandCompanyObject.value;
                    if (!!brandCompanyText && brandCompanyText != '--无--' && !!brandCompanyValue) {
                        var brandAmount = localParseFloat(brandAmountObject.value);
                        //console.log('brandAmount:'+brandAmount);
                        tempLostAmount = tempLostAmount + brandAmount;
                    }
                }
            }
            totalAmount.innerHTML = toNumComma(tempLostAmount);
            totalAmountHidden.value = tempLostAmount;
        }
        //console.log('setLostTotalAmount end');
    }
    setBrandName(brandNumber) {
        blockme();
        setbrand(brandNumber);
    }
    setBrandMannualName(brandNumber) {
        blockme();
        setbrandmannual(brandNumber);
    }
    // 失单品牌不等于其他时,失单品牌(手动)清空并且不允许填写,失单品牌等于其他时,失单对手型号不可用  thh 2022-01-13 start
    clearBrandMannualName(){
        if(document.getElementById('allPage:allForm:allBlock:EditPage:LostBrands:0:LostBrand:BrandContent:Lost_By_CompanyOut:Lost_By_Company').value == '其他'){
            j$(escapeVfId('allPage:allForm:allBlock:EditPage:LostBrands:0:LostBrand:productTable:0:LostProduct')).attr("disabled", true);
        } else{
            document.getElementById('allPage:allForm:allBlock:EditPage:LostBrands:0:LostBrand:BrandContent:Lost_By_Company_MannualOut:Lost_By_Company_Mannual').value = '';
            j$(escapeVfId('allPage:allForm:allBlock:EditPage:LostBrands:0:LostBrand:BrandContent:Lost_By_Company_MannualOut:Lost_By_Company_Mannual')).attr("disabled", true);
        }
    }
    // 失单品牌不等于其他时,失单品牌(手动)清空并且不允许填写,失单品牌等于其他时,失单对手型号不可用  thh 2022-01-13 end
}