mbos_其他外出.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. _this.pageinit = function () {
  2. newPageInit()
  3. }
  4. // 从其他页面跳过来时,获取日期
  5. function setDate() {
  6. var date = moment(mbos.getRequestParams().date).format('YYYY-MM-DD')
  7. if (date && mbos.getRequestParams().operateState == 'ADDNEW') {
  8. mbos('entries_startTime', 0).value(date + ' 08:00')
  9. getStartEndTime(0)
  10. }
  11. }
  12. // 异地办公类型F7 传递变量 ,TeleOfficeType为异地办公类型数据源的id
  13. mbos('TeleOfficeType').bind('beforeLoad', function (e) {
  14. var params = setParams('getOtherOffsiteFilter', e.index) // 获取参数
  15. mbos.variable.setValue("v_entry", encodeURIComponent(JSON.stringify(params))); //赋值给变量
  16. })
  17. // 交通工具F7 传递变量 ,AtsVehicle为交通工具数据源的id
  18. mbos('AtsVehicle').bind('beforeLoad', function (e) {
  19. var params = setParams('getTrafficFilter', e.index) // 获取参数
  20. mbos.variable.setValue("v_entry", encodeURIComponent(JSON.stringify(params))); //赋值给变量
  21. })
  22. // 在页面初始化加载之后
  23. mbos('page').bind('afterLoad', function () {
  24. _this.path = mbos.pageInfo.path// 轻应用的路径编码 例如 trip880
  25. _this.detailPageCode = mbos.pageInfo.name.replace('Add', 'View') // 详情页面的编码 (个别页面可特殊处理直接写入) 例如 offsiteView.editui
  26. _this.operateState = mbos.getRequestParams().operateState // 'ADDNEW' 'EDIT' 'VIEW'
  27. _this.type = mbos.getRequestParams().type || ''; // team 团队考勤
  28. // 单据说明
  29. mbos('description').bind('click', function () {
  30. handleClickDesc()
  31. })
  32. })
  33. mbos('entries').bind('afterRendered', function (e) {
  34. multiLangField(e.index)// 兼容多语言字段回显的问题
  35. _this.setDefaultValue(e.index);
  36. if (e.index == 0) {
  37. setDate()
  38. }
  39. //debugger;
  40. if(_this.type == 'team'){
  41. mbos('entries_person',e.index).show();
  42. mbos('entries_person',e.index).attr("mustinput",true)
  43. }
  44. // 出国(境)事由控制具体事由必填
  45. _this.controlRemarkRequired(e.index);
  46. // 初始化审批流
  47. _this.getNextPerson();
  48. })
  49. // 初始化审批流
  50. _this.getNextPerson = function(){
  51. var entries = setModel('getNextPerson');
  52. var data = JSON.parse(JSON.stringify(mbos('entity').value()));
  53. data.entries = JSON.parse(JSON.stringify(entries));
  54. var date = mbos.getRequestParams().date || new Date()
  55. var today = moment(date).format('YYYY-MM-DD')
  56. var beginTime = today + ' 00:00';
  57. var endTime = today + ' 23:59';
  58. mbos.eas.invokeScript({
  59. name: "getHROrgUnit",
  60. param: [{'beginTime': beginTime, 'endTime':endTime}],
  61. success: function (res) {
  62. console.log(res)
  63. if(res.hrOrgUnitId){
  64. data.hrOrgUnit = res.hrOrgUnitId
  65. }
  66. mbos('nextperson1').checkParticipantPerson({
  67. 'editdata': data,
  68. "callback": function () { }
  69. });
  70. }
  71. })
  72. }
  73. // 设置默认值
  74. _this.setDefaultValue = function(index){
  75. var type = mbos.getRequestParams().type;
  76. var teleOfficeType = mbos('entries_teleOfficeType',index).value();
  77. if(!teleOfficeType || type==="team"){
  78. mbos('entries_teleOfficeType',index).value({
  79. bosType: "C543D2BA",
  80. id: "rqRfuUU1RuGNkFYUz/SeksVD0ro=",
  81. name: "其它外出单",
  82. number: "0003"
  83. })
  84. }
  85. }
  86. // 提交前增加校验
  87. _this.verify = function(action){
  88. var flag = true;
  89. var entries = mbos('entity').data.entries
  90. $.each(entries, function(i,item){
  91. if(item.startTime >= item.endTime){
  92. mbos.ui.showInfo('开始时间应小于结束时间');
  93. flag = false;
  94. return false;
  95. }
  96. if(item.days === 0){
  97. mbos.ui.showInfo('天数不能为0');
  98. flag = false;
  99. return false;
  100. }
  101. })
  102. return flag;
  103. }
  104. // 保存按钮
  105. _this.save = function (event) {
  106. if(!_this.verify()){
  107. return false;
  108. }
  109. if(!_this.validateRemarkRequired()){
  110. return false;
  111. }
  112. setModel()
  113. //debugger
  114. var param = getModel('', 'save');
  115. if(_this.type == 'team'){
  116. param.assistBill = 1;
  117. param.permItemId = 'e87c4069-0622-47ed-b592-22bbe0cb1321PERMITEM';
  118. }
  119. baseInterface('save', toView, '', param) // 调用保存接口
  120. }
  121. // 提交按钮
  122. _this.submit = function (event) {
  123. if(!_this.verify()){
  124. return false;
  125. }
  126. if(!_this.validateRemarkRequired()){
  127. return false;
  128. }
  129. // 确认提交 弹框
  130. mbos.ui.showConfirm({
  131. title: localeResource.confirmSubmit,
  132. iconclass: "kdfont kdfont-zhuangtai_jingshi the_info",
  133. callback: function (data) {
  134. if (data == 0) {
  135. setModel()
  136. //debugger
  137. var param = getModel('', 'submit');
  138. if(_this.type == 'team'){
  139. param.assistBill = '1';
  140. param.permItemId = 'e87c4069-0622-47ed-b592-22bbe0cb1321PERMITEM';
  141. }
  142. baseInterface('submit', toView, '', param, _this.type) // 调用提交接口
  143. }
  144. }
  145. });
  146. }
  147. // 点击“保存、提交” 跳转页面
  148. function toView(res) {
  149. // 提交接口 返回的res.data为数组,取第一条数据
  150. if (res.data.keyValue || (res.data.length > 0 && res.data[0].keyValue)) {
  151. // 操作成功 提示弹框
  152. mbos.ui.showInfo({
  153. title: localeResource.succeed,
  154. iconclass: "kdfont kdfont-zhuangtai_wancheng the_success",
  155. callback: function () {
  156. openPage(_this.path, _this.detailPageCode, { billID: res.data.keyValue || res.data[0].keyValue, type: _this.type })
  157. }
  158. });
  159. }
  160. }
  161. // 给隐藏的model赋值
  162. function setModel(method) {
  163. if (typeof _this.operateState != "undefined" && (_this.operateState === "ADDNEW" || _this.operateState === "EDIT")) {
  164. var entries = mbos('entity').data.entries
  165. entries.map(function (entry,i) {
  166. if(_this.type != 'team'){
  167. entry.person = easContext.person
  168. }
  169. // entry.position = easContext.position.id
  170. // entry.adminOrgUnit = easContext.position.adminOrgUnit.id
  171. // mbos('entries_person',i).value(easContext.person);
  172. // mbos('entries_adminOrgUnit',i).value(easContext.position.adminOrgUnit);
  173. // mbos('entries_position',i).value(easContext.position);
  174. entry.hours = mbos('hours',i).value();
  175. getEntries(entry,method) // 各单据处理分录数据
  176. })
  177. return entries;
  178. }
  179. }
  180. // 各单据处理分录数据的函数
  181. function getEntries(entry,method) {
  182. // 给时间点赋值
  183. entry.startTimeHMS = entry.startTime
  184. entry.endTimeHMS = entry.endTime
  185. if(method == 'getNextPerson'){
  186. entry.position = easContext.position.id;
  187. entry.adminOrgUnit = easContext.position.adminOrgUnit.id;
  188. if(entry.startTime){
  189. entry.startTime = moment(entry.startTime).format('YYYY-MM-DD HH:mm:ss');
  190. }
  191. if(entry.endTime){
  192. entry.endTime = moment(entry.endTime).format('YYYY-MM-DD HH:mm:ss');
  193. }
  194. if(entry.startTimeHMS){
  195. entry.startTimeHMS = moment(entry.startTimeHMS).format('YYYY-MM-DD HH:mm:ss');
  196. }
  197. if(entry.endTimeHMS){
  198. entry.endTimeHMS = moment(entry.endTimeHMS).format('YYYY-MM-DD HH:mm:ss');
  199. }
  200. if(entry.startTimeDate){
  201. entry.startTimeDate = moment(entry.startTimeDate).format('YYYY-MM-DD HH:mm:ss');
  202. }
  203. if(entry.endTimeDate){
  204. entry.endTimeDate = moment(entry.endTimeDate).format('YYYY-MM-DD HH:mm:ss');
  205. }
  206. }else{
  207. delete entry.position;
  208. delete entry.adminOrgUnit;
  209. }
  210. }
  211. // 计算单据时长
  212. function getTimeLength(index) {
  213. var callback = function (res) {
  214. mbos('entries_days', index).value(res.data.days);
  215. mbos('hours', index).value(res.data.hours);
  216. }
  217. setModel(index)
  218. var entry = mbos('entity').data.entries[index]
  219. if (entry.endTime && entry.startTime) {
  220. baseInterface('getBillLength', callback, index)
  221. }
  222. }
  223. // 根据时间判断 是否展示弹性算时长字段
  224. function isElastic(index) {
  225. var callback = function (res) {
  226. if (res.data) {
  227. mbos('entries_isElasticCalLen', index).show()
  228. }
  229. }
  230. setModel(index)
  231. var entry = mbos('entity').data.entries[index]
  232. if (entry.endTime && entry.startTime) {
  233. baseInterface('showIsElasticCalCtrl', callback, index)
  234. }
  235. }
  236. // 获取整天的开始、结束时间
  237. function getStartEndTime(i) {
  238. var callback = function (res) {
  239. if(res.data.beginTime || res.data.endTime){
  240. mbos('entries_startTime', i).value(moment(res.data.beginTime).format('YYYY-MM-DD HH:mm'))
  241. mbos('entries_endTime', i).value(moment(res.data.endTime).format('YYYY-MM-DD HH:mm'))
  242. }
  243. }
  244. if (mbos('entries_startTime', i).value() || mbos('entries_endTime', i).value()){
  245. setModel(i)
  246. var params = _.cloneDeep(mbos('entity').data)
  247. var endTime = params.entries[i].endTime
  248. if (endTime && endTime.includes('00:00')) { // 防止结束日期会一直触发
  249. params.entries[i].endTime = moment(endTime).subtract(1, "minutes").format("YYYY-MM-DD HH:mm")
  250. }
  251. // 【BT-01684276】改为传一条分录数据
  252. params.entries = [params.entries[i]];
  253. baseInterface('getAllDayBeginAndEndTime', callback, i, params)
  254. }
  255. }
  256. // 如果是整天出差 则使用date;否则使用datetime,同时清空时长
  257. function recalcTime(event) {
  258. mbos('entries_days', event.index).value('')
  259. if (String(event.new_value) == 'true') {
  260. var entry = mbos('entity').data.entries[event.index]
  261. if (entry.endTime || entry.startTime) {
  262. getStartEndTime(event.index) // 获取pc端配置的起止时间
  263. // _this.startHadCalculate = true // 阻止二次触发 异地办公单整天时 开始时间触发问题
  264. // _this.endHadCalculate = true // 阻止二次触发
  265. }
  266. }
  267. }
  268. // 计算时长
  269. _this.calTime1 = function (event) {
  270. getTimeLength(event.index)
  271. isElastic(event.index)
  272. if (String(mbos('entries_isAllDay', event.index).value()) == 'true' && !Boolean(_this.startHadCalculate)) {
  273. getStartEndTime(event.index)
  274. // _this.startHadCalculate = true // 阻止二次触发
  275. } else {
  276. _this.startHadCalculate = false
  277. }
  278. console.log('startHadCalculate', _this.startHadCalculate)
  279. }
  280. _this.calTime2 = function (event) {
  281. getTimeLength(event.index)
  282. isElastic(event.index)
  283. if (String(mbos('entries_isAllDay', event.index).value()) == 'true' && !Boolean(_this.endHadCalculate)) {
  284. getStartEndTime(event.index)
  285. // _this.endHadCalculate = true// 阻止二次触发
  286. } else {
  287. _this.endHadCalculate = false
  288. }
  289. console.log('endHadCalculate', _this.endHadCalculate)
  290. }
  291. // 监听是否整天
  292. _this.calTime3 = function (event) {
  293. getTimeLength(event.index)
  294. recalcTime(event)
  295. }
  296. // 监听弹性
  297. _this.calTime4 = function (event) {
  298. getTimeLength(event.index)
  299. }
  300. // 时长更改时 做校验
  301. _this.lengthChange = function(event){
  302. var value = event.new_value
  303. // 判断是否小于0
  304. if (!isNaN(parseFloat(value)) && Number(value) < 0) {
  305. mbos.msgBox.showError(localeResource.lengthValid);
  306. setTimeout(()=>{
  307. mbos('entries_days',event.index).value(0)
  308. })
  309. return
  310. }
  311. }
  312. // 出国(境)事由:处理个人事务(枚举值 = 3)
  313. var CGSY_PERSONAL_AFFAIRS = '3';
  314. function isPersonalAffairs(cgsy) {
  315. if (cgsy == null || cgsy === '') {
  316. return false;
  317. }
  318. if (typeof cgsy === 'object') {
  319. return String(cgsy.value != null ? cgsy.value : cgsy) === CGSY_PERSONAL_AFFAIRS;
  320. }
  321. return String(cgsy) === CGSY_PERSONAL_AFFAIRS;
  322. }
  323. // 出国(境)事由变更,设计器绑定 onChange = _this.cgsyChange
  324. _this.cgsyChange = function (event) {
  325. _this.controlRemarkRequired(event.index);
  326. }
  327. // 控制具体事由必填 + 前端红星
  328. _this.controlRemarkRequired = function (index) {
  329. var needReq = isPersonalAffairs(mbos('entries_cgsy', index).value());
  330. // 1. 设置 MBOS 内部必录属性(给后台校验用)
  331. mbos('entries_remark', index).attr('mustinput', needReq);
  332. // 2. 找到具体事由的 label
  333. var $fieldContainer = $('#entries_remark_' + index);
  334. var $label = $fieldContainer.find('label.lclabel');
  335. if (!$label.length) return;
  336. // 3. 先移除旧的红星(防止重复添加)
  337. $label.find('i.mustinput').remove();
  338. // 4. 需要必填时,添加 MBOS 原生红星
  339. if (needReq) {
  340. $label.append('<i class="mustinput">*</i>');
  341. }
  342. }
  343. // 多分录具体事由必填校验
  344. _this.validateRemarkRequired = function () {
  345. var entries = mbos('entity').data.entries;
  346. if (!entries || entries.length === 0) return true;
  347. for (var i = 0; i < entries.length; i++) {
  348. var cgsy = mbos('entries_cgsy', i).value();
  349. var remark = mbos('entries_remark', i).value();
  350. if (isPersonalAffairs(cgsy) && (!remark || !String(remark).trim())) {
  351. mbos.msgBox.showError('第' + (i + 1) + '行:出国(境)事由为【处理个人事务】时,请填写具体事由!');
  352. return false;
  353. }
  354. }
  355. return true;
  356. };