/**
 * 合同签订拓展
 */

var partyName = "";
var selectPerson = "";
shr.defineClass(
  "shr.empContract.BatchContractSignBizBillEditEx",
  shr.empContract.ContractSignBizBillEdit,
  {
    initalizeDOM: function () {
      shr.empContract.BatchContractSignBizBillEditEx.superClass.initalizeDOM.call(
        this
      );
      var _self = this;
    },

    initalizeDefaultData: function () {
      var self = this;

      //初始化连续签订、连续签订次数
      this.initContinuousSigned();

      if (self.getOperateState() == "VIEW") {
        return;
      }

      var selectObj = self.getField("dataRangeSelected"),
        batchParma = empBatchParamUtils.getCacheData(),
        selectIds = batchParma.selectedIds,
        currentPageIds = batchParma.currentPageAllIds;
      if (selectIds) {
        selectObj.shrSelect("setValue", "selectedValue");
        if(self.operateState == 'ADDNEW'){
            self.setPartyData(selectIds); 
        }
      } else {
        //弃用currentPageValue
        selectObj.shrSelect("setValue", "allValue");
        selectObj.shrSelect("disable");
      }
    },

    setPartyData: function (selectIds) {
      var self = this;
      //var   batchParma = shr.empBatchParamUtils.getCacheData();
      //var  selectIds = batchParma.selectedIds;
      selectPerson = selectIds;
      //查询第一个的劳动合同主体
      //对selectIds使用","分割,去第一个元素
      var firstId = _self.getFirstElement(selectIds);
      //调用
      self.remoteCall({
        type: "post",
        async: false,
        method: "queryContractSub",
        param: {
          personId: firstId,
        },
        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);
        },
      });
    },

    getFirstElement: function (selectIds) {
      // 检查 selectIds 是否为 null 或空字符串
      if (selectIds == null || selectIds == undefined) {
        return null;
      }

      // 使用 "," 分割字符串
      var elements = selectIds.split(",");

      // 检查分割后的数组是否为空
      if (elements.length == 0) {
        return null;
      }

      // 返回第一个元素
      return elements[0];
    },
  

      //如果labContractFirstParty的值不同,则提示:
    validate:function(){
      var self = this;
      var partyInfo = $("#" + self.getRealId("labContractFirstParty")).shrPromptBox('getValue');
      var partyId = partyInfo.id;
        //调用
      self.remoteCall({
        type: "post",
        async: false,
        method: "checkContractSub",
        param: {
          personIds: selectPerson,
          partyId: partyId
        },
        success: function (resList) {
          //赋值到控件
          if (resList) {
            //,
            var personName = "";
            for (int i = 0; i < resList.size(); i++) {
                var valmap = resList.get(i);
                // 检查是否为第一个元素，避免在 personName 前面添加 ","
                if (i > 0) {
                    personName += ",";
                }
                personName += valmap.get("personName");
            }
            //员工:"" 
            var msgStr= "员工:"+personName+",选择劳动合同主体与入职流程约定不一致，是否继续提交?";
            shr.showConfirm(msgStr, function() {
              return true;
            },function(){
              return false;
            });
          }
        },
        error: function (res) {
          return false;
        },
      });
    },
      
   





});




