buli
2023-05-23 07390e2fcb4adf27c928335bf27ae7939c5a80ad
force-app/main/default/lwc/lexConInvoiceView/lexConInvoiceView.js
@@ -13,7 +13,11 @@
import serContact from "@salesforce/apex/lexSearchAgencyHospitalController.serContact";
import detailsInit from "@salesforce/apex/LexConInvoicedetailsController.init";
import detailsSave from "@salesforce/apex/LexConInvoicedetailsController.save";
import deleteAtt from '@salesforce/apex/LexConsumableController.deleteAtt';
import { NavigationMixin } from "lightning/navigation";
//table css
import { loadStyle } from "lightning/platformResourceLoader";
import WrappedHeaderTable from "@salesforce/resourceUrl/lexdatatable";
const hospitalColumns = [
    {
@@ -21,6 +25,7 @@
        fieldName: "Name",
        initialWidth: 400,
        hideDefaultActions: true,
        wrapText: true,
    },
    {
        label: "省份",
@@ -44,41 +49,52 @@
        label: "出库日期",
        fieldName: "esdetProductOutDate",
        hideDefaultActions: true,
        wrapText: true,
    },
    {
        label: "出库单编码",
        fieldName: "esdetInvoicedet1ODlinkName",
        wrapText: true,
        hideDefaultActions: true,
        wrapText: true,
    },
    {
        label: "产品型号",
        fieldName: "esdetAssetModelNo",
        hideDefaultActions: true,
        wrapText: true,
        initialWidth: 400,
    },
    {
        label: "单位",
        fieldName: "esdetInvoiceUnit",
        hideDefaultActions: true,
        wrapText: true,
        initialWidth: 50,
    },
    {
        label: "发票单价",
        fieldName: "esdetInvoiceUnitprice",
        hideDefaultActions: true,
        wrapText: true,
        type: "number",
        typeAttributes: {
            minimumFractionDigits: 8,
            minimumFractionDigits: 2,
        },
    },
    {
        label: "发票数量",
        fieldName: "esdetInvoicedCount",
        cellAttributes: { alignment: 'right' },
        hideDefaultActions: true,
        wrapText: true,
    },
    {
        label: "发票票面金额(元)",
        fieldName: "esdetInvoicedProCostRMB",
        hideDefaultActions: true,
        wrapText: true,
        cellAttributes: { alignment: 'right' },
        type: "number",
        typeAttributes: {
            minimumFractionDigits: 2,
@@ -90,6 +106,7 @@
        label: "发票日期",
        fieldName: "Invoice_Date__c",
        hideDefaultActions: true,
        initialWidth: 150
    },
    {
        label: "发票号",
@@ -110,6 +127,7 @@
        label: "发票状态",
        fieldName: "Invoice_status__c",
        hideDefaultActions: true,
        initialWidth: 100
    },
    {
        label: "发票账面金额(元)",
@@ -119,18 +137,21 @@
        typeAttributes: {
            minimumFractionDigits: 2,
        },
        initialWidth: 180
    },
    {
        label: "发票附件",
        fieldName: "Invoice_attachment__c",
        type: 'boolean',
        hideDefaultActions: true,
        initialWidth: 120
    },
    {
        label: "发票明细附件",
        fieldName: "Invoicedet_attachment__c",
        type: 'boolean',
        hideDefaultActions: true,
        initialWidth: 120
    },
];
const detailsColumns = [
@@ -204,7 +225,7 @@
        hideDefaultActions: true,
        type: "number",
        typeAttributes: {
            minimumFractionDigits: 8,
            minimumFractionDigits: 2,
        },
        initialWidth : 130
    },
@@ -213,6 +234,7 @@
        //fieldName: "invoiceCount",
        hideDefaultActions: true,
        type: "customShipment",
        cellAttributes: { alignment: 'right' },
        typeAttributes: {
            recordId: { fieldName: "recordId" },
            shipmentNumber: { fieldName: "shipmentNumber" },
@@ -220,6 +242,7 @@
    },
    {
        label: "发票票面金额(元)",
        cellAttributes: { alignment: 'right' },
        fieldName: "invoiceAllprice",
        hideDefaultActions: true,
        type: "number",
@@ -256,6 +279,7 @@
    @track invoiceData = [];
    @track invoiceAllpriceData = [];
    @track detailsSelectedRows = [];
    @track showAttPop = false;
    @track invoiceId = '';
    @track orderId = '';
@@ -335,6 +359,7 @@
    @track isDisabledReopen = false;
    @track isDisabledDelete = false;
    @track isDisabledAttachment = false;
    @track isOpenReportDisabled = true;
    //文件上传
    @track showLoadingSpinner = false;
@@ -380,12 +405,38 @@
            },
            hideDefaultActions: true,
        },
        {
            label: '',
            type: 'tableCellIcon',
            typeAttributes: {
                iconName: 'utility:delete',
                recordId: {
                    fieldName: 'Id'
                }
            },
            initialWidth: 50,
            hideDefaultActions: true
        },
    ];
    filesUploaded = [];
    fileContents;
    fileReader;
    content;
    MAX_FILE_SIZE = 1500000;
    stylesLoaded = false;
    renderedCallback() {
        if (!this.stylesLoaded) {
            Promise.all([loadStyle(this, WrappedHeaderTable)])
                .then(() => {
                    console.log("Custom styles loaded");
                    this.stylesLoaded = true;
                })
                .catch((error) => {
                    console.error("Error loading custom styles");
                });
        }
    }
    //获取链接参数
    getQueryString(name) {
@@ -403,6 +454,7 @@
    }
    init() {
        this.isShowSpinner = true;
        this.deliveryId = this.getQueryString("deliveryId");
        this.deliveryId = this.deliveryId == null ? "" : this.deliveryId;
        this.invoiceId = this.getQueryString("invoiceId");
@@ -472,7 +524,7 @@
                    this.isShowSpinner = false;
                    this.isDetailsShow = true;
                } else {
                    this.showToast("Error", r.msg);
                    this.showMyToast('初始化失败', r.msg, 'Error');
                }
            }).catch((error) => {
                this.isShowSpinner = false;
@@ -488,6 +540,8 @@
                    this.ConInvoiceListUserWorkLocation = r.entity.userWorkLocation;
                    this.ConInvoiceListAgencyProType = r.entity.agencyProType;
                    if (this.ConInvoiceListAgencyProType != 'ET')
                        this.isOpenReportDisabled = false;
                    this.invoiceData = r.entity.raesList;
                    for (var i in this.invoiceData) {
                        this.invoiceData[i]['NameUrl'] = '/lexconinvoiceview?invoiceId=' + this.invoiceData[i].Id;
@@ -503,7 +557,7 @@
                    console.log("this.invoiceStatusOptions = " + JSON.stringify(this.invoiceStatusOptions));
                    this.isShowSpinner = false;
                } else {
                    this.showToast("Error", r.msg);
                    this.showMyToast('初始化失败', r.msg, 'Error');
                }
            }).catch((error) => {
                console.log("error = " + JSON.stringify(error));
@@ -545,6 +599,7 @@
                            this.selectedRows.push(this.outboundData[i].esd.Id);
                    }
                    this.selectedRows = [...this.selectedRows];
                    console.log('r.entity.attachmentRecoeds = ' + JSON.stringify(r.entity.attachmentRecoeds))
                    if (!this.EditAble) {
                        //附件显示
                        this.showLoadingSpinner = true;
@@ -557,6 +612,8 @@
                            this.fileData[i]["CreatedByName"] = this.fileData[i].cvInfo.Owner.Name;
                            this.fileData[i]["CreatedByNameUrl"] = "/" + this.fileData[i].cvInfo.OwnerId;;
                            this.fileData[i]["CreatedDate"] = this.fileData[i].cvInfo.CreatedDate;
                            this.fileData[i]["attUrl"] = '/' + this.fileData[i].cvInfo.Id;
                            this.fileData[i]['downloadUrl'] = '/sfc/servlet.shepherd/document/download/' + this.fileData[i].cvInfo.ContentDocumentId + '?operationContext=S1';
                            if (this.isDisabledAttachment) {
                                console.log('进入this.isDisabledAttachment')
                                this.fileData[i]["isDisabledAttachment"] = true;
@@ -572,8 +629,8 @@
                            this.fileData[i]["typeOptions"] = typeOptions;
                            this.fileData[i]["mailSelectOptsin"] = this.fileData[i].mailSelectOptsin == null ? typeOptions[0].value : this.fileData[i].mailSelectOptsin;
                        }
                        console.log('this.fileData = ' + JSON.stringify(this.fileData))
                    }
                    console.log('this.fileData = ' + JSON.stringify(this.fileData));
                    //发票明细
                    this.invoiceOrderdetail1Recoeds = r.entity.invoiceOrderdetail1Recoeds;
@@ -590,6 +647,8 @@
                    this.HospitalName = r.entity.HospitalName;
                    this.HospitalInfo = r.entity.HospitalInfo;
                    this.agencyProType = r.entity.agencyProType;
                    if (this.agencyProType != 'ET')
                        this.isOpenReportDisabled = false;
                    //科室
                    this.ForCustomerText = this.coc.Order_ForCustomerText__c;
                    //备注
@@ -655,7 +714,7 @@
                            this.outboundData[i]['returnAmount'] = this.outboundData[i].esd.RrturnPro_total_amount__c;
                        }
                        this.outboundData[i]['uninvoicedAmount'] = this.outboundData[i].esd.InvoiceNotPro_money__c;
                        this.outboundData[i]['invoiceFaceAmount'] = this.outboundData[i].needInvoiceCount.toFixed(2);
                        this.outboundData[i]['invoiceFaceAmount'] = this.keepTwoDecimalStr(this.outboundData[i].needInvoiceCount);
                        if (!(this.outboundData[i].esd.Billed_Status__c == '全部开票' || this.EditAble || this.coc.Invoice_status__c != '草案中')) {
                            console.log('进入 if')
                            let url = "/lexconinvoiceview?orderId=" + this.outboundData[i].esd.Id + "&invoiceId=" + this.invoiceId;
@@ -663,6 +722,7 @@
                            if (index == 0) {
                                let object5 = {
                                    label: '发票票面金额(元)',
                                    cellAttributes: { alignment: 'right' },
                                    type: 'url',
                                    fieldName: "invoiceFaceAmountUrl",
                                    typeAttributes: {
@@ -679,8 +739,13 @@
                            if (index == 0) {
                                let object5 = {
                                    label: '发票票面金额(元)',
                                    cellAttributes: { alignment: 'right' },
                                    fieldName: "invoiceFaceAmount",
                                    hideDefaultActions: true,
                                    type: "number",
                                    typeAttributes: {
                                        minimumFractionDigits: 2,
                                    },
                                };
                                this.outboundColumns.push(object5)
                                index++;
@@ -693,9 +758,9 @@
                    //四舍五入
                    //this.sumPrice = this.sumPrice.toFixed(2);
                    //如果不四舍五入
                    // console.log('start keepTwoDecimalStr')
                    // this.sumPrice = keepTwoDecimalStr(this.sumPrice);
                    // console.log('end keepTwoDecimalStr = ' + this.sumPrice)
                    console.log('start keepTwoDecimalStr')
                    this.sumPrice = this.keepTwoDecimalStr(this.sumPrice);
                    console.log('end keepTwoDecimalStr = ' + this.sumPrice)
                    //加最后一行显示金额
                    if (this.EditAble) {
                        let lastOutboundData = {
@@ -714,7 +779,7 @@
                    this.isShowSpinner = false;
                    this.showLoadingSpinner = false;
                } else {
                    this.showToast("Error", r.msg);
                    this.showMyToast('失败', r.msg, 'Error');
                }
            }).catch((error) => {
                console.log("error = " + JSON.stringify(error));
@@ -722,6 +787,48 @@
        }
    }
    //上传配置单
    uploadOrder(event) {
        this.showAttPop = true;
    }
    //关闭附件弹窗
    closePop() {
        this.showAttPop = false;
        this.filesUploaded = [];
        this.fileName = null;
    }
    //附件change事件
    attChange(event) {
        if (event.target.files.length > 0) {
            this.filesUploaded = event.target.files;
            this.fileName = event.target.files[0].name;
            console.log('this.fileName:' + this.fileName);
        }
    }
    //移除附件
    removeAtt() {
        this.filesUploaded = [];
        this.fileName = '';
    }
    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");
@@ -887,30 +994,31 @@
                    },
                });
            } else {
                this.showToast("Error", r.msg);
                this.showMyToast('保存失败', r.msg, 'Error');
            }
        }).catch((error) => {
            console.log("error = " + JSON.stringify(error));
            this.showToast("Error", error.message);
        });
    }
    //上传附件,直接就保存好,然后展示
    handleFilesChange(event) {
        console.log("handleFilesChange");
        if (event.target.files.length > 0) {
            this.filesUploaded = event.target.files;
            this.fileName = event.target.files[0].name;
            this.handleSave();
        }
        // if (event.target.files.length > 0) {
        //     this.filesUploaded = event.target.files;
        //     this.fileName = event.target.files[0].name;
        //     this.handleSave();
        // }
    }
    handleSave() {
        this.isShowSpinner = true;
        console.log("saveFile");
        if (this.filesUploaded.length > 0) {
            this.file = this.filesUploaded[0];
            if (this.file.size > this.MAX_FILE_SIZE) {
                this.showToast("Error", "文件过大");
                this.showMyToast('保存失败', '文件过大', 'Error');
                return;
            }
            this.showLoadingSpinner = true;
@@ -929,8 +1037,6 @@
        }
    }
    select id,LatestPublishedVersionId, ParentId from ContentDocument where id = '0690l000003ZDBrAAO'
    saveToFile() {
        console.log("saveToFile");
        console.log("invoiceId = " +this.invoiceId);
@@ -945,14 +1051,15 @@
            console.log("r = " + JSON.stringify(r));
            if (r != '') {
                this.showLoadingSpinner = false;
                this.showToast("Success", "上传成功");
                this.showMyToast('附件上传成功', '', 'Success');
                this.closePop();
                this.init();
            } else {
                this.showToast("Error", r.msg);
                this.showMyToast('上传失败', r.msg, 'Error');
            }
        }).catch((error) => {
                console.log("error = " + error.message);
                this.showToast("Error", "上传失败");
            this.showMyToast('错误', '上传失败', 'Error');
        });
    }
@@ -1006,12 +1113,13 @@
            if (r.status == "Success") {
                this.showLoadingSpinner = false;
                this.isShowSpinner = true;
                const event = new ShowToastEvent({
                    title: 'Success',
                    variant: 'Success',
                    message: '上传成功',
                });
                this.dispatchEvent(event);
                // const event = new ShowToastEvent({
                //     title: 'Success',
                //     variant: 'Success',
                //     message: '保存成功',
                // });
                // this.dispatchEvent(event);
                this.showMyToast('附件保存成功', '', 'Success');
                //this.init();
                setTimeout(function(){
                    //1秒后执行刷新
@@ -1026,11 +1134,11 @@
                //     },
                // });
            } else {
                this.showToast("Error", r.msg);
                this.showMyToast('上传失败', r.msg, 'Error');
            }
        }).catch((error) => {
            console.log("error = " + error.message);
            this.showToast("Error", "上传失败");
            this.showMyToast('错误', '上传失败', 'Error');
        });
    }
@@ -1056,16 +1164,16 @@
                console.log("this.invoiceData = " + JSON.stringify(this.invoiceData));
                this.isShowSpinner = false;
                if (r.entity.raesListSize > 0) {
                    this.showToast("Success", "共检索到" + r.entity.raesListSize + "个发票");
                    this.showMyToast('搜索成功', '共检索到' + r.entity.raesListSize + '个发票', 'Success');
                } else {
                    this.showToast("Warning", "没有搜索到相关发票。");
                    this.showMyToast('搜索失败', '没有搜索到相关发票', 'Error');
                }
            } else {
                this.showToast("Error", r.msg);
                this.showMyToast('搜索失败', r.msg, 'Error');
            }
        }).catch((error) => {
            console.log("error = " + error.message);
            this.showToast("Error", "搜索失败");
            this.showMyToast('错误', '搜索失败', 'Error');
        });
    }
@@ -1087,7 +1195,7 @@
                console.log("this.invoiceData = " + JSON.stringify(this.invoiceData));
                this.isShowSpinner = false;
            } else {
                this.showToast("Error", r.msg);
                this.showMyToast('搜索失败', r.msg, 'Error');
            }
        }).catch((error) => {
            console.log("error = " + JSON.stringify(error));
@@ -1152,6 +1260,7 @@
                        if (index == 0) {
                            let object5 = {
                                label: '发票票面金额(元)',
                                cellAttributes: { alignment: 'right' },
                                type: 'url',
                                fieldName: "invoiceFaceAmountUrl",
                                typeAttributes: {
@@ -1167,6 +1276,7 @@
                        if (index == 0) {
                            let object5 = {
                                label: '发票票面金额(元)',
                                cellAttributes: { alignment: 'right' },
                                fieldName: "invoiceFaceAmount",
                                hideDefaultActions: true,
                            };
@@ -1179,11 +1289,11 @@
                }
                this.isShowSpinner = false;
            } else {
                this.showToast("Error", r.msg);
                this.showMyToast('搜索失败', r.msg, 'Error');
            }
        }).catch((error) => {
            console.log("error = " + error.message);
            this.showToast("Error", "搜索失败");
            this.showMyToast('错误', '搜索失败', 'Error');
        });
    }
@@ -1223,11 +1333,10 @@
                    },
                });
            } else {
                this.showToast("Error", r.msg);
                this.showMyToast('删除失败', r.msg, 'Error');
            }
        }).catch((error) => {
            console.log("error = " + error.message);
            this.showToast("Error", error.message);
        });
    }
@@ -1249,25 +1358,26 @@
            outOrderStringListLwc: this.outOrderStringListLwc,
            outordercountMapLwc: this.outordercountMapLwc,
            invoiceIdLwc : this.invoiceId
        }).then((r) => {
            r = JSON.parse(JSON.stringify(r));
            console.log("r = " + JSON.stringify(r));
            if (r.status == "Success") {
                this.isShowSpinner = false
                let url = "/lexconinvoiceview?invoiceId=" + this.invoiceId;
                let url = "/s/lexconinvoiceview?invoiceId=" + this.invoiceId;
                console.log('url = ' + url);
                this[NavigationMixin.Navigate]({
                    type: "standard__webPage",
                    attributes: {
                        url: url,
                    },
                });
                window.open(url, '_self');
                // this[NavigationMixin.Navigate]({
                //     type: "standard__webPage",
                //     attributes: {
                //         url: url,
                //     },
                // });
            } else {
                this.showToast("Error", r.msg);
                this.showMyToast('错误', r.msg, 'Error');
            }
        }).catch((error) => {
            console.log("error = " + error.message);
            this.showToast("Error", error.message);
        });
    }
@@ -1298,27 +1408,42 @@
        });
    }
    showToast(type, msg) {
    showMyToast(title, message, variant) {
        this.isShowSpinner = false;
        this.showLoadingSpinner = false;
        const event = new ShowToastEvent({
            title: type,
            variant: type,
            message: msg,
        });
        this.dispatchEvent(event);
        this.showAttPop = false;
        this.filesUploaded = [];
        this.fileName = null;
        console.log('show custom message');
        var iconName = '';
        var content = '';
        if (variant.toLowerCase() == 'success') {
            iconName = 'utility:check';
        } else {
            iconName = 'utility:error';
        }
        if (message != '') {
            content = '<h2><strong>' + title + '<strong/></h2><h5>' + message + '</h5>';
        } else {
            content = '<h2><strong>' + title + '<strong/></h2>';
        }
        this.template.querySelector('c-common-toast').showToast(variant, content, iconName, 10000);
    }
    handleLoad() {
        console.log('handleLoad')
        try {
            const style = document.createElement('style');
            style.innerText = '.slds-button__icon {display: none;}';
            style.innerText = '.hehe-layoutItem .slds-button__icon {display: none;}';
            this.template.querySelector('.hideHelpText').appendChild(style);
            const style2 = document.createElement('style');
            style2.innerText = '.hehe-layoutItem  .slds-form-element__label {padding : 0px}';
            this.template.querySelector('.hideHelpText').appendChild(style2);
            const style3 = document.createElement('style');
            style3.innerText = '.readOnly  .slds-form-element__label {padding-top: 7px;}';
            this.template.querySelector('.hideHelpText').appendChild(style3);
        } catch (error) {
            console.log(error);
        }
@@ -1342,7 +1467,7 @@
        console.log('handleLoad2')
        try {
            const style = document.createElement('style');
            style.innerText = '.slds-button__icon {display: none;}';
            style.innerText = '.hehe-layoutItem .slds-button__icon {display: none;}';
            this.template.querySelector('.hideHelpText').appendChild(style);
            const style2 = document.createElement('style');
@@ -1519,11 +1644,10 @@
                    },
                });
            }else {
                this.showToast("Error", r.msg);
                this.showMyToast('保存失败', r.msg, 'Error');
            }
        }).catch((error) => {
            console.log("error = " + error.message);
            this.showToast("Error", error.message);
        });
    }
@@ -1564,4 +1688,27 @@
        }
        return result;
    }
    //删除附件
    deleteAtt(event) {
        this.isShowSpinner = true;
        //var recordId = event.detail.data.recordId;
        var recordId = event.target.getAttribute("data-fileid");
        console.log('attid:' + recordId);
        deleteAtt({
            contentVersionId: recordId
        }).then(result => {
            if (result.result == 'Success') {
                this.showMyToast('成功', '删除成功', 'Success');
                if (this.fileData.length == 1)
                    window.location.reload();
                else
                    this.init();
            } else {
                this.showMyToast('删除失败', result.errorMsg, 'Error');
            }
        }).catch(error => {
            this.showMyToast('错误', '删除失败', 'Error');
        })
    }
}