黄千龙
2023-08-09 626f3c3bb25e204568019e8d568e2d7547d1037a
force-app/main/default/lwc/lexSendNFM103/lexSendNFM103.js
@@ -79,6 +79,7 @@
  AWSDataId;
  userName;
  profileName;
  Id;
  @wire(CurrentPageReference)
  getStateParameters(currentPageReference) {
@@ -102,7 +103,7 @@
        btns[i].disabled = true;
        btns[i].className = 'btnDisabled';
      }
      this.Id = result.Id;
      this.detailedAddress = result.detailedAddress;
      this.dealer = result.DealerC;
      this.numberofEffectiveContract = result.numberofEffectiveContract;
@@ -135,7 +136,7 @@
      this.DWSign = result.DWSign;
      this.DOJStatus = result.DOJStatus;
      this.SAPcondition = result.SAPcondition;
      this.salesOfficeCodeSelection = result.salesOfficeCodeSelection;
      this.salesOfficeCodeSelection = result.SalesOfficeCodeSelectionC;
      this.profileId = result.profileId;
      this.userId = result.userID;
      this.AWSDataId = result.AWSDataId;
@@ -169,234 +170,225 @@
    queryForrecords3({
      dealer: this.dealer
    }).then(result => {
      // if (result.length > 0 && result[0].FirstParagraph__c == true) {
      //   if (!confirm("该经销商为先款对象,是否继续申请修理?")) {
      //     return;
      //   }
      // }
      // if (
      //   this.numberofEffectiveContract == "无" && this.newProductGuaranteTxt != "2: 多年保修" &&
      //   this.newProductGuaranteTxt != "2: 服务多年保修" && this.newProductGuaranteTxt != "8: 市场多年保修" &&
      //   this.onSiteRepair == "直送SORC修理"
      // ) {
      //   if (!confirm("设备为非维修合同且非多年保修对象品,请确认是否直送SORC修理?")) {
      //     return;
      //   }
      // }
      // if ((this.maintenanceContract != undefined || this.VMMaintenanceContract != undefined) &&
      //   this.onSiteRepair == "RC修理" && this.FSEState == "山东省"
      // ) {
      //   if (!confirm("该设备为维修合同或多年保修对象品,请确认是否送至RC修理?")) {
      //     return;
      //   }
      // }
      // var today = Date.now();
      // var dateReceiptQuestions = Date.parse(this.dateReceiptQuestions);
      // var dates = (today - dateReceiptQuestions) / (24 * 60 * 60 * 1000);
      // if (this.profileName != "系统管理员" && this.userName != "胡 玉成" && this.userName != "李 琪清" &&
      //   this.userName != "郭 洋" &&
      //   this.delayReportReason == undefined && dates > "1" &&
      //   this.repairSource != "QIS转修理") {
      //   alert("申请修理时SAP修理申请日超过问题联络收到日1天,必须填写问超时报告的理由");
      //   return;
      // }
      // if (this.quickRepairSign == true && (this.numberofEffectiveContract == "有" || this.newProductGuaranteTxt == "2: 多年保修" ||
      //     this.newProductGuaranteTxt == "2: 服务多年保修" || this.newProductGuaranteTxt == "8: 市场多年保修") &&
      //   (this.onSiteRepair == "RC修理" || this.onSiteRepair == "办事处修理" || this.onSiteRepair == "现场修理")) {
      //   if (this.RCCD == "2.东北" || this.RCCD == "3.西北") {
      //     if (!confirm("该型号对应为合同或多年保对象品。如确认为大修理故障,需要选择直送SORC修理,请确认是否继续。")) {
      //       return;
      //     }
      //   } else if (this.RCCD == "1.华北" || this.RCCD == "6.华南" || this.RCCD == "4.西南") {
      //     if (!confirm("该型号对应为合同或多年保对象品。如确认为大修理故障,需要选择直送OGZ修理,请确认是否继续。")) {
      //       return;
      //     }
      //   }
      // }
      // var returnsProductWay = this.returnsProductway;
      // if (returnsProductWay == undefined) {
      //   if (!confirm("返品方式为空,是否继续申请修理!")) {
      //     return;
      //   }
      // }
      var DetailedAddress = this.detailedAddress;
      // if (this.assetOwner != "Olympus") {
      //   if (DetailedAddress != undefined) {
      //     var prompt = '当前直返收货地址为:' + DetailedAddress + ',您确认不修改了吗?';
      //     if (!confirm(prompt)) {
      //       return;
      //     }
      //   } else {
      //     alert('当前修理没有录入直返收货的详细地址,不能申请修理!');
      //     return;
      //   }
      // }
      // queryForEquipments({
      //   deliveredProductId: this.deliveredProductId,
      // }).then(equipments => {
      //   if (equipments != null && equipments.length > 0) {
      //     var equipment = equipments[0];
      //     if (equipment.Status == "廃棄") {
      //       alert("设备废弃,不能提交申请!");
      //       return;
      //     }
      //   }
      // });
      // if (this.FSEApplyForRepairTime != undefined) {
      //   alert("已修理申请,不再修理申请了");
      //   return;
      // }
      var surplusCount = 0;
      // if (this.URFReapir == false) {
      //   queryForUrfAsset({
      //     maintenanceContractId: this.maintenanceContractId,
      //     deliveredProductId: this.deliveredProductId,
      //   }).then(urfAsset => {
      //     var seriesMaxRepairCount = 0;
      //     var seriesRepairCount = 0;
      //     if (urfAsset != null && urfAsset.length > 0) {
      //       seriesMaxRepairCount = urfAsset[0].Series_MaxRepairCount_F__c;
      //       seriesRepairCount = urfAsset[0].Series_RepairCount_F__c;
      //       surplusCount = seriesMaxRepairCount - seriesRepairCount;
      //     }
      //   });
      //   queryForUrfSeriesInfo({
      //     URFLimitSerial: this.URFLimitSerial,
      //   }).then(urfSeriesInfo => {
      //     var urfSeries = "";
      //     if (urfSeriesInfo != null && urfSeriesInfo.length > 0) {
      //       urfSeries = urfSeriesInfo[0].URFLimitSerial__c;
      //     }
      //     queryForRepairCount({
      //       maintenanceContractId: this.maintenanceContractId,
      //       status1: "1.受理完毕",
      //       URFLimitSerial: urfSeries,
      //     }).then(repairCount => {
      //       if (repairCount.length > 0 && surplusCount == 1) {
      //         alert("该设备关联限次合同,目前剩余次数小于送修设备。请等待进行中修理完成后再进行申请");
      //         return;
      //       }
      //     });
      //   });
      // }
      // if (this.status != "草案中" && this.status != "1.受理完毕(SAP待发送)" && this.status != "4.修理品返送阶段") {
      //   alert("不是草案中不能申请");
      // } else {
      //   if (this.dealer != undefined) {
      //     queryForFindInvalidLicense({
      //       dealerId: this.dealerId,
      //     }).then(findInvalidLicense => {
      //       console.log(findInvalidLicense);
      //       if (findInvalidLicense.length > 0) {
      //         alert("经销商三证不在有效期,无法送修");
      //         return;
      //       }
      //     });
      //   }
      // }
      // if (this.ifDeadHurt == "有") {
      //   if (!confirm("是否确认AE要提交?")) {
      //     return;
      //   }
      // }
      // if (this.dayLater30 == "是") {
      //   alert("创建后超过30天,不能申请了");
      //   return;
      // }
      // var prompt11 = "合同内大修次数已用完,当前修理为合同外的修理,是否继续?";
      // if (this.URFReapir == false && surplusCount == 0) {
      //   if (!confirm(prompt11)) {
      //     return;
      //   }
      // }
      updateForRepair1({
        recordId: this.Id,
      }).then(result => {
        if (result.length > 0) {
          var split = result.split(", ");
          alert(split[1]);
      if (result.length > 0 && result[0].FirstParagraph__c == true) {
        if (!confirm("该经销商为先款对象,是否继续申请修理?")) {
          return;
        }
      }
      if (
        this.numberofEffectiveContract == "无" && this.newProductGuaranteTxt != "2: 多年保修" &&
        this.newProductGuaranteTxt != "2: 服务多年保修" && this.newProductGuaranteTxt != "8: 市场多年保修" &&
        this.onSiteRepair == "直送SORC修理"
      ) {
        if (!confirm("设备为非维修合同且非多年保修对象品,请确认是否直送SORC修理?")) {
          return;
        }
      }
      if ((this.maintenanceContract != undefined || this.VMMaintenanceContract != undefined) &&
        this.onSiteRepair == "RC修理" && this.FSEState == "山东省"
      ) {
        if (!confirm("该设备为维修合同或多年保修对象品,请确认是否送至RC修理?")) {
          return;
        }
      }
      var today = Date.now();
      var dateReceiptQuestions = Date.parse(this.dateReceiptQuestions);
      var dates = (today - dateReceiptQuestions) / (24 * 60 * 60 * 1000);
      if (this.profileName != "系统管理员" && this.userName != "胡 玉成" && this.userName != "李 琪清" &&
        this.userName != "郭 洋" &&
        this.delayReportReason == undefined && dates > "1" &&
        this.repairSource != "QIS转修理") {
        alert("申请修理时SAP修理申请日超过问题联络收到日1天,必须填写问超时报告的理由");
        return;
      }
      if (this.quickRepairSign == true && (this.numberofEffectiveContract == "有" || this.newProductGuaranteTxt == "2: 多年保修" ||
          this.newProductGuaranteTxt == "2: 服务多年保修" || this.newProductGuaranteTxt == "8: 市场多年保修") &&
        (this.onSiteRepair == "RC修理" || this.onSiteRepair == "办事处修理" || this.onSiteRepair == "现场修理")) {
        if (this.RCCD == "2.东北" || this.RCCD == "3.西北") {
          if (!confirm("该型号对应为合同或多年保对象品。如确认为大修理故障,需要选择直送SORC修理,请确认是否继续。")) {
            return;
          }
        } else if (this.RCCD == "1.华北" || this.RCCD == "6.华南" || this.RCCD == "4.西南") {
          if (!confirm("该型号对应为合同或多年保对象品。如确认为大修理故障,需要选择直送OGZ修理,请确认是否继续。")) {
            return;
          }
        }
      }
      var returnsProductWay = this.returnsProductway;
      if (returnsProductWay == undefined) {
        if (!confirm("返品方式为空,是否继续申请修理!")) {
          return;
        }
      }
      var DetailedAddress = this.detailedAddress;
      if (this.assetOwner != "Olympus") {
        if (DetailedAddress != undefined) {
          var prompt = '当前直返收货地址为:' + DetailedAddress + ',您确认不修改了吗?';
          if (!confirm(prompt)) {
            return;
          }
        } else {
          alert('当前修理没有录入直返收货的详细地址,不能申请修理!');
          return;
        }
      }
      queryForEquipments({
        deliveredProductId: this.deliveredProductId,
      }).then(equipments => {
        if (equipments != null && equipments.length > 0) {
          var equipment = equipments[0];
          if (equipment.Status == "廃棄") {
            alert("设备废弃,不能提交申请!");
            return;
          }
        }
      });
      if (this.FSEApplyForRepairTime != undefined) {
        alert("已修理申请,不再修理申请了");
        return;
      }
      var surplusCount = 0;
      if (this.URFReapir == false) {
        queryForUrfAsset({
          maintenanceContractId: this.maintenanceContractId,
          deliveredProductId: this.deliveredProductId,
        }).then(urfAsset => {
          var seriesMaxRepairCount = 0;
          var seriesRepairCount = 0;
          if (urfAsset != null && urfAsset.length > 0) {
            seriesMaxRepairCount = urfAsset[0].Series_MaxRepairCount_F__c;
            seriesRepairCount = urfAsset[0].Series_RepairCount_F__c;
            surplusCount = seriesMaxRepairCount - seriesRepairCount;
          }
        });
        queryForUrfSeriesInfo({
          URFLimitSerial: this.URFLimitSerial,
        }).then(urfSeriesInfo => {
          var urfSeries = "";
          if (urfSeriesInfo != null && urfSeriesInfo.length > 0) {
            urfSeries = urfSeriesInfo[0].URFLimitSerial__c;
          }
          queryForRepairCount({
            maintenanceContractId: this.maintenanceContractId,
            status1: "1.受理完毕",
            URFLimitSerial: urfSeries,
          }).then(repairCount => {
            if (repairCount.length > 0 && surplusCount == 1) {
              alert("该设备关联限次合同,目前剩余次数小于送修设备。请等待进行中修理完成后再进行申请");
              return;
            }
          });
        });
      }
      if (this.status != "草案中" && this.status != "1.受理完毕(SAP待发送)" && this.status != "4.修理品返送阶段") {
        alert("不是草案中不能申请");
      } else {
        if (this.dealer != undefined) {
        queryForReocrds({
          inchargeStaffId: this.inchargeStaffId,
        }).then(records => {
          if (records != null && records.length > 0) {
            var staff = records[0];
            updateRepair2({
              recordId: this.Id,
              staff: staff,
              DWSign: this.DWSign,
              statusc: "1.受理完毕",
              DOJStatus: this.DOJStatus,
              SAPcondition: this.SAPcondition,
            }).then(result => {
              if (result.length > 0) {
                var split = result.split(", ");
                alert(split[1]);
              } else {
                if (this.salesOfficeCodeSelection == "成都RC") {
                  alert("现阶段,成都RC仅受理四川(西藏)内镜、西南全域CV/CLV,其余实物请发至广州RC。");
          queryForFindInvalidLicense({
            dealerId: this.dealerId,
          }).then(findInvalidLicense => {
            console.log(findInvalidLicense);
            if (findInvalidLicense.length > 0) {
              alert("经销商三证不在有效期,无法送修");
              return;
            }
          });
        }
      }
      if (this.ifDeadHurt == "有") {
        if (!confirm("是否确认AE要提交?")) {
          return;
        }
      }
      if (this.dayLater30 == "是") {
        alert("创建后超过30天,不能申请了");
        return;
      }
      var prompt11 = "合同内大修次数已用完,当前修理为合同外的修理,是否继续?";
      if (this.URFReapir == false && surplusCount == 0) {
        if (!confirm(prompt11)) {
          return;
        }
      }
      updateForRepair1({
        recordId: this.Id
      }).then(result => {
        if (result != null && result.length > 0) {
          var split = result.split(", ");
          alert(split[1]);
        } else {
          queryForReocrds({
            inchargeStaffId: this.inchargeStaffId,
          }).then(records => {
            if (records != null && records.length > 0) {
              var staff = records[0];
              console.log(staff);
              updateRepair2({
                recordId: this.Id,
                staff: staff,
                DWSign: this.DWSign,
                statusc: "1.受理完毕",
                DOJStatus: this.DOJStatus,
                SAPcondition: this.SAPcondition,
              }).then(result => {
                console.log(result);
                if (result != null && result.length > 0) {
                  var split = result.split(", ");
                  alert(split[1]);
                } else {
                  if (this.salesOfficeCodeSelection == "成都RC") {
                    alert("现阶段,成都RC仅受理四川(西藏)内镜、西南全域CV/CLV,其余实物请发至广州RC。");
                  }
                }
              }
              });
              queryForRds({
                recordId: this.Id,
              }).then(rds => {
                if (rds != null && rds.length > 0) {
                  var repairAft = rds[0];
                  if (
                    repairAft.NewProductGuarante_Formula__c != repairAft.ProductGuarante_Create__c
                  ) {
                  if (repairAft.NewProductGuarante_Formula__c != repairAft.ProductGuarante_Create__c) {
                    alert("该设备保修信息已发生变化,请了解");
                  }
                }
              });
            });
          } else {
            alert("没有找到 修理委托者");
          }
        });
            } else {
              alert("没有找到 修理委托者");
            }
          });
        }
      });
    });
    // var staticResource;
    // getStaticResource({
    //   sobj: "Repair__c"
    // }).then(result => {
    //   console.log(result);
    //   staticResource = JSON.parse(result);
    var staticResource;
    var DetailedAddress = this.detailedAddress;
    //   window.AWSService.query(staticResource.queryUrl,
    //     this.AWSDataId,
    //     function (data) {
    //       console.log(data);
    //       if (data && data.object) {
    //         DetailedAddress = data.object.detailedAddress;
    //       }
    //       this.foo();
    //     },
    //     staticResource.token)
    // })
    getStaticResource({
      sobj: "Repair__c"
    }).then(result => {
      console.log(result);
      staticResource = JSON.parse(result);
      Promise.all([
        loadScript(this, AWSService + '/AWSService.js'),
        loadScript(this, jqueryurl),
        loadScript(this, jq + "/dist/jquery.js"),
        loadScript(this, con),
        loadScript(this, apex),
        loadScript(this, common)
      ]).then(() => {
        window.AWSService.query(staticResource.queryUrl,
          this.AWSDataId,
          function (data) {
            console.log(data);
            if (data && data.object) {
               DetailedAddress = data.object.detailedAddress;
            }
            this.foo();
          },
          staticResource.token);
      });
    })
  }
  ShowToastEvent(msg, type) {