inventoryAttributeTransfer.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. $(function() {
  2. var detailOperate = 'add';
  3. var $detailForm = $('#inventoryAttributeTransferDetailForm');
  4. var $inventoryTransferForm = $('#inventoryAttributeTransferForm');
  5. var $locationContainerForm = $('#locationContainerSearchForm');
  6. var $inventoryAttributeTransferId = $inventoryTransferForm.find("input[name='inventoryAttributeTransferId']");
  7. $('#transferTypeSel').combobox({
  8. onChange:function (newValue, oldValue){
  9. // 根据转移类型动态展示
  10. hideOrShow(newValue);
  11. },
  12. onBeforeLoad:function(){
  13. // 根据转移类型动态展示
  14. hideOrShow($(this).val());
  15. }
  16. });
  17. /**
  18. * 跳转到明细页面
  19. */
  20. $("#addDetailBtn").bind("click",function() {
  21. if ($inventoryTransferForm.find("input[name='customerId']").val() == "") {
  22. $.messager.alert("提示", "请先填写基本信息", "error");
  23. } else {
  24. showWindow({
  25. title:'详情明细',
  26. width:860,
  27. height:400,
  28. closed : false,
  29. cache : false,
  30. modal : true,
  31. onOpen:function() {
  32. document.getElementById("addDetailTabs").style.display='block';
  33. $('#transferTypeTr').find('input,select,textarea,a,span').removeAttr("disabled");
  34. $detailForm.find('a,span').removeAttr("disabled");
  35. $detailForm.form('reset');
  36. $("#addDetailTabs").tabs('select',0);
  37. $("#addDetailTabs").tabs('disableTab',1);
  38. detailOperate = 'add';
  39. }
  40. });
  41. }
  42. });
  43. // 保存明细的方法
  44. $("#submitDetailBtn").click(function() {
  45. if ($detailForm.form('validate')) {
  46. if($.InventoryAttributeTransferDetailEdit.changeList.length>0){
  47. var postData = {
  48. formData: $.encodeJSON($detailForm.getFormValue()),
  49. updateFields : JSON.stringify($.InventoryAttributeTransferDetailEdit.changeList),
  50. inventoryAttributeTransferId : $("input[name='inventoryAttributeTransferId']").val(),
  51. operate : detailOperate
  52. };
  53. ajaxRequest(WEBROOT + '/InventoryAttributeTransfer/doSaveDetail.action', postData, function(response) {
  54. if (response.code == "success") {// succeed
  55. showMsg('提示', '保存成功');
  56. $("#detailList").datagrid('reload');
  57. // 关闭窗口前,回复明细的操作符为新增
  58. detailOperate = 'add';
  59. closeWindow();
  60. } else {
  61. var errorDesc = response.errorDesc;
  62. showMsg('保存失败', errorDesc);
  63. };
  64. });
  65. }
  66. else {
  67. showMsg('提示', '数据未更新');
  68. }
  69. }
  70. });
  71. // 删除明细的方法
  72. $("#removeDetailBtn").click(function() {
  73. var rows = $("#detailList").datagrid('getSelections');
  74. var ids = [];
  75. for ( var i = 0; i < rows.length; i++) {
  76. if (rows[i].id) {
  77. ids.push(rows[i].id);
  78. }
  79. }
  80. if (ids.length > 0) {
  81. $.messager.confirm('提示', '共选择:' + ids.length + '条记录,确定要删除吗?',
  82. function(result) {
  83. if (result) {
  84. ajaxRequest(WEBROOT + "/InventoryAttributeTransfer/doDeleteDetail.action", {
  85. ids : $.encodeJSON(ids)
  86. }, function(data) {
  87. $("#detailList").datagrid('reload');
  88. rows.length=0;
  89. showMsg('提示', '删除成功');
  90. });
  91. }
  92. });
  93. } else {
  94. $.messager.alert("提示", "请选择要删除的行", "error");
  95. }
  96. });
  97. var detailId1;
  98. /**
  99. * 明细列表的展示
  100. */
  101. $("#detailList").datagrid({
  102. width : '90%',
  103. checkOnSelect:true,
  104. nowrap : false,
  105. striped : true,
  106. collapsible : false,
  107. fitColumns : true,
  108. idField : 'id',
  109. url : WEBROOT + '/InventoryAttributeTransfer/showDetailList.action',
  110. queryParams : {
  111. inventoryTransferId: $inventoryAttributeTransferId.val()
  112. },
  113. remoteSort : true,
  114. rownumbers : true,
  115. onDblClickRow : function(index,rowdata){
  116. detailId1 = rowdata.id;
  117. if($inventoryAttributeTransferId.val() == "") {
  118. $.messager.alert("提示", "请先保存基本信息", "error");
  119. } else {
  120. $("#addDetailTabs").tabs('enableTab',1);
  121. showWindow({
  122. title:'详细明细',
  123. width:950,
  124. height:400,
  125. onOpen:function() {
  126. document.getElementById("addDetailTabs").style.display="";
  127. setTimeout(function(){
  128. $("#addDetailTabs").tabs('select',0);
  129. ajaxRequest(WEBROOT + "/InventoryAttributeTransfer/showDetailEdit.action", {
  130. id : detailId1
  131. }, function(data) {
  132. $.InventoryAttributeTransferDetailEdit.fillData(data);
  133. detailOperate = 'edit';
  134. $('#transferTypeTr').find('input,select,textarea,a,span').attr("disabled","true");
  135. $detailForm.find('a,span').attr("disabled","true");
  136. // 根据转移类型动态展示
  137. hideOrShow(data['transferType']);
  138. });
  139. },1000);
  140. /**
  141. * 处理明细页面的展示(当双击转移明细时,要带出转移明细下对应的处理明细)
  142. */
  143. // 查询处理明细的URL
  144. var handleDetailSearchUrl = WEBROOT + '/InventoryAttributeTransfer/doSearchHandleDetail.action';
  145. // 查询处理明细的参数
  146. var queryHandleParams = {
  147. inventoryAttributeTransferDetailId : rowdata.id
  148. };
  149. $("#handeleDetailList").datagrid({
  150. width : '90%',
  151. nowrap : false,
  152. striped : true,
  153. collapsible : false,
  154. fitColumns : false,
  155. pagination : true,
  156. pageSize : 5,
  157. idField : 'id',
  158. url : handleDetailSearchUrl,
  159. queryParams : queryHandleParams,
  160. remoteSort : true,
  161. rownumbers : true,
  162. pageList : [ 5, 10, 20, 30, 50, 100 ],
  163. onDblClickRow : function(index,rowdata){
  164. $('#finalDealHandeleDetail').window({
  165. title : '处理明细信息',
  166. width : 500,
  167. height : 150,
  168. closed : false,
  169. cache : false,
  170. modal : true,
  171. onOpen:function() {
  172. $('#finalDealHandeleDetail').find('input[name=id]').val(rowdata.id);
  173. $('#finalDealHandeleDetail').find('input[name=locationContainerId]').val(rowdata.locationContainerId);
  174. $('#finalDealHandeleDetail').find('input[name=locationName]').val(rowdata.locationName);
  175. $('#finalDealHandeleDetail').find('input[name=itemCode]').val(rowdata.itemCode);
  176. $('#finalDealHandeleDetail').find('input[name=itemName]').val(rowdata.itemName);
  177. $('#finalDealHandeleDetail').find('input[name=quantity]').val(rowdata.quantity);
  178. $('#finalDealHandeleDetail').find('input[name=newLocationName]').val(rowdata.toLocationName);
  179. $("#finalDealHandeleDetail").find("input[name=operate]").val('edit');
  180. }
  181. });
  182. }
  183. });
  184. }
  185. });
  186. }
  187. }
  188. });
  189. /**
  190. * 弹出处理明细页面
  191. */
  192. $("#addHandeleDetailBtn").bind("click",function() {
  193. $('#addHandleDetail').window({
  194. title : '处理明细',
  195. width : 1150,
  196. height : 350,
  197. closed : false,
  198. cache : false,
  199. modal : true
  200. });
  201. /**
  202. * 点击处理明细新增页面时,默认查询数据
  203. */
  204. // 查询库存明细的URL
  205. var locationContainerSearchUrl = WEBROOT + '/InventoryAttributeTransfer/doSearchLocationContainer.action';
  206. // 查询库存明细的参数
  207. var queryParams = {
  208. warehouseId : $inventoryTransferForm.find("input[name='warehouseId']").val(),
  209. customerId : $inventoryTransferForm.find("input[name=customerId]").val(),
  210. itemId : $detailForm.find("input[name=itemId]").val(),
  211. relationedCustomerId : $detailForm.find("input[name=relationedCustomerId]").val(),
  212. normalFlag : $detailForm.find("input[name=normalFlag]").val(),
  213. lotNumber : $detailForm.find("input[name=lotNumber]").val(),
  214. produceDate : $detailForm.find("input[name=produceDate]").val(),
  215. locationName : $locationContainerForm.find("input[name=queryLocationName]").val(),
  216. quantity : $locationContainerForm.find("input[name=queryQuantity]").val(),
  217. inventoryAttributeTransferDetailId : $detailForm.find("input[name=id]").val()
  218. };
  219. $("#locationContainerList").datagrid({
  220. width : '100%',
  221. nowrap : false,
  222. striped : true,
  223. collapsible : false,
  224. fitColumns : false,
  225. pagination : true,
  226. singleSelect : true,
  227. pageSize : 5,
  228. idField : 'id',
  229. url : locationContainerSearchUrl,
  230. queryParams : queryParams,
  231. remoteSort : true,
  232. rownumbers : true,
  233. pageList : [ 5, 10, 20, 30, 50, 100 ]
  234. });
  235. });
  236. /**
  237. * 库存明细数据列表填充以及查询
  238. */
  239. var locationContainerSearchForm = $locationContainerForm.searchForm();
  240. // 处理明细的按钮查询事件
  241. $("#locationContainerSearch").bind("click",function() {
  242. $("#locationContainerList").datagrid('load', {
  243. warehouseId : $inventoryTransferForm.find("input[name='warehouseId']").val(),
  244. customerId : $inventoryTransferForm.find("input[name=customerId]").val(),
  245. itemId : $detailForm.find("input[name=itemId]").val(),
  246. relationedCustomerId : $detailForm.find("input[name=relationedCustomerId]").val(),
  247. normalFlag : $detailForm.find("input[name=normalFlag]").val(),
  248. lotNumber : $detailForm.find("input[name=lotNumber]").val(),
  249. produceDate : $detailForm.find("input[name=produceDate]").val(),
  250. locationName : $locationContainerForm.find("input[name=queryLocationName]").val(),
  251. quantity : $locationContainerForm.find("input[name=queryQuantity]").val(),
  252. inventoryAttributeTransferDetailId : $detailForm.find("input[name=id]").val()
  253. });
  254. });
  255. /**
  256. * 最后弹出窗口输入数量和新储位
  257. */
  258. $("#submitHandeleDetailBtn").bind("click",function() {
  259. var rows = $("#locationContainerList").datagrid('getSelections');
  260. var ids = [];
  261. for ( var i = 0; i < rows.length; i++) {
  262. if (rows[i].id) {
  263. ids.push(rows[i].id);
  264. }
  265. }
  266. if (ids.length != 1) {
  267. $.messager.alert("提示", "请选择一条具体明细", "error");
  268. }else{
  269. $('#finalDealHandeleDetail').window({
  270. title : '处理明细信息',
  271. width : 500,
  272. height : 150,
  273. closed : false,
  274. cache : false,
  275. modal : true,
  276. onOpen:function() {
  277. $('#finalDealHandeleDetail').find('input[name=locationContainerId]').val(rows[0].id);
  278. $('#finalDealHandeleDetail').find('input[name=locationName]').val(rows[0].locationName);
  279. $('#finalDealHandeleDetail').find('input[name=itemCode]').val(rows[0].itemCode);
  280. $('#finalDealHandeleDetail').find('input[name=itemName]').val(rows[0].itemName);
  281. $('#finalDealHandeleDetail').find('select[name=toLocationName]').val(rows[0].toLocationName);
  282. $("#finalDealHandeleDetail").find("input[name=operate]").val('add');
  283. }
  284. });
  285. }
  286. });
  287. /**
  288. * 保存或修改处理明细至DB
  289. */
  290. $("#submitHandleDetailBtn").bind("click",function(){
  291. if ($('#finalDealHandeleDetailForm').form('validate')) {
  292. ajaxRequest(WEBROOT + "/InventoryAttributeTransfer/doSaveInventoryAttributeTransferHandleDetail.action", {
  293. id : $('#finalDealHandeleDetail').find('input[name=id]').val(),
  294. locationContainerId : $('#finalDealHandeleDetail').find('input[name=locationContainerId]').val(),
  295. transferQuantity : $('#finalDealHandeleDetail').find('input[name=quantity]').val(),
  296. toLocationId : $('#finalDealHandeleDetail').find('input[name=toLocationId]').val(),
  297. inventoryAttributeTransferDetailId : $detailForm.find("input[name=id]").val(),
  298. operate : $("#finalDealHandeleDetail").find("input[name=operate]").val()
  299. }, function(data) {
  300. $('#finalDealHandeleDetail').window('close');
  301. if('add' == $("#finalDealHandeleDetail").find("input[name=operate]").val()){
  302. $('#addHandleDetail').window('close');
  303. }
  304. $("#handeleDetailList").datagrid('reload');
  305. });
  306. }
  307. });
  308. // 删除处理明细的方法
  309. $("#removeHandleDetailBtn").click(function() {
  310. var rows = $("#handeleDetailList").datagrid('getSelections');
  311. var ids = [];
  312. for ( var i = 0; i < rows.length; i++) {
  313. if (rows[i].id) {
  314. ids.push(rows[i].id);
  315. }
  316. }
  317. if (ids.length > 0) {
  318. $.messager.confirm('提示', '共选择:' + ids.length + '条记录,确定要删除吗?',
  319. function(result) {
  320. if (result) {
  321. ajaxRequest(WEBROOT + "/InventoryAttributeTransfer/doDeleteHandleDetail.action", {
  322. ids : $.encodeJSON(ids)
  323. }, function(data) {
  324. $("#handeleDetailList").datagrid('reload');
  325. showMsg('提示', '删除成功');
  326. });
  327. }
  328. });
  329. } else {
  330. $.messager.alert("提示", "请选择要删除的行", "error");
  331. }
  332. });
  333. // 货主关系人suggestBox
  334. $('#relationedCustomerId').combobox({
  335. url:WEBROOT + "/loadData.action?entity=customerRelation",
  336. mode: 'remote',
  337. showHeader : false,
  338. valueField:'relationedCustomerId',
  339. textField:'relationedCustomerName',
  340. delay: 500,
  341. columns:[[
  342. {field:'relationedCustomerId',hidden:true},
  343. {field:'relationedCustomerName',title:'关系人名称',width:150},
  344. {field:'relationedCustomerCode',title:'关系人代码',width:150,hidden:true}
  345. ]],
  346. onSelectAfter:function(record){
  347. $detailForm.find("input[name='relationedCustomerName']").val(record.relationedCustomerName);
  348. $detailForm.find("input[name='relationedCustomerCode']").val(record.relationedCustomerCode);
  349. $detailForm.find("input[name='relationedCustomerAlias']").val(record.relationedCustomerAlias);
  350. },
  351. onBeforeLoad:function(param){
  352. param.customerId = $inventoryTransferForm.find("input[name='customerId']").val();
  353. //此设置使控件不会自动加载数据
  354. /**
  355. if (!$('#relationedCustomerId').combobox('getText'))
  356. {
  357. return false;
  358. }
  359. else
  360. {
  361. return true;
  362. }
  363. */
  364. },
  365. onShowPanel:function(){
  366. //在第一次触发下拉框事件是加载数据
  367. if (!$(this).combobox('getText'))
  368. {
  369. $(this).combobox({onBeforeLoad:function(param){
  370. param.customerId = $inventoryTransferForm.find("input[name='customerId']").val();
  371. return true;
  372. }});
  373. }
  374. }
  375. });
  376. // 新货主关系人suggestBox
  377. $('#toRelationedCustomerId').combobox({
  378. url:WEBROOT + "/loadData.action?entity=customerRelation",
  379. mode: 'remote',
  380. valueField:'relationedCustomerId',
  381. textField:'relationedCustomerName',
  382. delay: 500,
  383. showHeader : false,
  384. columns:[[
  385. {field:'relationedCustomerId',hidden:true},
  386. {field:'relationedCustomerName',title:'关系人名称',width:150},
  387. {field:'relationedCustomerCode',title:'关系人代码',width:150,hidden:true}
  388. ]],
  389. onSelectAfter:function(record){
  390. $detailForm.find("input[name='toRelationedCustomerName']").val(record.relationedCustomerName);
  391. $detailForm.find("input[name='toRelationedCustomerCode']").val(record.relationedCustomerCode);
  392. $detailForm.find("input[name='toRelationedCustomerAlias']").val(record.relationedCustomerAlias);
  393. },
  394. onBeforeLoad:function(param){
  395. param.customerId = $inventoryTransferForm.find("input[name='customerId']").val();
  396. //此设置使控件不会自动加载数据
  397. /**
  398. if (!$('#toRelationedCustomerId').combogrid('getText'))
  399. {
  400. return false;
  401. }
  402. else
  403. {
  404. return true;
  405. }*/
  406. },
  407. onShowPanel:function(){
  408. //在第一次触发下拉框事件是加载数据
  409. if (!$(this).combobox('getText'))
  410. {
  411. $(this).combobox({onBeforeLoad:function(param){
  412. param.customerId = $inventoryTransferForm.find("input[name='customerId']").val();
  413. return true;
  414. }});
  415. }
  416. }
  417. });
  418. // 产品suggestBox
  419. $('#itemId').combogrid({
  420. url:WEBROOT + "/loadData.action?entity=item",
  421. mode: 'remote',
  422. showHeader : false,
  423. idField:'itemId',
  424. textField:'itemName',
  425. delay: 500,
  426. columns:[[
  427. {field:'itemId',hidden:true},
  428. {field:'itemName',title:'产品名称',width:120},
  429. {field:'itemCode',title:'产品代码',width:150,hidden:true}
  430. ]],
  431. onSelectAfter:function(rowIndex, record){
  432. $detailForm.find("input[name='itemName']").val(record.itemName);
  433. $detailForm.find("input[name='itemCode']").val(record.itemCode);
  434. },
  435. onBeforeLoad:function(param){
  436. param.customerId = $inventoryTransferForm.find("input[name='customerId']").val();
  437. //此设置使控件不会自动加载数据
  438. if (!$('#itemId').combogrid('getText'))
  439. {
  440. return false;
  441. }
  442. else
  443. {
  444. return true;
  445. }
  446. },
  447. onShowPanel:function(){
  448. //在第一次触发下拉框事件是加载数据
  449. if (!$(this).combogrid('getText'))
  450. {
  451. $(this).combogrid({onBeforeLoad:function(param){
  452. param.customerId = $inventoryTransferForm.find("input[name='customerId']").val();
  453. return true;
  454. }});
  455. }
  456. }
  457. });
  458. // 储位suggestBox
  459. $('#toLocationId').combogrid({
  460. url:WEBROOT + "/loadData.action?entity=location",
  461. mode: 'remote',
  462. showHeader : false,
  463. idField:'locationId',
  464. textField:'locationName',
  465. delay: 500,
  466. columns:[[
  467. {field:'locationId',hidden:true},
  468. {field:'zoneName',title:'库区名称',width:120,hidden:true},
  469. {field:'locationName',title:'储位名称',width:150}
  470. ]],
  471. onSelectAfter:function(rowIndex, record){
  472. $detailForm.find("input[name='locationName']").val(record.locationName);
  473. },
  474. onBeforeLoad:function(param){
  475. param.warehouseId = $inventoryTransferForm.find("input[name='warehouseId']").val();
  476. //此设置使控件不会自动加载数据
  477. if (!$('#itemId').combogrid('getText'))
  478. {
  479. return false;
  480. }
  481. else
  482. {
  483. return true;
  484. }
  485. },
  486. onShowPanel:function(){
  487. //在第一次触发下拉框事件是加载数据
  488. if (!$(this).combogrid('getText'))
  489. {
  490. $(this).combogrid({onBeforeLoad:function(param){
  491. param.warehouseId = $inventoryTransferForm.find("input[name='warehouseId']").val();
  492. return true;
  493. }});
  494. }
  495. }
  496. });
  497. /**
  498. * 完成转移
  499. */
  500. $('#completeInventoryAttributeTransferBtn').bind('click',function(){
  501. if('0' == $("#detailList").datagrid('getRows').length){
  502. $.messager.alert("提示", "没有任何明细", "error");
  503. }else{
  504. $(this).attr("disabled",true);
  505. ajaxRequest(WEBROOT + "/InventoryAttributeTransfer/doCompleteTransfer.action", {
  506. id : $inventoryAttributeTransferId.val()
  507. }, function(data) {
  508. msg = '转移完成';
  509. if('fail' == data['code']){
  510. msg = data['errorDesc'];
  511. $('#completeInventoryAttributeTransferBtn').attr("disabled",false);
  512. }else{
  513. $("#transferStatus").attr('value', '4102');
  514. $inventoryTransferForm.form('load',{
  515. transferBy : data.data.transferBy,
  516. transferTime : data.data.transferTime,
  517. customerRefferenceId : data.data.customerRefferenceId,
  518. comment : data.data.comment
  519. });
  520. $(document).find('input,select,textarea,a,span').attr("disabled","true");
  521. // 兼容IE8以上,火狐浏览器a标签事件无法灰化
  522. $(document).find('input,select,textarea,a,span').css("color","gray");
  523. $(document).find('input,select,textarea,a,span').unbind("click");
  524. }
  525. showMsg('提示', msg);
  526. });
  527. }
  528. });
  529. });
  530. /**
  531. * 根据转移类型动态展示
  532. * @param obj
  533. */
  534. function hideOrShow(obj){
  535. if("4302" == obj){
  536. // 按IMEI
  537. $('#quantity').validatebox({
  538. required: false,
  539. validType:'number'
  540. });
  541. $('#snList').validatebox({
  542. required: true
  543. });
  544. $('#noScanIMEITr').add('#noScanIMEITr1').add('#relationedCustomerIdTr').hide();
  545. $('#scanIMEITr').show();
  546. $("#addDetailTabs").tabs('disableTab',1);
  547. }else{
  548. // 按商品
  549. $('#quantity').validatebox({
  550. required: true,
  551. validType:'number'
  552. });
  553. $('#snList').validatebox({
  554. required: false
  555. });
  556. $('#noScanIMEITr').add('#noScanIMEITr1').add('#relationedCustomerIdTr').show();
  557. $('#scanIMEITr').hide();
  558. };
  559. }