buli
2023-05-30 41ad0c0840a6135b7acf2280f0eebdc29bf6479b
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;
        //解决整数没有小数点方法
        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({