From d533f39b6fa798e238810d17e928dee75d5b1af7 Mon Sep 17 00:00:00 2001
From: yumenghui <953181891@qq.com>
Date: 星期五, 11 八月 2023 16:02:17 +0800
Subject: [PATCH] 备注添加改造
---
force-app/main/default/lwc/inventoryEditingLWC/inventoryEditingLWC.js | 186 ++++++++++++++++++++++++++++++++++------------
1 files changed, 138 insertions(+), 48 deletions(-)
diff --git a/force-app/main/default/lwc/inventoryEditingLWC/inventoryEditingLWC.js b/force-app/main/default/lwc/inventoryEditingLWC/inventoryEditingLWC.js
index 2f064df..51671f9 100644
--- a/force-app/main/default/lwc/inventoryEditingLWC/inventoryEditingLWC.js
+++ b/force-app/main/default/lwc/inventoryEditingLWC/inventoryEditingLWC.js
@@ -1,30 +1,79 @@
import { LightningElement, track,api } from 'lwc';
-import Product_Number_FIELD from '@salesforce/schema/Dealer_Stock__c.Product_Code__c';
-import ONE_FIELD from '@salesforce/schema/Dealer_Stock__c.Product_Code__c';
-import TWO_FIELD from '@salesforce/schema/Dealer_Stock__c.Product_Code__c';
+import oninit from "@salesforce/apex/LexProductLimitEditController.init";
+import save from "@salesforce/apex/LexUpAccountProLimit.upAccount";
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
export default class InventoryEditingLWC extends LightningElement {
- // @track invRecord = {ProductNumber : Product_Number_FIELD,Inventory1: ONE_FIELD,Inventory2 : TWO_FIELD,key : Math.random().toString(36).substring(2, 15)};
- @track invRecord = {ProductNumber : Product_Number_FIELD,Inventory1: ONE_FIELD,Inventory2 : TWO_FIELD,key : Math.random().toString(36).substring(2, 15)};
@track invRecords = [];
- toSaveLabel = 'Save';
+ @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;
+ }
connectedCallback(){
+ this.showSpinner = true;
console.log(' === connectedCallback === ');
- this.inventoryTempRecords();
- }
- inventoryTempRecords(){
- console.log('===>鍒濆鍖�');
- this.invRecord = [];
- // for(var i=0; i < 1 ; i++){
- // this.invRecords.push({ProductNumber : Product_Number_FIELD,Inventory1: ONE_FIELD,Inventory2 : TWO_FIELD,key : Math.random().toString(36).substring(2, 15)});
- // }
+ //鑾峰彇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) => {
+ 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){
+ var arry = arr[i].split('|');
+ this.invRecords.push({
+ productNumber: arry[0],
+ inventory1:arry[1],
+ inventory2:arry[2]
+ });
+ }
+ this.showSpinner = false;
+ console.log('this.invRecords'+JSON.stringify(this.invRecords));
+ }else{
+ this.showSpinner = false;
+ console.log("error = " + JSON.stringify(error));
+
+ }
+ }).catch((error) => {
+ this.showSpinner = false;
+ console.log("error = " + JSON.stringify(error));
+ });
+ // this.inventoryTempRecords();
+
}
addRow(){
- console.log('=====>杩涘叆琛岄」鐩�');
- const len = this.invRecords.length;
- this.invRecords.push({ProductNumber : Product_Number_FIELD,Inventory1: ONE_FIELD,Inventory2 : TWO_FIELD,key : Math.random().toString(36).substring(2, 15)});
+ let objRow = {
+ productNumber: '',
+ inventory1: '',
+ inventory2: '',
+ id: ++this.keyIndex
+ }
+ this.invRecords = [...this.invRecords, Object.create(objRow)];
}
removeRow(event){
const indexPos = event.currentTarget.name;
@@ -34,43 +83,84 @@
this.invRecords = remList;
}
handleClick(){
+ this.showSpinner = true;
console.log('淇濆瓨');
- this.toSaveLabel = 'Saving...'
- let toSaveList = this.invRecords.slice(0);;
- toSaveList.forEach((element, index) => {
- console.log( index + ' ==> ' + JSON.stringify(element.Name));
- let eleType = typeof element.Name;
- console.log( 'typeof ==> ' + eleType);
- if(element.Name === '' || eleType=='object'){
- toSaveList.splice(index);
+ 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("杈撳叆鏍煎紡涓嶆纭�,璇疯緭鍏ユ暟瀛�!");
+ return;
}
- });
- // refreshApex(this.invRecord);
-
+ if(this.invRecords[i]["inventory1"] == ''||this.invRecords[i]["inventory1"] == null ||this.invRecords[i]["inventory2"] == null ||
+ this.invRecords[i]["inventory2"] == ''){
+ alert('璇疯緭鍏�' +this.invRecords[i]["productNumber"] + '搴撳瓨涓婁笅闄愪俊鎭紒');
+ return;
+ }
+ if(Number(this.invRecords[i]["inventory1"])>Number(this.invRecords[i]["inventory2"])){
+ alert( this.invRecords[i]["productNumber"] + '搴撳瓨涓嬮檺澶т簬涓婇檺锛�');
+ 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) => {
+ result = JSON.parse(JSON.stringify(result));
+ console.log('result'+JSON.stringify(result));
+ if(result.status == 'Success'){
+ const evt = new ShowToastEvent({
+ title: "淇濆瓨鎴愬姛",
+ message: result.msg,
+ variant: "Success",
+ });
+ this.dispatchEvent(evt);
+ this.showSpinner = false;
+ }else{
+ const evt = new ShowToastEvent({
+ title: "淇濆瓨澶辫触",
+ message: result.msg,
+ variant: "Error",
+ });
+ this.dispatchEvent(evt);
+ this.showSpinner = false;
+
+ }
+ }).catch((error) => {
+ console.log("error = " + JSON.stringify(error));
+ this.showSpinner = false;
+ });
+
this.inventoryTempRecords();
console.log( 'Save ==> ' + JSON.stringify(toSaveList));
}
- handleProductChange(event){
-
- let foundelement = this.invRecords.find(ele => ele.key == event.target.dataset.id);
- console.log('=====>foundelement'+foundelement);
- foundelement.productNumber = event.target.value;
- this.accRecords = [this.accRecords];
- console.log(' ==>绗竴琛�' + JSON.stringify(this.invRecords));
+ 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;
+ }
}
- handleinv1Change(event){
- let foundelement = this.invRecords.find(ele => ele.key == event.target.dataset.id);
- foundelement.inventory1 = event.target.value;
- this.accRecords = [this.accRecords];
- console.log(' ==> 绗簩' + JSON.stringify(this.invRecords));
+
+//鏁板瓧楠岃瘉
+isNum(num){
+ var reNum =/^[0-9]+$/;
+ return (reNum.test(num));
}
-
- handleinv2Change(event){
- let foundelement = this.invRecords.find(ele => ele.key == event.target.dataset.id);
- foundelement.inventory2 = event.target.value;
- this.accRecords = [this.accRecords];
- console.log(' ==>绗笁' + JSON.stringify(this.invRecords));
- }
-
}
\ No newline at end of file
--
Gitblit v1.9.1