/**
 * 合同签订
 */
var selectPerson = "";
shr.defineClass("shr.empContract.SingleContractSignBizBillEditEx", shr.empContract.ContractSignBizBillEdit, {
	initalizeDOM : function () {
		shr.empContract.SingleContractSignBizBillEditEx.superClass.initalizeDOM.call(this);
		var _self= this;
    var personInfo =  $("#" + _self.getRealId('entrys.person')).shrPromptBox('getValue')
    if(null != personInfo){
        selectPerson = personInfo.id
    }
    //如果是新增的时候
    if(_self.operateState == 'ADDNEW' && "" != selectPerson){
        //设置默认值
        _self.setPartyData(selectPerson);
      }
  },
  
  setPartyData: function (selectId) {
      var self = this;
      //调用
      self.remoteCall({
        type: "post",
        async: false,
        method: "queryContractSub",
        param: {
          personId: selectId,
        },
        success: function (res) {
          //赋值到控件
          if (res) {
            $("#" + self.getRealId("labContractFirstParty")).shrPromptBox(
              "setValue",
              { id: res["id"], name: res["name"], number: res["number"] }
            );
          }
        },
        error: function (res) {
          console.log(res);
        },
      });
    },



    //如果labContractFirstParty的值不同,则提示:
    valiPartyAndSave: function(event,action) {
      var self = this;
      var partyId = $("#" + self.getRealId("labContractFirstParty")).shrPromptBox('getValue').id;
      if ("" == selectPerson || null == partyId) {
        shr.showError({message : "选取的员工或者劳动合同主体为空，请检查"});
        return false;
      }
      self.remoteCall({
          type: "post",
          async: true,
          method: "checkContractSub",
          param: {
            personIds: selectPerson,
            partyId: partyId
          },
          success: function(resList) {
            if (resList && Array.isArray(resList) && resList.length > 0) {
              const personName = resList.map(personData => personData["personName"]).join(",");
              const message = '员工:'+personName+',选择劳动合同主体与入职流程约定不一致，是否继续提交?';
              // 如果确认，返回true，否则返回false
              shr.showConfirm(message, function(){
                if(action && action =='submitEffect'){
                  self.prepareSubmitEffect(event,'submitEffect');
                }else if(action && action =='save'){
                  self.doSave(event,'save');
                }else if(action && action =='submit'){
                  self.doSubmit(event,'submit');
                } 
              });
            } else {
              if(action && action =='submitEffect'){
                self.prepareSubmitEffect(event,'submitEffect');
              }else if(action && action =='save'){
                self.doSave(event,'save');
              }else if(action && action =='submit'){
                self.doSubmit(event,'submit');
              } 
            }
          },
          error: function(res) {
            shr.showError({message :"远程调用失败:", res});
          },
        });
    },
 
  /**
	 * 保存
	 */
	saveAction: function(event) {
		var _self = this;
		if (_self.validate() && _self.verify()) {		
      _self.valiPartyAndSave(event,'save');	
		}else{
			if(_self != top){// in iframe
				shr.setIframeHeight(window.name);
			} 
		}	
	},
  
  //提交即生效
  submitEffectAction : function (event) {
    var _self = this;
    if (_self.validate() && _self.verify()) {
      shr.showConfirm(jsBizMultLan.emp_shrContractBillBaseEdit_i18n_0, function() {
        // _self.prepareSubmitEffect(event, 'submitEffect');
        _self.valiPartyAndSave(event,'submitEffect');	
      });
    }
  },
    
   //提交
  submitAction: function(event) {
    var _self = this;
    if (_self.validate() && _self.verify()) {
      shr.showConfirm($.shrI18n.common.tips.submitConfirm, function() {
        _self.valiPartyAndSave(event,'submitEffect');	
      });
    }else{
      if(_self != top){// in iframe
        shr.setIframeHeight(window.name);
      } 
    }		
  },
  

    

});