lizhidan.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. var _person = {}
  2. var _hrOrgUnit = {}
  3. var _HRBizDefine = [] // 用户设置的变动操作
  4. var isSameDatePersonChange = null
  5. //是否一天多次变动 是,最后工作日等于离职日期;
  6. //false:根据 isDefaultSameday判断最后工作日和离职日期是否同一天
  7. var isDefaultSameday = null
  8. //最后工作日和离职日期是否同一天( true:同一天;false:最后工作日是离职日期前一天)
  9. var isResignNextMonth = null
  10. _this.pageinit = function () {
  11. initHeader()
  12. checkIsExistResignBill()
  13. // getExistResignBillInfo()
  14. // $("#btnAddnew").hide()
  15. // mbos('editgrid1').addEntry()
  16. if (requestParam.operateState === "ADDNEW") {
  17. mbos('editgrid1').addEntry()
  18. setTimeout(function () {
  19. setBillId()
  20. CheckDefaultSameDayService("")
  21. getHRBizDefineByUiClass()
  22. }, 1000)
  23. }
  24. mbos("applicationHistory").bind("click", function () {
  25. mbos.ui.open({
  26. path: mbos.pageInfo.path,
  27. name: "bill.listui",
  28. });
  29. })
  30. $("#application_img").on('error', function () {
  31. $(this).attr('src', '/mbos/store/4000148/'+mbos.pageInfo.path+'/default.png');
  32. });
  33. }
  34. _this.edit = function (event) {
  35. return page.edit && page.edit(event);
  36. }
  37. _this.addnew = function (event) {
  38. return page.addnew && page.addnew(event);
  39. }
  40. _this.save = function (event) {
  41. var vali = mbos.ng.invokeAllScope("validate", { method: "save" });
  42. if (!vali) {
  43. return;
  44. }
  45. if (event.isvaliSuccess === false) {
  46. return;
  47. }
  48. if (requestParam.operateState === "ADDNEW") {
  49. mbos("billState").value({ isenum: true, value: 0 })
  50. }
  51. function _save() {
  52. return CheckResignBillInfoService(function () { save(event) })
  53. }
  54. //弱校验提示
  55. CheckWeakService(_save);
  56. //CheckResignAssign(_save)
  57. }
  58. _this.submit = function (event) {
  59. var vali = mbos.ng.invokeAllScope("validate", { method: "submit" });
  60. if (!vali) {
  61. return;
  62. }
  63. mbos("billState").value({ isenum: true, value: 1 })
  64. function _submit() {
  65. return CheckResignBillInfoService(function () { submit(event) })
  66. }
  67. //弱校验提示
  68. CheckWeakService(_submit);
  69. // CheckResignAssign(_submit)
  70. }
  71. _this.back = function (event) {
  72. return page.back && page.back(event);
  73. }
  74. _this.afterSave = function (e) {
  75. if (requestParam.operateState === "ADDNEW") {
  76. mbos.ui.open({
  77. path: mbos.pageInfo.path,
  78. name: "application.editui",
  79. params: {
  80. billID: e.keyValue,
  81. operateState: "EDIT"
  82. }
  83. });
  84. } else {
  85. }
  86. }
  87. mbos('entity').bind('afterLoad', function () {
  88. if (requestParam.operateState !== "ADDNEW") {
  89. getHRBizDefineByUiClass()
  90. }
  91. })
  92. // 获取变动操作联动数据
  93. function getHRBizDefineByUiClass() {
  94. mbos.eas.invokeScript({
  95. name: "commonOSFservice",
  96. param: ['getHRBizDefineByUiClass', JSON.stringify({ uiClass: "com.kingdee.eas.hr.affair.app.ResignBizBill.form" })],
  97. success: function (res) {
  98. _HRBizDefine = res
  99. var { outEmpType, affairActionReason, variationReason } = res[0] || {outEmpType:[], affairActionReason: [], variationReason: []}
  100. var first = res.map((item) => "'" + item.number + "'");
  101. var sec = outEmpType.map((item) => "'" + item.number + "'");
  102. var thrid = affairActionReason.map((item) => "'" + item.number + "'");
  103. var fourth = variationReason.map((item) => "'" + item.number + "'");
  104. if (requestParam.operateState === "ADDNEW" && res.length) {
  105. mbos("entrys.hrBizDefine", 0).value({ name: res[0].name, id: res[0].id, number: res[0].number });
  106. if (sec.length === 1) mbos("entrys.oldEmpType", 0).value(outEmpType[0])
  107. if (thrid.length === 1) mbos("entrys.affairActionReason", 0).value(affairActionReason[0])
  108. if (fourth.length === 1) mbos("entrys.variationReason", 0).value(variationReason[0])
  109. }
  110. // 用户设置的F7选项为空时, 把过滤条件设成xnull, 否则会全部显示
  111. if (first.length === 0) { first = ['"xnull"'] }
  112. if (sec.length === 0) { sec = ['"xnull"'] }
  113. if (thrid.length === 0) { thrid = ['"xnull"'] }
  114. if (fourth.length === 0) { fourth = ['"xnull"'] }
  115. // F7 选项 过滤
  116. mbos("entrys.hrBizDefine", 0).attr('dynamicFilter', 'number in (' + first.join(",") + ')');
  117. mbos("entrys.oldEmpType", 0).attr('dynamicFilter', 'number in (' + sec.join(",") + ')');
  118. mbos("entrys.affairActionReason", 0).attr('dynamicFilter', 'number in (' + thrid.join(",") + ')');
  119. mbos("entrys.variationReason", 0).attr('dynamicFilter', 'number in (' + fourth.join(",") + ')');
  120. },
  121. error: function (data) {
  122. if (typeof (data) == "string") {
  123. mbos.msgBox.showError("", data);
  124. } else {
  125. mbos.msgBox.showError({ ...data, msg: "" });
  126. }
  127. }
  128. })
  129. }
  130. _this.bizdatachange = function (event) {
  131. // isSameDatePersonChange
  132. //是否一天多次变动 是,最后工作日等于离职日期;
  133. //false:根据 isDefaultSameday判断最后工作日和离职日期是否同一天
  134. //isDefaultSameday
  135. var value = event.new_value
  136. if (!value) return
  137. CheckDefaultSameDayService(value, callback)
  138. function callback() {
  139. var nextDate = "";
  140. if (isSameDatePersonChange) {
  141. mbos("entrys.leftCompanyDate", 0).value(value);
  142. } else {
  143. if (isDefaultSameday) {
  144. mbos("entrys.leftCompanyDate", 0).value(value)
  145. } else {
  146. var prev = getPrevDate(value)
  147. mbos("entrys.leftCompanyDate", 0).value(prev)
  148. }
  149. }
  150. }
  151. }
  152. //后一天
  153. function getNextDate(value) {
  154. var date = new Date(value)
  155. var nextDate = new Date(date.getTime() + 24 * 60 * 60 * 1000)
  156. nextDate = nextDate.format('yyyy-MM-dd')
  157. return nextDate
  158. }
  159. function getPrevDate(value, day) {
  160. var date = new Date(value)
  161. var prevDate = day ? new Date(date.getTime() + day * 24 * 60 * 60 * 1000) : new Date(date.getTime() - 24 * 60 * 60 * 1000)
  162. var s1 = prevDate.format('yyyy-MM-dd')
  163. return s1
  164. }
  165. _this.leftdatechange = function (event) {
  166. var value = event.new_value
  167. var bizDate = mbos("entrys.bizDate", 0).value()
  168. if (!bizDate) {
  169. var param1 = { title: localeResource.msg50 };
  170. mbos.ui.showInfo(param1);
  171. return
  172. }
  173. var prev = getPrevDate(bizDate)
  174. if (isSameDatePersonChange) {
  175. if (value !== bizDate) {
  176. var param2 = { title: localeResource.msg43 };
  177. mbos.ui.showInfo(param2);
  178. mbos("entrys.leftCompanyDate", 0).value(bizDate);
  179. //禁用用户日期
  180. nextDate = getNextDate(bizDate);
  181. mbos("entrys.forbidUserDate", 0).value(nextDate);
  182. }
  183. } else {
  184. if (value !== bizDate && value !== prev) {
  185. var param3 = { title: localeResource.msg44 };
  186. mbos.ui.showInfo(param3);
  187. mbos("entrys.leftCompanyDate", 0).value(bizDate);
  188. //禁用用户日期
  189. nextDate = getNextDate(bizDate);
  190. mbos("entrys.forbidUserDate", 0).value(nextDate);
  191. }else{
  192. //禁用用户日期
  193. nextDate = getNextDate(value);
  194. mbos("entrys.forbidUserDate", 0).value(nextDate);
  195. }
  196. }
  197. }
  198. mbos('page').bind('afterRendered', function () {
  199. })
  200. mbos("page").bind("afterSave", function (e) {
  201. var param1 = { title: localeResource.msg45 };
  202. mbos.ui.showInfo(param1);
  203. if (requestParam.operateState === "ADDNEW") {
  204. mbos.ui.open({
  205. path: mbos.pageInfo.path,
  206. name: "application.editui",
  207. params: {
  208. billID: e.keyValue,
  209. operateState: "EDIT"
  210. }
  211. });
  212. }
  213. })
  214. mbos("page").bind("afterSubmit", function (e) {
  215. var param1 = { title: localeResource.msg46 };
  216. mbos.ui.showInfo(param1);
  217. mbos.ui.open({
  218. path: mbos.pageInfo.path,
  219. name: "bill.listui",
  220. params: {
  221. billID: mbos("entity").value().id,
  222. }
  223. });
  224. })
  225. //保存,提交弱校验提示
  226. function CheckWeakService(callback) {
  227. initEntityDataBeforeRequest()
  228. var data = mbos('entity').data
  229. mbos.eas.invokeScript({
  230. name: "commonOSFservice",
  231. param: ['checkWeakHireOrFlucExisService', JSON.stringify({ model: data })],
  232. success: function (res) {
  233. if (res.errorCode == '1') {
  234. mbos.ui.showConfirm({
  235. title: localeResource.msg53,
  236. msg: res.msg,
  237. callback: function (data) {
  238. if (data == 0) {
  239. //点击确定
  240. CheckResignAssign(callback)
  241. //callback && callback()
  242. }
  243. }
  244. });
  245. } else {
  246. CheckResignAssign(callback)
  247. }
  248. },
  249. error: function (data) {
  250. if (typeof (data) == "string") {
  251. mbos.msgBox.showError("", data);
  252. } else {
  253. mbos.msgBox.showError({ ...data, msg: "" });
  254. }
  255. }
  256. })
  257. }
  258. function setBillId() {
  259. var param = [];
  260. param[0] = mbos('entity').data.bosType;
  261. mbos.eas.invokeScript({
  262. name: "getbillid",
  263. param: param,
  264. success: function (data) {
  265. mbos('entity').data.id = data;
  266. }
  267. })
  268. }
  269. function initEntityDataBeforeRequest() {
  270. mbos("hrOrgUnit").value(_hrOrgUnit)
  271. mbos('entrys.person', 0).value(_person)
  272. mbos("applier").value(_person)
  273. mbos("isMultiEntry").value(false)
  274. var data = mbos('entity').data
  275. data._entityName = "com.kingdee.eas.hr.affair.app.ResignBizBill"
  276. data.ismobile = "true"
  277. }
  278. // 获取头部信息
  279. function initHeader() {
  280. mbos.eas.invokeScript({
  281. name: "commonOSFservice",
  282. param: ['getMobileUserInfoService', JSON.stringify({})],
  283. success: function (res) {
  284. var { personName, companyName, photo = "xxx", positionName, departmentName, personNumber, hrOrgUnit } = res
  285. _person.name = personName
  286. _person.id = easContext.person.id
  287. console.log(easContext.person)
  288. _person.bosType = easContext.person.bosType
  289. _hrOrgUnit = hrOrgUnit // id name
  290. $("#applicationHistory").text(localeResource.msg7)
  291. console.log($("#application_number"), personNumber, "per")
  292. $("#application_img").attr("src", photo ? "data:image/png;base64," + photo : '/mbos/store/4000148/'+mbos.pageInfo.path+'/default.png')
  293. $("#application_name").text(personName)
  294. $("#application_number").text(personNumber)
  295. $("#application_job").text(positionName + (departmentName ? (" | " + departmentName) : ""))
  296. $("#application_company").text(companyName);
  297. mbos("entrys_oldAdminOrg", 0).value({ name: res.adminName, id: res.adminId });
  298. mbos("entrys_oldPosition", 0).value({ name: res.positionName, id: res.positionId });
  299. mbos("entrys_oldJobGrade", 0).value({ name: res.jobGradeName, id: res.jobGradeId });
  300. mbos("entrys_oldJobLevel", 0).value({ name: res.jobLevelName, id: res.jobLevelId });
  301. $(".header_container").css("visibility", "visible")
  302. if (requestParam.operateState === "ADDNEW") {
  303. GetResignEmpBillNum()
  304. }
  305. setTimeout(function(){
  306. var dataSubmit = mbos('entity').value();
  307. mbos('nextperson1').checkParticipantPerson({
  308. editdata: dataSubmit,
  309. callback: function(){
  310. var nextPerson = mbos('entity').data.workflowNextPerson;
  311. }
  312. });
  313. },1000);
  314. },
  315. error: function (e) {
  316. $("#applicationHeader").hide()
  317. }
  318. })
  319. }
  320. //是否存在在途的单据
  321. function getExistResignBillInfo() {
  322. mbos.eas.invokeScript({
  323. name: "commonOSFservice",
  324. param: ['GetExistResignBillInfoService', JSON.stringify({})],
  325. success: function (res) {
  326. if (res.isExist) {
  327. mbos.ui.open({
  328. path: mbos.pageInfo.path,
  329. name: "billDetail.editui",
  330. params: {
  331. billID: mbos("entity").value().id,
  332. }
  333. });
  334. }
  335. },
  336. error: function (e) {
  337. console.log(e);
  338. }
  339. })
  340. }
  341. //检查员工有待办任务时是否允许提交离职申请
  342. function CheckResignAssign(callback) {
  343. initEntityDataBeforeRequest()
  344. var data = mbos('entity').data
  345. console.log(data, "检查员工有待办任务时是否允许提交离职申请 data--------")
  346. mbos.eas.invokeScript({
  347. name: "commonOSFservice",
  348. param: ['CheckResignAssignService', JSON.stringify({ model: data })],
  349. success: function (res) {
  350. var { isContainAssign, isResignCheck, assignMsg } = res
  351. if (isContainAssign) {
  352. if (isResignCheck) {
  353. mbos.ui.showConfirm({
  354. title: assignMsg,
  355. msg: "",
  356. callback: function (data) {
  357. if (data == 0) {
  358. callback && callback()
  359. }
  360. }
  361. });
  362. } else {
  363. mbos.ui.showInfo({ title: assignMsg, msg: "" });
  364. }
  365. } else {
  366. callback && callback()
  367. }
  368. },
  369. error: function (data) {
  370. if (typeof (data) == "string") {
  371. mbos.msgBox.showError("", data);
  372. } else {
  373. mbos.msgBox.showError({ ...data, msg: "" });
  374. }
  375. }
  376. })
  377. }
  378. // 保存和提交前校验业务数据
  379. function CheckResignBillInfoService(callback, fallback) {
  380. var data = mbos('entity').data
  381. mbos.eas.invokeScript({
  382. name: "commonOSFservice",
  383. param: ['CheckResignBillInfoService', JSON.stringify({ model: data })],
  384. success: function (res) {
  385. callback && callback()
  386. },
  387. error: function (data) {
  388. if (typeof (data) == "string") {
  389. mbos.msgBox.showError("", data);
  390. } else {
  391. mbos.msgBox.showError({ ...data, msg: "" });
  392. }
  393. }
  394. })
  395. }
  396. // 是否申请记录存在单据
  397. function checkIsExistResignBill() {
  398. mbos.eas.invokeScript({
  399. name: "commonOSFservice",
  400. param: ['IsExistResignBillRecordsService', JSON.stringify({})],
  401. success: function (res) {
  402. if (res.isExist) {
  403. $("#applicationHistory").show()
  404. }
  405. },
  406. error: function (e) {
  407. console.log(e);
  408. }
  409. })
  410. }
  411. // 获取单据编号
  412. function GetResignEmpBillNum() {
  413. var data = {
  414. hrOrgUnitId: _hrOrgUnit.id,
  415. businessType: 3,
  416. personId: _person.id
  417. }
  418. mbos.eas.invokeScript({
  419. name: "commonOSFservice",
  420. param: ['GetResignEmpBillNumService', JSON.stringify(data)],
  421. success: function (res) {
  422. if (res.respObj) {
  423. mbos('number').value(res.respObj)
  424. } else {
  425. mbos('number').show()
  426. }
  427. },
  428. error: function (data) {
  429. if (typeof (data) == "string") {
  430. mbos.msgBox.showError("", data);
  431. } else {
  432. mbos.msgBox.showError({ ...data, msg: "" });
  433. }
  434. }
  435. })
  436. }
  437. _this.bdczchange = function (event) {
  438. console.log(_HRBizDefine)
  439. console.log(event)
  440. var { outEmpType, affairActionReason, variationReason } = _HRBizDefine.find((item) => item.id === event.new_value.id) || { outEmpType: [], affairActionReason: [], variationReason: [] }
  441. var sec = outEmpType.map((item) => "'" + item.number + "'");
  442. var thrid = affairActionReason.map((item) => "'" + item.number + "'");
  443. var fourth = variationReason.map((item) => "'" + item.number + "'");
  444. if (sec.length === 1) mbos("entrys.oldEmpType", 0).value(outEmpType[0])
  445. if (thrid.length === 1) mbos("entrys.affairActionReason", 0).value(affairActionReason[0])
  446. if (fourth.length === 1) mbos("entrys.variationReason", 0).value(variationReason[0])
  447. if (sec.length === 0) { sec = ['"xnull"'] }
  448. if (thrid.length === 0) { thrid = ['"xnull"'] }
  449. if (fourth.length === 0) { fourth = ['"xnull"'] }
  450. mbos("entrys.oldEmpType", 0).attr('dynamicFilter', 'number in (' + sec.join(",") + ')');
  451. mbos("entrys.affairActionReason", 0).attr('dynamicFilter', 'number in (' + thrid.join(",") + ')');
  452. mbos("entrys.variationReason", 0).attr('dynamicFilter', 'number in (' + fourth.join(",") + ')');
  453. }
  454. function getEditData() {
  455. mbos('entity').data.fromMbos = true;
  456. return mbos('entity').data;
  457. }
  458. function save(e) {
  459. var vali = mbos.ng.invokeAllScope("validate", { method: "save" });
  460. if (!vali) {
  461. return;
  462. }
  463. if (e.isvaliSuccess === false) {
  464. return;
  465. }
  466. // this should be a init Action! TODO
  467. mbos.post({
  468. url: "/mbos/editpage/save",
  469. param: {
  470. "bostype": getEditData().bosType,
  471. "model": JSON.stringify(getEditData()),
  472. "uiname": requestParam.name
  473. },
  474. success: function (data) {
  475. event = event || {};
  476. angular.extend(event, data);
  477. mbos.page.fire("afterSave", event);
  478. },
  479. error: function (data) {
  480. if (typeof (data) == "string") {
  481. mbos.msgBox.showError("", data);
  482. } else {
  483. mbos.msgBox.showError({ ...data, msg: "" });
  484. }
  485. }
  486. });
  487. }
  488. function submit(e) {
  489. console.log(111111)
  490. var vali = mbos.ng.invokeAllScope("validate", { method: "submit" });
  491. if (!vali) {
  492. return;
  493. }
  494. if (e.isvaliSuccess === false) {
  495. return;
  496. }
  497. //
  498. if (requestParam.isfromlcjs) {
  499. getEditData().isfromlcjs = requestParam.isfromlcjs;
  500. }
  501. if (requestParam.ssotype == "workflow") {
  502. getEditData().isfromlcjs = requestParam.isfromlcjs;
  503. }
  504. if (e.isvaliSuccess === false) {
  505. return;
  506. }
  507. mbos.post({
  508. url: "/mbos/editpage/submit",
  509. param: { "bostype": getEditData().bosType, "uiname": requestParam.name, "model": JSON.stringify(getEditData()) },
  510. success: function (data) {
  511. event = event || {};
  512. if (requestParam.ssotype == "workflow") {
  513. window.parent.postMessage("hasmbos", "*");
  514. return;
  515. }
  516. mbos.page.fire("afterSubmit", event);
  517. //mbos._invoke("afterSubmit", event);
  518. },
  519. error: function (data) {
  520. if (typeof (data) == "string") {
  521. mbos.msgBox.showError("", data);
  522. } else {
  523. mbos.msgBox.showError({ ...data, msg: "" });
  524. }
  525. }
  526. });
  527. };
  528. // 离职日期和最后工作日期是否同一天
  529. function CheckDefaultSameDayService(date, callback) {
  530. var data = {
  531. personId: easContext.person.id,
  532. hrOrgUnitId: _hrOrgUnit.id,
  533. date: date
  534. }
  535. mbos.eas.invokeScript({
  536. name: "commonOSFservice",
  537. param: ['CheckDefaultSameDayService', JSON.stringify(data)],
  538. success: function (res) {
  539. console.log(res, 'res--------------')
  540. if (res.respCode == "000000") {
  541. isDefaultSameday = res.respObj.isDefaultSameday
  542. isSameDatePersonChange = res.respObj.isSameDatePersonChange
  543. isResignNextMonth = res.respObj.isResignNextMonth
  544. var bizDate = res.respObj.bizDate
  545. console.log(bizDate, '--bizDate-----')
  546. if (bizDate) {
  547. mbos('entrys.bizDate', 0).value(bizDate)
  548. }
  549. callback && callback()
  550. }
  551. },
  552. error: function (data) {
  553. if (typeof (data) == "string") {
  554. mbos.msgBox.showError("", data);
  555. } else {
  556. mbos.msgBox.showError({ ...data, msg: "" });
  557. }
  558. }
  559. })
  560. }
  561. Date.prototype.format = function (fmt) {
  562. var o = {
  563. "M+": this.getMonth() + 1, //月份
  564. "d+": this.getDate(), //日
  565. "H+": this.getHours(), //小时
  566. "m+": this.getMinutes(), //分
  567. "s+": this.getSeconds(), //秒
  568. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  569. "S": this.getMilliseconds() //毫秒
  570. };
  571. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  572. for (var k in o)
  573. if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  574. return fmt;
  575. }
  576. _this.suggestchange = function (event) {
  577. var value = event.new_value
  578. if (value.length >= 200) {
  579. mbos.ui.showInfo({ title: localeResource.msg52 });
  580. mbos('textarea2', 0).value(value.substr(0, 200))
  581. }
  582. }