import { LightningElement, wire, api, track } from 'lwc';
|
import { ShowToastEvent } from "lightning/platformShowToastEvent";
|
import { NavigationMixin } from "lightning/navigation";
|
import { CurrentPageReference } from "lightning/navigation";
|
|
|
|
//table css
|
import { loadStyle } from "lightning/platformResourceLoader";
|
import WrappedHeaderTable from "@salesforce/resourceUrl/lexdatatable";
|
import init from '@salesforce/apex/lexToMcpApprovalController.init';
|
import save from '@salesforce/apex/lexToMcpApprovalController.save';
|
import mcpAprroval from '@salesforce/apex/lexToMcpApprovalController.mcpAprroval';
|
|
|
|
export default class lexToMcpApproval extends LightningElement {
|
recordId;
|
mcpeId='';
|
isShowNewContactModal = true;
|
IsLoading=true;
|
selectMce = [];
|
@track mceList =[];
|
selectMceMap = {};
|
mcpeReson;
|
reson;
|
isMcpeDecide;
|
mceSelects;
|
saveResult ={};
|
isNotApprove = false;
|
isDecideDisabled = true;
|
@track consumptionRateSolution;
|
solution;
|
@track initResult =[];
|
|
|
//==================服务打包合同的id================
|
ParamIdStr = ''; // url 参数Id
|
getQueryVariable(variable)
|
{
|
var query = window.location.search.substring(1);
|
var vars = query.split("&");
|
for (var i=0;i<vars.length;i++) {
|
var pair = vars[i].split("=");
|
if(pair[0] == variable){return pair[1];}
|
}
|
return(false);
|
}
|
|
|
|
|
connectedCallback(){
|
var mcpeId = this.getQueryVariable('mcpeId');
|
var paramId = this.getQueryVariable('id');
|
if (paramId == null || paramId == '') {
|
return ;
|
}
|
this.recordId = paramId;
|
if (mcpeId && mcpeId!='false') {
|
this.mcpeId = mcpeId;
|
}
|
|
console.log(this.recordId);
|
init({
|
recordId: this.recordId,
|
mcpeId:this.mcpeId
|
}).then(result => {
|
console.log('init result:');
|
console.log(result);
|
this.initResult = result;
|
if (result != null && result.length>0) {
|
this.mcpeReson = result[0].mcpeReson;
|
this.reson = result[0].mcpeReson;
|
this.consumptionRateSolution = result[0].consumptionRateSolution;
|
this.solution = result[0].consumptionRateSolution;
|
this.isMcpeDecide = result[0].isMcpeDecide;
|
this.mceSelects = result[0].mceIds;
|
if(result[0].processStatus =='申请中' || result[0].processStatus =='批准'|| result[0].processStatus =='中止') {
|
this.isNotApprove = true;
|
}
|
if(result[0].processStatus =='批准') {
|
this.isDecideDisabled = false;
|
}
|
|
this.mceSelects = result[0].mceIds;
|
const nowDate = new Date();
|
|
for(var i=0;i<result.length;i++) {
|
for(var j=0;j<result[i].mceList.length;j++){
|
if(this.mceSelects && this.mceSelects.indexOf(result[i].mceList[j].Name) != -1) {
|
this.selectMceMap[result[i].mcId] = result[i].mceList[j].Name;
|
this.initResult[i].mceList[j].checked = true;
|
} else if(!this.mceSelects) {
|
this.selectMceMap[result[i].mcId] = '';
|
}
|
|
console.log(typeof(result[i].mceList[j].CreatedDate));
|
var CreatedDate = new Date(result[i].mceList[j].CreatedDate);
|
console.log('相差月份:');
|
console.log(this.beforeThreeMonth(nowDate,CreatedDate));
|
if(this.beforeThreeMonth(nowDate,CreatedDate) || this.isNotApprove) {
|
this.initResult[i].mceList[j].disabled = true;
|
}
|
|
// if(result[i].mceList[j].Submit_quotation_day__c) {
|
// this.initResult[i].mceList[j].checked = true;
|
// }
|
}
|
}
|
// this.initResult = result;
|
|
|
|
// for(var i=0;i<result.length;i++) {
|
// var mceOption = {};
|
// mceOption.mcName = result[i].mcName;
|
// mceOption.mcId = result[i].mcId;
|
// mceOption.radioName = 'mceGroup'+i;
|
// mceOption.radioValue = 'mceGroupValue'+i;
|
// var optionOne = [];
|
// for(var j=0;j<result[i].mceList.length;j++){
|
// var map1 = {};
|
// map1.label = result[i].mceList[j].Name;
|
// map1.value = result[i].mceList[j].Name;
|
// if(this.mceSelects && this.mceSelects.indexOf(map1.value) != -1) {
|
// mceOption.radioValue = map1.value;
|
// this.selectMceMap[mceOption.radioName] = map1.value;
|
// }
|
// optionOne.push(map1);
|
// }
|
// mceOption.options = optionOne;
|
// this.mceList.push(mceOption);
|
// }
|
}
|
|
}).catch(error => {
|
console.log("error");
|
console.log(error);
|
});
|
|
}
|
beforeThreeMonth(nowDay,submitDay) {
|
var months;
|
if(nowDay.getDate()>submitDay.getDate()) {
|
months = (nowDay.getFullYear() - submitDay.getFullYear()) * 12 + (nowDay.getMonth() - submitDay.getMonth()) ;
|
} else {
|
months = (nowDay.getFullYear() - submitDay.getFullYear()) * 12 + (nowDay.getMonth() - submitDay.getMonth()) -1;
|
}
|
if(months<3) {
|
return false;
|
} else {
|
return true;
|
}
|
|
}
|
//取消
|
async cancle() {
|
window.location = '/'+this.recordId;
|
}
|
|
async saveMcpGroup() {
|
|
this.selectMce = [];
|
for(var key in this.selectMceMap) {
|
if(this.selectMceMap[key] != '') {
|
this.selectMce.push(this.selectMceMap[key]);
|
}
|
}
|
console.log('save:mcpeId:');
|
console.log(this.mcpeId);
|
console.log(this.mcpeReson);
|
if(!this.reson) {
|
alert('请填写申请理由');
|
return;
|
}
|
if(!this.solution) {
|
alert('请填写消费率改善方案');
|
return;
|
}
|
if(this.selectMce.length != this.initResult.length) {
|
alert('每个合同必须选择一条报价!');
|
} else{
|
if(!this.isMcpeDecide) {
|
this.isMcpeDecide = false;
|
}
|
save({
|
recordId: this.recordId,
|
mcpeReson:this.reson,
|
mceIds:this.selectMce,
|
mcpeId:this.mcpeId,
|
isDecide:this.isMcpeDecide,
|
consumptionRateSolution:this.solution
|
|
}).then(returnData=>{
|
console.log('returnData:');
|
console.log(returnData);
|
this.saveResult = returnData;
|
if(returnData.result == '1') {
|
this.mcpeId = returnData.mcpeId;
|
alert('组合保存成功!');
|
window.location = '/'+this.recordId;
|
} else {
|
alert(returnData.result);
|
}
|
|
});
|
|
}
|
|
}
|
async mcpApproval() {
|
|
this.selectMce = [];
|
for(var key in this.selectMceMap) {
|
if(this.selectMceMap[key] != '') {
|
this.selectMce.push(this.selectMceMap[key]);
|
}
|
}
|
console.log('save:mcpeId:');
|
console.log(this.mcpeId);
|
console.log(this.mcpeReson);
|
if(!this.reson) {
|
alert('请填写申请理由');
|
return;
|
}
|
if(!this.solution) {
|
alert('请填写消费率改善方案');
|
return;
|
}
|
if(this.selectMce.length != this.initResult.length) {
|
alert('每个合同必须选择一条报价!');
|
} else{
|
if(!this.isMcpeDecide) {
|
this.isMcpeDecide = false;
|
}
|
mcpAprroval({
|
recordId: this.recordId,
|
mcpeReson:this.reson,
|
mceIds:this.selectMce,
|
mcpeId:this.mcpeId,
|
isDecide:this.isMcpeDecide,
|
consumptionRateSolution:this.solution
|
}).then(result=>{
|
if(result == '1') {
|
alert('提交审批成功!');
|
// window.location.reload();
|
// window.close();
|
window.location = '/'+this.recordId;
|
|
} else {
|
alert(result);
|
}
|
|
});
|
}
|
|
|
}
|
toEditMce(event) {
|
window.open('/' + event.target.name,'_blank');
|
}
|
selectMceEvent(event){
|
this.selectMceMap[event.target.name] = event.target.value;
|
}
|
changeMceGroupReson(event){
|
this.reson = event.target.value;
|
|
}
|
changeMcpeDecide(event){
|
this.isMcpeDecide =event.target.checked;
|
}
|
changeConsumptionRateSolution(event){
|
this.solution =event.target.value;
|
}
|
|
|
closeContactModal() {
|
this.isShowNewContactModal = false;
|
}
|
}
|