import { LightningElement,api, track} from 'lwc';
|
import getPicklistValues from '@salesforce/apex/CommonUtils.getPicklistValues';
|
|
|
export default class JzPickList extends LightningElement {
|
|
connectedCallback()
|
{
|
this.InitData();
|
|
}
|
|
|
|
|
|
@api option = {}
|
@api orderdata=[];
|
|
|
|
|
@api name ;
|
|
option0=undefined;
|
option1=undefined;
|
option2=undefined;
|
option3=undefined;
|
option4=undefined;
|
|
OriData = [];
|
InitData()
|
{
|
var lengs = this.option.props.length;
|
|
this.option.props.forEach(item => {
|
getPicklistValues({objApiName:this.option.objName,controlField:item.controllProp,dependentField:item.dependProp}).then(response=>{
|
var temp ={order:item.order,data:response};
|
let dataTemp = {order:item.order,labelname:item.labelname,placeholder:item.placeholder,data:temp}
|
|
this.OriData.push({order:item.order,list:response});
|
lengs --;
|
if (item.order == 0) {
|
|
this.option0 = dataTemp;
|
}
|
if (item.order == 1) {
|
this.option1 = dataTemp;
|
}
|
if (item.order == 2) {
|
this.option2 = dataTemp;
|
}
|
if (item.order == 3) {
|
this.option3 = dataTemp;
|
}
|
if (item.order == 4) {
|
this.option4 = dataTemp;
|
}
|
|
if (lengs == 0) {
|
this.CheckData();
|
}
|
})
|
});
|
}
|
|
|
CheckData()
|
{
|
var newData = [];
|
if (this.option0!=undefined && this.option0 != {}) {
|
newData.push(this.option0);
|
}
|
|
if (this.option1!=undefined && this.option1 != {}) {
|
newData.push(this.option1);
|
}
|
if (this.option2!=undefined && this.option2 != {}) {
|
newData.push(this.option2);
|
}
|
if (this.option3!=undefined && this.option3 != {}) {
|
newData.push(this.option3);
|
}
|
if (this.option4!=undefined && this.option4 != {}) {
|
newData.push(this.option4);
|
}
|
|
this.orderdata = newData;
|
this.AddEndList();
|
this.ClearNotFirstData();
|
}
|
|
@api lastname;
|
@api lastplaceholder;
|
AddEndList(){
|
var temp = {data:[],labelname:this.lastname,placeholder:this.lastplaceholder,order:this.orderdata.length};
|
this.orderdata.push(temp);
|
}
|
|
ClearNotFirstData(){
|
|
var newData = [];
|
this.orderdata.forEach(item=>{
|
var temp = {...{},...item};
|
if (item.order != 0) {
|
temp.data.data = [];
|
}
|
newData.push(temp);
|
})
|
this.orderdata = newData;
|
}
|
|
labelChange(event)
|
{
|
var order = event.target.name;
|
var value = event.target.value;
|
this.changeData(order,value)
|
}
|
|
|
changeData(fromOrder,value)
|
{
|
this.saveReturnData(fromOrder,value);
|
this.CheckNextData(fromOrder,value);
|
|
}
|
CheckNextData(fromOrder,value)
|
{
|
var toOrder = (fromOrder+1);
|
|
|
|
|
var fromData = this.orderdata[fromOrder];
|
var deps = [];
|
fromData.data.data.forEach(item=>{
|
if (item.label == value) {
|
deps = item.dependents
|
}
|
})
|
|
if (toOrder < this.OriData.length ) {
|
var toData = [];
|
this.OriData.forEach(ditem=>{
|
var temp = {...{},...ditem};
|
if (temp.order == toOrder) {
|
toData = ditem.list;
|
}
|
})
|
|
|
var toDataTemp = [];
|
deps.forEach(dep=>{
|
toData.forEach(item=>{
|
if (dep.label == item.label) {
|
toDataTemp.push(item);
|
return;
|
}
|
})
|
})
|
var newData = []
|
this.orderdata.forEach(item=>{
|
var temp = {...{},...item};
|
if (item.order==toOrder) {
|
temp.data.data = toDataTemp;
|
newData.push(temp);
|
}else{
|
newData.push(temp);
|
}
|
})
|
this.orderdata = newData;
|
}else{
|
var newData = []
|
this.orderdata.forEach(item=>{
|
var temp = {...{},...item};
|
if (item.order==toOrder) {
|
temp.data.data = deps;
|
newData.push(temp);
|
}else{
|
newData.push(temp);
|
}
|
})
|
this.orderdata = newData;
|
}
|
}
|
returndata=[]; // {order , value}
|
saveReturnData(order,value)
|
{
|
var falg = true;
|
this.returndata.forEach(item=>{
|
if (item.order == order) {
|
falg = false;
|
item.value = value;
|
}
|
})
|
if (falg) {
|
this.returndata.push({order:order,value:value});
|
}
|
|
|
this.ChangeDataValues(order,value);
|
var returns = [...[],... this.returndata];
|
|
const getSearchParamsEvent = new CustomEvent('datachange', {
|
detail: {data:returns}
|
});
|
this.dispatchEvent(getSearchParamsEvent);
|
}
|
deleteReturnData(order)
|
{
|
this.returndata.forEach(item=>{
|
if (item.order == order) {
|
item.value = '';
|
}
|
})
|
|
this.ChangeDataValues(order,"")
|
|
for (let index = ++order; index < this.orderdata.length; index++) {
|
this.orderdata[index].data.data = [];
|
|
}
|
}
|
ChangeDataValues(order,value)
|
{
|
var newData = [];
|
this.orderdata.forEach(item=>{
|
var temp = {...{},...item};
|
if (item.order == order) {
|
temp.value = value;
|
}
|
newData.push(temp);
|
})
|
this.orderdata = newData;
|
}
|
deleteData(event){
|
var order = event.target.name;
|
|
const getSearchParamsEvent = new CustomEvent('datadelete', {
|
detail: {data:{order:order}}
|
});
|
this.dispatchEvent(getSearchParamsEvent);
|
|
this.deleteReturnData(order);
|
}
|
|
@api getvalue(){
|
return this.returndata;
|
}
|
// {order,value}
|
@api setvalue(orders){
|
orders.forEach(item=>{
|
this.changeData(item.order,item.value);
|
})
|
|
}
|
|
@api setdisabled(){
|
var combbox = this.template.querySelectorAll('lightning-combobox');
|
combbox.forEach(fileInput=>{
|
fileInput.disabled = true;
|
})
|
|
var icons = this.template.querySelectorAll('lightning-button-icon');
|
icons.forEach(fileInput=>{
|
fileInput.disabled = true;
|
})
|
}
|
}
|