From 4488f711dbc01a8db6753907cae2ef4021dede68 Mon Sep 17 00:00:00 2001 From: FUYU <fuyu@prec-tech.com> Date: 星期三, 13 十二月 2023 16:30:27 +0800 Subject: [PATCH] 修改前备份 --- force-app/main/default/lwc/lexProductLimitEdit/lexProductLimitEdit.js | 286 ++++++++++++++++++++++++++++++++------------------------ 1 files changed, 163 insertions(+), 123 deletions(-) diff --git a/force-app/main/default/lwc/lexProductLimitEdit/lexProductLimitEdit.js b/force-app/main/default/lwc/lexProductLimitEdit/lexProductLimitEdit.js index c6976a3..6c15970 100644 --- a/force-app/main/default/lwc/lexProductLimitEdit/lexProductLimitEdit.js +++ b/force-app/main/default/lwc/lexProductLimitEdit/lexProductLimitEdit.js @@ -1,193 +1,233 @@ import { LightningElement, wire, api, track } from 'lwc'; -import oninit from "@salesforce/apex/LexProductLimitEditController.init"; -import save from "@salesforce/apex/LexUpAccountProLimit.upAccount"; +import oninit from '@salesforce/apex/LexProductLimitEditController.init'; +import save from '@salesforce/apex/LexUpAccountProLimit.upAccount'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; -import { NavigationMixin } from "lightning/navigation"; -export default class InventoryEditingLWC extends NavigationMixin(LightningElement){ +import { NavigationMixin } from 'lightning/navigation'; +export default class LexProductLimitEdit extends NavigationMixin( + LightningElement +) { @track invRecords = []; @track accountid; @track upstring = ''; @track userPro_Type; @track showSpinner = true; //鑾峰彇閾炬帴鍙傛暟 - getQueryString(name) { - console.log("getQueryString name " + name); - let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); - let r = window.location.search.substr(1).match(reg); - if (r != null) { - return decodeURIComponent(r[2]); - } - return null; - } + getQueryString(name) { + console.log('getQueryString name ' + name); + let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'); + let r = window.location.search.substr(1).match(reg); + if (r != null) { + return decodeURIComponent(r[2]); + } + return null; + } - connectedCallback(){ + connectedCallback() { this.showSpinner = true; console.log(' === connectedCallback === '); //鑾峰彇accountid userPro_Type - this.accountid = this.getQueryString("accountid"); - this.accountid = this.accountid == null ? "" : this.accountid; - this.userPro_Type = this.getQueryString("userPro_Type"); - this.userPro_Type = this.userPro_Type == null ? "" : this.userPro_Type; - //鑾峰彇鏁版嵁 - oninit({ - accountid:this.accountid, - userPro_Type:this.userPro_Type - - }).then((result) => { + this.accountid = this.getQueryString('accountid'); + this.accountid = this.accountid == null ? '' : this.accountid; + this.userPro_Type = this.getQueryString('userPro_Type'); + this.userPro_Type = this.userPro_Type == null ? '' : this.userPro_Type; + //鑾峰彇鏁版嵁 + oninit({ + accountid: this.accountid, + userPro_Type: this.userPro_Type + }) + .then((result) => { result = JSON.parse(JSON.stringify(result)); - console.log('result'+JSON.stringify(result)); - if(result.status == 'Success'){ - console.log('11===>'+result.entity.product_Limit); - console.log('11===>'+typeof(result.entity.product_Limit)); - let str = result.entity.product_Limit; - var arr = str.split(','); - console.log('arr==>'+ arr); - console.log('arr==>'+ arr.length); - console.log('arr==>'+ typeof(arr)); - for(var i in arr){ + console.log('result' + JSON.stringify(result)); + if (result.status == 'Success') { + console.log('11===>' + result.entity.product_Limit); + console.log('11===>' + typeof result.entity.product_Limit); + let str = result.entity.product_Limit; + var arr = str.split(','); + console.log('arr==>' + arr); + console.log('arr==>' + arr.length); + console.log('arr==>' + typeof arr); + for (var i in arr) { var arry = arr[i].split('|'); - this.invRecords.push({ + this.invRecords.push({ productNumber: arry[0], - inventory1:arry[1], - inventory2:arry[2] + inventory1: arry[1], + inventory2: arry[2] }); } this.showSpinner = false; - console.log('this.invRecords'+JSON.stringify(this.invRecords)); - }else{ + console.log( + 'this.invRecords' + JSON.stringify(this.invRecords) + ); + } else { this.showSpinner = false; - console.log("error = " + JSON.stringify(error)); - + console.log('error = ' + JSON.stringify(error)); } - }).catch((error) => { + }) + .catch((error) => { this.showSpinner = false; - console.log("error = " + JSON.stringify(error)); - }); + console.log('error = ' + JSON.stringify(error)); + }); // this.inventoryTempRecords(); - } - addRow(){ + addRow() { let objRow = { productNumber: '', inventory1: '', inventory2: '', id: ++this.keyIndex - } + }; this.invRecords = [...this.invRecords, Object.create(objRow)]; } - removeRow(event){ + removeRow(event) { const indexPos = event.currentTarget.name; let remList = []; remList = this.invRecords; - remList.splice(indexPos,1); + remList.splice(indexPos, 1); this.invRecords = remList; } - handleClick(){ + handleClick() { this.showSpinner = true; console.log('淇濆瓨'); - console.log('this.invRecords'+JSON.stringify(this.invRecords)); - for(var i in this.invRecords){ - console.log('inven'+this.invRecords[i]["inventory1"]); - console.log('鏁板瓧'+this.isNum(this.invRecords[i]["inventory1"])); - - if(this.isNum(this.invRecords[i]["inventory1"]) == false || this.isNum(this.invRecords[i]["inventory2"]==false)){ - // alert("杈撳叆鏍煎紡涓嶆纭�,璇疯緭鍏ユ暟瀛�!"); - this.showMyToast('淇濆瓨澶辫触','杈撳叆鏍煎紡涓嶆纭�,璇疯緭鍏ユ暟瀛�','error'); + console.log('this.invRecords' + JSON.stringify(this.invRecords)); + for (var i in this.invRecords) { + console.log('inven1' + this.invRecords[i]['inventory1']); + console.log('鏁板瓧1' + this.isNum(this.invRecords[i]['inventory1'])); + console.log('inven2' + this.invRecords[i]['inventory2']); + console.log('鏁板瓧2' + this.isNum(this.invRecords[i]['inventory2'])); + if ( + this.invRecords[i]['inventory1'] == '' || + this.invRecords[i]['inventory1'] == null || + this.invRecords[i]['inventory2'] == null || + this.invRecords[i]['inventory2'] == '' + ) { + this.showMyToast( + '淇濆瓨澶辫触', + '杈撳叆鏍煎紡涓嶆纭�,璇疯緭鍏ユ暟瀛�', + 'error' + ); this.showSpinner = false; return; } - if(this.invRecords[i]["inventory1"] == ''||this.invRecords[i]["inventory1"] == null ||this.invRecords[i]["inventory2"] == null || - this.invRecords[i]["inventory2"] == ''){ - // alert('璇疯緭鍏�' +this.invRecords[i]["productNumber"] + '搴撳瓨涓婁笅闄愪俊鎭紒'); - this.showMyToast('淇濆瓨澶辫触','璇疯緭鍏�' +this.invRecords[i]["productNumber"] + '搴撳瓨涓婁笅闄愪俊鎭�','error'); + if ( + this.isNum(this.invRecords[i]['inventory1']) == false || + this.isNum(this.invRecords[i]['inventory2']) == false + ) { + this.showMyToast( + '淇濆瓨澶辫触', + '杈撳叆鏍煎紡涓嶆纭�,璇疯緭鍏ユ暟瀛�', + 'error' + ); this.showSpinner = false; return; } - if(Number(this.invRecords[i]["inventory1"])>Number(this.invRecords[i]["inventory2"])){ - // alert( this.invRecords[i]["productNumber"] + '搴撳瓨涓嬮檺澶т簬涓婇檺锛�'); - this.showMyToast('淇濆瓨澶辫触',this.invRecords[i]["productNumber"] + '搴撳瓨涓嬮檺澶т簬涓婇檺','error'); + if ( + Number(this.invRecords[i]['inventory1']) > + Number(this.invRecords[i]['inventory2']) + ) { + this.showMyToast( + '淇濆瓨澶辫触', + this.invRecords[i]['productNumber'] + '搴撳瓨涓嬮檺澶т簬涓婇檺', + 'error' + ); this.showSpinner = false; return; } } - let dataStr = '' - for(var i in this.invRecords){ - dataStr = dataStr+this.invRecords[i]["productNumber"] +'|'+this.invRecords[i]["inventory1"]+'|'+this.invRecords[i]["inventory2"]+','; - } - console.log('dataStr==>'+dataStr); - this.upstring = dataStr.substring(0, dataStr.lastIndexOf(',')); - console.log('upstring'+ this.upstring); - save({ - accountId: this.accountid, - productLimit: this.upstring, - userPro_Type:this.userPro_Type - }).then((result) => { + let dataStr = ''; + for (var i in this.invRecords) { + dataStr = + dataStr + + this.invRecords[i]['productNumber'] + + '|' + + this.invRecords[i]['inventory1'] + + '|' + + this.invRecords[i]['inventory2'] + + ','; + } + console.log('dataStr==>' + dataStr); + this.upstring = dataStr.substring(0, dataStr.lastIndexOf(',')); + console.log('upstring' + this.upstring); + save({ + accountId: this.accountid, + productLimit: this.upstring, + userPro_Type: this.userPro_Type + }) + .then((result) => { result = JSON.parse(JSON.stringify(result)); - console.log('result===>'+JSON.stringify(result)); - if(result.status == 'Success'){ - this.showMyToast('淇濆瓨鎴愬姛','','success'); + console.log('result===>' + JSON.stringify(result)); + if (result.status == 'Success') { + this.showMyToast('淇濆瓨鎴愬姛', '', 'success'); this.showSpinner = false; - // setTimeout(this.toLexToppage(),5000 ); + // setTimeout(this.toLexToppage(),5000 ); setTimeout(() => { this.toLexToppage(); }, 500); - - }else{ - this.showMyToast('淇濆瓨澶辫触',result.msg,'error'); + } else { + this.showMyToast('淇濆瓨澶辫触', result.msg, 'error'); this.showSpinner = false; - } - }).catch((error) => { - console.log("error = " + JSON.stringify(error)); + }) + .catch((error) => { + console.log('error = ' + JSON.stringify(error)); this.showSpinner = false; - }); - + }); + this.inventoryTempRecords(); - console.log( 'Save ==> ' + JSON.stringify(toSaveList)); + console.log('Save ==> ' + JSON.stringify(toSaveList)); } - handleProductChange(event){ + handleProductChange(event) { if (event.target.name == 'productNumber') { - this.invRecords[event.currentTarget.dataset.index].productNumber = event.target.value; - console.log('===>invrecords'+JSON.stringify(this.invRecords)); - } - else if (event.target.name == 'inventory1') { - this.invRecords[event.currentTarget.dataset.index].inventory1 = event.target.value; - } - else if (event.target.name == 'inventory2') { - this.invRecords[event.currentTarget.dataset.index].inventory2 = event.target.value; + this.invRecords[event.currentTarget.dataset.index].productNumber = + event.target.value; + console.log('===>invrecords' + JSON.stringify(this.invRecords)); + } else if (event.target.name == 'inventory1') { + this.invRecords[event.currentTarget.dataset.index].inventory1 = + event.target.value; + console.log('===>invrecords' + JSON.stringify(this.invRecords)); + } else if (event.target.name == 'inventory2') { + this.invRecords[event.currentTarget.dataset.index].inventory2 = + event.target.value; + console.log('===>invrecords' + JSON.stringify(this.invRecords)); } } - -//鏁板瓧楠岃瘉 -isNum(num){ - var reNum =/^[0-9]+$/; - return (reNum.test(num)); + + //鏁板瓧楠岃瘉 + isNum(num) { + var reNum = /^[0-9]+$/; + return reNum.test(num); } showMyToast(title, message, variant) { console.log('show custom message'); var iconName = ''; var content = ''; - if(variant == 'success'){ - iconName = 'utility:check'; - }else{ - iconName = 'utility:error'; + if (variant == '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>'; + 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); - } - toLexToppage(){ - this[NavigationMixin.Navigate]({ - type: 'standard__webPage', - attributes: { - url: '/lextoppage' - } - }); - } -} \ No newline at end of file + this.template + .querySelector('c-common-toast') + .showToast(variant, content, iconName, 10000); + } + toLexToppage() { + this[NavigationMixin.Navigate]({ + type: 'standard__webPage', + attributes: { + url: '/lextoppage' + } + }); + } +} -- Gitblit v1.9.1