纽威
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.

418 lines
17 KiB

3 years ago
3 years ago
  1. @{
  2. ViewBag.Title = "Form";
  3. Layout = "~/Views/Shared/_Form.cshtml";
  4. }
  5. <link href="~/Content/css/CommonReport/CommonReport.css" rel="stylesheet" />
  6. <script src="~/Content/js/CommonReport/CommonReport.js"></script>
  7. <link href="~/Content/css/bootstrap/bootstrap-select.css" rel="stylesheet" />
  8. <script src="~/Content/js/bootstrap/bootstrap-select.min.js"></script>
  9. <link href="~/Content/css/ColorPicker/bootstrap-colorpicker.css" rel="stylesheet" />
  10. <script src="~/Content/js/ColorPicker/bootstrap-colorpicker.min.js"></script>
  11. <style>
  12. .input-lg {
  13. height:100%;
  14. width:75% !important;
  15. }
  16. .form-control {
  17. height:20px;
  18. }
  19. .ui-jqgrid .table-bordered td {
  20. line-height:12px;
  21. vertical-align:middle;
  22. }
  23. </style>
  24. <script>
  25. var SourceID = $.request("SourceID");
  26. var cols = new Array();
  27. var LogString_Num = new Array();
  28. var LogString_Str = new Array();
  29. var LogString_Date = new Array();
  30. var LogString_Bool = new Array();
  31. var NewLine = 0;
  32. var FirstShow = 0;
  33. $(function () {
  34. LogString_Num = GetLogString("数值型");
  35. LogString_Str = GetLogString("字符型");
  36. LogString_Date = GetLogString("日期型");
  37. LogString_Bool = GetLogString("布尔值");
  38. GetCols();
  39. gridList();
  40. $(window).resize(function () {
  41. $("#gridList").setGridWidth($(window).width() * 0.99);
  42. $("#gridList").setGridWidth(document.body.clientWidth * 0.99);
  43. $("#gridList").setGridHeight($(window).height() - 96);
  44. $("#gridList").setGridHeight(document.body.clientHeight - 96);
  45. });
  46. });
  47. function GetCols()
  48. {
  49. $.ajax({
  50. url: "/SystemManage/CommonReport/GetCols?SourceID=" + SourceID + "&" + Math.random(),
  51. dataType: "json",
  52. async: false,
  53. success: function (aa) {
  54. if (aa != null) {
  55. var data = aa.rows;
  56. if (data != false && data != null && data.length > 0) {
  57. cols=new Array();
  58. $("#Select_cols").find("option").remove();
  59. $("#Select_cols").append("<option value=''></option>");
  60. for (var i = 0; i < data.length; i++) {
  61. $("#Select_cols").append("<option value='" + data[i].IDStr + "'>" + data[i].ColFiledName + "</option>");
  62. cols.push({ IDStr: data[i].IDStr, DataType: data[i].DataType });
  63. }
  64. }
  65. $('#Select_cols').selectpicker('refresh');
  66. $('#Select_cols').selectpicker('render');
  67. $('#Select_cols').val(data[0].IDStr);
  68. $('#Select_cols').selectpicker('refresh');
  69. }
  70. }
  71. });
  72. }
  73. function GetDataTypeStr()
  74. {
  75. if (cols.length > 0)
  76. {
  77. for (var i = 0; i < cols.length ; i++)
  78. {
  79. if (cols[i].IDStr == $('#Select_cols').val())
  80. {
  81. return GetDataTypeByNum(cols[i].DataType);
  82. }
  83. }
  84. }
  85. }
  86. function gridList() {
  87. document.getElementsByClassName("gridPanel")[0].innerHTML = ' <table id="gridList"></table>';
  88. var DataTypeStr = GetDataTypeStr();
  89. var $gridList = $("#gridList");
  90. $gridList.dataGrid({
  91. url: "/SystemManage/CommonReport/GetGridFormat?" + Math.random(),
  92. postData: { ColId: $('#Select_cols').val() },
  93. height: $(window).height() - 96,
  94. width:"100%",
  95. colModel: [//ID ColId LogStr SValue DValue Color AllRowFlag
  96. { label: 'ID', name: 'ID', width: 80, align: 'left', sortable: false, },
  97. { label: 'ColId', name: 'ColId', width: 80, align: 'left', sortable: false, },
  98. {
  99. label: 'LogStr', name: 'LogStr', width: 95, align: 'left', sortable: false,
  100. },
  101. {
  102. label: '运算符', width: 95, align: 'left', sortable: false,
  103. formatter: function (cellvalue, options, rowObject) {
  104. // $("#LogStr_" + rowObject.ID).find("option").remove();
  105. var LogString = new Array();
  106. switch (DataTypeStr) {
  107. case "数值型":
  108. LogString = LogString_Num;
  109. break;
  110. case "字符型":
  111. LogString = LogString_Str;
  112. break;
  113. case "日期型":
  114. LogString = LogString_Date;
  115. break;
  116. case "布尔值":
  117. LogString = LogString_Bool;
  118. break;
  119. }
  120. var str_retrun = '<select class="selectpicker" id="LogStr_' + rowObject.ID + '" Title="" data-width="65px" > ';
  121. str_retrun += "<option value=''></option>";
  122. for (var i = 0; i < LogString.length; i++) {
  123. str_retrun += "<option value=\"" + LogString[i].value + "\">" + LogString[i].Str + "</option>";
  124. }
  125. str_retrun += '</select>';
  126. return cellvalue = str_retrun;
  127. },
  128. },
  129. {
  130. label: '值1', name: 'SValue', width: 120, align: 'left', sortable: false,
  131. formatter: function (cellvalue, options, rowObject) {
  132. switch (DataTypeStr) {
  133. case "数值型":
  134. case "布尔值":
  135. case "字符型":
  136. var str_retrun = '<input type="text" class="form-control" id="SValue_' + rowObject.ID + '" value="' + cellvalue + '" />';
  137. return cellvalue = str_retrun;
  138. break;
  139. case "日期型":
  140. var str_retrun = '<input type="text" class="form-control" id="SValue_' + rowObject.ID + '" value="' + cellvalue + '" onclick="WdatePicker({ dateFmt: \'yyyy-MM-dd\'})" />';
  141. return cellvalue = str_retrun;
  142. break;
  143. }
  144. //var str_retrun = '<input type="text" class="form-control" id="SValue_' + rowObject.ID + '" value="' + cellvalue + '" />';
  145. //return cellvalue = str_retrun;
  146. },
  147. },
  148. {
  149. label: '值2', name: 'DValue', width: 120, align: 'left', sortable: false,
  150. formatter: function (cellvalue, options, rowObject) {
  151. switch (DataTypeStr) {
  152. case "数值型":
  153. case "布尔值":
  154. case "字符型":
  155. var str_retrun = '<input type="text" class="form-control" id="DValue_' + rowObject.ID + '" value="' + cellvalue + '" />';
  156. return cellvalue = str_retrun;
  157. break;
  158. case "日期型":
  159. var str_retrun = '<input type="text" class="form-control" id="DValue_' + rowObject.ID + '" value="' + cellvalue + '" onclick="WdatePicker({ dateFmt: \'yyyy-MM-dd\'})" />';
  160. return cellvalue = str_retrun;
  161. break;
  162. }
  163. //var str_retrun = '<input type="text" class="form-control" id="DValue_' + rowObject.ID + '" value="' + cellvalue + '" />';
  164. //return cellvalue = str_retrun;
  165. },
  166. },
  167. {
  168. label: '颜色', name: 'Color', width: 180, align: 'left', sortable: false,
  169. formatter: function (cellvalue, options, rowObject) {
  170. var str_retrun = '<div id="ColorInput_' + rowObject.ID + '" class="input-group colorpicker-component" style="height:12px;top:5px">';
  171. str_retrun += ' <input type="text" style="height:12px" class="form-control input-lg" id="ColorInputStr_' + rowObject.ID + '" value="' + cellvalue + '" />';
  172. str_retrun += ' <span class="input-group-addon" style="height:12px"><i style="height:12px"></i></span>';
  173. str_retrun += ' </div> ';
  174. return cellvalue = str_retrun;
  175. }
  176. }, {
  177. label: '是否影响全行', name: 'AllRowFlag', width: 80, align: 'left', sortable: false,
  178. formatter: function (cellvalue, options, rowObject) {
  179. if (cellvalue ) {
  180. var str_retrun = '<input type="checkbox" name="AllRowFlag_' + rowObject.ID + '" ';
  181. str_retrun += ' id="AllRowFlag_' + rowObject.ID + '" checked="checked"/> ';
  182. return cellvalue = str_retrun;
  183. }
  184. else {
  185. var str_retrun = '<input type="checkbox" name="AllRowFlag_' + rowObject.ID + '" ';
  186. str_retrun += ' id="AllRowFlag_' + rowObject.ID + '" /> ';
  187. return cellvalue = str_retrun;
  188. }
  189. }
  190. } ,
  191. ],
  192. viewrecords: true,
  193. rownumbers: true,
  194. multiselect: true,
  195. rowNum: 500,
  196. gridComplete: function () {
  197. $("#gridList").setGridParam().hideCol("ColId");//隐藏
  198. $("#gridList").setGridParam().hideCol("ID");//隐藏
  199. $("#gridList").setGridParam().hideCol("LogStr");//隐藏
  200. var strIds = $("#gridList").jqGrid("getDataIDs");
  201. if (FirstShow == 0) {
  202. for (var i = 0; i < strIds.length; i++) {
  203. var ID = $("#gridList").jqGrid("getCell", strIds[i], "ID");
  204. var LogStr = $("#gridList").jqGrid("getCell", strIds[i], "LogStr");
  205. $('#ColorInput_' + ID).colorpicker();
  206. $("#LogStr_" + ID).selectpicker('refresh');
  207. if (LogStr != "")
  208. {
  209. $("#LogStr_" + ID).val( LogStr );
  210. $("#LogStr_" + ID).selectpicker('refresh');
  211. }
  212. }
  213. FirstShow = 1;
  214. }
  215. NewLine = strIds.length;
  216. $("#gridList").jqGrid('hideCol', 'cb');//隐藏勾选框 //勾选框选中的时候 与行选中有异常,所以隐藏
  217. },
  218. });
  219. }
  220. function SHowcols(colname) {
  221. $("#gridList").setGridParam().showCol(colname);
  222. }
  223. function Hiddencols(colname) {
  224. $("#gridList").setGridParam().hideCol(colname);
  225. }
  226. //换栏位
  227. function ChangeCols() {
  228. NewLine = 0;
  229. FirstShow = 0;
  230. gridList();
  231. }
  232. //新增一行
  233. function btn_ADD() {
  234. NewLine = NewLine + 1;
  235. var ids = jQuery("#gridList").jqGrid('getDataIDs');
  236. if (ids.length == 0) {
  237. ids = [0];
  238. }
  239. //获得当前最大行号(数据编号)
  240. var rowid = Math.max.apply(Math, ids);
  241. //获得新添加行的行号(数据编号)
  242. var newrowid = rowid + 1;
  243. $("#gridList").addRowData(newrowid,
  244. {//ID ColId LogStr SValue DValue Color AllRowFlag
  245. "ID": NewLine.toString(),
  246. "ColId": $('#Select_cols').val(),
  247. "LogStr": "",
  248. "SValue": "",
  249. "DValue": "",
  250. "Color": "",
  251. "AllRowFlag": false,
  252. },
  253. "last");
  254. var unwritten = document.getElementsByClassName("unwritten")[0];
  255. if (unwritten != null && unwritten != 'undefined') {
  256. unwritten.style.display = "none";
  257. }
  258. // $(".unwritten").attr("display", "none");
  259. //colorpick
  260. var strIds = $("#gridList").jqGrid("getDataIDs");
  261. var rr = strIds.length - 1;
  262. var ID = $("#gridList").jqGrid("getCell", strIds[rr], "ID");
  263. $('#ColorInput_' + ID).colorpicker();
  264. $("#LogStr_" + ID).selectpicker('refresh');
  265. }
  266. //删除选中行
  267. function btn_Del() {
  268. var selectedRowIds = $("#gridList").jqGrid("getGridParam", "selarrrow");
  269. var len = selectedRowIds.length;
  270. for (var i = 0; i < len ; i++) {
  271. $("#gridList").jqGrid("delRowData", selectedRowIds[i]);
  272. }
  273. var selectedRowIds = $("#gridList").jqGrid("getGridParam", "selarrrow");
  274. var len = selectedRowIds.length;
  275. for (var i = 0; i < len ; i++) {
  276. $("#gridList").jqGrid("delRowData", selectedRowIds[i]);
  277. }
  278. }
  279. function btn_Save() {
  280. var SubmitLine = new Array();
  281. var strIds = $("#gridList").jqGrid("getDataIDs");
  282. for (var i = 0; i < strIds.length; i++) {
  283. //ID ColId LogStr SValue DValue Color AllRowFlag
  284. var ID = $("#gridList").jqGrid("getCell", strIds[i], "ID");
  285. var LogStr = $("#LogStr_" + ID).val();
  286. var SValue = $("#SValue_" + ID).val();
  287. var DValue = $("#DValue_" + ID).val();
  288. var Color = $("#ColorInputStr_" + ID).val();
  289. var AllRowFlag = checkboxToNumStr(document.getElementById("AllRowFlag_" + ID));
  290. var obj = {
  291. ID:"",
  292. ColId: $('#Select_cols').val(),
  293. LogStr: LogStr,
  294. SValue: SValue,
  295. DValue: DValue,
  296. Color: Color,
  297. AllRowFlag: AllRowFlag,
  298. }
  299. SubmitLine.push(obj);
  300. }
  301. $.ajax({
  302. url: "/SystemManage/CommonReport/SetGridFormat" + "?" + Math.random(),
  303. type: "post",
  304. data: { ColId: $('#Select_cols').val(), List_GridFormat: JSON.stringify(SubmitLine), },
  305. async: false,
  306. success: function (data) {
  307. alert(data);
  308. },
  309. error: function (aa) {
  310. //alert("异常:" + aa.responseText);
  311. $.modalAlertNew("WMS00015", aa.responseText);
  312. }
  313. });
  314. }
  315. </script>
  316. <form id="form1">
  317. <div style="margin-top: 10px; margin-left: 10px; margin-right: 10px;">
  318. <div class="form-group" style="height:40px;margin-bottom:5px">
  319. <table class="form" style="width:700px" >
  320. <tr>
  321. <th class="formTitle">字段名称: </th>
  322. <td class="formValue" style="width:160px">
  323. <select id="Select_cols" name="Select_cols" onchange="ChangeCols()" title="" class="selectpicker " data-width="140px" style="margin-right:100px"></select>
  324. </td>
  325. <td class="formValue">
  326. <a id="Btn_ADD" authorize="yes" class="btn btn-primary dropdown-text " onclick="btn_ADD()"><i class="fa fa-plus"></i>添加格式化条件</a>
  327. </td>
  328. <td class="formValue">
  329. <a id="Btn_Del" authorize="yes" class="btn btn-primary dropdown-text " onclick="btn_Del()"><i class="fa fa-minus"></i>移除格式化条件</a>
  330. </td>
  331. <td class="formValue">
  332. <a id="Btn_Save" authorize="yes" class="btn btn-primary dropdown-text " onclick="btn_Save()"><i class="fa fa-save"></i>保存</a>
  333. </td>
  334. </tr>
  335. </table>
  336. </div>
  337. <div class="gridPanel">
  338. <table id="gridList"></table>
  339. @*<div id="gridPager"></div>*@
  340. </div>
  341. </div>
  342. </form>