From 41ad0c0840a6135b7acf2280f0eebdc29bf6479b Mon Sep 17 00:00:00 2001
From: buli <137736985@qq.com>
Date: 星期二, 30 五月 2023 14:25:11 +0800
Subject: [PATCH] backup0530

---
 force-app/main/default/lwc/lexConsumableAccount/lexConsumableAccount.js |  190 +++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 165 insertions(+), 25 deletions(-)

diff --git a/force-app/main/default/lwc/lexConsumableAccount/lexConsumableAccount.js b/force-app/main/default/lwc/lexConsumableAccount/lexConsumableAccount.js
index f7bfe18..8687cd2 100644
--- a/force-app/main/default/lwc/lexConsumableAccount/lexConsumableAccount.js
+++ b/force-app/main/default/lwc/lexConsumableAccount/lexConsumableAccount.js
@@ -1,6 +1,7 @@
 import { LightningElement, wire, api, track } from "lwc";
 import { ShowToastEvent } from "lightning/platformShowToastEvent";
 import init from "@salesforce/apex/LexConsumableAccountController.init";
+import changeFiscalYearView from "@salesforce/apex/LexConsumableAccountController.changeFiscalYearView";
 import changelistView from "@salesforce/apex/LexConsumableAccountController.changelistView";
 import accountInit from "@salesforce/apex/LexConsumableAccountInfoController.init";
 //table css
@@ -165,12 +166,12 @@
     {
         label: "鎿嶄綔",
         fieldName: "Town__c",
-        type:'weeklyReport',
-        initialWidth:150,
+        type: 'weeklyReport',
+        initialWidth: 150,
         typeAttributes: {
             recordId: { fieldName: "Id" },
-            hospitalName : { fieldName: "Name" },
-            isShowButton : { fieldName: "isShowButton" },
+            hospitalName: { fieldName: "Name" },
+            isShowButton: { fieldName: "isShowButton" },
         },
         hideDefaultActions: true,
     }
@@ -253,7 +254,18 @@
         parentName: "",
     };
 
+
     stylesLoaded = false;
+
+    //璐㈠勾
+    @track fiscalYearOptions = [
+        { label: '鏈储骞�', value: 'thisYear' },
+        { label: '涓婁竴璐㈠勾', value: 'lastYear' },
+        { label: '涓婁竴璐㈠勾+鏈储骞�', value: 'allYear' },
+    ];
+    @track fiscalYearOption = 'thisYear';
+    @track topInfo = [];
+
     renderedCallback() {
         if (!this.stylesLoaded) {
             Promise.all([loadStyle(this, WrappedHeaderTable)])
@@ -338,6 +350,7 @@
             init({
                 pageSizeLWC: this.pageSize,
                 pageTokenLWC: this.currentPageToken,
+                fiscalYear: this.fiscalYearOption
             }).then((r) => {
                 r = JSON.parse(JSON.stringify(r));
                 console.log("r = " + JSON.stringify(r));
@@ -370,14 +383,18 @@
                         "this.listViewOptions = " + JSON.stringify(this.listViewOptions)
                     );
 
+                    console.log('r.entity.topInfo = ' + JSON.stringify(r.entity.topInfo))
                     //top10瀹㈡埛
-                    this.topAccountData = r.entity.acList;
+                    this.topInfo = r.entity.topInfo;
+                    console.log("this.topInfo = " + JSON.stringify(this.topInfo));
+                    this.topAccountData = this.topInfo.acList;
                     console.log(
                         "this.topAccountData = " + JSON.stringify(this.topAccountData)
                     );
-                    let proportionTest = 11;
-                    let proportionTest1 = 16;
+                    console.log('9/3 = ' + this.keepTwoDecimalStr(this.amend(9, 3, '/').toFixed(2)));
+                    let total = 100;
                     for (var i in this.topAccountData) {
+                        console.log('i = ' + i);
                         this.topAccountData[i]["NameUrl"] = "/lexconsumableaccount?AccId=" + this.topAccountData[i].Id;
                         this.topAccountData[i]["StateMasterName"] = this.topAccountData[i].State_Master__r.Name;
                         this.topAccountData[i]["StateMasterUrl"] = "/" + this.topAccountData[i].State_Master__c;
@@ -385,25 +402,30 @@
                         this.topAccountData[i]["CityMasterNameUrl"] = "/" + this.topAccountData[i].City_Master__c;
                         this.topAccountData[i]["RecordTypeName"] = this.topAccountData[i].RecordType.Name;
                         this.topAccountData[i]["isShowButton"] = true;
-
-                        this.topAccountData[i]["proportion"] = proportionTest + '%';
-                        if(proportionTest1 == 16){
-                            this.topAccountData[i]["proportion"] = proportionTest1 + '%';
-                            proportionTest1--;
-                        }
-                        proportionTest--;
+                        let number = this.keepTwoDecimalStr((this.amend(this.topInfo.deList[i], this.topInfo.saleAmount, '/') * 100).toFixed(2));
+                        total -= number;
+                        this.topAccountData[i]["proportion"] = number + '%';
                     }
 
-                    //鍏朵粬
-                    this.topAccountData.push({
-                        Name : '...',
-                        NameUrl : '/lexconsumableaccount',
-                        proportion : '30%',
-                        CityMasterName : '...',
-                        CityMasterNameUrl:'/lexconsumableaccount',
-                        Town__c:'...',
-                        isShowButton : false
-                    })
+                    // //鍏朵粬
+                    if (total != 100) {
+                        this.topAccountData.push({
+                            Name: '...',
+                            NameUrl: '/lexconsumableaccount',
+                            proportion: total.toFixed(2) + '%',
+                            CityMasterName: '...',
+                            CityMasterNameUrl: '/lexconsumableaccount',
+                            Town__c: '...',
+                            isShowButton: false
+                        })
+                    } else {
+                        let title = '';
+                        for (var key in this.fiscalYearOptions) {
+                            if (this.fiscalYearOption == this.fiscalYearOptions[key].value)
+                                title = this.fiscalYearOptions[key].label;
+                        }
+                        this.showMyToast(title, '鏃犳暟鎹�', 'Error');
+                    }
                     this.isShowSpinner = false;
                 } else {
                     console.log("r = " + JSON.stringify(r));
@@ -416,18 +438,136 @@
         }
     }
 
+    amend(num1, num2, symbol) {
+        var str1 = num1.toString(),
+            str2 = num2.toString(),
+            result,
+            str1Length,
+            str2Length;
+        //瑙e喅鏁存暟娌℃湁灏忔暟鐐规柟娉�
+        try {
+            str1Length = str1.split(".")[1].length;
+        } catch (error) {
+            str1Length = 0;
+        }
+        try {
+            str2Length = str2.split(".")[1].length;
+        } catch (error) {
+            str2Length = 0;
+        }
+        var step = Math.pow(10, Math.max(str1Length, str2Length));
+        console.log(step);
+        switch (symbol) {
+            case "+":
+                result = (num1 * step + num2 * step) / step;
+                break;
+            case "-":
+                result = (num1 * step - num2 * step) / step;
+                break;
+            case "*":
+                result = (num1 * step * (num2 * step)) / step / step;
+                break;
+            case "/":
+                result = (num1 * step) / (num2 * step);
+                break;
+            default:
+                break;
+        }
+        return result;
+    }
+
+
+    keepTwoDecimalStr(num) {
+        const result = Number(num.toString().match(/^\d+(?:\.\d{0,2})?/));
+        let s = result.toString();
+        let rs = s.indexOf('.');
+        if (rs < 0) {
+            rs = s.length;
+            s += '.';
+        }
+        while (s.length <= rs + 2) {
+            s += '0';
+        }
+        return s;
+    };
+
     dataChange(event) {
         let fieldName = event.target.getAttribute("data-field");
         let value = event.detail.value;
         console.log("fieldName = " + fieldName + " value = " + value);
         switch (fieldName) {
-            case "viewOption":
+            case 'viewOption':
                 this.viewOption = value;
                 this.changelistView();
                 break;
+            case 'fiscalYearOption':
+                this.fiscalYearOption = value;
+                this.changeFiscalYear();
+                break;
         }
     }
 
+    changeFiscalYear() {
+        this.isShowSpinner = true;
+        changeFiscalYearView({
+            fiscalYear: this.fiscalYearOption
+        }).then((r) => {
+            r = JSON.parse(JSON.stringify(r));
+            console.log("r = " + JSON.stringify(r));
+            if (r.status == "Success") {
+                //top10瀹㈡埛
+                this.topInfo = r.entity.topInfo;
+                console.log("this.topInfo = " + JSON.stringify(this.topInfo));
+                this.topAccountData = this.topInfo.acList;
+                console.log(
+                    "this.topAccountData = " + JSON.stringify(this.topAccountData)
+                );
+                let total = 100;
+                for (var i in this.topAccountData) {
+                    console.log('i = ' + i);
+                    this.topAccountData[i]["NameUrl"] = "/lexconsumableaccount?AccId=" + this.topAccountData[i].Id;
+                    this.topAccountData[i]["StateMasterName"] = this.topAccountData[i].State_Master__r.Name;
+                    this.topAccountData[i]["StateMasterUrl"] = "/" + this.topAccountData[i].State_Master__c;
+                    this.topAccountData[i]["CityMasterName"] = this.topAccountData[i].City_Master__r.Name;
+                    this.topAccountData[i]["CityMasterNameUrl"] = "/" + this.topAccountData[i].City_Master__c;
+                    this.topAccountData[i]["RecordTypeName"] = this.topAccountData[i].RecordType.Name;
+                    this.topAccountData[i]["isShowButton"] = true;
+                    let number = this.keepTwoDecimalStr((this.amend(this.topInfo.deList[i], this.topInfo.saleAmount, '/') * 100).toFixed(2));
+                    total -= number;
+                    this.topAccountData[i]["proportion"] = number + '%';
+                }
+
+                // //鍏朵粬
+                if (total != 100) {
+                    this.topAccountData.push({
+                        Name: '...',
+                        NameUrl: '/lexconsumableaccount',
+                        proportion: total.toFixed(2) + '%',
+                        CityMasterName: '...',
+                        CityMasterNameUrl: '/lexconsumableaccount',
+                        Town__c: '...',
+                        isShowButton: false
+                    })
+                } else {
+                    let title = '';
+                    for (var key in this.fiscalYearOptions) {
+                        if (this.fiscalYearOption == this.fiscalYearOptions[key].value)
+                            title = this.fiscalYearOptions[key].label;;
+                    }
+                    this.showMyToast(title, '鏃犳暟鎹�', 'Error');
+                }
+
+                this.isShowSpinner = false;
+            } else {
+                console.log("r = " + JSON.stringify(r));
+                this.showMyToast('Error', r.msg, 'Error');
+            }
+        }).catch((error) => {
+            console.log("error = " + JSON.stringify(error));
+            this.showMyToast('Error', '閿�閲忓墠鍗佸鎴峰垵濮嬪寲澶辫触', 'Error');
+        });
+    }
+
     changelistView() {
         this.isShowSpinner = true;
         changelistView({

--
Gitblit v1.9.1