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.

527 lines
20 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. //定制模态框的参数
  2. let currentModalId = 0;
  3. let currentSearchCon = '';
  4. let customerTableUrl = '';//table请求的url
  5. let tableColumns = '';//table的列集合
  6. let customerTableColumns = '';//table的列数组
  7. let customerTableWidth = 0;//定制table的宽度
  8. let customerTableHeight = 0;//定制table的高度
  9. let customerTableTop = 0;//定制table距离顶部div的高度
  10. let customerTableBottom = 0;//定制table距离底部div的高度
  11. let customerSearchDivWidth = 0;
  12. let customerSearchDivHeight = 0;
  13. let customerSearchDivTop = 0;
  14. let customerSearchDivBottom = 0;
  15. let customerSearchDivColumns;//定制模态框查询的列
  16. let customerSqlColumnMap;//查询数据的字段
  17. let customerSqlConFlag = "N";//查询数据的标记
  18. let customerSearchConFlag = 'N';//查询div的标记
  19. let customerReturnField;//定制table的返回字段
  20. let selectDataFlag = 'N';//是否选择好数据的标记
  21. let customerModalData;
  22. let customerReturnData;//负责接收换回的数据
  23. /*$(function(){
  24. 全局时间选择器
  25. $(".date-pickers").datetimepicker({//日期选择器
  26. format : 'hh:ii',//显示格式
  27. maxView : 0,//最高能展示的时间,Number, String类型 默认值:4, 年
  28. minView : 2,//日期时间选择器所能够提供的最精确的时间选择视图
  29. autoclose : true,//选择后自动关闭
  30. todayBtn : true,//开启选择今天的按钮
  31. todayHighlight: true,//今天日期高亮显示 如果为true, 高亮当前日期。Boolean类型 ,默认值:false ,
  32. language : 'zh-CN'//语言选择中文
  33. });
  34. //时间选择器 时:分
  35. lay('.time-pickers').each(function(){
  36. laydate.render({
  37. elem: this
  38. ,type: 'time'
  39. ,format: 'H:mm'
  40. ,trigger: 'click'
  41. });
  42. });
  43. });*/
  44. //公共方法
  45. // 获取选择格式的时间 + n天
  46. function getStringTimeByNow(AddDay, separator){
  47. let date = new Date();
  48. date.setDate(date.getDate()+AddDay);
  49. let year = date.getFullYear();
  50. let month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
  51. let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
  52. return year + separator + month + separator + day;
  53. }
  54. //获取指定日期的字符串日期
  55. function getStringTimeByStartDay(startDay, AddDay, separator){
  56. let date = new Date(startDay.replace(/-/g,'/'));
  57. date.setDate(date.getDate()+AddDay);
  58. let year = date.getFullYear();
  59. let month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
  60. let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
  61. return year + separator + month + separator + day;
  62. }
  63. //获取时间段数据
  64. function getStringPeriodByStartDay(startDay, AddDay, separator){
  65. let date = new Date(startDay.replace(/-/g,'/'));
  66. date.setDate(date.getDate()+AddDay);
  67. let year = date.getFullYear();
  68. let month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
  69. let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
  70. let hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
  71. let minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
  72. return year + separator + month + separator + day + " " + hours + ":" + minutes;
  73. }
  74. //获取只到分钟的字符串
  75. function getStringToMinuteByNow(AddDay, separator){
  76. let date = new Date();
  77. date.setDate(date.getDate()+AddDay);
  78. let year = date.getFullYear();
  79. let month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
  80. let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
  81. let hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
  82. let minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
  83. return year + separator + month + separator + day + " " + hours + ":" + minutes;
  84. }
  85. //比较字符串的日期
  86. function compareStringTime(startDay, endDay){
  87. let start_date = new Date(startDay.replace(/-/g,'/'));
  88. let end_date = new Date(endDay.replace(/-/g,'/'));
  89. if(start_date.getTime() > end_date.getTime()){
  90. return false;
  91. }else{
  92. return true;
  93. }
  94. }
  95. //获取时间格式(年月日时分)
  96. function getStringTimeWithHours(strDate, addHours, separator){
  97. let date = new Date();
  98. if(null != strDate){
  99. date = new Date(strDate.replace(/-/g,'/'));
  100. }
  101. //判断是否转时间
  102. let milliSeconds = parseInt((addHours*60*60*1000).toFixed(0));
  103. date.setTime(date.getTime() + milliSeconds);
  104. let year = date.getFullYear();
  105. let month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
  106. let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
  107. let hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
  108. let minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
  109. return year+separator+month+separator+day+" "+hours+":"+minutes;
  110. }
  111. //获取当天日期时间
  112. function getNowDate() {
  113. let date = new Date();
  114. let seperator1 = "-";
  115. let seperator2 = ":";
  116. let month = date.getMonth() + 1<10? "0"+(date.getMonth() + 1):date.getMonth() + 1;
  117. let strDate = date.getDate()<10? "0" + date.getDate():date.getDate();
  118. let hours = date.getHours()<10? "0" + date.getHours():date.getHours();
  119. let minutes = date.getMinutes()<10? "0" + date.getMinutes():date.getMinutes();
  120. let seconds = date.getSeconds()<10? "0" + date.getSeconds():date.getSeconds();
  121. let currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
  122. + " " + hours + seperator2 + minutes;
  123. return currentdate;
  124. }
  125. //获取当前时间,格式YYYY-MM-DD
  126. function getNowFormatDate() {
  127. let date = new Date();
  128. let seperator1 = "-";
  129. let year = date.getFullYear();
  130. let month = date.getMonth() + 1;
  131. let strDate = date.getDate();
  132. if (month >= 1 && month <= 9) {
  133. month = "0" + month;
  134. }
  135. if (strDate >= 0 && strDate <= 9) {
  136. strDate = "0" + strDate;
  137. }
  138. let currentdate = year + seperator1 + month + seperator1 + strDate;
  139. return currentdate;
  140. }
  141. /*通过不同的参数个数来实现方法的重载*/
  142. function getStringTime(startDay, AddDay, separator){
  143. if(arguments.length == 2){
  144. return getStringTimeByNow(startDay, AddDay);
  145. }else if(arguments.length == 3){
  146. return getStringTimeByStartDay(startDay, AddDay, separator);
  147. }
  148. str = str+day;
  149. return str;
  150. }
  151. //格式化Linux时间戳
  152. function formatLinuxDate(value) {
  153. if (value && value!='') {
  154. let date = new Date(value);
  155. let month = date.getMonth() < 9 ? '0'+(date.getMonth()+1):date.getMonth()+1;
  156. let days = date.getDate() <= 9 ? '0' +date.getDate() : date.getDate();
  157. let hours = date.getHours()<= 9 ? '0' +date.getHours() : date.getHours();
  158. let minutes = date.getMinutes() <= 9 ? '0' +date.getMinutes() : date.getMinutes();
  159. let seconds = date.getSeconds() <= 9 ? '0' +date.getSeconds() : date.getSeconds();
  160. let datestring = date.getFullYear() + "-" + month + "-" + days+" "+hours+":"+minutes;
  161. return datestring;
  162. }
  163. return "";
  164. }
  165. //判断当前输入的时间是否是一整天
  166. function whetherAllDay(strDay){
  167. //判断是否是空值 空字符串
  168. if(null == strDay || '' == strDay){
  169. return false;
  170. }
  171. //获取全部日期对应的数据
  172. let str_date = new Date(strDay.replace(/-/g,'/'));
  173. //获取整天对应的数据
  174. let all_day = new Date(strDay.substring(0, 10).replace(/-/g,'/'));
  175. //判断数值是否相同
  176. //if(str_date.getTime() == all_day.getTime()){
  177. if(str_date - all_day == 0){
  178. return true;
  179. }else{
  180. return false;
  181. }
  182. }
  183. //处理集合的参数
  184. function processColumnArray(){
  185. //初始化数组
  186. customerTableColumns = new Array();
  187. //循环处理数据
  188. for(let i = 0; i < tableColumns.length; i++){
  189. let tempRow = tableColumns[i];
  190. let columnFormatter = tempRow.columnFormatter;
  191. if(null == columnFormatter || 'null' == columnFormatter || '' == columnFormatter){
  192. //let currentRow = ;
  193. customerTableColumns.push({
  194. field: tableColumns[i].tableColumn,
  195. title: tableColumns[i].columnDesc,
  196. width: parseInt(tempRow.columnWidth),
  197. valign: 'middle',
  198. align: 'center',
  199. });
  200. }else{
  201. let currentRow = {field: tempRow.tableColumn, title: tempRow.columnDesc, valign: 'middle',
  202. align: 'center', width: parseInt(tempRow.columnWidth), formatter: tempRow.columnFormatter};
  203. customerTableColumns.push(currentRow);
  204. }
  205. }
  206. }
  207. //处理查询条件的map
  208. function processCustomerSqlCon(row, sqlColumns){
  209. customerSqlColumnMap = {};
  210. //循环处理map数据
  211. for(let i = 0; i < sqlColumns.length; i++){
  212. let key = sqlColumns[i];
  213. let tempValue = row[key];
  214. customerSqlColumnMap[key] = tempValue;
  215. }
  216. //填充是否解析map的标记
  217. customerSqlColumnMap.sqlConFlag = "Y";
  218. //填充开发人员自定义的查询的sql
  219. customerSqlColumnMap.searchCon = currentSearchCon;
  220. //设置modalId
  221. customerSqlColumnMap.modalId = currentModalId;
  222. }
  223. //处理查询div样式
  224. function processCustomerSearchDiv(rows){
  225. let tags = '';
  226. //循环产生div
  227. for(let i = 0; i < rows.length; i++){
  228. let row = rows[i];
  229. tags+='<span class="customer-modal-span">' + row.searchColumnDesc + ':</span>';
  230. tags+='<input id="' + row.searchColumnId+ '" class="customer-modal-input" value="'
  231. + row.searchColumnDefault + '" style="width:' + row.searchColumnWidth + 'px;">';
  232. }
  233. //设置div
  234. $('#customer_page_con_div').html(tags);
  235. }
  236. //处理定制表格的列名以及相关的参数
  237. function processCustomerModal(modalId, row){
  238. $.ajax({
  239. url: "/modal/processCustomerModal",
  240. type: "POST",
  241. async: false,
  242. contentType: 'application/x-www-form-urlencoded',
  243. data: {"site": $("#current_site").val(),
  244. "modalId": modalId},
  245. dataType:"JSON",
  246. success: function (data) {
  247. layer.closeAll('loading');
  248. if (data.success) {
  249. let obj = data.obj;
  250. //设置modal的参数
  251. customerTableUrl = obj.modalUrl;//table请求的url
  252. $('.customer-legend').html(obj.modalLegend);
  253. //table的样式
  254. customerTableWidth = obj.tableWidth;
  255. customerTableHeight = obj.tableHeight;
  256. customerTableTop = obj.tableTop;
  257. customerTableBottom = obj.tableBottom;
  258. //查询页面的样式
  259. customerSearchDivWidth = obj.pageSearchWidth;
  260. customerSearchDivHeight = obj.pageSearchHeight;
  261. customerSearchDivTop = obj.pageSearchTop;
  262. customerSearchDivBottom = obj.pageSearchBottom;
  263. //目前仅设置高度的样式
  264. $('#customer_page_con_div').css('height', customerSearchDivHeight+"px");
  265. customerReturnField = obj.returnField;
  266. customerSqlConFlag = obj.sqlConFlag;
  267. customerSearchConFlag = obj.pageConFlag;
  268. //设置样式
  269. $('#custom_form').parents('.modal-dialog').css("width", obj.modalWidth+"px");
  270. $('#customer_table_div').css('margin-top', customerTableTop+"px");
  271. $('#customer_table_div').css('margin-bottom', customerTableBottom+"px");
  272. tableColumns = obj.tableColumns;
  273. //处理集合,整理成当前table的列
  274. processColumnArray();
  275. //判断是否继续处理查询条件的赋值
  276. if("Y" == customerSqlConFlag){
  277. //处理查询的数据(填充查询条件)
  278. processCustomerSqlCon(row, obj.sqlColumns);
  279. }
  280. //处理查询div的输入框
  281. $('#customer_page_con_div').html('');
  282. if("Y" == customerSearchConFlag){
  283. processCustomerSearchDiv(obj.searchColumns);
  284. customerSearchDivColumns = obj.searchColumns;
  285. }
  286. }
  287. },
  288. error: function(data) {
  289. let responseText = data.responseText;
  290. let json_str = JSON.parse(responseText);
  291. let status = json_str.status;
  292. let message = json_str.message;
  293. //判断是否是session超时
  294. if(403==status){
  295. layer.alert(message,function(){
  296. window.parent.subCallBackReload();
  297. });
  298. }
  299. layer.closeAll('loading');
  300. }
  301. });
  302. }
  303. //添加页面的查询值到map中
  304. function addSearchDivParams(){
  305. let rows = customerSearchDivColumns;
  306. //循环处理数据
  307. for(let i = 0; i < rows.length; i < i++){
  308. let row = rows[i];
  309. let key = row.sqlColumnId;
  310. let value = $.trim($('#'+ row.searchColumnId).val());
  311. customerSqlColumnMap[key] = value;
  312. }
  313. }
  314. //初始化定制的modal
  315. function customerTableInit(){
  316. $('#customer_modal_table').bootstrapTable({
  317. url: customerTableUrl, //请求后台的URL(*)
  318. method: 'POST', //请求方式(*)
  319. contentType:'application/json;charset=utf-8',
  320. toolbar: '#toolbar', //工具按钮用哪个容器
  321. striped: true, //是否显示行间隔色
  322. cache: false, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
  323. pagination: false, //是否显示分页(*)
  324. sortable: false, //是否启用排序
  325. sortOrder: "asc", //排序方式
  326. queryParamsType : "undefined", //排序方式
  327. queryParams: function queryParams(params) {
  328. //设置查询参数
  329. let param = {
  330. };
  331. //添加页面上的查询条件
  332. if('Y' == customerSearchConFlag){
  333. addSearchDivParams();
  334. }
  335. //覆盖
  336. param = customerSqlColumnMap;
  337. return JSON.stringify(param);
  338. },
  339. sidePagination: "server", //分页方式:client客户端分页,server服务端分页(*)
  340. pageNumber: 1, //初始化加载第一页,默认第一页
  341. pageSize: 10, //每页的记录行数(*)
  342. pageList: [10, 25, 50, 100], //可供选择的每页的行数(*)
  343. search: false, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大
  344. searchTimeOut:1000,
  345. // : true,
  346. showColumns: false, //是否显示所有的列
  347. showRefresh: false, //是否显示刷新按钮
  348. minimumCountColumns: 2, //最少允许的列数
  349. clickToSelect: true, //是否启用点击选中行
  350. singleSelect: false,
  351. //height: 400, //行高,如果没有设置height属性,表格自动根据记录条数觉得表格高度
  352. uniqueId: "id", //每一行的唯一标识,一般为主键列
  353. // showToggle: true, //是否显示详细视图和列表视图的切换按钮
  354. cardView: false, //是否显示详细视图
  355. detailView: false, //是否显示父子表
  356. columns: customerTableColumns,
  357. onPostHeader: function(){
  358. $('#customer_modal_table').parents('.fixed-table-container').css("height", customerTableHeight+"px");
  359. },
  360. onPostBody: function(data){
  361. $('#customer_modal_table').parents('.fixed-table-container').css("height", customerTableHeight+"px");
  362. },
  363. onLoadSuccess: function (data){
  364. $('#customer_modal_table').parents('.fixed-table-container').css("height", customerTableHeight+"px");
  365. },
  366. onDblClickRow: function(row, $element, field){
  367. //获取数据
  368. if(null == customerReturnField || "null" == customerReturnField || "" == customerReturnField){
  369. customerReturnData = row;
  370. }else{
  371. customerReturnData = row[customerReturnField];
  372. }
  373. //设置取到数据
  374. selectDataFlag = 'Y';
  375. //隐藏模态框
  376. $('#hide_customer_modal').click();
  377. }
  378. });
  379. }
  380. //处理通用table(modalId: modal的编号 row: 查询数据的row searchCon:另外的查询条件)
  381. function customerModal(modalId, row, searchCon){
  382. //覆盖原来的参数
  383. currentModalId = modalId;
  384. currentSearchCon = searchCon;
  385. //1.处理查询的table的列名和url
  386. processCustomerModal(modalId, row);
  387. //2.先销毁表格
  388. $('#customer_modal_table').bootstrapTable('destroy');
  389. //3.加载表格数据
  390. console.log(customerTableColumns);
  391. customerTableInit();
  392. //展示模态框
  393. $('#customer_modal').modal();
  394. }
  395. //刷新table的数据
  396. function refreshCustomerTable(){
  397. $('#customer_modal_table').bootstrapTable('refresh');
  398. }
  399. //卷的打印单个标签通用方法
  400. function printSingleLabel(row){
  401. $("#iframe_for_print").attr("src", '/print/getPrintDataWithCondition?searchStr=' + escape(JSON.stringify(row)));
  402. }
  403. //卷批量打印的方法
  404. function batchPrintLabel(row){
  405. $("#iframe_for_print").attr("src", '/print/batchPrintLabel?searchStr=' + escape(JSON.stringify(row)));
  406. }
  407. //通用的按钮控制方法
  408. function customerBtnControl(tableTags, row, statusCode){
  409. //判断是会否选中行
  410. if(row == null || "" == row){
  411. $("button.control-btn").prop("disabled", true);
  412. }else{
  413. $("button.control-btn").prop("disabled", false);
  414. }
  415. //根据不同的状态码设置不同的参数
  416. if("deleted" == statusCode){
  417. $("button.control-btn").prop("disabled", true);
  418. }
  419. //判断是否存在rows
  420. let rows = $('#'+tableTags).bootstrapTable("getData");
  421. let len = rows.length;
  422. //不存在数据则禁用所有的按钮
  423. if(len == 0){
  424. $("button.control-btn").prop("disabled", true);
  425. }else{
  426. //释放下载
  427. $("#download_button").prop("disabled", false);
  428. }
  429. }
  430. /*判断终端是手机还是电脑--用于判断文件是否导出(电脑需要导出)*/
  431. function phoneOrPc(){
  432. var sUserAgent = navigator.userAgent.toLowerCase();
  433. var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
  434. var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
  435. var bIsMidp = sUserAgent.match(/midp/i) == "midp";
  436. var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
  437. var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
  438. var bIsAndroid = sUserAgent.match(/android/i) == "android";
  439. var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
  440. var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
  441. if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
  442. return false;
  443. } else {
  444. return true;
  445. }
  446. }
  447. //格式化数字
  448. function DoOnMsoNumberFormat(cell, row, col) {
  449. var result = "";
  450. if (row > 0 && col == 0)
  451. debugger;
  452. result = "\\@";
  453. return result;
  454. }
  455. // 日期数字格式化
  456. function generateTimeReqestNumber() {
  457. var date = new Date();
  458. return date.getFullYear().toString() + pad2(date.getMonth() + 1) + pad2(date.getDate()) + pad2(date.getHours()) + pad2(date.getMinutes()) + pad2(date.getSeconds());
  459. }
  460. function pad2(n) {
  461. return n < 10 ? '0' + n : n
  462. }
  463. // 时间搜索框
  464. function InfoDate(date){
  465. // var default_date = getNowFormatDate();
  466. // $("#"+date).val(default_date);
  467. $.fn.datetimepicker.dates['zh-CN'] = {
  468. days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"],
  469. daysShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六", "周日"],
  470. daysMin: ["日", "一", "二", "三", "四", "五", "六", "日"],
  471. months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
  472. monthsShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
  473. today: "今天",
  474. suffix: [],
  475. meridiem: ["上午", "下午"]
  476. };
  477. //初始化模态框的日期
  478. $("#"+date).datetimepicker({
  479. format : 'yyyy-mm-dd',//显示格式
  480. startView: "month", //初始化视图是‘年’
  481. maxView : 4,//最高能展示的时间,Number, String类型 默认值:4, 年
  482. minView : 'year',//日期时间选择器所能够提供的最精确的时间选择视图
  483. autoclose : true,//选择后自动关闭
  484. todayBtn : true,//开启选择今天的按钮
  485. todayHighlight: true,//今天日期高亮显示 如果为true, 高亮当前日期。Boolean类型 ,默认值:false ,
  486. language : 'zh-CN'//语言选择中文
  487. });
  488. }
  489. // 判断 是否是数字
  490. function myIsNaN(value) {
  491. return typeof value === 'number' && !isNaN(value);
  492. }