You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

480 lines
20 KiB

2 years ago
2 years ago
  1. 'use strict';
  2. var
  3. /**
  4. * 設定部門主管下拉選單
  5. * @param {Object} handle 當前控件
  6. * @param {String} deptid 部門id
  7. * @return {Object} Ajax 物件
  8. */
  9. fnSetDeptDrop = function (handle, deptid) {
  10. var oParm = {};
  11. oParm.OrgID = parent.OrgID;
  12. oParm.DeptID = deptid || '';
  13. return g_api.ConnectLite(Service.sys, 'GetDepartmentList', oParm,
  14. function (res) {
  15. if (res.RESULT) {
  16. var saData = res.DATA.rel;
  17. handle.html(createOptions(saData, 'DepartmentID', 'AccountNameSort', true));
  18. }
  19. });
  20. },
  21. /**
  22. * 設定部門主管下拉選單
  23. * @param {Object} handle 當前控件
  24. * @param {String} deptid 部門id
  25. * @return {Object} Ajax 物件
  26. */
  27. fnSetDeptDropWithLimtedDeptId = function (handle) {
  28. var oParm = {};
  29. oParm.OrgID = parent.OrgID;
  30. oParm.DeptID = '';
  31. return g_api.ConnectLite(Service.sys, 'GetDepartmentListNoVoid', oParm,
  32. function (res) {
  33. if (res.RESULT) {
  34. //debugger;
  35. var saData = res.DATA.rel;
  36. var DepId = parent.UserInfo.DepartmentID;
  37. var AdminUser = parent.UserInfo.roles.toLowerCase().indexOf('admin') > -1;
  38. if (!AdminUser) {
  39. saData = saData.filter(c => c.ParentDepartmentID === DepId || c.DepartmentID === DepId || c.DepartmentID1 === DepId);
  40. }
  41. handle.html(createOptions(saData, 'DepartmentID', 'AccountNameSort', true));
  42. if (!AdminUser) {
  43. $(handle.selector + ' option:first').remove();
  44. }
  45. }
  46. });
  47. },
  48. /**
  49. * 設定人員下拉選單
  50. * @param {Object} drops 當前控件
  51. * @return {Object} Ajax 物件
  52. */
  53. fnSetUserDrop = function (drops) {
  54. var saPost = [];
  55. $.each(drops, function (index, drop) {
  56. drop.Effective = 'Y';
  57. //if (drop.Action && drop.Action.toLowerCase() === 'add') {
  58. // drop.Effective = 'Y';
  59. //}
  60. saPost.push(g_api.ConnectLite(Service.com, ComFn.GetUserList,
  61. {
  62. DepartmentID: drop.DepartmentID || '',
  63. MemberID: drop.MemberID || '',
  64. UserIDs: drop.UserIDs || '',
  65. NotUserIDs: drop.NotUserIDs || '',
  66. ServiceCode: drop.ServiceCode || '',
  67. Effective: drop.Effective || ''
  68. },
  69. function (res) {
  70. if (res.RESULT) {
  71. var saRes = res.DATA.rel;
  72. if (drop.Select) {
  73. drop.Select.html(createOptions(saRes, 'MemberID', 'MemberName', drop.ShowId || false));
  74. if (drop.DefultVal) {
  75. drop.Select.val(drop.DefultVal);
  76. }
  77. if (drop.Select2) {
  78. drop.Select.each(function () {
  79. $(this).select2();
  80. $(this).next().after($(this));
  81. });
  82. }
  83. }
  84. if (drop.CallBack && typeof drop.CallBack === 'function') {
  85. drop.CallBack(saRes);
  86. }
  87. }
  88. }));
  89. });
  90. return $.whenArray(saPost);
  91. },
  92. /**
  93. * 設定下拉選單(參數設定)
  94. * @param {Array} drops 下拉配置
  95. * @return {Object} Ajax 物件
  96. */
  97. fnSetArgDrop = function (drops) {
  98. var saPost = [];
  99. $.each(drops, function (index, drop) {
  100. if (drop.ArgClassID) {
  101. saPost.push(g_api.ConnectLite(Service.com, ComFn.GetArguments,
  102. {
  103. ArgClassID: drop.ArgClassID,
  104. ParentID: drop.ParentID || '',
  105. ArgIDs: drop.Ids || '',
  106. LevelOfArgument: drop.Level || -1,
  107. OrgID: drop.OrgID || ''
  108. },
  109. function (res) {
  110. if (res.RESULT) {
  111. var saRes = res.DATA.rel;
  112. if (drop.Select) {
  113. drop.Select.html(createOptions(saRes, 'id', 'text', drop.ShowId || false))
  114. .on('change', function () {
  115. if (drop.OnChange && typeof drop.OnChange === 'function') {
  116. drop.OnChange(this.value);
  117. }
  118. });
  119. if (drop.DefultVal) {
  120. drop.Select.val(drop.DefultVal);
  121. }
  122. if (drop.Select2) {
  123. drop.Select.each(function () {
  124. $(this).select2();
  125. $(this).next().after($(this));
  126. });
  127. }
  128. }
  129. if (drop.CallBack && typeof drop.CallBack === 'function') {
  130. drop.CallBack(saRes);
  131. }
  132. }
  133. }));
  134. }
  135. });
  136. return $.whenArray(saPost);
  137. },
  138. /**
  139. * 設定展覽下拉選單
  140. * @param {Object} drop 當前控件
  141. * @return {Object} Ajax 物件
  142. */
  143. fnSetEpoDrop = function (drop) {
  144. return g_api.ConnectLite('Exhibition_Upd', 'GetExhibitions',
  145. {
  146. SN: drop.SN || ''
  147. },
  148. function (res) {
  149. if (res.RESULT) {
  150. var saRes = res.DATA.rel;
  151. if (drop.Select) {
  152. drop.Select.html(createOptions(saRes, drop.IdName || 'SN', drop.TextName || 'ExhibitioFullName', drop.ShowId || false));
  153. if (drop.DefultVal) {
  154. drop.Select.val(drop.DefultVal);
  155. }
  156. if (drop.Select2) {
  157. drop.Select.each(function () {
  158. $(this).select2();
  159. $(this).next().after($(this));
  160. });
  161. }
  162. }
  163. if (drop.CallBack && typeof drop.CallBack === 'function') {
  164. drop.CallBack(saRes);
  165. }
  166. }
  167. });
  168. },
  169. /*
  170. * 設定展覽選單(ExhibitionCode)
  171. */
  172. fnSetEpoDropWithExhibitionCode = function (drop) {
  173. return g_api.ConnectLite('BillsReport', 'GetProjects', {}, function (res) {
  174. if (res.RESULT) {
  175. var saRes = res.DATA.rel;
  176. if (drop.Select) {
  177. drop.Select.html(createOptions(saRes, drop.IdName || 'id', drop.TextName || 'text', drop.ShowId || false));
  178. if (drop.DefultVal) {
  179. drop.Select.val(drop.DefultVal);
  180. }
  181. if (drop.Select2) {
  182. drop.Select.each(function () {
  183. $(this).select2();
  184. $(this).next().after($(this));
  185. });
  186. }
  187. }
  188. if (drop.CallBack && typeof drop.CallBack === 'function') {
  189. drop.CallBack(saRes);
  190. }
  191. }
  192. });
  193. },
  194. /*
  195. * 設定客戶資料(customer_guid)
  196. */
  197. fnSetCustomerWithGuid = function (drop) {
  198. return g_api.ConnectLite(Service.sys, 'GetCustomerlist', {}, function (res) {
  199. if (res.RESULT) {
  200. var saRes = res.DATA.rel;
  201. if (drop.Select) {
  202. drop.Select.html(createOptions(saRes, 'id', 'text', drop.ShowId || false));
  203. if (drop.DefultVal) {
  204. drop.Select.val(drop.DefultVal);
  205. }
  206. if (drop.Select2) {
  207. drop.Select.each(function () {
  208. $(this).select2();
  209. $(this).next().after($(this));
  210. });
  211. }
  212. }
  213. if (drop.CallBack && typeof drop.CallBack === 'function') {
  214. drop.CallBack(saRes);
  215. }
  216. }
  217. });
  218. },
  219. /**
  220. * 設定展覽下拉選單
  221. * @param {Object} o 參數
  222. * @return {Object} Ajax 物件
  223. */
  224. fnGetOfficeTempls = function (o) {
  225. return g_api.ConnectLite(Service.com, 'GetOfficeTempls',
  226. {
  227. TemplID: o.TemplID || ''
  228. },
  229. function (res) {
  230. if (res.RESULT) {
  231. var saRes = res.DATA.rel;
  232. if (o.CallBack && typeof o.CallBack === 'function') {
  233. o.CallBack(saRes);
  234. }
  235. }
  236. });
  237. },
  238. /**
  239. * 開啟單選選單Pop
  240. * @param {Object} option 配置
  241. */
  242. oPenPops = function (option) {
  243. var oGrid = null,
  244. oCurItem = null,
  245. sContent = '',
  246. sGrid = '<div class="row popsrow"><div class="shadowbox"><div id="PopsGrid"></div></div></div>',
  247. saRow = [];
  248. $.each(option.SearchFields, function (index, item) {
  249. var oLabel = $('<Label />', { 'class': 'col-sm-2 w20p control-label' }),
  250. oSpan = $('<span />', { 'data-i18n': item.i18nkey }),
  251. oInputDiv = $('<div />', { 'class': 'col-sm-3' });
  252. switch (item.type) {
  253. case 'text':
  254. $('<input />', { 'type': 'text', 'id': item.id, 'name': item.id, 'maxlength': '50', 'class': 'form-control w100p' }).appendTo(oInputDiv);
  255. break;
  256. case 'select':
  257. $('<select />', { 'id': item.id, 'name': item.id, 'class': 'form-control w100p', 'html': item.html }).appendTo(oInputDiv);
  258. break;
  259. }
  260. saRow.push(oLabel.append(oSpan, ':'));
  261. saRow.push(oInputDiv);
  262. if (saRow.length === 4 || option.SearchFields.length === index + 1) {
  263. var oSearchDiv = $('<div />', { 'class': 'row popsrow' });
  264. oSearchDiv.append(saRow);
  265. sContent += oSearchDiv[0].outerHTML;
  266. saRow = [];
  267. }
  268. });
  269. sContent += sGrid;
  270. layer.open({
  271. type: 1,
  272. title: option.Title || i18next.t('common.PopsMenu'),//╠common.PopsMenu⇒單選選單╣
  273. shadeClose: false,
  274. shade: 0.5,
  275. maxmin: true, //开启最大化最小化按钮
  276. area: ['800px', option.SearchFields.length > 2 ? '615px' : '565px'],
  277. content: sContent,
  278. success: function (layero, index) {
  279. $("#PopsGrid").jsGrid({
  280. width: "98%",
  281. height: "390px",
  282. autoload: true,
  283. pageLoading: true,
  284. sorting: true,
  285. paging: true,
  286. pageIndex: 1,
  287. pageSize: option.PageSize || 10,
  288. pagePrevText: "<",
  289. pageNextText: ">",
  290. pageFirstText: "<<",
  291. pageLastText: ">>",
  292. pageButtonCount: 10,
  293. rowClick: function (args) {
  294. oCurItem = args.item;
  295. },
  296. rowDoubleClick: function (args) {
  297. oCurItem = args.item;
  298. option.Callback(oCurItem);
  299. layer.close(index);
  300. },
  301. fields: option.Fields,
  302. controller: {
  303. loadData: function (args) {
  304. return option.Get(args);
  305. }
  306. },
  307. onInit: function (args) {
  308. oGrid = args.grid;
  309. }
  310. });
  311. layero.find('.layui-layer-btn1').css({ 'border-color': '#4898d5', 'background-color': '#1E9FFF', 'color': '#fff' });
  312. if (typeof option.PopSuccessCallback === 'function') {
  313. option.PopSuccessCallback();
  314. }
  315. },
  316. btn: [i18next.t('common.Toolbar_Qry'), i18next.t('common.Confirm'), i18next.t('common.Cancel')],//╠common.Toolbar_Qry⇒查詢╣ ╠common.Confirm⇒確定╣ ╠common.Cancel⇒取消╣
  317. yes: function (index, layero) {
  318. var iNum = $('.layui-layer #PerPageNum').val();
  319. oGrid.pageSize = iNum === '' ? 10 : iNum;
  320. oGrid.openPage(1);
  321. oCurItem = null;
  322. return false;
  323. },
  324. btn2: function (index, layero) {
  325. if (typeof option.Callback === 'function') { option.Callback(oCurItem || {}); }
  326. layer.close(index);
  327. },
  328. btn3: function (index) {
  329. if (typeof option.CancelCallback === 'function') { option.CancelCallback(); }
  330. },
  331. cancel: function () {
  332. if (typeof option.CancelCallback === 'function') { option.CancelCallback(); }
  333. }
  334. });
  335. },
  336. /**
  337. * 開啟複選選單Pop
  338. * @param {Object} option 配置
  339. */
  340. oPenPopm = function (option) {
  341. var oGrid = null,
  342. sContent = '',
  343. sGrid = '<div class="row popsrow"><div class="shadowbox"><div id="PopmGrid"></div></div></div>',
  344. saRow = [],
  345. saRetn = [],
  346. saFields = [{
  347. width: 50, sorting: false, align: "center",
  348. headerTemplate: function () {
  349. return [$("<input>", {
  350. id: 'SelectAll',
  351. type: 'checkbox', click: function () {
  352. if (this.checked) {
  353. $("#PopmGrid").find('[type=checkbox]').each(function () {
  354. this.checked = true;
  355. });
  356. saRetn = oGrid.data;
  357. }
  358. else {
  359. $("#PopmGrid").find('[type=checkbox]').each(function () {
  360. this.checked = false;
  361. });
  362. saRetn = [];
  363. }
  364. }
  365. }), $('<label />', { for: 'SelectAll', 'data-i18n': 'common.SelectAll' })];
  366. },
  367. itemTemplate: function (value, item) {
  368. return $("<input>", {
  369. type: 'checkbox', click: function (e) {
  370. e.stopPropagation();
  371. if (this.checked) {
  372. saRetn.push(item);
  373. }
  374. else {
  375. var saNewList = [];
  376. $.each(saRetn, function (idx, data) {
  377. if (item.RowIndex !== data.RowIndex) {
  378. saNewList.push(data);
  379. }
  380. });
  381. saRetn = saNewList;
  382. $('#PopmGrid').find('#SelectAll')[0].checked = false;
  383. }
  384. }
  385. });
  386. }
  387. }];
  388. $.each(option.SearchFields, function (index, item) {
  389. var oLabel = $('<Label />', { 'class': 'col-sm-2 w20p control-label' }),
  390. oSpan = $('<span />', { 'data-i18n': item.i18nkey }),
  391. oInputDiv = $('<div />', { 'class': 'col-sm-3' });
  392. switch (item.type) {
  393. case 'text':
  394. $('<input />', { 'type': 'text', 'id': item.id, 'name': item.id, 'maxlength': '50', 'class': 'form-control w100p' }).appendTo(oInputDiv);
  395. break;
  396. case 'select':
  397. $('<select />', { 'id': item.id, 'name': item.id, 'class': 'form-control w100p', 'html': item.html }).appendTo(oInputDiv);
  398. break;
  399. }
  400. saRow.push(oLabel.append(oSpan, ':'));
  401. saRow.push(oInputDiv);
  402. if (saRow.length === 4 || option.SearchFields.length === index + 1) {
  403. var oSearchDiv = $('<div />', { 'class': 'row popsrow' });
  404. oSearchDiv.append(saRow);
  405. sContent += oSearchDiv[0].outerHTML;
  406. saRow = [];
  407. }
  408. });
  409. sContent += sGrid;
  410. saFields.push.apply(saFields, option.Fields);
  411. layer.open({
  412. type: 1,
  413. title: option.Title || i18next.t('common.PopmMenu'),//╠common.PopmMenu⇒複選選單╣
  414. shadeClose: false,
  415. shade: 0.5,
  416. maxmin: true, //开启最大化最小化按钮
  417. area: [option.Width || '800px', option.SearchFields.length > 2 ? '615px' : '565px'],
  418. content: (option.ContentPlush || '') + sContent,
  419. success: function (layero, index) {
  420. $("#PopmGrid").jsGrid({
  421. width: "98%",
  422. height: "400px",
  423. autoload: true,
  424. pageLoading: true,
  425. sorting: true,
  426. paging: true,
  427. pageIndex: 1,
  428. pageSize: option.PageSize || 10,
  429. pagePrevText: "<",
  430. pageNextText: ">",
  431. pageFirstText: "<<",
  432. pageLastText: ">>",
  433. pageButtonCount: 10,
  434. rowClick: function (args) {
  435. $(args.event.currentTarget).find('[type=checkbox]').click();
  436. },
  437. fields: saFields,
  438. controller: {
  439. loadData: function (args) {
  440. return option.Get(args);
  441. }
  442. },
  443. onInit: function (args) {
  444. oGrid = args.grid;
  445. }
  446. });
  447. layero.find('.layui-layer-btn1').css({ 'border-color': '#4898d5', 'background-color': '#1E9FFF', 'color': '#fff' });
  448. if (typeof option.PopSuccessCallback === 'function') {
  449. option.PopSuccessCallback();
  450. }
  451. },
  452. btn: [i18next.t('common.Toolbar_Qry'), i18next.t('common.Confirm'), i18next.t('common.Cancel')],//╠common.Toolbar_Qry⇒查詢╣ ╠common.Confirm⇒確定╣ ╠common.Cancel⇒取消╣
  453. yes: function (index, layero) {
  454. var iNum = $('.layui-layer #PerPageNum').val();
  455. oGrid.pageSize = iNum === '' ? 10 : iNum;
  456. oGrid.openPage(1);
  457. saRetn = [];
  458. $('#PopmGrid').find('#SelectAll')[0].checked = false;
  459. return false;
  460. },
  461. btn2: function (index, layero) {
  462. if (typeof option.Callback === 'function') { option.Callback(saRetn); }
  463. layer.close(index);
  464. },
  465. btn3: function (index) {
  466. if (typeof option.CancelCallback === 'function') { option.CancelCallback(); }
  467. },
  468. cancel: function () {
  469. if (typeof option.CancelCallback === 'function') { option.CancelCallback(); }
  470. }
  471. });
  472. };