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.

297 lines
14 KiB

2 years ago
  1. 'use strict';
  2. var sProgramId = getProgramId(),
  3. sEditPrgId = getEditPrgId(),
  4. sViewPrgId = sProgramId.replace('_Qry', '_View'),
  5. oGrid = null,
  6. fnPageInit = function () {
  7. var oForm = $('#form_main'),
  8. oBaseQueryPm = {
  9. pageIndex: 1,
  10. pageSize: parent.SysSet.GridRecords || 10,
  11. sortField: 'ModifyDate',
  12. sortOrder: 'desc'
  13. },
  14. /**
  15. * 獲取資料
  16. */
  17. fnGet = function (args) {
  18. var oQueryPm = getFormSerialize(oForm);
  19. $.extend(oQueryPm, oBaseQueryPm, args);
  20. oBaseQueryPm.pageIndex = oQueryPm.pageIndex;
  21. oQueryPm.ComplaintType = !oQueryPm.ComplaintType ? Enumerable.From($('[name=ComplaintType]:checkbox')).Select("x=>x.value").ToArray().join(',') : oQueryPm.ComplaintType.join(',');
  22. oQueryPm.DataType = !oQueryPm.DataType ? Enumerable.From($('[name=DataType]:checkbox')).Select("x=>x.value").ToArray().join(',') : oQueryPm.DataType.join(',');
  23. oQueryPm.Roles = parent.UserInfo.roles;
  24. console.log("oQueryPm:", oQueryPm);
  25. return g_api.ConnectLite(sProgramId, ComFn.GetPage, oQueryPm, function (res) {
  26. if (res.RESULT) {
  27. var oRes = res.DATA.rel;
  28. if (args.Excel) {//匯出
  29. DownLoadFile(oRes);
  30. }
  31. }
  32. });
  33. },
  34. /**
  35. * 獲取客訴來源
  36. */
  37. setComplaintSourceDrop = function () {
  38. return g_api.ConnectLite(Service.com, ComFn.GetArguments, {
  39. OrgID: 'TE',
  40. ArgClassID: 'CRMComplaintSource'
  41. }, function (res) {
  42. if (res.RESULT) {
  43. let QueryData = res.DATA.rel;
  44. if (QueryData.length > 0) {
  45. $('#ComplaintSource').append(createOptions(QueryData, 'id', 'text', true)).select2();
  46. }
  47. }
  48. });
  49. },
  50. /**
  51. * 獲取組團單位
  52. */
  53. fnSetGroupUnit = function () {
  54. g_api.ConnectLite('Complaint_Qry', 'GetGroupUnit', {}, function (res) {
  55. if (res.RESULT) {
  56. var saList = res.DATA.rel;
  57. var sOptions = createOptions(saList, 'guid', 'CustomerShotCName');
  58. $('#GroupUnit').html(sOptions).select2();
  59. }
  60. });
  61. },
  62. /**
  63. * 獲取配合代理
  64. */
  65. fnSetCoopAgent= function () {
  66. g_api.ConnectLite('Complaint_Qry', 'GetCoopAgent', {}, function (res) {
  67. if (res.RESULT) {
  68. var saList = res.DATA.rel;
  69. var sOptions = createOptions(saList, 'guid', 'CustomerShotCName');
  70. $('#CoopAgent').html(sOptions).select2();
  71. }
  72. });
  73. },
  74. /**
  75. * 打開要匯出的pop選擇匯出類別
  76. */
  77. fnOpenPopToExcel = function () {
  78. layer.open({
  79. type: 1,
  80. title: i18next.t('common.DownLoadDocuments'),// ╠common.DownLoadDocuments⇒下載文檔╣
  81. area: ['300px', '160px'],//寬度
  82. shade: 0.75,//遮罩
  83. shadeClose: true,
  84. btn: [i18next.t('common.Cancel')],// ╠common.Cancel⇒取消╣
  85. content: '<div class="pop-box">\
  86. <button type="button" data-i18n="common.BasicInformation" id="Complaint_BasicInformation" class="btn-custom green">基本資料</button>\
  87. </div>',//common.BasicInformation基本資料common.WenzhongPrjFile文中專案檔
  88. success: function (layero, idx) {
  89. $('.pop-box :button').click(function () {
  90. var sToExcelType = this.id;
  91. fnGet({
  92. Excel: true,
  93. ExcelType: sToExcelType,
  94. Index: idx
  95. });
  96. });
  97. transLang(layero);
  98. }
  99. });
  100. },
  101. /**
  102. * ToolBar 按鈕事件 function
  103. * @param {Object}inst 按鈕物件對象
  104. * @param {Object} e 事件對象
  105. */
  106. fnButtonHandler = function (inst, e) {
  107. var sId = inst.id;
  108. switch (sId) {
  109. case "Toolbar_Qry":
  110. var iNum = $('#PerPageNum').val();
  111. oGrid.pageSize = iNum === '' ? parent.SysSet.GridRecords || 10 : iNum;
  112. cacheQueryCondition();
  113. oGrid.openPage(window.bToFirstPage ? 1 : oBaseQueryPm.pageIndex);
  114. break;
  115. case "Toolbar_Save":
  116. break;
  117. case "Toolbar_ReAdd":
  118. break;
  119. case "Toolbar_Clear":
  120. clearPageVal();
  121. break;
  122. case "Toolbar_Leave":
  123. break;
  124. case "Toolbar_Add":
  125. parent.openPageTab(sEditPrgId, '?Action=Add');
  126. break;
  127. case "Toolbar_Upd":
  128. break;
  129. case "Toolbar_Copy":
  130. break;
  131. case "Toolbar_Del": // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  132. break;
  133. case "Toolbar_Exp":
  134. if (oGrid.data.length === 0) {
  135. showMsg(i18next.t("message.NoDataExport"));// ╠message.NoDataExport⇒沒有資料匯出╣
  136. return false;
  137. }
  138. fnOpenPopToExcel();
  139. break;
  140. default:
  141. alert("No handle '" + sId + "'");
  142. break;
  143. }
  144. },
  145. /**
  146. * 頁面初始化
  147. */
  148. init = function () {
  149. commonInit({
  150. PrgId: sProgramId,
  151. ButtonHandler: fnButtonHandler,
  152. SearchBar: true
  153. });
  154. $.whenArray([
  155. fnSetUserDrop([
  156. {
  157. Select: $('#CreateUser'),
  158. Select2: true,
  159. ShowId: true
  160. }
  161. ]),
  162. setComplaintSourceDrop(),
  163. fnSetCoopAgent(),
  164. fnSetGroupUnit(),
  165. fnSetUserDrop([
  166. {
  167. Select: $('#Applicant'),
  168. ShowId: true,
  169. Select2: true,
  170. }
  171. ])
  172. ]).done(function () {
  173. reSetQueryPm(sProgramId);
  174. var iHeight = $('body').height() - $('.page-title').height() - $('#searchbar').height() - 87;
  175. $("#jsGrid").jsGrid({
  176. width: "100%",
  177. height: iHeight + "px",
  178. autoload: true,
  179. pageLoading: true,
  180. inserting: false,
  181. editing: true,
  182. sorting: true,
  183. paging: true,
  184. pageIndex: window.bToFirstPage ? 1 : window.QueryPageidx || 1,
  185. pageSize: parent.SysSet.GridRecords || 10,
  186. pageButtonCount: parent.SysSet.GridPages || 15,
  187. pagePrevText: "<",
  188. pageNextText: ">",
  189. pageFirstText: "<<",
  190. pageLastText: ">>",
  191. rowClass: function (item) {
  192. if (item.Status === 'X') {
  193. return 'data-void';
  194. }
  195. },
  196. onPageChanged: function (args) {
  197. cacheQueryCondition(args.pageIndex);
  198. },
  199. rowClick: function (args) {
  200. if (navigator.userAgent.match(/mobile/i)) {
  201. if ('A,C'.indexOf(args.item.DataType) > -1 && args.item.AskTheDummy === parent.UserID) {
  202. goToEdit(sEditPrgId, '?Action=Upd&Guid=' + args.item.Guid);
  203. }
  204. else {
  205. goToEdit(sViewPrgId, '?Action=Upd&Guid=' + args.item.Guid);
  206. }
  207. }
  208. },
  209. rowDoubleClick: function (args) {
  210. if ('A,C'.indexOf(args.item.DataType) > -1 && args.item.CreateUser === parent.UserID) {
  211. parent.openPageTab(sEditPrgId, '?Action=Upd&Guid=' + args.item.Guid);
  212. }
  213. else {
  214. parent.openPageTab(sViewPrgId, '?Action=Upd&Guid=' + args.item.Guid);
  215. }
  216. },
  217. fields: [
  218. { name: "RowIndex", title: 'common.RowNumber', align: 'center', width: 40, sorting: false },
  219. { name: "ComplaintNumber", title: '客訴編號', width: 60 },
  220. {
  221. name: "ComplaintTitle", title: '客訴主旨', width: 200, itemTemplate: function (val, item) {
  222. var sVal = val,
  223. oStatus = {
  224. 'A': i18next.t('common.Draft'),// ╠common.Draft⇒草稿╣
  225. 'B': i18next.t('common.InAudit'),// ╠common.InAudit⇒審核中╣
  226. 'C-O': i18next.t('common.HasReEdited'),// ╠common.HasReEdited⇒已抽單╣
  227. 'D-O': i18next.t('common.HasReturned'),// ╠common.HasReturned⇒已退件╣
  228. 'H-O': i18next.t('common.Hashandle'),// ╠common.Hashandle⇒已經辦╣
  229. 'E': i18next.t('common.ToHandle'),// ╠common.ToHandle⇒待經辦╣
  230. 'X': i18next.t('common.HasVoid')// ╠common.HasVoid⇒已作廢╣
  231. };
  232. sVal += oStatus[item.DataType] ? '<span style="color:#DF5F09">(' + oStatus[item.DataType] + ')</span>' : '';
  233. if (item.Important > 1) {
  234. for (var i = 0; i < item.Important - 1; i++) {
  235. sVal += ' <img src="../../images/star.gif">';
  236. }
  237. }
  238. return $('<a>', { html: sVal });
  239. }
  240. },
  241. {
  242. name: "ComplaintType", title: '類型', width: 70, align: 'center', itemTemplate: function (val, item) {
  243. var sVal = '',
  244. ComplaintTypeArray = {
  245. '1': '貨損',
  246. '2': '延誤',
  247. '3': '遺失',
  248. '4': '抱怨'
  249. };
  250. sVal = ComplaintTypeArray[item.ComplaintType];
  251. return sVal;
  252. } },
  253. { name: "ExhibitioShotName_TW", title: '展覽簡稱', width: 200, align: 'center' },//ComplaintTypeArray
  254. { name: "CustomerCName", title: '客戶名稱', width: 200, align: 'center' },
  255. { name: "Complainant", title: '申訴人', width: 70, align: 'center' },
  256. { name: "CreateUser", title: 'common.CreateUser', width: 70, align: 'center' },
  257. {
  258. name: "CreateDate", title: 'common.CreateDate', width: 90, align: 'center', itemTemplate: function (val, item) {
  259. return newDate(val);
  260. }
  261. }
  262. ],
  263. controller: {
  264. loadData: function (args) {
  265. return fnGet(args);
  266. },
  267. },
  268. onInit: function (args) {
  269. oGrid = args.grid;
  270. }
  271. });
  272. })
  273. };
  274. init();
  275. };
  276. require(['base', 'select2', 'jsgrid', 'util'], fnPageInit);