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.

385 lines
21 KiB

3 weeks ago
  1. @{
  2. ViewBag.Title = "Index";
  3. Layout = "~/Views/Shared/_Index.cshtml";
  4. }
  5. <script src="~/Content/js/datepicker/WdatePicker.js"></script>
  6. <!--引入 element-ui 的样式,-->
  7. <link rel="stylesheet" href="~/Content/element-ui/lib/theme-chalk/index.css">
  8. <script src="~/Content/vue/dist/vue.js"></script>
  9. <script src="~/Content/element-ui/lib/index.js"></script>
  10. <script src="~/Content/axios.min.js"></script>
  11. <style>
  12. </style>
  13. <form id="form1">
  14. <div id="app">
  15. <div class="topPanel" style="height:100px;">
  16. <div class="toolbar">
  17. <div class="btn-group">
  18. <input id="FileUp" name="FileUp" type="file" style="display:none;" accept=".csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
  19. <input id='FileUp2' type='file' style="display: none" />
  20. <a id="NF-Add" authorize="yes" style="margin-left:3px;" class="btn btn-primary" onclick="btn_Add()"><i class="fa fa-pencil-square-o"></i>新增</a>
  21. <a id="NF-Remove" authorize="yes" style="margin-left:3px;" class="btn btn-primary" onclick="btn_Remove()"><i class="fa fa-pencil-square-o"></i>删除</a>
  22. <a id="NF-Edit" authorize="yes" style="margin-left:3px;" class="btn btn-primary" onclick="btn_Edit()"><i class="fa fa-pencil-square-o"></i>修改</a>
  23. <a id="NF-Introduction" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_UPload()">导入</a>
  24. <a href="~/File/IQC/物料关联检验项目.xlsx" id="NF-IntroductionMould" authorize="no" class="btn btn-primary dropdown-text"><i class="fa fa-file-excel-o"></i>导入模板下载</a>
  25. <a id="NF-ExportAll" authorize="no" class="btn btn-primary"><i class="fa fa-download"></i>导出</a>
  26. <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
  27. </div>
  28. <div class="btn-group" style="display:block;padding-left:2px;">
  29. <a class="btn btn-primary" id="downPrintControl" href="~/PrintActivex.exe" style="display:none">点击下载打印组件</a>
  30. </div>
  31. @*<script>$('.toolbar').authorizeButton()</script>*@
  32. </div>
  33. <div class="search">
  34. <table>
  35. <tr>
  36. <td class="HideItems" style="text-align:right;"><label class="lglabel HideItems" for="txt_InvCode">&nbsp;&nbsp;&nbsp;&nbsp;物料编码</label>:</td>
  37. <td class="HideItems">
  38. <div class="input-group HideItems">
  39. <input id="txt_InvCode" type="text" class="form-control HideItems" style="width: 200px;">
  40. </div>
  41. </td>
  42. <td class="HideItems" style="text-align:right;"><label class="lglabel HideItems" for="txt_InvName">&nbsp;&nbsp;&nbsp;&nbsp;物料名称</label>:</td>
  43. <td class="HideItems">
  44. <div class="input-group HideItems">
  45. <input id="txt_InvName" type="text" class="form-control HideItems" style="width: 200px;">
  46. </div>
  47. </td>
  48. <td class="HideItems" style="text-align:right;"><label class="lglabel HideItems" for="txt_GroupCode">&nbsp;&nbsp;&nbsp;&nbsp;检验项目组编码</label>:</td>
  49. <td class="HideItems">
  50. <div class="input-group HideItems">
  51. <input id="txt_GroupCode" type="text" class="form-control HideItems" style="width: 200px;">
  52. </div>
  53. </td>
  54. <td class="HideItems" style="text-align:right;"><label class="lglabel HideItems" for="txt_GroupName">&nbsp;&nbsp;&nbsp;&nbsp;检验项目组名称</label>:</td>
  55. <td class="HideItems">
  56. <div class="input-group HideItems">
  57. <input id="txt_GroupName" type="text" class="form-control HideItems" style="width: 200px;">
  58. </div>
  59. </td>
  60. <td>
  61. <span class="input-group-btn">
  62. <button id="btn_search" type="button" class="btn btn-primary"><i class="fa fa-search"></i></button>
  63. </span>
  64. </td>
  65. </tr>
  66. </table>
  67. </div>
  68. </div>
  69. <div class="gridPanel">
  70. <table id="gridList"></table>
  71. <div id="gridPager"></div>
  72. </div>
  73. </div>
  74. </form>
  75. <script type="text/javascript">
  76. function btn_UPload() {
  77. $("#FileUp").click();
  78. }
  79. function UpLoadClick() {
  80. var ids = $("#gridList").jqGrid('getGridParam', 'selarrrow');
  81. if (ids.length != 1) {
  82. $.modalAlertNew("WMS00050");
  83. return;
  84. }
  85. $("#FileUp2").click();
  86. }
  87. $(function () {
  88. var service = {
  89. isCanEditDate: false,
  90. Init: function () {
  91. var that = this;
  92. that.initControl();
  93. that.loadGrid();
  94. that.loadEvent();
  95. },
  96. initControl: function () {
  97. let that = this;
  98. let userName = '@NFine.Code.OperatorProvider.Provider.GetCurrent().UserName';
  99. },
  100. // 1. 主表加载:仅保留物料核心字段,开启子表
  101. loadGrid: function () {
  102. var that = this;
  103. var queryJson = {
  104. InvCode: $("#txt_InvCode").val(),
  105. InvName: $("#txt_InvName").val(),
  106. GroupCode: $("#txt_GroupCode").val(),
  107. GroupName: $("#txt_GroupName").val(),
  108. // 筛选条件简化:仅保留物料相关,检验项目筛选移到子表(如需子表筛选需额外开发)
  109. }
  110. var $gridList = $("#gridList");
  111. $gridList.dataGrid({
  112. url: "/DHAY/IQCQuality/GetItemMainGridJson" + "?" + Math.random(), // 主表接口:需返回汇总后的物料数据
  113. postData: { queryJson: JSON.stringify(queryJson) },
  114. mtype: "POST",
  115. height: $(window).height() - 200,
  116. width: $(window).width() - 300,
  117. cellEdit: false, // 主表仅展示,关闭单元格编辑
  118. cellsubmit: "clientArray",
  119. colModel: [
  120. { label: "物料编码", name: "InvCode", width: 120, align: 'left', sortable: true },
  121. { label: "物料名称", name: "InvName", width: 180, align: 'left', sortable: true },
  122. { label: "检验项目组编码", name: "GroupCode", width: 180, align: 'left', sortable: true },
  123. { label: "检验项目组名称", name: "GroupName", width: 180, align: 'left', sortable: true },
  124. { label: "维护人", name: "MUSERName", width: 100, align: 'left' },
  125. { label: "维护时间", name: "MTIME", width: 160, align: 'left', formatter: "datetime", formatoptions: { newformat: "Y-m-d H:i:s" } }
  126. ],
  127. shrinkToFit: true,
  128. width: "100%",
  129. autowidth: true,
  130. gridComplete: function () {
  131. // 主表加载完成后无额外操作(如需高亮等可在此添加)
  132. },
  133. pager: "#gridPager",
  134. sortname: 'MTIME',
  135. sortorder: "desc",
  136. viewrecords: true,
  137. multiselect: true,
  138. subGrid: true, // 2. 开启子表功能
  139. // 3. 子表展开事件:加载当前物料的检验项目数据
  140. subGridRowExpanded: function (subgrid_id, rowid) {
  141. // 取消主表行选中(避免冲突)
  142. $("#gridList").jqGrid("setSelection", rowid, false);
  143. // 加载子表
  144. that.bindSubGrid(subgrid_id, rowid);
  145. }
  146. });
  147. },
  148. // 4. 子表加载:原主表的检验项目字段全部移到子表
  149. bindSubGrid: function (subgrid_id, rowid) {
  150. var that = this;
  151. // 子表容器ID和分页容器ID
  152. var subgrid_table_id = subgrid_id + "_t";
  153. var subgrid_pager_id = subgrid_id + "_pgr";
  154. // 创建子表DOM结构
  155. $("#" + subgrid_id).html("<table id='" + subgrid_table_id + "' class='scroll'></table><div id='" + subgrid_pager_id + "' class='scroll'></div>");
  156. // 获取主表当前行的物料编码(子表查询条件)
  157. var invCode = $("#gridList").jqGrid('getRowData', rowid).InvCode;
  158. var invName = $("#gridList").jqGrid('getRowData', rowid).InvName;
  159. // 子表初始化:原主表的所有检验项目字段移到这里
  160. $("#" + subgrid_table_id).dataGrid({
  161. url: "/DHAY/IQCQuality/GetItemSubGridJson" + "?" + Math.random(), // 子表接口:按物料编码查检验项目
  162. postData: {
  163. InvCode: invCode, // 子表查询条件:物料编码
  164. InvName: invName // 可选:物料名称辅助筛选
  165. },
  166. mtype: "POST",
  167. height: "auto", // 子表高度自适应内容
  168. width: $("#gridList").width() - 40, // 子表宽度比主表略窄(避免滚动条)
  169. cellEdit: false, // 子表仅展示(如需编辑需额外开发)
  170. cellsubmit: "clientArray",
  171. colModel: [
  172. { label: "检验项目主键", name: "ID", hidden: true, key: true }, // 子表唯一标识
  173. { label: "检验类型(编码)", name: "EATTRIBUTE6", width: 100, align: 'left', hidden: true },
  174. { label: "检验类型", name: "Type", width: 100, align: 'left' },
  175. { label: "检验项目代码", name: "ListCode", width: 120, align: 'left' },
  176. { label: "检验项目名称", name: "ListName", width: 180, align: 'left' },
  177. { label: "标准下限", name: "SetValueMin", width: 100, align: 'left' },
  178. { label: "标准上限", name: "SetValueMax", width: 100, align: 'left' },
  179. { label: "单位", name: "Unit", width: 80, align: 'left' },
  180. { label: "检验标准", name: "EATTRIBUTE1", width: 150, align: 'left' },
  181. { label: "抽样水准", name: "EATTRIBUTE2", width: 100, align: 'left' },
  182. { label: "允收标准", name: "EATTRIBUTE3", width: 100, align: 'left' },
  183. { label: "必填标识(编码)", name: "EATTRIBUTE4", width: 100, align: 'left', hidden: true },
  184. { label: "抽检实际值是否必填", name: "CEATTRIBUTE4", width: 150, align: 'left' },
  185. { label: "AQL代码", name: "EATTRIBUTE5", width: 100, align: 'left' },
  186. { label: "是否可用", name: "CEnable", width: 100, align: 'left' },
  187. { label: "维护人", name: "MUSERName", width: 100, align: 'left' },
  188. { label: "维护时间", name: "MTIME", width: 160, align: 'left', formatter: "date", formatoptions: { newformat: "Y-m-d H:i:s" } }
  189. ],
  190. shrinkToFit: true,
  191. multiselect: false, // 子表不支持多选(避免与主表冲突)
  192. viewrecords: true,
  193. pager: subgrid_pager_id, // 子表独立分页
  194. rowNum: 10, // 子表每页条数
  195. sortname: 'ListCode',
  196. sortorder: "asc"
  197. });
  198. },
  199. // 5. 搜索逻辑:仅筛选主表的物料数据
  200. query: function () {
  201. var queryJson = {
  202. InvCode: $("#txt_InvCode").val(),
  203. InvName: $("#txt_InvName").val(),
  204. GroupCode: $("#txt_GroupCode").val(),
  205. GroupName: $("#txt_GroupName").val(),
  206. }
  207. $("#gridList").jqGrid('setGridParam', {
  208. postData: { queryJson: JSON.stringify(queryJson) },
  209. }).trigger('reloadGrid');
  210. },
  211. // 6. 事件绑定:保持原逻辑不变(编辑仍传物料编码)
  212. loadEvent: function () {
  213. var that = this;
  214. // 搜索按钮
  215. $("#btn_search").click(function () {
  216. that.query();
  217. });
  218. // 新增按钮
  219. $("#NF-Add").click(function () {
  220. $.modalOpen({
  221. id: "Form",
  222. title: "物料关联检验项目",
  223. url: "/DHAY/IQCQuality/Item2CheckItemGroupBind",
  224. width: "1200px",
  225. height: "800px",
  226. callBack: function (iframeId) {
  227. top.frames[iframeId].submitForm();
  228. }
  229. });
  230. });
  231. // 编辑按钮:仍按物料编码打开子页面
  232. $("#NF-Edit").click(function () {
  233. var ids = $("#gridList").jqGrid('getGridParam', 'selarrrow');
  234. if (ids.length != 1) {
  235. $.modalMsg("请选择一条数据", "warning");
  236. return;
  237. }
  238. var selectInvCode = $("#gridList").jqGrid('getRowData', ids[0]).InvCode;
  239. $.modalOpen({
  240. id: "Form",
  241. title: "编辑",
  242. url: "/DHAY/IQCQuality/Item2CheckItemGroupEdit?INVCode=" + selectInvCode + "",
  243. width: "1000px",
  244. height: "800px",
  245. callBack: function (iframeId) {
  246. top.frames[iframeId].submitForm();
  247. }
  248. });
  249. });
  250. // 删除按钮:按主表选中行删除(需确保接口支持按物料编码批量删除)
  251. $("#NF-Remove").click(function () {
  252. var ids = $("#gridList").jqGrid('getGridParam', 'selarrrow');
  253. if (ids.length < 1) {
  254. $.modalMsg("请选择数据", "warning");
  255. return;
  256. }
  257. // 收集选中行的物料编码(而非原主键)
  258. let invCodeList = [];
  259. for (var i = 0; i < ids.length; i++) {
  260. var invCode = $("#gridList").jqGrid('getRowData', ids[i]).InvCode;
  261. invCodeList.push(invCode);
  262. }
  263. $.ajax({
  264. url: "/DHAY/IQCQuality/DeleteItem2CheckItem",
  265. type: "POST",
  266. dataType: "json",
  267. async: false,
  268. data: {
  269. keyValue: JSON.stringify(invCodeList) // 传物料编码列表到接口
  270. },
  271. success: function (data) {
  272. if (data.state == "success") {
  273. $.modalMsg("操作成功", "success");
  274. that.query();
  275. } else {
  276. $.modalMsg(data.message, "warning");
  277. }
  278. }
  279. });
  280. });
  281. // 导出按钮:按物料筛选条件导出(如需导出子表需额外处理)
  282. $("#NF-ExportAll").click(function () {
  283. let queryJson = {
  284. InvCode: $("#txt_InvCode").val(),
  285. InvName: $("#txt_InvName").val(),
  286. };
  287. var postData = "&InvCode=" + queryJson.InvCode + "";
  288. postData += "&InvName=" + queryJson.InvName;
  289. $.download("/DHAY/IQCQuality/ExportAllItem2CheckItem" + "?" + Math.random(), postData, 'post');
  290. });
  291. // 导入按钮:保持原逻辑
  292. $("#FileUp").on("change", function (up) {
  293. var form = new FormData(document.getElementById("form1"));
  294. $.ajax({
  295. url: "/DHAY/IQCQuality/ImportItem2CheckGroup?" + Math.random(),
  296. type: "post",
  297. data: form,
  298. contentType: false,
  299. processData: false,
  300. success: function (data) {
  301. if (data == "true" || data == true) {
  302. alert("导入成功");
  303. that.query();
  304. } else {
  305. alert(data);
  306. }
  307. },
  308. error: function (aa) {
  309. alert("导入失败:" + aa);
  310. }
  311. });
  312. });
  313. // FileUp2上传:保持原逻辑(需确保接口支持按物料编码关联文件)
  314. $("#FileUp2").on("change", function (e) {
  315. var objList = $("#gridList").jqGrid('getGridParam', 'selarrrow');
  316. if (objList.length != 1) {
  317. $.modalMsg("请选择一条数据", "warning");
  318. return;
  319. }
  320. var rowData = $("#gridList").jqGrid('getRowData', objList[0]);
  321. var invCode = rowData.InvCode; // 传物料编码而非原ID
  322. var files = e.target.files;
  323. if (files.length == 0) return;
  324. var data = new FormData();
  325. jQuery.each(jQuery('#FileUp2')[0].files, function (i, file) {
  326. data.append('file-' + i, file);
  327. });
  328. data.append("InvCode", invCode); // 传物料编码到接口
  329. $.modalConfirm("确定上传文件吗?", function (r) {
  330. if (r) {
  331. $.ajax({
  332. url: "/DHAY/IQCQuality/UpLoadItemRuleFile" + "?" + Math.random(),
  333. type: "post",
  334. data: data,
  335. contentType: false,
  336. processData: false,
  337. dataType: "json",
  338. success: function (data) {
  339. if (data.message == "上传成功!") {
  340. $.modalMsg("操作成功", "success");
  341. that.query();
  342. } else {
  343. $.modalMsg(data.message, "warning");
  344. }
  345. },
  346. error: function (aa) {
  347. $.modalAlertNew("WMS00016", aa);
  348. }
  349. });
  350. }
  351. });
  352. });
  353. // 查看文件按钮:保持原逻辑(需接口支持按物料编码查文件)
  354. $("#NF-ViewFile").click(function () {
  355. var ids = $("#gridList").jqGrid('getGridParam', 'selarrrow');
  356. if (ids.length != 1) {
  357. $.modalMsg("请选择一条数据", "warning");
  358. return;
  359. }
  360. var invCode = $("#gridList").jqGrid('getRowData', ids[0]).InvCode;
  361. $.modalOpen({
  362. id: "Form",
  363. title: "质量履历文件查看",
  364. url: "/DHAY/IQCQuality/Item2AqlFileView?invCode=" + invCode + "", // 传物料编码
  365. width: "1200px",
  366. height: "400px",
  367. callBack: function (iframeId) {
  368. top.frames[iframeId].submitForm();
  369. }
  370. });
  371. });
  372. }
  373. }
  374. service.Init();
  375. })
  376. </script>