DFM1509.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. var acceptClick;
  2. var selectBomInfo;
  3. var calQty;
  4. var BillBomInfo = [];
  5. var BomsetCode = '';
  6. var keyValue = request('keyValue');
  7. var bootstrap = function ($, learun) {
  8. "use strict";
  9. const SpoolTypes = ["WS09"]; //工字轮型号
  10. var classnames = ['yellowCircle', 'purpleCircle', 'lightgreenCircle'];
  11. var reg = /^(\-|\+)?\d+(\.\d+)?$/;
  12. var regex = /^[1-9]\d*$/;
  13. var page = {
  14. init: function () {
  15. page.bind();
  16. page.initData();
  17. },
  18. bind: function () {
  19. $('#ProMaterCode').lrselect({
  20. url: top.$.rootUrl + "/FJManager/BaseMatinfo/GetList",
  21. allowSearch: true,
  22. width: 280,
  23. });
  24. $("#HWCountQty").on('change', function () {
  25. calQty();
  26. });
  27. $('#SelectBomCode').on('click', function () {
  28. learun.layerForm({
  29. id: 'SelectBomCodeform',
  30. title: '查询',
  31. url: top.$.rootUrl + '/FJManager/BillBomInfo/SelectForm?SpoolType=' + SpoolTypes,
  32. width: 1050,
  33. height: 690,
  34. callBack: function (id) {
  35. return top[id].acceptClick(selectBomInfo);
  36. },
  37. });
  38. });
  39. // 设置小圆圈的点击事件
  40. $('.clickcircle').click(function () {
  41. for (var i = 0; i < classnames.length; i++) {
  42. if ($(this).attr('class').indexOf(classnames[i]) >= 0) {
  43. $(this).removeClass(classnames[i]);
  44. $(this).addClass('selectedactive');
  45. }
  46. }
  47. $(this).toggleClass('selectedactive');
  48. });
  49. $("#SaveOne").on('click', function () {
  50. var matcode0 = $("#MatCode0").val();
  51. if (matcode0 == "") {
  52. learun.alert.error('请输入第一种湿拉物料');
  53. return false;
  54. }
  55. var qty = $("#QtyMaxCount0").val();
  56. if (qty == "" && !reg.test(qty)) {
  57. learun.alert.error('请输入第一种湿拉物料的数量');
  58. return false;
  59. }
  60. var selectqty = $("#allcontainer > div").find("." + classnames[0]).length + $("#allcontainer > div").find(".selectedactive").length;
  61. if (parseInt(qty) != selectqty) {
  62. learun.alert.error('选择的数量与第一种湿拉物料的数量不相符!');
  63. return false;
  64. }
  65. $("#allcontainer > div").children().each(function () {
  66. var classname = $(this).attr('class');
  67. if (classname.indexOf('selectedactive') >= 0) {
  68. $(this).removeClass('selectedactive');
  69. $(this).addClass(classnames[0]);
  70. }
  71. });
  72. });
  73. $("#SaveTwo").on('click', function () {
  74. var matcode1 = $("#MatCode1").val();
  75. if (matcode1 == "") {
  76. learun.alert.error('请输入第二种湿拉物料');
  77. return false;
  78. }
  79. var qty = $("#QtyMaxCount1").val();
  80. if (qty == "" && !reg.test(qty)) {
  81. learun.alert.error('请输入第二种湿拉物料的数量');
  82. return false;
  83. }
  84. var selectqty = $("#allcontainer > div").find("." + classnames[1]).length + $("#allcontainer > div").find(".selectedactive").length;
  85. if (parseInt(qty) != selectqty) {
  86. learun.alert.error('选择的数量与第二种湿拉物料的数量不相符!');
  87. return false;
  88. }
  89. $("#allcontainer > div").children().each(function () {
  90. var classname = $(this).attr('class');
  91. if (classname.indexOf('selectedactive') >= 0) {
  92. $(this).removeClass('selectedactive');
  93. $(this).addClass(classnames[1]);
  94. }
  95. });
  96. });
  97. $("#SaveThree").on('click', function () {
  98. var matcode2 = $("#MatCode2").val();
  99. if (matcode2 == "") {
  100. learun.alert.error('请输入第三种湿拉物料');
  101. return false;
  102. }
  103. var qty = $("#QtyMaxCount2").val();
  104. if (qty == "" && !reg.test(qty)) {
  105. learun.alert.error('请输入第三种湿拉物料的数量');
  106. return false;
  107. }
  108. var selectqty = $("#allcontainer > div").find("." + classnames[2]).length + $("#allcontainer > div").find(".selectedactive").length;
  109. if (parseInt(qty) != selectqty) {
  110. learun.alert.error('选择的数量与第三种湿拉物料的数量不相符!');
  111. return false;
  112. }
  113. $("#allcontainer > div").children().each(function () {
  114. var classname = $(this).attr('class');
  115. if (classname.indexOf('selectedactive') >= 0) {
  116. $(this).removeClass('selectedactive');
  117. $(this).addClass(classnames[2]);
  118. }
  119. });
  120. });
  121. },
  122. change: function (classname) {
  123. $("#allcontainer > div").children().each(function () {
  124. var classname = $(this).attr('class');
  125. if (classname.indexOf('selectedactive') >= 0) {
  126. $(this).removeClass('selectedactive');
  127. $(this).addClass(classname);
  128. }
  129. });
  130. },
  131. initData: function () {
  132. if (!!keyValue) {
  133. learun.httpAsync('GET', top.$.rootUrl + '/FJManager/BillBomSet/GetBillBomsetinfo', { id: keyValue }, function (res) {
  134. if (res.code > 0) {
  135. let BomsetInfo = res.data;
  136. $('#ProMaterCode').lrselectRefresh({
  137. url: top.$.rootUrl + "/FJManager/BaseMatinfo/GetListByProCode",
  138. param: { queryJson: JSON.stringify({ Code: BomsetInfo.BomCode }) },
  139. allowSearch: true,
  140. width: 280,
  141. });
  142. for (var i = 0; i < BomsetInfo.Bomsetinfos.length; i++) {
  143. var item = BomsetInfo.Bomsetinfos[i];
  144. $("#MatCode" + item.CategoryId).val(item.MatCode);
  145. $("#SilkDiam" + item.CategoryId).val(item.SilkDiam);
  146. $("#QtyMaxCount" + item.CategoryId).val(item.QtyMaxCount);
  147. $("#allcontainer > div").children().each(function () {
  148. var id = $(this).text();
  149. if (item.XYNo == id) {
  150. $(this).removeClass('selectedactive');
  151. $(this).addClass(classnames[item.CategoryId]);
  152. }
  153. });
  154. }
  155. BomsetCode = BomsetInfo.BomCode;
  156. $("#BomName").val(BomsetInfo.BomName);
  157. learun.httpAsync('GET', top.$.rootUrl + '/FJManager/BillBomInfo/GetList', { queryJson: JSON.stringify({ ProCode: BomsetInfo.BomCode, SpoolType: SpoolTypes }) }, function (res) {
  158. if (res.code > 0) {
  159. BillBomInfo = res.data;
  160. calQty();
  161. }
  162. });
  163. setTimeout($('#form').lrSetFormData(res.data), 300);
  164. //learun.httpAsync('GET', top.$.rootUrl + '/FJManager/BillBomInfo/GetList', { queryJson: JSON.stringify({ Code: BomsetInfo.BomCode, SpoolType: SpoolTypes }) }, function (res) {
  165. // if (res.code > 0) {
  166. // $("#BomName").val(res.data[0].Name);
  167. // }
  168. //});
  169. }
  170. });
  171. }
  172. }
  173. };
  174. selectBomInfo = function (rowData) {
  175. if (!!rowData) {
  176. $("#BomName").val('');
  177. //$("#BomName").val(code);
  178. learun.httpAsync('GET', top.$.rootUrl + '/FJManager/BillBomInfo/GetList', { queryJson: JSON.stringify({ ProCode: rowData.ProCode, SpoolType: SpoolTypes, Code: rowData.Code }) }, function (res) {
  179. if (res.code > 0) {
  180. //$('#ProMaterCode').lrselect({
  181. // url: top.$.rootUrl + "/FJManager/BaseMatinfo/GetListByBomCode",
  182. // param: { queryJson: JSON.stringify({ Code: code }) },
  183. // allowSearch: true,
  184. // width: 280,
  185. //});
  186. $(".lr-select-placeholder").empty();
  187. $("#learun_select_option_contentProMaterCode").children().empty();
  188. $('#ProMaterCode').lrselectRefresh({
  189. url: top.$.rootUrl + "/FJManager/BaseMatinfo/GetListByBomCode",
  190. param: { queryJson: JSON.stringify({ Code: rowData.Code }) },
  191. allowSearch: true,
  192. width: 280,
  193. });
  194. for (var i = 0; i < 3; i++) {
  195. $("#MatCode" + i).val('');
  196. }
  197. $("#BomName").val(res.data[0].Name);
  198. BomsetCode = res.data[0].ProCode;
  199. BillBomInfo = res.data;
  200. calQty();
  201. }
  202. });
  203. }
  204. };
  205. calQty = function () {
  206. var totalQty = 0;
  207. for (var i = 0; i < BillBomInfo.length; i++) {
  208. totalQty += parseInt(BillBomInfo[i].HWCountQty);
  209. }
  210. if (totalQty == 0) {
  211. totalQty = 1;
  212. }
  213. var HWCountQty = $("#HWCountQty").val();
  214. for (var i = 0; i < BillBomInfo.length; i++) {
  215. $("#MatCode" + i).val(BillBomInfo[i].MatCode);
  216. if (HWCountQty != "" && reg.test(HWCountQty)) {
  217. var qty = Math.round(parseInt(HWCountQty) / totalQty);
  218. if (BillBomInfo[i].HWCountQty == 0) {
  219. $("#QtyMaxCount" + i).val(qty);
  220. }
  221. else {
  222. $("#QtyMaxCount" + i).val(qty * parseInt(BillBomInfo[i].HWCountQty));
  223. }
  224. }
  225. }
  226. };
  227. // 保存数据
  228. acceptClick = function (callBack) {
  229. if (!$('#form').lrValidform()) {
  230. return false;
  231. }
  232. if ($("#BomName").val() == '') {
  233. learun.alert.error('请输入投料信息');
  234. return false;
  235. }
  236. var HWCountQty = $("#HWCountQty").val();
  237. if (HWCountQty == "" || parseInt(HWCountQty) == 0 || !reg.test(HWCountQty)) {
  238. learun.alert.error('请输入工字轮个数');
  239. return false;
  240. }
  241. var LayerCountQty = $("#LayerCountQty").val();
  242. if (LayerCountQty == "" || parseInt(LayerCountQty) == 0 || !regex.test(LayerCountQty)) {
  243. learun.alert.error('请输入层数');
  244. return false;
  245. }
  246. var ShortCode = $("#ShortCode").val();
  247. if (ShortCode == "" || parseInt(ShortCode) == 0 || !regex.test(ShortCode)) {
  248. learun.alert.error('请输入短编号');
  249. return false;
  250. }
  251. var matcode0 = $("#MatCode0").val();
  252. if (matcode0 != "") {
  253. var selectqty0 = $("#allcontainer > div").find("." + classnames[0]).length;
  254. if (selectqty0 == 0) {
  255. learun.alert.error('请选择第一种湿拉物料的跺型编号!');
  256. return false;
  257. }
  258. }
  259. var matcode1 = $("#MatCode1").val();
  260. if (matcode1 != "") {
  261. var selectqty1 = $("#allcontainer > div").find("." + classnames[1]).length;
  262. if (selectqty1 == 0) {
  263. learun.alert.error('请选择第二种湿拉物料的跺型编号!');
  264. return false;
  265. }
  266. }
  267. var matcode2 = $("#MatCode2").val();
  268. if (matcode2 != "") {
  269. var selectqty2 = $("#allcontainer > div").find("." + classnames[2]).length;
  270. if (selectqty2 == 0) {
  271. learun.alert.error('请选择第三种湿拉物料的跺型编号!');
  272. return false;
  273. }
  274. }
  275. var qty0 = $("#QtyMaxCount0").val();
  276. if (qty0 != "") {
  277. if (!reg.test(qty0) || parseInt(qty0) == 0) {
  278. learun.alert.error('请输入第一种湿拉物料的数量');
  279. return false;
  280. }
  281. else {
  282. var selectqty0 = $("#allcontainer > div").find("." + classnames[0]).length;
  283. if (parseInt(qty0) != selectqty0) {
  284. learun.alert.error('选择的数量与第一种湿拉物料的数量不相符!');
  285. return false;
  286. }
  287. }
  288. }
  289. var qty1 = $("#QtyMaxCount1").val();
  290. if (qty1 != "") {
  291. if (!reg.test(qty1) || parseInt(qty1) == 0) {
  292. learun.alert.error('请输入第二种湿拉物料的数量');
  293. return false;
  294. }
  295. else {
  296. var selectqty1 = $("#allcontainer > div").find("." + classnames[1]).length;
  297. if (parseInt(qty1) != selectqty1) {
  298. learun.alert.error('选择的数量与第二种湿拉物料的数量不相符!');
  299. return false;
  300. }
  301. }
  302. }
  303. var qty2 = $("#QtyMaxCount2").val();
  304. if (qty2 != "") {
  305. if (!reg.test(qty2) || parseInt(qty2) == 0) {
  306. learun.alert.error('请输入第三种湿拉物料的数量');
  307. return false;
  308. }
  309. else {
  310. var selectqty2 = $("#allcontainer > div").find("." + classnames[2]).length;
  311. if (parseInt(qty2) != selectqty2) {
  312. learun.alert.error('选择的数量与第三种湿拉物料的数量不相符!');
  313. return false;
  314. }
  315. }
  316. }
  317. var postData = $('#form').lrGetFormData();
  318. var setInfos = [];
  319. $("#allcontainer > div").children().each(function () {
  320. for (var i = 0; i < classnames.length; i++) {
  321. var setinfo = {};
  322. if ($(this).attr('class').indexOf(classnames[i]) >= 0) {
  323. setinfo["XYNo"] = $(this).text();
  324. setinfo["CategoryId"] = i;
  325. setinfo["MatCode"] = $("#MatCode" + i).val();
  326. setinfo["SilkDiam"] = $("#SilkDiam" + i).val();
  327. setinfo["QtyMaxCount"] = $("#QtyMaxCount" + i).val();
  328. setinfo["IsEmpty"] = 0;
  329. setInfos.push(setinfo);
  330. }
  331. }
  332. });
  333. if (!$('#form').lrValidform()) {
  334. return false;
  335. }
  336. if (setInfos.length == 0) {
  337. learun.alert.error('请选择跺型编号。');
  338. return false;
  339. }
  340. //if (setInfos.length != HWCountQty) {
  341. // learun.alert.error('勾选的跺型编号与输入的工字轮个数不符。');
  342. // return false;
  343. //}
  344. postData.BomName = $("#BomName").val();
  345. postData.ProCode = BomsetCode;
  346. postData.Category = 1;
  347. postData.StampType = 1;
  348. postData.Bomsetinfos = setInfos;
  349. postData.TotalQty = $(".clickcircle").length;
  350. $.lrSaveForm(top.$.rootUrl + '/FJManager/BillBomSet/Save09Form?keyValue=' + keyValue, postData, function (res) {
  351. // 保存成功后才回调
  352. if (!!callBack) {
  353. callBack();
  354. }
  355. });
  356. };
  357. page.init();
  358. }