diff --git a/code/base-project/base-app/test2.html b/code/base-project/base-app/test2.html index 0beebca9..cbea7827 100644 --- a/code/base-project/base-app/test2.html +++ b/code/base-project/base-app/test2.html @@ -1,169 +1,170 @@ + - -DataGrid 多选删除 + 单行编辑示例 - - - - - - - - + + DataGrid 编辑 + 多选删除 + 彻底删除 + + + + + + + -

DataGrid 编辑 + 多选删除 + 彻底删除 示例(维护 allRows)

+

DataGrid 编辑 + 多选删除 + 彻底删除 示例(维护 allRows)

- - - - - - - - - - -
ID姓名出生日期成绩
+
-
- 保存当前行 - 删除所选 - 彻底删除 - 新增一行 -
+
+ 保存当前行 + 删除所选 + 彻底删除 + 新增一行 + 获取数据 +
- + // 点击行编辑 + function onClickRow(index) { + if (editIndex !== index) { + if (endEditRow()) { + $('#subgrid').datagrid('beginEdit', index); + editIndex = index; + } + } + } + + // 保存行 + function endEditRow() { + if (editIndex === undefined) return true; + if ($('#subgrid').datagrid('validateRow', editIndex)) { + $('#subgrid').datagrid('endEdit', editIndex); + editIndex = undefined; + return true; + } else { + $.messager.alert('提示', '请填写完整!'); + return false; + } + } + + // 新增行 + function addRow() { + if (!endEditRow()) return; + + let newRow = { id: getNextId(), name: '', birth: '', score: '' }; + allRows.push(newRow); + $('#subgrid').datagrid('loadData', allRows); + + let newIndex = allRows.length - 1; + $('#subgrid').datagrid('selectRow', newIndex); + $('#subgrid').datagrid('beginEdit', newIndex); + editIndex = newIndex; + $('#subgrid').datagrid('scrollTo', newIndex); + } + + // 删除行 + function removeRows() { + let selected = $('#subgrid').datagrid('getChecked'); + if (selected.length === 0) { $.messager.alert('提示', '请先勾选要删除的行'); return; } + let ids = selected.map(r => r.id); + allRows = allRows.filter(r => !ids.includes(r.id)); + $('#subgrid').datagrid('loadData', allRows); + editIndex = undefined; + } + + function getData() { + console.log("===getData===") + console.log($('#subgrid').datagrid('getData')); + console.log("===getChanges===") + console.log($('#subgrid').datagrid('getChanges')); + } + + // 打印数据 + function confirmDelete() { console.log('当前有效数据:', allRows); } + + // ID 生成 + function getNextId() { + if (allRows.length === 0) return 1; + return Math.max(...allRows.map(r => r.id)) + 1; + } + + // 生成模拟数据 + function createMockData(count = 100) { + let data = []; + for (let i = 1; i <= count; i++) { + data.push({ + id: i, + name: "用户" + i, + birth: randomDate("1980-01-01", "2005-12-31"), + score: Math.floor(Math.random() * 41) + 60 + }); + } + return data; + } + + // 随机日期 + function randomDate(start, end) { + let st = new Date(start).getTime(); + let et = new Date(end).getTime(); + let t = st + Math.random() * (et - st); + let d = new Date(t); + return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`; + } + - + + \ No newline at end of file diff --git a/editbuyin.jsp b/editbuyin.jsp index a41dd72f..bec427a3 100644 --- a/editbuyin.jsp +++ b/editbuyin.jsp @@ -1,52 +1,39 @@ -<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> -<%@ include file="../ini.jsp"%> -<% - String id = request.getParameter("id"); - if (id == null) { - id = ""; - } - String father = request.getParameter("father"); - if (father == null) { - father = ""; - } -%> - - - - - 买箱入库 - - - - - - - +<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %> + <%@ include file="../ini.jsp" %> + <% String id=request.getParameter("id"); if (id==null) { id="" ; } String father=request.getParameter("father"); if + (father==null) { father="" ; } %> + + + + + 买箱入库 + + + + + + + - + - - - - -
-
-
- - - - - - - -
-
-
- 买箱入库 -
-
-
- - - - -
-
- - -
-
- - -
+
+
+ 买箱入库 +
+
+
+ + + + +
+
+ + +
+
+ + + +
-
- - -
- -
- - -
-
- - - - -
-
- - -
- -
- - - -
-
- - -
-
- - - -
- -
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
- -
- - -
- - - -
-
- +
+
- >
+<%-- " --%> + > +
+
+
+
+ +
+
-
-
-
- -
- -
-
- -
- - - - - - - +
+ +
+ + + + + + + - - - - - + + + + +
-
- - -
+
+ + +
-
+
删除
"+newjsons[j]['mx_conno']+'; '; - Modifyb=Modifyb+"箱号:"+oldjson['mx_conno']+'; '; - Modifyh=Modifyh+newjsons[j]['mx_conno']+'; '; - }*/ - - if(newjsons[j]['mx_contype'] !=oldjson['mx_contype']){ - strMainUpdate=strMainUpdate+";箱型:"+oldjson['mx_contype']+"-->"+newjsons[j]['mx_contype']+'; '; - Modifyb=Modifyb+";箱型:"+oldjson['mx_contype']+'; '; - Modifyh=Modifyh+";箱型:"+newjsons[j]['mx_contype']+'; '; - } - - if(newjsons[j]['mx_xk'] !=oldjson['mx_xk']){ - strMainUpdate=strMainUpdate+";箱况:"+oldjson['mx_xk']+"-->"+newjsons[j]['mx_xk']+'; '; - Modifyb=Modifyb+";箱况:"+oldjson['mx_xk']+'; '; - Modifyh=Modifyh+";箱况:"+newjsons[j]['mx_xk']+'; '; - } - - if(newjsons[j]['mx_ccdate'] !=oldjson['mx_ccdate']){ - strMainUpdate=strMainUpdate+";制造日期:"+oldjson['mx_ccdate']+"-->"+newjsons[j]['mx_ccdate']+'; '; - Modifyb=Modifyb+";制造日期:"+oldjson['mx_ccdate']+'; '; - Modifyh=Modifyh+";制造日期:"+newjsons[j]['mx_ccdate']+'; '; - } - - if(newjsons[j]['mx_txid']!= oldjson['mx_txid']){ - strMainUpdate=strMainUpdate+" ;提箱单号:"+oldjson['mx_txid']+"-->"+newjsons[j]['mx_txid']+'; '; - Modifyb=Modifyb+" ;提箱单号:"+oldjson['mx_txid']+'; '; - Modifyh=Modifyh+" ;提箱单号:"+newjsons[j]['mx_txid']+'; '; - } - - if(newjsons[j]['mx_atwhere']!= oldjson['mx_atwhere']){ - strMainUpdate=strMainUpdate+" ;存放堆场:"+oldjson['v_mx_atwhere_name']+"-->"+newjsons[j]['v_mx_atwhere_name']+'; '; - Modifyb=Modifyb+" ;存放堆场:"+oldjson['v_mx_atwhere_name']+'; '; - Modifyh=Modifyh+" ;存放堆场:"+newjsons[j]['v_mx_atwhere_name']+'; '; - } - - - if(newjsons[j]['mx_zxdate']!= oldjson['mx_zxdate']){ - strMainUpdate=strMainUpdate+" ;进场日期:"+oldjson['mx_zxdate']+"-->"+newjsons[j]['mx_zxdate']+'; '; - Modifyb=Modifyb+" ;进场日期:"+oldjson['mx_zxdate']+'; '; - Modifyh=Modifyh+" ;进场日期:"+newjsons[j]['mx_zxdate']+'; '; - } - - /* if(newjsons[j]['mx_city_id']!= oldjson['mx_city_id']){ - strMainUpdate=strMainUpdate+" ;还箱城市:"+oldjson['v_mx_cityoutname']+"-->"+newjsons[j]['v_mx_cityoutname']+'; '; - Modifyb=Modifyb+" ;还箱城市:"+oldjson['v_mx_cityoutname']+'; '; - Modifyh=Modifyh+" ;还箱城市:"+newjsons[j]['v_mx_cityoutname']+'; '; - } - - if(newjsons[j]['mx_atwhere_hx']!= oldjson['mx_atwhere_hx']){ - strMainUpdate=strMainUpdate+" ;还箱堆场:"+oldjson['v_mx_atwhere_name_hx']+"-->"+newjsons[j]['v_mx_atwhere_name_hx']+'; '; - Modifyb=Modifyb+" ;还箱堆场:"+oldjson['v_mx_atwhere_name_hx']+'; '; - Modifyh=Modifyh+" ;还箱堆场:"+newjsons[j]['v_mx_atwhere_name_hx']+'; '; - }*/ - - if(newjsons[j]['mx_bz']!= oldjson['mx_bz']){ - strMainUpdate=strMainUpdate+" ;备注:"+oldjson['mx_bz']+"-->"+newjsons[j]['mx_bz']+'; '; - Modifyb=Modifyb+" ;备注:"+oldjson['mx_bz']+'; '; - Modifyh=Modifyh+" ;备注:"+newjsons[j]['mx_bz']+'; '; - } - - - - if (strMainUpdate !=''){ - /* var feetype=oldjson['v_mx_feetype_name']; - strMainUpdate=type+feetype+" " +strMainUpdate; - var Fuser=getfieldvaluebyid("b_user","b_name","b_id",userid); - Modifyh=Modifyh+newjsons[j]['mx_inputdate']+'; '+Fuser+': '; - Modifyb=Modifyb+oldjson['mx_inputdate']+'; '+oldjson['v_mx_inputman_name']+': ';*/ - //alert(strMainUpdate); - var conno=oldjson['mx_conno']; - strMainUpdate=type+oldjson['mx_conno']+"-->"+newjsons[j]['mx_conno']+'; ' +strMainUpdate; - Modifyh=type+newjsons[j]['mx_conno']+" " +Modifyh; - Modifyb=type+oldjson['mx_conno']+" " +Modifyb; - saveLog('xg_buyin',strMainUpdate,"","[]","[]","[]",recordID,subid,Modifyb,Modifyh); - }else if(newjsons[j]['mx_conno'] !=oldjson['mx_conno']){ - strMainUpdate=type+oldjson['mx_conno']+"-->"+newjsons[j]['mx_conno']+'; '; - Modifyb=type+oldjson['mx_conno']+'; '; - Modifyh=type+newjsons[j]['mx_conno']+'; '; - saveLog('xg_buyin',strMainUpdate,"","[]","[]","[]",recordID,subid,Modifyb,Modifyh); - } - finded=true; - break; - } - } - if (!finded){ - //alert("11") - var conno=oldjson['mx_conno']; - var contype=oldjson['mx_contype']; - var atwhere=oldjson['v_mx_atwhere_name']; - var strMainDelete=type+conno+";箱型:"+contype+atwhere; - var strMainDelete="删除"+type+conno+";箱型:"+contype+" ;提箱堆场:"+atwhere+"!" - saveLog('xg_buyin',"",strMainDelete,"[]","[]","[]",recordID,subid,"",""); - - } - } -} - - function setywwcqty(){ - var strid=$("#b_id").val(); - var stridval = "买箱入库"; - stridval = stridval+","+strid; - var resdata=ExecProcedure('p_update_xgwcqty',{stridarr: stridval}); - } - - - function showattach1(){ - var strid=$("#b_id").val(); - var iread='0'; - if ($('#btn_save').attr('disabled')=='disabled'){ - iread='1'; - } - if (document.getElementById("b_id").readOnly){ - }else{ - alert('请先保存数据'); - return; - } - getattachfile(strid,'xg_buyin_files',iread); - } - - - function showattach(){ - if(strid == ""){return;} - parent.$('
').dialog({ - title : '箱证管理'+strid, - width : 540, - height : 320, - cache: false, - onClose:function(){ - $(this).remove(); - }, - top : 90, - content : '', - modal : true - }); - } + Modifyb = Modifyb + "箱号:" + oldjson['mx_conno'] + '; '; + Modifyh = Modifyh + newjsons[j]['mx_conno'] + '; '; + }*/ - function b_customer_idChange(){ - if ($("#b_customer_id").val()==""){ - $("#v_customer_name").val(''); - }else{ - var s=getfieldvaluebyid('b_othercompany', 'b_name', 'b_id',$("#b_customer_id").val()); - $("#v_customer_name").val(s); - } - } - - function b_atwhereChange(){ - if ($("#b_atwhere").val()==""){ - $("#v_b_atwhere_name").val(''); - }else{ - var s=getfieldvaluebyid('b_othercompany', 'b_name', 'b_id',$("#b_atwhere").val()); - $("#v_b_atwhere_name").val(s); - } - } - - - function b_customer_idChange(){ - if ($("#b_customer_id").val()==""){ - $("#v_customer_name").val(''); - $("#v_customer_linkman_ch").val(''); - // custid=''; - - }else{ - var s=getfieldvaluebyid('b_othercompany', 'b_name', 'b_id',$("#b_customer_id").val()); - $("#v_customer_name").val(s); - var s=getfieldvaluebyid('b_contact', 'b_name_ch', 'b_customer_id',$("#b_customer_id").val()); - $("#v_customer_linkman_ch").val(s); - // var s=getfieldvaluebyid('b_contact', 'b_', 'b_phone',s); - //$("#b_custlinkman_phone").val(s); - // custid=$("#b_customer_id").val(); - } - } - - function v_customer_linkman_chChange(){ - // alert('11'); - if ($("#v_customer_linkman_ch").val()==""){ - $("#b_custlinkman_id").val(''); - // $("#b_custlinkman_phone").val(''); - }else{ - var s=getfieldvaluebyid('b_contact', 'b_id', 'b_name_ch',$("#v_customer_linkman_ch").val()); - $("#b_custlinkman_id").val(s); - // var s=getfieldvaluebyid('b_contact', 'b_phone', 'b_name_ch',$("#v_customer_linkman_ch").val()); - // $("#b_custlinkman_phone").val(s); - } - } - - - function v_ownernameChange(){ - if ($("#v_ownername").val()==""){ - $("#b_owner_id").val(''); - }else{ - var s=getfieldvaluebyid('b_user', 'b_id', 'b_name',$("#v_ownername").val()); - $("#b_owner_id").val(s); - } - } - - function v_moneynameChange(){ - // thischanged='1'; - if ($("#v_moneyname").val()==""){ - $("#b_money_id").val(''); - } - } - - function v_sales_nameChange(){ - if ($("#v_sales_name").val()==""){ - $("#b_sales_id").val(''); - }else{ - var s=getfieldvaluebyid('b_user', 'b_id', 'b_name',$("#v_sales_name").val()); - $("#b_sales_id").val(s); - } - } - - function b_mycompany_idChange(){ - if ($("#b_mycompany_id").val()==""){ - $("#v_company_name").val(''); - }else{ - var s=getfieldvaluebyid('b_othercompany', 'b_name', 'b_id',$("#b_mycompany_id").val()); - $("#v_company_name").val(s); - } - } - - - - - jQuery_1_2_6("document").ready(function(){ - - setAutoCompleteSimple('#b_xz',[["是"],["否"]]); - - setAutoComplete('#b_supply_id', 'v_b_othercompany_shipcompany','b_id','b_name',''); - jQuery_1_2_6("#b_supply_id").result(function(event, data, formatted){ - if (data){ - $("#v_supply_name").val(data.b_name); - } - }); - - setAutoComplete('#b_mycompany_id','v_b_othercompany_my','b_id','b_name',''); - jQuery_1_2_6("#b_mycompany_id").result(function(event, data, formatted){ - if (data) - $("#v_company_name").val(data.b_name); - }); - - setAutoCompleteEx('#v_sales_name','b_user','b_name','b_id',"b_salesman='1'",''); - jQuery_1_2_6("#v_sales_name").result(function(event, data, formatted){ - if (data) - $("#b_sales_id").val(data.b_id); - }); - - setAutoComplete('#b_contype', 'b_con_type', 'b_name','b_id',''); - setAutoComplete('#b_xk', 'b_xiangkuang', 'b_name','b_id',''); - setAutoComplete('#b_ywtype', 'b_ywtype_xg', 'b_name','b_id',''); - - setAutoComplete('#b_atwhere','v_b_othercompany_duichang','b_id','b_name',''); - jQuery_1_2_6('#b_atwhere').result(function(event, data, formatted){ - if (data){ - $('#v_b_atwhere_name').val(data.b_name); - $('#v_b_atwhere_addr').val(data.b_addr); - $('#v_cityname').val(data.v_city_name); - $('#b_city_id').val(data.b_city_id); - } - }); - setAutoComplete('#v_cityname','b_city','b_name_c','b_id',''); - jQuery_1_2_6('#v_cityname').result(function(event, data, formatted){ - if (data){ - $('#b_city_id').val(data.b_id); - } - }); - setAutoComplete('#v_ownername','b_user','b_name','b_id',''); - jQuery_1_2_6("#v_ownername").result(function(event, data, formatted){ - if (data) - $("#b_owner_id").val(data.b_id); - }); - - setAutoComplete_moneytype('#b_money_id','b_money','b_name','b_id',''); - /*jQuery_1_2_6("#v_moneyname").result(function(event, data, formatted){ - if (data){ - $("#b_money_id").val(data.b_id); - //var exrate=getfieldvaluebyid('b_money', 'b_hl', 'b_id', data.b_id); - // $("#b_exrate").val(exrate); - } - });*/ - - setAutoComplete_moneytype('#b_fktk','b_othercompany_type_3','b_name','b_id',''); - setAutoComplete_moneytype('#b_payment','b_payment','b_name','b_id',''); - setAutoComplete('#b_customer_id','v_b_othercompany_xy','b_id','b_name',''); - jQuery_1_2_6("#b_customer_id").result(function(event, data, formatted){ - if (data){ - $("#v_customer_name").val(data.b_name); - var type3=getfieldvaluebyid('v_b_othercompany', 'v_type3_name', 'b_id', data.b_id); - $("#b_fktk").val(type3); - var payment=getfieldvaluebyid('b_othercompany', 'b_payment', 'b_id', data.b_id); - $("#b_payment").val(payment); - - - } - }); - }) - - - function checkchange(){ - //endEditing_fee(); - endEditing_sub(); - if ($('#btn_save').attr('disabled')=='disabled'){ - return false; - } - var formobj=app.serializeObject2($('#buyinform')); - delete formobj["bcheck"]; - newformjson=app.jsonToString(formobj); - // var gridrows=$("#feegrid").datagrid("getRows"); - //newgridjson=app.jsonToString(gridrows); - var gridrows=$('#subgrid').datagrid('getData').firstRows || []; - newsubgridjson=app.jsonToString(gridrows); - //alert(oldformjson); - //alert(newformjson); - //console.log(subgridjson); - //console.log(newsubgridjson); - if(newformjson!=oldformjson||newsubgridjson!=subgridjson){ //||newgridjson!=feegridjson - //alert('111'); - return true; - }else{ - return false; - } - } - - - - ////////////////////// - var editIndex_fee = undefined; - function endEditing_fee() { - if (editIndex_fee == undefined) { - return true - } - if ($('#feegrid').datagrid('validateRow', editIndex_fee)) { - $('#feegrid').datagrid('endEdit', editIndex_fee); - editIndex_fee = undefined; - return true; - } else { - return false; - } - } - - var editIndex_sub = undefined; - function endEditing_sub() { - if (editIndex_sub == undefined) { - return true - } - if ($('#subgrid').datagrid('validateRow', editIndex_sub)) { - $('#subgrid').datagrid('endEdit', editIndex_sub); - editIndex_sub = undefined; - return true; - } else { - return false; - } - } - - function setAutoComplete_moneytype(comboname, viewname, field1, field2, userid) { - jQuery_1_2_6(comboname).unautocomplete(); - jQuery_1_2_6(comboname).autocomplete('jsp/getAutocompleteData.jsp', { - minChars : 0, - width : 250, - max : 11, - matchContains : true, - mustMatch:true, - extraParams : { - viewname : viewname, - field1 : field1, - field2 : field2, - userid : userid - }, - dataType : "json", - matchSubset : false, - - parse : function(data) { - var rows = data.rows; - return $.map(rows, function(row) { - return { - data : row, - value : row[field1], - result : row[field1] + if (newjsons[j]['mx_contype'] != oldjson['mx_contype']) { + strMainUpdate = strMainUpdate + ";箱型:" + oldjson['mx_contype'] + "-->" + newjsons[j]['mx_contype'] + '; '; + Modifyb = Modifyb + ";箱型:" + oldjson['mx_contype'] + '; '; + Modifyh = Modifyh + ";箱型:" + newjsons[j]['mx_contype'] + '; '; } - }); - }, - formatItem : function(item) {// 显示下拉列表的内容 - return "
" + item[field1] + "|" + item[field2] - + "
"; - }, - formatMatch : function(item) { - return item[field1]; - }, - formatResult : function(item) { - return item[field1]; - } - }) - } - - - function getfocusedcol(grid){ - if (editIndex_fee!=undefined){ - var editor; - for(var j=0; j" + newjsons[j]['mx_xk'] + '; '; + Modifyb = Modifyb + ";箱况:" + oldjson['mx_xk'] + '; '; + Modifyh = Modifyh + ";箱况:" + newjsons[j]['mx_xk'] + '; '; + } + + if (newjsons[j]['mx_ccdate'] != oldjson['mx_ccdate']) { + strMainUpdate = strMainUpdate + ";制造日期:" + oldjson['mx_ccdate'] + "-->" + newjsons[j]['mx_ccdate'] + '; '; + Modifyb = Modifyb + ";制造日期:" + oldjson['mx_ccdate'] + '; '; + Modifyh = Modifyh + ";制造日期:" + newjsons[j]['mx_ccdate'] + '; '; + } + + if (newjsons[j]['mx_txid'] != oldjson['mx_txid']) { + strMainUpdate = strMainUpdate + " ;提箱单号:" + oldjson['mx_txid'] + "-->" + newjsons[j]['mx_txid'] + '; '; + Modifyb = Modifyb + " ;提箱单号:" + oldjson['mx_txid'] + '; '; + Modifyh = Modifyh + " ;提箱单号:" + newjsons[j]['mx_txid'] + '; '; + } + + if (newjsons[j]['mx_atwhere'] != oldjson['mx_atwhere']) { + strMainUpdate = strMainUpdate + " ;存放堆场:" + oldjson['v_mx_atwhere_name'] + "-->" + newjsons[j]['v_mx_atwhere_name'] + '; '; + Modifyb = Modifyb + " ;存放堆场:" + oldjson['v_mx_atwhere_name'] + '; '; + Modifyh = Modifyh + " ;存放堆场:" + newjsons[j]['v_mx_atwhere_name'] + '; '; + } + + + if (newjsons[j]['mx_zxdate'] != oldjson['mx_zxdate']) { + strMainUpdate = strMainUpdate + " ;进场日期:" + oldjson['mx_zxdate'] + "-->" + newjsons[j]['mx_zxdate'] + '; '; + Modifyb = Modifyb + " ;进场日期:" + oldjson['mx_zxdate'] + '; '; + Modifyh = Modifyh + " ;进场日期:" + newjsons[j]['mx_zxdate'] + '; '; + } + + /* if(newjsons[j]['mx_city_id']!= oldjson['mx_city_id']){ + strMainUpdate=strMainUpdate+" ;还箱城市:"+oldjson['v_mx_cityoutname']+"-->"+newjsons[j]['v_mx_cityoutname']+'; '; + Modifyb=Modifyb+" ;还箱城市:"+oldjson['v_mx_cityoutname']+'; '; + Modifyh=Modifyh+" ;还箱城市:"+newjsons[j]['v_mx_cityoutname']+'; '; + } + + if(newjsons[j]['mx_atwhere_hx']!= oldjson['mx_atwhere_hx']){ + strMainUpdate=strMainUpdate+" ;还箱堆场:"+oldjson['v_mx_atwhere_name_hx']+"-->"+newjsons[j]['v_mx_atwhere_name_hx']+'; '; + Modifyb=Modifyb+" ;还箱堆场:"+oldjson['v_mx_atwhere_name_hx']+'; '; + Modifyh=Modifyh+" ;还箱堆场:"+newjsons[j]['v_mx_atwhere_name_hx']+'; '; + }*/ + + if (newjsons[j]['mx_bz'] != oldjson['mx_bz']) { + strMainUpdate = strMainUpdate + " ;备注:" + oldjson['mx_bz'] + "-->" + newjsons[j]['mx_bz'] + '; '; + Modifyb = Modifyb + " ;备注:" + oldjson['mx_bz'] + '; '; + Modifyh = Modifyh + " ;备注:" + newjsons[j]['mx_bz'] + '; '; + } + + + + if (strMainUpdate != '') { + /* var feetype=oldjson['v_mx_feetype_name']; + strMainUpdate=type+feetype+" " +strMainUpdate; + var Fuser=getfieldvaluebyid("b_user","b_name","b_id",userid); + Modifyh=Modifyh+newjsons[j]['mx_inputdate']+'; '+Fuser+': '; + Modifyb=Modifyb+oldjson['mx_inputdate']+'; '+oldjson['v_mx_inputman_name']+': ';*/ + //alert(strMainUpdate); + var conno = oldjson['mx_conno']; + strMainUpdate = type + oldjson['mx_conno'] + "-->" + newjsons[j]['mx_conno'] + '; ' + strMainUpdate; + Modifyh = type + newjsons[j]['mx_conno'] + " " + Modifyh; + Modifyb = type + oldjson['mx_conno'] + " " + Modifyb; + saveLog('xg_buyin', strMainUpdate, "", "[]", "[]", "[]", recordID, subid, Modifyb, Modifyh); + } else if (newjsons[j]['mx_conno'] != oldjson['mx_conno']) { + strMainUpdate = type + oldjson['mx_conno'] + "-->" + newjsons[j]['mx_conno'] + '; '; + Modifyb = type + oldjson['mx_conno'] + '; '; + Modifyh = type + newjsons[j]['mx_conno'] + '; '; + saveLog('xg_buyin', strMainUpdate, "", "[]", "[]", "[]", recordID, subid, Modifyb, Modifyh); + } + finded = true; + break; + } + } + if (!finded) { + //alert("11") + var conno = oldjson['mx_conno']; + var contype = oldjson['mx_contype']; + var atwhere = oldjson['v_mx_atwhere_name']; + var strMainDelete = type + conno + ";箱型:" + contype + atwhere; + var strMainDelete = "删除" + type + conno + ";箱型:" + contype + " ;提箱堆场:" + atwhere + "!" + saveLog('xg_buyin', "", strMainDelete, "[]", "[]", "[]", recordID, subid, "", ""); + + } + } +} + + function setywwcqty() { + var strid = $("#b_id").val(); + var stridval = "买箱入库"; + stridval = stridval + "," + strid; + var resdata = ExecProcedure('p_update_xgwcqty', { stridarr: stridval }); } - ); - if (editor){ - if (editor.target.is(":focus")){ - fieldname=columnarray[j]; - } - } - } - } - } - - function onBeginEdit_sub(index,row){ - setEditing_sub(index); - } - function setEditing_sub(rowIndex){ - //alert('bbb'); - //$('#subgrid').datagrid('getEditor', {index: rowIndex, field:'v_mx_atwhere_addr'}).target.attr("readonly","readonly"); - // $('#subgrid').datagrid('getEditor', {index: rowIndex, field:''}).target.attr("readonly","readonly"); - - //$('#subgrid').datagrid('getEditor', {index: rowIndex, field:'v_mx_dw_name'}).target.attr("readonly","readonly"); - } - function onBeginEdit_fee(index,row){ - var editor_sh=$('#feegrid').datagrid('getEditor', { - index : index, - field : 'mx_sh' - });/* + + + function showattach1() { + var strid = $("#b_id").val(); + var iread = '0'; + if ($('#btn_save').attr('disabled') == 'disabled') { + iread = '1'; + } + if (document.getElementById("b_id").readOnly) { + } else { + alert('请先保存数据'); + return; + } + getattachfile(strid, 'xg_buyin_files', iread); + } + + + function showattach() { + if (strid == "") { return; } + parent.$('
').dialog({ + title: '箱证管理' + strid, + width: 540, + height: 320, + cache: false, + onClose: function () { + $(this).remove(); + }, + top: 90, + content: '', + modal: true + }); + } + + function b_customer_idChange() { + if ($("#b_customer_id").val() == "") { + $("#v_customer_name").val(''); + } else { + var s = getfieldvaluebyid('b_othercompany', 'b_name', 'b_id', $("#b_customer_id").val()); + $("#v_customer_name").val(s); + } + } + + function b_atwhereChange() { + if ($("#b_atwhere").val() == "") { + $("#v_b_atwhere_name").val(''); + } else { + var s = getfieldvaluebyid('b_othercompany', 'b_name', 'b_id', $("#b_atwhere").val()); + $("#v_b_atwhere_name").val(s); + } + } + + + function b_customer_idChange() { + if ($("#b_customer_id").val() == "") { + $("#v_customer_name").val(''); + $("#v_customer_linkman_ch").val(''); + // custid=''; + + } else { + var s = getfieldvaluebyid('b_othercompany', 'b_name', 'b_id', $("#b_customer_id").val()); + $("#v_customer_name").val(s); + var s = getfieldvaluebyid('b_contact', 'b_name_ch', 'b_customer_id', $("#b_customer_id").val()); + $("#v_customer_linkman_ch").val(s); + // var s=getfieldvaluebyid('b_contact', 'b_', 'b_phone',s); + //$("#b_custlinkman_phone").val(s); + // custid=$("#b_customer_id").val(); + } + } + + function v_customer_linkman_chChange() { + // alert('11'); + if ($("#v_customer_linkman_ch").val() == "") { + $("#b_custlinkman_id").val(''); + // $("#b_custlinkman_phone").val(''); + } else { + var s = getfieldvaluebyid('b_contact', 'b_id', 'b_name_ch', $("#v_customer_linkman_ch").val()); + $("#b_custlinkman_id").val(s); + // var s=getfieldvaluebyid('b_contact', 'b_phone', 'b_name_ch',$("#v_customer_linkman_ch").val()); + // $("#b_custlinkman_phone").val(s); + } + } + + + function v_ownernameChange() { + if ($("#v_ownername").val() == "") { + $("#b_owner_id").val(''); + } else { + var s = getfieldvaluebyid('b_user', 'b_id', 'b_name', $("#v_ownername").val()); + $("#b_owner_id").val(s); + } + } + + function v_moneynameChange() { + // thischanged='1'; + if ($("#v_moneyname").val() == "") { + $("#b_money_id").val(''); + } + } + + function v_sales_nameChange() { + if ($("#v_sales_name").val() == "") { + $("#b_sales_id").val(''); + } else { + var s = getfieldvaluebyid('b_user', 'b_id', 'b_name', $("#v_sales_name").val()); + $("#b_sales_id").val(s); + } + } + + function b_mycompany_idChange() { + if ($("#b_mycompany_id").val() == "") { + $("#v_company_name").val(''); + } else { + var s = getfieldvaluebyid('b_othercompany', 'b_name', 'b_id', $("#b_mycompany_id").val()); + $("#v_company_name").val(s); + } + } + + + + + jQuery_1_2_6("document").ready(function () { + + setAutoCompleteSimple('#b_xz', [["是"], ["否"]]); + + setAutoComplete('#b_supply_id', 'v_b_othercompany_shipcompany', 'b_id', 'b_name', ''); + jQuery_1_2_6("#b_supply_id").result(function (event, data, formatted) { + if (data) { + $("#v_supply_name").val(data.b_name); + } + }); + + setAutoComplete('#b_mycompany_id', 'v_b_othercompany_my', 'b_id', 'b_name', ''); + jQuery_1_2_6("#b_mycompany_id").result(function (event, data, formatted) { + if (data) + $("#v_company_name").val(data.b_name); + }); + + setAutoCompleteEx('#v_sales_name', 'b_user', 'b_name', 'b_id', "b_salesman='1'", ''); + jQuery_1_2_6("#v_sales_name").result(function (event, data, formatted) { + if (data) + $("#b_sales_id").val(data.b_id); + }); + + setAutoComplete('#b_contype', 'b_con_type', 'b_name', 'b_id', ''); + setAutoComplete('#b_xk', 'b_xiangkuang', 'b_name', 'b_id', ''); + setAutoComplete('#b_ywtype', 'b_ywtype_xg', 'b_name', 'b_id', ''); + + setAutoComplete('#b_atwhere', 'v_b_othercompany_duichang', 'b_id', 'b_name', ''); + jQuery_1_2_6('#b_atwhere').result(function (event, data, formatted) { + if (data) { + $('#v_b_atwhere_name').val(data.b_name); + $('#v_b_atwhere_addr').val(data.b_addr); + $('#v_cityname').val(data.v_city_name); + $('#b_city_id').val(data.b_city_id); + } + }); + setAutoComplete('#v_cityname', 'b_city', 'b_name_c', 'b_id', ''); + jQuery_1_2_6('#v_cityname').result(function (event, data, formatted) { + if (data) { + $('#b_city_id').val(data.b_id); + } + }); + setAutoComplete('#v_ownername', 'b_user', 'b_name', 'b_id', ''); + jQuery_1_2_6("#v_ownername").result(function (event, data, formatted) { + if (data) + $("#b_owner_id").val(data.b_id); + }); + + setAutoComplete_moneytype('#b_money_id', 'b_money', 'b_name', 'b_id', ''); + /*jQuery_1_2_6("#v_moneyname").result(function(event, data, formatted){ + if (data){ + $("#b_money_id").val(data.b_id); + //var exrate=getfieldvaluebyid('b_money', 'b_hl', 'b_id', data.b_id); + // $("#b_exrate").val(exrate); + } + });*/ + + setAutoComplete_moneytype('#b_fktk', 'b_othercompany_type_3', 'b_name', 'b_id', ''); + setAutoComplete_moneytype('#b_payment', 'b_payment', 'b_name', 'b_id', ''); + setAutoComplete('#b_customer_id', 'v_b_othercompany_xy', 'b_id', 'b_name', ''); + jQuery_1_2_6("#b_customer_id").result(function (event, data, formatted) { + if (data) { + $("#v_customer_name").val(data.b_name); + var type3 = getfieldvaluebyid('v_b_othercompany', 'v_type3_name', 'b_id', data.b_id); + $("#b_fktk").val(type3); + var payment = getfieldvaluebyid('b_othercompany', 'b_payment', 'b_id', data.b_id); + $("#b_payment").val(payment); + + + } + }); + }) + + + function checkchange() { + //endEditing_fee(); + endEditing_sub(); + if ($('#btn_save').attr('disabled') == 'disabled') { + return false; + } + var formobj = app.serializeObject2($('#buyinform')); + delete formobj["bcheck"]; + + newformjson = app.jsonToString(formobj); + newsubgridjson = app.jsonToString(subgridRows); + + if (newformjson != oldformjson || newsubgridjson != subgridjson) { //||newgridjson!=feegridjson + //alert('111'); + return true; + } else { + return false; + } + } + + + + ////////////////////// + var editIndex_fee = undefined; + function endEditing_fee() { + if (editIndex_fee == undefined) { + return true + } + if ($('#feegrid').datagrid('validateRow', editIndex_fee)) { + $('#feegrid').datagrid('endEdit', editIndex_fee); + editIndex_fee = undefined; + return true; + } else { + return false; + } + } + + var editIndex_sub = undefined; + + function endEditing_sub() { + if (editIndex_sub == undefined) { + return true + } + if ($('#subgrid').datagrid('validateRow', editIndex_sub)) { + $('#subgrid').datagrid('endEdit', editIndex_sub); + editIndex_sub = undefined; + return true; + } else { + return false; + } + } + + function setAutoComplete_moneytype(comboname, viewname, field1, field2, userid) { + jQuery_1_2_6(comboname).unautocomplete(); + jQuery_1_2_6(comboname).autocomplete('jsp/getAutocompleteData.jsp', { + minChars: 0, + width: 250, + max: 11, + matchContains: true, + mustMatch: true, + extraParams: { + viewname: viewname, + field1: field1, + field2: field2, + userid: userid + }, + dataType: "json", + matchSubset: false, + + parse: function (data) { + var rows = data.rows; + return $.map(rows, function (row) { + return { + data: row, + value: row[field1], + result: row[field1] + } + }); + }, + formatItem: function (item) {// 显示下拉列表的内容 + return "
" + item[field1] + "|" + item[field2] + + "
"; + }, + formatMatch: function (item) { + return item[field1]; + }, + formatResult: function (item) { + return item[field1]; + } + }) + } + + + function getfocusedcol(grid) { + if (editIndex_fee != undefined) { + var editor; + for (var j = 0; j < columnarray.length; j++) { + editor = grid.datagrid('getEditor', + { + index: editIndex_fee, + field: columnarray[j] + } + ); + if (editor) { + if (editor.target.is(":focus")) { + fieldname = columnarray[j]; + } + } + } + } + } + + function onBeginEdit_sub(index, row) { + setEditing_sub(index); + } + function setEditing_sub(rowIndex) { + //alert('bbb'); + //$('#subgrid').datagrid('getEditor', {index: rowIndex, field:'v_mx_atwhere_addr'}).target.attr("readonly","readonly"); + // $('#subgrid').datagrid('getEditor', {index: rowIndex, field:''}).target.attr("readonly","readonly"); + + //$('#subgrid').datagrid('getEditor', {index: rowIndex, field:'v_mx_dw_name'}).target.attr("readonly","readonly"); + } + function onBeginEdit_fee(index, row) { + var editor_sh = $('#feegrid').datagrid('getEditor', { + index: index, + field: 'mx_sh' + });/* if (editor_sh.target.prop("checked")){ if ((canedit=='0')||(feeshqx!='1')){ $('#feegrid').datagrid('endEdit',index); @@ -3161,2287 +2866,2061 @@ } }*/ - - if (feeshqx!='1'){ - editor_sh.target.bind('click', function(){ - return false; - }); - }else{ - editor_sh.target.bind('change', function(){ - if (!editor_sh.target.prop("checked")){ - $('#feegrid').datagrid('getEditor', { - index : index, - field : 'mx_sh' - }).target.prop("checked",false); - $('#feegrid').datagrid('getEditor', { - index : index, - field : 'mx_sh' - }).target.val('0'); - $('#feegrid').datagrid('getEditor', { - index : index, - field : 'mx_shman_id' - }).target.val(''); - - $('#feegrid').datagrid('getEditor', { - index : index, - field : 'mx_shdate' - }).target.val(''); - }else { - $('#feegrid').datagrid('getEditor', { - index : index, - field : 'mx_sh' - }).target.prop("checked",true); - $('#feegrid').datagrid('getEditor', { - index : index, - field : 'mx_sh' - }).target.val('1'); - $('#feegrid').datagrid('getEditor', { - index : index, - field : 'mx_shman_id' - }).target.val(userid); - $('#feegrid').datagrid('getEditor', { - index : index, - field : 'mx_shdate' - }).target.val(getnowdate()); - } - }); - } - - $('#feegrid').datagrid('getEditor', { - index : index, - field : 'mx_dw_id' - }).target.bind('change', function(){ - var editdwid=$('#feegrid').datagrid('getEditor', { - index : index, - field : 'mx_dw_id' - }); - var editdwname=$('#feegrid').datagrid('getEditor', { - index : index, - field : 'v_mx_dw_name' - }); - if (editdwid.target.val()==""){ - editdwname.target.val(''); - }else{ - var s=getfieldvaluebyid('b_othercompany', 'b_name', 'b_id',editdwid.target.val()); - editdwname.target.val(s); - //row.v_mx_dw_name=s; - } - }); - setEditing(index); - } - - - function setEditing(rowIndex){ - columnarray =getVisibleColumn('feegrid'); - //alert('1111111'); - //$('#feegrid').datagrid('getEditor', {index: rowIndex, field:'mx_sh'}).target.prop("disabled",true); - $('#feegrid').datagrid('getEditor', {index: rowIndex, field:'mx_amount_root'}).target.attr("readonly","readonly"); - $('#feegrid').datagrid('getEditor', {index: rowIndex, field:'v_mx_dw_name'}).target.attr("readonly","readonly"); - $('#feegrid').datagrid('getEditor', {index: rowIndex, field:'mx_amount'}).target.attr("readonly","readonly"); - $('#feegrid').datagrid('getEditor', {index: rowIndex, field:'mx_shman_id'}).target.attr("readonly","readonly"); - $('#feegrid').datagrid('getEditor', {index: rowIndex, field:'mx_shdate'}).target.attr("readonly","readonly"); - //var editors = $('#feegrid').datagrid('getEditors', rowIndex); - var priceEditor = $('#feegrid').datagrid('getEditor', { - index : rowIndex, - field : 'mx_price' - }); - - var qtyEditor = $('#feegrid').datagrid('getEditor', { - index : rowIndex, - field : 'mx_qty' - }); - var amountEditor = $('#feegrid').datagrid('getEditor', { - index : rowIndex, - field : 'mx_amount_root' - }); - var exrateEditor = $('#feegrid').datagrid('getEditor', { - index : rowIndex, - field : 'mx_exrate' - }); - var amountrmbEditor = $('#feegrid').datagrid('getEditor', { - index : rowIndex, - field : 'mx_amount' - }); - priceEditor.target.bind('change', function(){ - calculate(); - }); - qtyEditor.target.bind('change', function(){ - calculate(); - }); - exrateEditor.target.bind('change', function(){ - calculate(); - }); - - $('#feegrid').datagrid('getEditor', { - index : rowIndex, - field : 'mx_invoiceno' - }).target.bind('change',function(){ - $('#feegrid').datagrid('getEditor', { - index : rowIndex, - field : 'mx_invoicedate' - }).target.val($(this).val()?getnowdate():''); - }); - - function calculate(){ - //alert('calculate'); - var strprice=priceEditor.target.val(); - //strprice=strprice.replace(/(^\s*)|(\s*$)/g, ''); - var strqty=qtyEditor.target.val(); - //strqty=strqty.replace(/(^\s*)|(\s*$)/g, ''); - var x=/^(\+|-)?\d+($|\.\d+$)/; - if (!x.test(strprice)){ - //priceEditor.target.val('0'); - strprice=0; - priceEditor.target.val(0); - } - if (!x.test(strqty)){ - //qtyEditor.target.val('0'); - strqty=0; - qtyEditor.target.val(0); - } - var cost = strprice*strqty; - amountEditor.target.val(cost); - var amountrmb=cost*exrateEditor.target.val(); - amountrmbEditor.target.val(amountrmb); - calcw(); - } - } - - -function calcw(){ - var t_ysrmb=0,t_ysusd=0,ysrmb=0,ysusd=0,sel_srmb=0,sel_susd=0; - var t_yfrmb=0,t_yfusd=0,yfrmb=0,yfusd=0,sel_frmb=0,sel_fusd=0; + if (feeshqx != '1') { + editor_sh.target.bind('click', function () { + return false; + }); + } else { + editor_sh.target.bind('change', function () { + if (!editor_sh.target.prop("checked")) { + $('#feegrid').datagrid('getEditor', { + index: index, + field: 'mx_sh' + }).target.prop("checked", false); + $('#feegrid').datagrid('getEditor', { + index: index, + field: 'mx_sh' + }).target.val('0'); + $('#feegrid').datagrid('getEditor', { + index: index, + field: 'mx_shman_id' + }).target.val(''); - var moneyArray=[]; - var data = $('#feegrid').datagrid('getRows'); - var amount_ze_ys= 0; - var amount_ze_yf= 0; - var amount_tax_ys= 0; - var amount_tax_yf= 0; - for (i in data){ - var amount_ys= 0; - var amount_yf= 0; - canadd=true; - if(data[i].mx_type_id=='应收'){ - amount_ys=Number(data[i].mx_amount_root); - amount_ze_ys=Number(amount_ze_ys)+Number(data[i].mx_amount); - // amount_tax_ys=Number(amount_tax_ys)+Number(data[i].v_ivtaxamount); - } - if(data[i].mx_type_id=='应付'){ - amount_yf=Number(data[i].mx_amount_root); - amount_ze_yf=Number(amount_ze_yf)+Number(data[i].mx_amount); - // amount_tax_yf=Number(amount_tax_yf)+Number(data[i].v_ivtaxamount); - } - for(var k in moneyArray){ - if(moneyArray[k].moneyname==data[i].mx_moneytype_id){ - moneyArray[k].amount_ys=moneyArray[k].amount_ys+amount_ys; - moneyArray[k].amount_yf=moneyArray[k].amount_yf+amount_yf; - var canadd=false; + $('#feegrid').datagrid('getEditor', { + index: index, + field: 'mx_shdate' + }).target.val(''); + } else { + $('#feegrid').datagrid('getEditor', { + index: index, + field: 'mx_sh' + }).target.prop("checked", true); + $('#feegrid').datagrid('getEditor', { + index: index, + field: 'mx_sh' + }).target.val('1'); + $('#feegrid').datagrid('getEditor', { + index: index, + field: 'mx_shman_id' + }).target.val(userid); + $('#feegrid').datagrid('getEditor', { + index: index, + field: 'mx_shdate' + }).target.val(getnowdate()); + } + + }); } - } - if(canadd){ - if(data[i].mx_moneytype_id!=''){ - moneyArray.push({ - moneyname: data[i].mx_moneytype_id, - // v_moneyname: data[i].v_mx_moneytype_name, - amount_ys: amount_ys, - amount_yf: amount_yf, - }) - } - } - } - var tmp_ys_total=''; - var tmp_yf_total=''; - var tmp_ys_dz=''; - var tmp_yf_dz=''; - var tmp_ys_sel=''; - var tmp_yf_sel=''; - var tmp_zd_total_c=''; - //=====数组排序------ - for(var j=0;jlaststr){ - var temp = moneyArray[i]; - moneyArray[i] = moneyArray[i+1]; - moneyArray[i+1] = temp; - } - } - } - for(var i in moneyArray){ - tmp_ys_total=tmp_ys_total+'
'+moneyArray[i].moneyname+':' - +''+Math.round(Number(moneyArray[i].amount_ys)*100)/100+'
'; - tmp_yf_total=tmp_yf_total+'
'+moneyArray[i].moneyname+':' - +''+Math.round(Number(moneyArray[i].amount_yf)*100)/100+'
'; - tmp_zd_total_c=tmp_zd_total_c+'
'+moneyArray[i].moneyname+':' - +''+Math.round(Number(Number(moneyArray[i].amount_ys)-Number(moneyArray[i].amount_yf))*100)/100 - +'
'; - } - document.getElementById('ys_total').innerHTML=tmp_ys_total; - document.getElementById('yf_total').innerHTML=tmp_yf_total; - document.getElementById('lr_total').innerHTML=tmp_zd_total_c; - - var ze_ys='
' - +''+Math.round(Number(amount_ze_ys)*100)/100+'
'; - document.getElementById('ys_amount').innerHTML=ze_ys; - - var ze_yf='
' - +''+Math.round(Number(amount_ze_yf)*100)/100+'
'; - document.getElementById('yf_amount').innerHTML=ze_yf; - - var mlamount=Number(Math.round((Number(amount_ze_ys)-Number(amount_ze_yf))*100)/100); - var tmp_ze='
' - +''+mlamount+'
'; - document.getElementById('lr_amount').innerHTML=tmp_ze; - } - - - function SetLabelUSD(){ - $('#lab_ysusd').text('应收美金'); - $('#lab_yfusd').text('应付美金'); - $('#lab_lrusd').text('美金利润'); - } - - - function calculateAmount(rowIndex){ - //alert('calculateAmount'); - - var priceEditor = $('#feegrid').datagrid('getEditor', { - index : rowIndex, - field : 'mx_price' - }); - var qtyEditor = $('#feegrid').datagrid('getEditor', { - index : rowIndex, - field : 'mx_qty' - }); - var amountEditor = $('#feegrid').datagrid('getEditor', { - index : rowIndex, - field : 'mx_amount_root' - }); - var exrateEditor = $('#feegrid').datagrid('getEditor', { - index : rowIndex, - field : 'mx_exrate' - }); - var amountrmbEditor = $('#feegrid').datagrid('getEditor', { - index : rowIndex, - field : 'mx_amount' - }); - var strprice=priceEditor.target.val(); - var strqty=qtyEditor.target.val(); - var x=/^(\+|-)?\d+($|\.\d+$)/; - if (!x.test(strprice)){ - //priceEditor.target.val('0'); - strprice=0; - priceEditor.target.val(0); - } - if (!x.test(strqty)){ - //qtyEditor.target.val('0'); - strqty=0; - qtyEditor.target.val(0); - } - var cost = strprice*strqty; - //priceEditor.target.val() * qtyEditor.target.val(); - amountEditor.target.val(cost); - var amountrmb=cost*exrateEditor.target.val(); - amountrmbEditor.target.val(amountrmb); - calcw(); - - } - - function onClickRow_fee(index,row) { - if (row.mx_sh=='1' || row.alreadyamount>0){ - //alert('12321'); - //$('#feegrid').datagrid('getEditor', {index: index, field:'mx_sh'}).target.attr("readonly",true); - return; - } - // if (editIndex_fee != index){ - if (endEditing_fee()) { - $('#feegrid').datagrid('beginEdit', index); - editIndex_fee = index; - setEditing(index); - } else { - $('#feegrid').datagrid('selectRow', editIndex_fee); - } - // } - - } - function onClickRow_sub(index,row) { - /*if (endEditing_sub()) { - $('#subgrid').datagrid('beginEdit', index); - editIndex_sub = index; - //setEditing_sub(index); - } else { - $('#subgrid').datagrid('selectRow', editIndex_sub); - }*/ - loaddata_detail_feesuo('feegridsuo', 'v_xg_buyin_cw', strid, row.subid, row.mx_keyid,''); - } - - function showfee(i) { - /*if (endEditing_sub()) { - $('#subgrid').datagrid('beginEdit', index); - editIndex_sub = index; - //setEditing_sub(index); - } else { - $('#subgrid').datagrid('selectRow', editIndex_sub); - }*/ - var e = window.event || e; - if (e.stopPropagation) { - e.stopPropagation(); //阻止事件 冒泡传播 - } - var index = $(i).parents("tr:first").attr("datagrid-row-index"); - index = parseInt(index); - console.log(index); - var row = $('#subgrid').datagrid('getRows')[index]; - //console.log(row); - - loaddata_detail_feesuo('feegridsuo', 'v_xg_buyin_cw', strid, row.subid, row.mx_keyid,''); - } - - - function loaddata_detail_feesuo(gridname, viewname, strid, subid,conno,options) { - var strid = strid; - if(!subid){ - return - } - //var strtemp=getFeeLevelSQL(userid); - var ssubid=subid.replace('{',''); - ssubid=subid.replace('}',''); - var searchcondition = "father = '" + strid +"'"+" and (mx_linkfd_id='"+ssubid+"' or mx_linkfd_id='"+subid+"')"; - if (loginfee=='1'){ - searchcondition =searchcondition+ " and mx_feetype_id in (select b_feetype_id from b_user_feetype where b_user_id='"+userid+"')"; - } - //var searchcondition = "(father='" + strid + "') and "+strtemp+ "' and mx_linkcon_id= '"+ Fconsubid +"'"; - //alert(searchcondition); - $.ajax({ - type : 'post', - url : 'jsp/loaddata.jsp', - cache : false, - async : false, - data : { - soption : options, - searchcondition : searchcondition, - viewname : viewname, - orderfield : 'mx_xh' - }, - dataType : 'json', // 服务器返回时接收的数据类型 - success : function(result) { - $('#' + gridname).datagrid('loadData', result); - }, - error : function(result) { - - } - - }); - - } - - - - - function removeitfee(o) { - var e = window.event || e; - if (e.stopPropagation) { - e.stopPropagation(); //阻止事件 冒泡传播 - } - // var selindex = $(o).attr('attr1'); - // let editIndex=Number(curindex) + 1; - // var gridid = 'feegrid'; - - var selid = $(o).attr('attr1'); - var selindex = $("#feegrid").datagrid('getRowIndex', selid); - var curindex = $("#feegrid").datagrid('getRows').length; - if($("#feegrid").datagrid('getRows')[selindex].alreadyamount==0){ - $.messager.confirm("操作提示", '您确定要删除选中的数据吗?', function (r) { - if (!r) { - return false; - }else{ - $("#feegrid").datagrid('deleteRow',selindex); - $("#feegrid").datagrid('options').editIndex = undefined; - let rows=$("#feegrid").datagrid('getRows'); - for(var i=selindex;i=irow){ - $('#feegrid').datagrid('appendRow', { - mx_xh: Number(curindex) + 1, - mx_level : 1, - //mx_type_id : '应收', - mx_hstype_id : '买箱入库', - mx_intputman_id : userid, - mx_inputdate : getnowdate(), - alreadyamount: 0, - notamount:0, + $('#feegrid').datagrid('getEditor', { + index: index, + field: 'mx_dw_id' + }).target.bind('change', function () { + var editdwid = $('#feegrid').datagrid('getEditor', { + index: index, + field: 'mx_dw_id' + }); + var editdwname = $('#feegrid').datagrid('getEditor', { + index: index, + field: 'v_mx_dw_name' + }); + if (editdwid.target.val() == "") { + editdwname.target.val(''); + } else { + var s = getfieldvaluebyid('b_othercompany', 'b_name', 'b_id', editdwid.target.val()); + editdwname.target.val(s); + //row.v_mx_dw_name=s; + } }); - }else{ - $('#feegrid').datagrid('insertRow', { - index : editIndex, - row : { - mx_xh: Number(curindex) + 1, - mx_level : 1, - //mx_type_id : '应收', - mx_hstype_id : '买箱入库', - mx_intputman_id:userid, - mx_inputdate:getnowdate(), - alreadyamount: 0, - notamount:0, - } - }); - } - let rows=$('#feegrid').datagrid('getRows'); - for(var i=editIndex;i=0; i--){ - if (selectedrows[i].mx_sh == '1'){ - hassh = true; - } else { - $('#feegrid').datagrid('deleteRow',$('#feegrid').datagrid('getRowIndex',selectedrows[i])); - } - } - if (hassh) - alert('已经审核的费用不能删除'); - //setxh_fee2(); - editIndex_fee = undefined; - } - }); - } - + function setEditing(rowIndex) { + columnarray = getVisibleColumn('feegrid'); + //alert('1111111'); + //$('#feegrid').datagrid('getEditor', {index: rowIndex, field:'mx_sh'}).target.prop("disabled",true); + $('#feegrid').datagrid('getEditor', { index: rowIndex, field: 'mx_amount_root' }).target.attr("readonly", "readonly"); + $('#feegrid').datagrid('getEditor', { index: rowIndex, field: 'v_mx_dw_name' }).target.attr("readonly", "readonly"); + $('#feegrid').datagrid('getEditor', { index: rowIndex, field: 'mx_amount' }).target.attr("readonly", "readonly"); + $('#feegrid').datagrid('getEditor', { index: rowIndex, field: 'mx_shman_id' }).target.attr("readonly", "readonly"); + $('#feegrid').datagrid('getEditor', { index: rowIndex, field: 'mx_shdate' }).target.attr("readonly", "readonly"); + //var editors = $('#feegrid').datagrid('getEditors', rowIndex); + var priceEditor = $('#feegrid').datagrid('getEditor', { + index: rowIndex, + field: 'mx_price' + }); - - function selecthistory() { - //alert('111'); - if ($('#b_customer_id').val() == '') { - alert('请先选定委托单位,再来选择业务费用!'); - return; - } - var sparams = new Array(); - var desgrid = "feegrid"; - var selectid = "hishtcw_bsys"; - var moduleid = "bs_ht"; - var userid = ""; - var parentfrm = self.name; - var options = "{mx_date:'" + getnowdate() + "',mx_user_id:'" + "'}"; - // alert(options); - - sparams.push($('#b_customer_id').val()); - //sparams.push("ZHOUSHANPENGXIANG"); - var psparams = sparams.join(","); - var url = "jselectdialog/dataSelectMuti.jsp?parentfrm=" + parentfrm - + "&desgrid=" + desgrid + "&selectid=" + selectid + "&moduleid=" - + moduleid + "&psparams=" + psparams + "&userid=" + userid - + "&options=" + options; - - var datadialog = parent.$('
').dialog({ - title : '数据选取', - width: 888, - height: 500, - // left:50, - top : 50, - onClose: function(event, ui) { - updatehl(); - }, - content : '', - modal : true - }); - } - - - function showxzmod() { - var row = $('#feegrid').datagrid('getSelected'); - var url; - if (row != undefined) { - if (row.mx_type_id == '应付') { - url = "jcw/payxzmod.jsp?businessid=" + row.subid; - } else if (row.mx_type_id == '应收') { - url = "jcw/receivexzmod.jsp?businessid=" + row.subid; - } - if (url != undefined) { - var datadialog = parent.$('
').dialog({ - title : '销账明细', - width : 640, - height : 400, - content : '', - modal : true - }); - } - } - } - - function loaddata_detail_fee(gridname, viewname, strid, options) { - var strid = strid; - var strtemp=getFeeLevelSQL(userid); - var searchcondition = "(father='" + strid + "') and "+strtemp; - $.ajax({ - type : 'post', - url : 'jsp/loaddata.jsp', - cache : false, - async : false, - data : { - soption : options, - searchcondition : searchcondition, - viewname : viewname, - orderfield : 'mx_xh' - }, - dataType : 'json', // 服务器返回时接收的数据类型 - success : function(result) { - $('#' + gridname).datagrid('loadData', result); - }, - error : function(result) { + var qtyEditor = $('#feegrid').datagrid('getEditor', { + index: rowIndex, + field: 'mx_qty' + }); + var amountEditor = $('#feegrid').datagrid('getEditor', { + index: rowIndex, + field: 'mx_amount_root' + }); + var exrateEditor = $('#feegrid').datagrid('getEditor', { + index: rowIndex, + field: 'mx_exrate' + }); + var amountrmbEditor = $('#feegrid').datagrid('getEditor', { + index: rowIndex, + field: 'mx_amount' + }); + priceEditor.target.bind('change', function () { + calculate(); + }); + qtyEditor.target.bind('change', function () { + calculate(); + }); + exrateEditor.target.bind('change', function () { + calculate(); + }); - } - }); - } - - function loaddata_detail_sub(gridname, viewname, strid, options) { - var strid = strid; - - var searchcondition = "(father='" + strid + "') "; - $.ajax({ - type : 'post', - url : 'jsp/loaddata.jsp', - cache : false, - async : false, - data : { - soption : options, - searchcondition : searchcondition, - viewname : viewname, - orderfield : 'mx_xh' - }, - dataType : 'json', // 服务器返回时接收的数据类型 - success: function(result) { - var $grid = $('#' + gridname); - $grid.datagrid('loadData', result); + $('#feegrid').datagrid('getEditor', { + index: rowIndex, + field: 'mx_invoiceno' + }).target.bind('change', function () { + $('#feegrid').datagrid('getEditor', { + index: rowIndex, + field: 'mx_invoicedate' + }).target.val($(this).val() ? getnowdate() : ''); + }); - - $('#subgrid').datagrid('clearSelections'); - $('#subgrid').datagrid('clearChecked'); - }, - error : function(result) { - - } - }); - } - - function savecolumn_con(){ - saveColumn('subgrid','v_xg_buyin_sub'); - } - - function savecolumn_fee(){ - saveColumn('feegrid','v_xg_buyin_cw'); - } - - function createcon(){ - var qty = parseInt($('#b_qty').val()); - if ($('#b_qty').val()=='' || $('#b_contype').val()=='' || $('#v_b_atwhere_name').val()==''|| $('#b_xk').val()==''){ - alert('数量、箱型、箱况或堆场为空,请检查!'); - return; - } - - var allRows = $('#subgrid').datagrid('getData').firstRows || []; - var irow = allRows.length; - - var contype = $('#b_contype').val(); - var Fdate = ''; - if (orgid != 'shltpn') { - Fdate = $('#b_date').val(); - } - - for (var i = irow; i < qty; i++){ - allRows.push({ - mx_contype: contype, - mx_xh: getguid(), - mx_xk: $('#b_xk').val(), - mx_xz: '是', - mx_type: '买箱入库', - mx_zxdate: Fdate, - mx_city_id: $('#b_city_id').val(), - v_mx_city_name: $('#v_cityname').val(), - mx_atwhere: $('#b_atwhere').val(), - v_mx_atwhere_name: $('#v_b_atwhere_name').val(), - mx_txid: $('#b_txid').val() - }); - } - - // 更新 datagrid - $('#subgrid').datagrid('loadData', allRows); - - $('#subgrid').datagrid('scrollTo', allRows.length - 1); - } - - - - function canitemidexists(){ - var itemrows = $('#subgrid').datagrid('getData').firstRows || [] - - var irow = itemrows.length; - var arritem=[]; - var canuse=true; - var conno='' - for (var i = 0; i < irow; i++) { - var mxitemid=itemrows[i].mx_conno; - //alert(mxitemid); - if((mxitemid=='')||(mxitemid==undefined)){ - continue; - //canuse = false; - //break; - } - if(arritem.indexOf(mxitemid)>-1){ - if (conno!=''){ - conno=conno+";" ; - } - conno=conno+mxitemid ; - //canuse = false; - continue; - } - arritem.push(mxitemid); - }; - if (conno!=''){ - conno=conno+";" ; - alert("箱号:"+conno+"有重复,不能保存"); - canuse = false; - } - - return canuse; - } - - - - /*function canitemidexists(){ - var itemrows = $('#subgrid').datagrid('getRows'); - var irow = itemrows.length; - var arritem=[]; - var canuse=true; - var conno='' - for (var i = 0; i < irow; i++) { - var mxitemid=itemrows[i].mx_conno; - //alert(mxitemid); - if((mxitemid=='')||(mxitemid==undefined)){ - continue; - //canuse = false; - //break; - } - if(arritem.indexOf(mxitemid)>-1){ - canuse = false; - break; - } - arritem.push(mxitemid); - }; - return canuse; - }*/ - - - function createconno() { - if (checkchange()){ - alert('请先保存,再生成系统箱号!'); - return; - } - var sid=$('#b_id').val(); - var rows = $('#subgrid').datagrid('getData').firstRows || []; - var irow = $('#subgrid').datagrid('getData').firstRows || [].length; - var value = ""; - for (i = 0; i < irow; i++) { - var keyid=rows[i].mx_keyid; - // alert(keyid); - if ((keyid=='')||(keyid==null)||(keyid==undefined)){ - alert("请先确认入库!"); - return; - } - //alert(keyid); - var conn=rows[i].mx_conno; - if ((conn!='')&&(conn!=null)&&(conn!=undefined)){ - //alert("111"); - continue; - } - - var tmpjson=loaddatas('v_gx_keyrecords', "='"+keyid+"'", 'mx_shdatetime desc', ''); - if(tmpjson.length>0){ - if(tmpjson[0].father!=strid){ - alert("112"); - // alert('该箱子已使用,不能撤删!'); - continue; - } - } - - if (value!=''){ - value= value+',' - } - value = value+"{father:'" +sid+ - "',mx_conno:'" + rows[i].mx_keyid+ - "',subid:'" + rows[i].subid+ - "'}" - } - - if (value==''){ - // alert('费用导入失败,不能重复导入费用!'); - return; - } - - value = "["+value+"]"; - //alert(value); - $.ajax({ - type : 'post', - url : 'jsp/savesubtable.jsp', - cache : false, - data : { - subtable:'xg_buyin_sub', - subinsertvalue: '[]', - subdelvalue:'[]', - subupdatevalue:value, - father:sid - }, - dataType : 'text', - success : function(result) { - alert('箱号生成成功!'); - loaddata_detail_sub('subgrid','v_xg_buyin_sub',strid,''); - gridrows=$('#subgrid').datagrid('getData').firstRows || []; - subgridjson=app.jsonToString(gridrows); - }, - error : function(result) { + function calculate() { + //alert('calculate'); + var strprice = priceEditor.target.val(); + //strprice=strprice.replace(/(^\s*)|(\s*$)/g, ''); + var strqty = qtyEditor.target.val(); + //strqty=strqty.replace(/(^\s*)|(\s*$)/g, ''); + var x = /^(\+|-)?\d+($|\.\d+$)/; + if (!x.test(strprice)) { + //priceEditor.target.val('0'); + strprice = 0; + priceEditor.target.val(0); + } + if (!x.test(strqty)) { + //qtyEditor.target.val('0'); + strqty = 0; + qtyEditor.target.val(0); + } + var cost = strprice * strqty; + amountEditor.target.val(cost); + var amountrmb = cost * exrateEditor.target.val(); + amountrmbEditor.target.val(amountrmb); + calcw(); } - }); - - } - - - - function sh(){ - $('#btn_check').attr('disabled','disabled'); - if (checkchange()){ - alert('请先保存数据!'); - $('#btn_check').removeAttr("disabled"); - return; - } - var Fid=$('#b_id').val(); - var Fdwid=$('#b_customer_id').val(); - if (Fdwid== ''){ - alert('箱公司不能为空!'); - $('#btn_check').removeAttr("disabled"); - return; - } - if (!canitemidexists()){ - //alert('箱号有重复,不能更新箱池!'); - return; - } - var rows = $('#subgrid').datagrid('getChecked'); - if (rows.length<=0){ - var rows=$('#subgrid').datagrid('getData').firstRows || []; - //return false; - }; - var tmpjson; - if (!rows){alert('未输入买入的箱子'); - $('#btn_check').removeAttr("disabled"); - return;} - - /* var connoArray=[]; - var Fsql=" mx_type not in('卖箱出库','还箱退租','代管出库')" - if (Fid!=''){ - Fsql=Fsql+" and father<>'"+Fid+"'"; - } - var tmpjson=loaddatas('xg_conmaxtype', Fsql, '', ''); - for(var k in tmpjson){ - if (!(strinArray(connoArray,tmpjson[k].mx_conno))){ - connoArray.push(tmpjson[k].mx_conno); - } - } */ - - // ========= 第一轮循环:收集要批量查询的 key ========= - - var subidList = []; - var connoList = []; - - for (var i = 0; i < rows.length; i++) { - var r = rows[i]; - - if (r.mx_contype == '' || r.mx_contype == null) { - alert('箱型不能为空'); - $('#btn_check').removeAttr("disabled"); - return; - } - if (r.mx_atwhere == '' || r.mx_atwhere == null) { - alert('存放堆场不能为空'); - $('#btn_check').removeAttr("disabled"); - return; - } - if (r.mx_txid == '' || r.mx_txid == null) { - alert('提箱单号不能为空'); - $('#btn_check').removeAttr("disabled"); - return; - } - - // 已确认记录直接跳过,不参与重复确认查询 - if (r.mx_keyid != '' && r.mx_keyid != null && r.mx_keyid != undefined) { - continue; - } - - // subid 批量收集(包含 { } 两种形式) - if (r.subid) { - var s1 = r.subid; - var s2 = r.subid.replace('{','').replace('}',''); - subidList.push(s1, s2); - } - - // conno 批量收集 - if (r.mx_conno) { - connoList.push(r.mx_conno); - } - } - - // 去重 - subidList = Array.from(new Set(subidList)); - connoList = Array.from(new Set(connoList)); - // ========= 第二阶段:一次性批量查询 DB ========= - - // ① 已确认的箱(避免重复确认) - var confirmedMap = new Set(); - if (subidList.length > 0) { - var sql1 = " father = '" + Fid + "' AND mx_link_id IN ('" + subidList.join("','") + "')"; - var tmp1 = loaddatas('xg_conmaxtype', sql1, '', ''); - for (var t = 0; t < tmp1.length; t++) { - confirmedMap.add(tmp1[t].mx_link_id); - } - } - - // ② 箱池中已存在的箱号(避免重复输入) - var connoMap = new Set(); - if (connoList.length > 0) { - var sql2 = - " father <> '" + Fid + "' " + - " AND mx_conno IN ('" + connoList.join("','") + "')" + - " AND mx_type NOT IN ('卖箱出库','还箱退租','代管出库')"; - var tmp2 = loaddatas('xg_conmaxtype', sql2, '', ''); - for (var k = 0; k < tmp2.length; k++) { - connoMap.add(tmp2[k].mx_conno); - } - } - - - // ========= 第三轮循环:逐条判断 ========= - for (var i = 0; i < rows.length; i++) { - var r = rows[i]; - - // 跳过已确认记录 - if (!(r.mx_keyid != '' && r.mx_keyid != null && r.mx_keyid != undefined)) { - - // 判断 subid 是否重复确认 - if (r.subid) { - var s1 = r.subid; - var s2 = r.subid.replace('{','').replace('}',''); - if (confirmedMap.has(s1) || confirmedMap.has(s2)) { - alert('已确认的箱子不可重复确认!'); - $('#btn_sh').removeAttr("disabled"); - return; - } - } - } - - // 判断箱号是否在箱池中存在 - if (r.mx_conno) { - if (connoMap.has(r.mx_conno)) { - alert('箱号:' + r.mx_conno + '在箱池中已经存在,不可重复输入!'); - $('#btn_check').removeAttr("disabled"); - return; - } - } - } - - - var rows1=[]; - var minid=getAutoID('xg_buyin_autokeyid','g3soft'); - if ((minid=='')||(minid==null)||(minid==undefined)){ - alert('系统箱号出错,确认失败,请重新确认!'); - $('#btn_check').removeAttr("disabled"); - return; - } - var Fstrid=$('#b_id').val(); - var Fywid=''; - Fywid=Fstrid.substr(Fstrid.length-3, Fstrid.length); - var n=0; - console.log(Fywid); - // return; - // alert(minid); - - var Fdate=getnowtime(); - - var subdata=[]; - var subdata1=[]; - var subdata2=[]; - var subdata3=[]; - var maindata={}; - var tmpdata={}; - var tmpdata1={}; - var tmpdata2={}; - var tmpdata3={}; - /////////修改确认xg_buyin////// - maindata={}; - maindata.b_id=$('#b_id').val(); - maindata.b_sh='1'; - maindata.b_shman_id=userid; - maindata.b_shdatetime=Fdate; - ////////////////// - - for (var i = 0; i < rows.length; i++) { - var Fkeyid = rows[i].mx_keyid; - if ((Fkeyid != '') && (Fkeyid != null) && (Fkeyid != undefined)) { - continue; - } - var conkeyid = (Number(minid) + n).toString() + '1' + Fywid; - n = n + 1; - - var contype = rows[i].mx_contype; - var txid = rows[i].mx_txid; - var xk = rows[i].mx_xk; - var atwhere = rows[i].mx_atwhere; - var txdate = rows[i].mx_zxdate; - var bz1 = rows[i].mx_bz1; - - if ((contype == undefined) || (contype == null)) { contype = ''; } - if ((txid == undefined) || (txid == null)) { txid = ''; } - if ((xk == undefined) || (xk == null)) { xk = ''; } - if ((atwhere == undefined) || (atwhere == null)) { atwhere = ''; } - if ((txdate == undefined) || (txdate == null)) { txdate = ''; } - if ((bz1 == undefined) || (bz1 == null)) { bz1 = ''; } - - /////////修改确认/xg_buyin_sub////// - tmpdata = {}; - tmpdata.mx_sh = '1'; - tmpdata.mx_shman_id = userid; - tmpdata.mx_shdatetime = Fdate; - tmpdata.mx_keyid = conkeyid; - tmpdata.mx_date = $('#b_date').val(); - tmpdata.mx_dw_id = Fdwid; - tmpdata.subid = rows[i].subid; - subdata.push(tmpdata); - - //////////插入xg_keyrecords////// - tmpdata1 = {}; - tmpdata1.mx_conno = rows[i].mx_conno; - tmpdata1.mx_contype = contype; - tmpdata1.mx_txid = txid; - tmpdata1.mx_xk = xk; - tmpdata1.mx_bz1 = bz1; - tmpdata1.mx_atwhere = atwhere; - tmpdata1.mx_txdate = txdate; - tmpdata1.mx_xgyw = 'xg'; - tmpdata1.father = $('#b_id').val(); - tmpdata1.mx_sh = '1'; - tmpdata1.mx_shman_id = userid; - tmpdata1.mx_shdatetime = Fdate; - tmpdata1.mx_keyid = conkeyid; - tmpdata1.mx_date = $('#b_date').val(); - tmpdata1.mx_dw_id = Fdwid; - tmpdata1.mx_link_id = rows[i].subid; - tmpdata1.mx_type = '买箱入库'; - subdata1.push(tmpdata1); - - //////////插入xg_conmaxtype/////// - tmpdata2 = {}; - tmpdata2.mx_conno = rows[i].mx_conno; - tmpdata2.mx_contype = contype; - tmpdata2.mx_txid = txid; - tmpdata2.mx_xk = xk; - tmpdata2.mx_bz1 = bz1; - tmpdata2.mx_atwhere = atwhere; - tmpdata2.mx_txdate = txdate; - tmpdata2.mx_xgyw = 'xg'; - tmpdata2.father = $('#b_id').val(); - tmpdata2.mx_sh = '1'; - tmpdata2.mx_shman_id = userid; - tmpdata2.mx_shdatetime = Fdate; - tmpdata2.mx_keyid = conkeyid; - tmpdata2.mx_date = $('#b_date').val(); - tmpdata2.mx_dw_id = Fdwid; - tmpdata2.mx_link_id = rows[i].subid; - tmpdata2.mx_type = '买箱入库'; - subdata2.push(tmpdata2); - } - - // ===== 优化 xg_cw 查询 ===== - // 收集所有 subid(包含 {} 形式) - var allSubidList = []; - rows.forEach(r => { - if (r.subid) { - allSubidList.push(r.subid); - allSubidList.push(r.subid.replace('{','').replace('}','')); - } - }); - allSubidList = Array.from(new Set(allSubidList)); - - // 一次性批量查询 xg_cw - var xgcwMap = {}; // key: mx_linkfd_id -> 对应 xg_cw 记录数组 - if (allSubidList.length > 0) { - var searchsqlcw = " father ='" + Fid + "' AND (" + - allSubidList.map(sid => "mx_linkfd_id='" + sid + "'").join(" OR ") + - ")"; - var xgcwrows = loaddatas('xg_cw', searchsqlcw, 'subid', ''); - xgcwrows.forEach(r => { - if (!xgcwMap[r.mx_linkfd_id]) xgcwMap[r.mx_linkfd_id] = []; - xgcwMap[r.mx_linkfd_id].push(r); - }); - } - - // 循环 rows,生成 subdata3 - for (var i = 0; i < rows.length; i++) { - var r = rows[i]; - var conkeyid = (Number(minid) + i).toString() + '1' + Fywid; // 保持原 keyid 逻辑 - var contype = r.mx_contype || ''; - var txid = r.mx_txid || ''; - var xk = r.mx_xk || ''; - var atwhere = r.mx_atwhere || ''; - var txdate = r.mx_zxdate || ''; - - var subid = r.subid; - var ssubid = subid.replace('{','').replace('}',''); - - var relatedCw = (xgcwMap[subid] || []).concat(xgcwMap[ssubid] || []); - relatedCw.forEach(cw => { - var tmpdata3 = {}; - tmpdata3.mx_keyid = conkeyid; - tmpdata3.mx_shdatetime = Fdate; - tmpdata3.mx_conno = r.mx_conno; - tmpdata3.mx_contype = contype; - tmpdata3.mx_txid = txid; - tmpdata3.mx_xk = xk; - tmpdata3.mx_atwhere = atwhere; - tmpdata3.mx_txdate = txdate; - tmpdata3.subid = cw.subid; - subdata3.push(tmpdata3); - }); - } - - ///////////////////// - //console.log('vcvcvcvcvcvc'); - var subjson=app.jsonToString(subdata); - //console.log('subjson:'+subjson); - var subjson1=app.jsonToString(subdata1); - //console.log("subjson1:"+subjson1); - var subjson2=app.jsonToString(subdata2); - //console.log("subjson2:"+subjson2); - var subjson3=app.jsonToString(subdata3); - //console.log("subjson3:"+subjson3); - //alert(subjson); - ////////////////////////////////////////// - var subtable=new Array(); - var keyid=new Array(); - var subinsertvalue=new Array(); - var subupdatevalue=new Array(); - var subdelvalue=new Array(); - subtable.push('xg_buyin'); - subtable.push('xg_buyin_sub'); - subtable.push('xg_keyrecords'); - subtable.push('xg_conmaxtype'); - subtable.push('xg_cw'); - - var formjson=app.jsonToString(maindata); - //console.log("formjson:"+formjson); - subinsertvalue.push('[]'); - subinsertvalue.push('[]'); - subinsertvalue.push(subjson1); - subinsertvalue.push(subjson2); - subinsertvalue.push('[]'); - - subupdatevalue.push('['+formjson+']'); - subupdatevalue.push(subjson); - subupdatevalue.push('[]'); - subupdatevalue.push('[]'); - subupdatevalue.push(subjson3); - - subdelvalue.push('[]'); - subdelvalue.push('[]'); - subdelvalue.push('[]'); - subdelvalue.push('[]'); - subdelvalue.push('[]'); - - keyid.push('b_id'); - keyid.push('subid'); - keyid.push('subid'); - keyid.push('subid'); - keyid.push('subid'); - - // console.log(subtable) - // console.log(subinsertvalue) - // console.log(subdelvalue) - // console.log(subupdatevalue) - // console.log(keyid) - - var sResult=''; - sResult=saveobjt(subtable,subinsertvalue,subdelvalue,subupdatevalue,keyid); - if(sResult=='OK'){ - alert('确认成功!'); - $('#btn_check').removeAttr("disabled"); - setywwcqty(); - loaddata('buyinform','v_xg_buyin',strid,'main'); - // $('#btn_sh').attr('disabled','disabled'); - //$('#btn_createcon').attr('disabled','disabled'); - var formobj=app.serializeObject2($('#buyinform')); - delete formobj["bcheck"]; - oldformjson=app.jsonToString(formobj); - - loaddata_detail_sub('subgrid','v_xg_buyin_sub',strid,''); - - gridrows=$('#subgrid').datagrid('getData').firstRows || []; - subgridjson=app.jsonToString(gridrows); - }else{ - alert(sResult); - $('#btn_check').removeAttr("disabled"); - } - $('#btn_check').removeAttr("disabled"); - } - - - function sh_old(){ - if (checkchange()){ - alert('请先保存数据!'); - return; - } - - var Fid=$('#b_id').val(); - var Fdwid=$('#b_customer_id').val(); - if (Fdwid== ''){ - alert('箱公司不能为空!'); - return; - } - if (!canitemidexists()){ - //alert('箱号有重复,不能更新箱池!'); - return; - } - var rows = $('#subgrid').datagrid('getChecked'); - if (rows.length<=0){ - var rows=$('#subgrid').datagrid('getRows'); - }; - var tmpjson; - if (!rows){alert('未输入买入的箱子');return;} - - var connoArray=[]; - var Fsql=" mx_type not in('卖箱出库','还箱退租','代管出库')" - if (Fid!=''){ - Fsql=Fsql+" and father<>'"+Fid+"'"; - } - var tmpjson=loaddatas('xg_conmaxtype', Fsql, '', ''); - for(var k in tmpjson){ - if (!(strinArray(connoArray,tmpjson[k].mx_conno))){ - connoArray.push(tmpjson[k].mx_conno); - } - } - - - for (var i = 0; i < rows.length; i++) { - if (rows[i].mx_contype==''||rows[i].mx_contype==null){ - alert('箱型不能为空'); - $('#btn_check').removeAttr("disabled"); - return; - } - if (rows[i].mx_atwhere==''||rows[i].mx_atwhere==null){ - alert('存放堆场不能为空'); - $('#btn_check').removeAttr("disabled"); - return; - } - - if (rows[i].mx_txid==''||rows[i].mx_txid==null){ - alert('提箱单号不能为空'); - $('#btn_check').removeAttr("disabled"); - return; - } - var keyid=rows[i].mx_keyid; - if ((keyid!='')&&(keyid!=null)&&(keyid!=undefined)){ - continue; - } - if ((rows[i].mx_conno!='')){ - if (strinArray(connoArray,rows[i].mx_conno)){ - alert('箱号:'+rows[i].mx_conno+'在箱池中已经存在,不可重复输入!'); - return; - } - } - } - var rows1=[]; - var minid=getAutoID('xg_buyin_autokeyid','g3soft'); - // alert(minid); - var subvalue = ""; - var xgcwvalue = ""; - var Fdate=getnowtime(); - //alert(Fdate); - var n=0; - for (var i = 0; i < rows.length; i++) { - var Fkeyid=rows[i].mx_keyid; - if ((Fkeyid!='')&&(Fkeyid!=null)&&(Fkeyid!=undefined)){ - continue; - } - - rows[i].mx_keyid=(Number(minid)+n).toString(); - n=n+1; - if (subvalue!=''){ - subvalue+=','; - } - subvalue = subvalue+"{mx_sh:'" +'1'+ - "',mx_shman_id:'" + userid+ - "',mx_shdatetime:'" +Fdate+ - "',mx_keyid:'" + rows[i].mx_keyid+ - "',mx_date:'" + $('#b_date').val()+ - //"',mx_ywtype:'" + $('#b_ywtype').val()+ - "',mx_dw_id:'" + Fdwid+ - "',subid:'" + rows[i].subid+ - "'}" - ///////////////修改修改费用的keyid//////// - - var subid=rows[i].subid; - var ssubid=subid.replace('{',''); - ssubid=subid.replace('}',''); - var searchsqlcw=" father ='" +Fid+ "' "+" and (mx_linkfd_id='"+ssubid+"' or mx_linkfd_id='"+subid+"')"; - //alert(searchsqlcw); - var xgcwrows=loaddatas('xg_cw', searchsqlcw, 'subid', ''); - if (xgcwrows.length>0){ - for ( var m in xgcwrows){ - var contype=rows[i].mx_contype; - var txid=rows[i].mx_txid; - var xk=rows[i].mx_xk; - var atwhere=rows[i].mx_atwhere; - var txdate=rows[i].mx_zxdate; - if ((contype==undefined)||(contype==null)){contype='';} - if ((txid==undefined)||(txid==null)){txid='';} - if ((xk==undefined)||(xk==null)){xk='';} - if ((atwhere==undefined)||(atwhere==null)){atwhere='';} - if ((txdate==undefined)||(txdate==null)){txdate='';} - if (xgcwvalue!=''){ - xgcwvalue+=','; - } - if(xgcwrows[m].subid!=undefined){ - xgcwvalue = xgcwvalue+"{mx_keyid:'" +rows[i].mx_keyid+ - "',mx_shdatetime:'" +Fdate+ - "',mx_conno:'" + rows[i].mx_conno+ - "',mx_contype:'" +contype+ - "',mx_txid:'" + txid+ - "',mx_xk:'" +xk+ - "',mx_atwhere:'" +atwhere+ - "',mx_txdate:'" +txdate+ - "',subid:'" + xgcwrows[m].subid+ - "'}" - } - } - } - ///////////////////// - } - // rows1.push({b_id:Fid,b_state:'审核通过',b_sh:'1',b_shman_id:userid,b_shdatetime:Fdate}); - var mainjson='{b_id:"'+Fid+'",b_sh:"1"'+',b_shman_id:"'+userid+'",b_shdatetime:"'+Fdate+'"}'; //,b_state:"审核通过"' - var subupdatavalue = "["+subvalue+"]"; - //alert(mainjson); - //alert(subupdatavalue); - $.ajax({ - type:'post' , //请求方式 - url:'jsp/saveobj.jsp' , //地址 - cache: false, - async : false, - traditional: true, - data:{ - maintable:'xg_buyin', - mainvalue:mainjson, - subtable:['xg_buyin_sub'], - subinsertvalue:'[]', - subdelvalue:'[]', - subupdatevalue:subupdatavalue, - flag:'mod' - }, - dataType:'text' , //服务器返回时接收的数据类型 - success:function(result){ - if (result=="OK"){ - alert('确认成功!'); - if (xgcwvalue!=''){ - var subupdatevaluexgcw = "["+xgcwvalue+"]"; - //alert(subupdatevaluexgcw); - saveupdatecw('xg_cw',subupdatevaluexgcw); - } - setywwcqty(); - //$(":button[tag*='"+3+"']").attr("disabled","disabled"); - //$('#btn_updatecon').removeAttr("disabled"); - // $('#btn_delcon').removeAttr("disabled"); - loaddata('buyinform','v_xg_buyin',strid,'main'); - // $('#btn_sh').attr('disabled','disabled'); - //$('#btn_createcon').attr('disabled','disabled'); - var formobj=app.serializeObject2($('#buyinform')); - delete formobj["bcheck"]; - oldformjson=app.jsonToString(formobj); - loaddata_detail_sub('subgrid','v_xg_buyin_sub',strid,''); - gridrows=$('#subgrid').datagrid('getData').firstRows || []; - subgridjson=app.jsonToString(gridrows); - }else{ - alert(result); - } - } , - error:function(result){ - } - }); - } - - - function saveupdatecw(table,subupdatevalue){ - //alert(subupdatevalue); - $.ajax({ - type : 'post', - url : 'jsp/savesubdata.jsp', - cache : false, - data : { - subtable: table, - subinsertvalue: '[]', - subdelvalue: '[]', - subupdatevalue: subupdatevalue - }, - dataType : 'text', - success : function(result) { - - //alert('更新箱号成功!'); - }, - error : function(result) { } - }); - } - - function savesubtable(rowsjson){ - var sresult=''; - $.ajax({ - type : 'post', - url : 'jsp/savesubtable.jsp', - cache : false, - async : false, - data : { - subtable:'xg_buyin_sub', - subinsertvalue:'[]', - subdelvalue:'[]', - subupdatevalue:rowsjson, - father:'' - }, - dataType : 'text', - success : function(result) { - sresult = result; - }, - error : function(result) { - } - - }); - return sresult; - } - - - function canupdateconno(keyid,conno){ - var sstate=getfieldvaluebyid('v_xg_constate', 'b_state', 'b_id', keyid); - if (sstate!='可用'){ - alert('key值:'+keyid+'的箱子当前状态为:'+sstate+',不能更新箱号'); - return false; - } - var tmpjson=loaddatas('v_xg_constate', "mx_conno='"+conno+"' and v_constate not in('卖箱出库','还箱退租')", 'b_id', ''); - //var skeyid=getfieldvaluebyid('xg_container', 'b_id', 'b_conno', conno); - if (tmpjson.length>0) - if (tmpjson[0].b_id!=keyid){ - alert('箱号:'+conno+'箱池里已经存在,不能输入重复的箱号!'); - return false; - } - return true; - } - - function updateconno(){ - endEditing_sub(); - var rows1=[]; - var subvalue = ""; - var rows=$('#subgrid').datagrid('getChecked'); - - //alert(rows.length); - // alert(app.jsonToString(rows)); - if (rows.length<=0){ - alert('请选择要更新箱号的箱子'); - return; - } - if (!canitemidexists()){ - //alert('箱号有重复,不能更新箱池!'); - return; - } - //var rows=$('#subgrid').datagrid('getRows'); - for (var i = 0; i < rows.length; i++) { - if (!canupdateconno(rows[i].mx_keyid,rows[i].mx_conno)){ - return; - } - if (subvalue!=''){ - subvalue+=','; - } - subvalue = subvalue+"{mx_conno:'" + rows[i].mx_conno+ - //"',:'" + rows[i].+ - "',subid:'" + rows[i].subid+ - "'}" - } - - var subdelvalue = "["+subvalue+"]"; - $.ajax({ - type : 'post', - url : 'jsp/savesubdata.jsp', - cache : false, - data : { - subtable: 'xg_buyin_sub', - subinsertvalue: '[]', - subdelvalue: '[]', - subupdatevalue: subdelvalue - }, - dataType : 'text', - success : function(result) { - loaddata_detail_sub('subgrid','v_xg_buyin_sub',strid,''); - gridrows=$('#subgrid').datagrid('getData').firstRows || []; - subgridjson=app.jsonToString(gridrows); - alert('更新箱号成功!'); - }, - error : function(result) { + + + function calcw() { + var t_ysrmb = 0, t_ysusd = 0, ysrmb = 0, ysusd = 0, sel_srmb = 0, sel_susd = 0; + var t_yfrmb = 0, t_yfusd = 0, yfrmb = 0, yfusd = 0, sel_frmb = 0, sel_fusd = 0; + + var moneyArray = []; + var data = $('#feegrid').datagrid('getRows'); + var amount_ze_ys = 0; + var amount_ze_yf = 0; + var amount_tax_ys = 0; + var amount_tax_yf = 0; + for (i in data) { + var amount_ys = 0; + var amount_yf = 0; + canadd = true; + if (data[i].mx_type_id == '应收') { + amount_ys = Number(data[i].mx_amount_root); + amount_ze_ys = Number(amount_ze_ys) + Number(data[i].mx_amount); + // amount_tax_ys=Number(amount_tax_ys)+Number(data[i].v_ivtaxamount); + } + if (data[i].mx_type_id == '应付') { + amount_yf = Number(data[i].mx_amount_root); + amount_ze_yf = Number(amount_ze_yf) + Number(data[i].mx_amount); + // amount_tax_yf=Number(amount_tax_yf)+Number(data[i].v_ivtaxamount); + } + for (var k in moneyArray) { + if (moneyArray[k].moneyname == data[i].mx_moneytype_id) { + moneyArray[k].amount_ys = moneyArray[k].amount_ys + amount_ys; + moneyArray[k].amount_yf = moneyArray[k].amount_yf + amount_yf; + var canadd = false; + } + } + if (canadd) { + if (data[i].mx_moneytype_id != '') { + moneyArray.push({ + moneyname: data[i].mx_moneytype_id, + // v_moneyname: data[i].v_mx_moneytype_name, + amount_ys: amount_ys, + amount_yf: amount_yf, + }) + } + } + } + var tmp_ys_total = ''; + var tmp_yf_total = ''; + var tmp_ys_dz = ''; + var tmp_yf_dz = ''; + var tmp_ys_sel = ''; + var tmp_yf_sel = ''; + var tmp_zd_total_c = ''; + //=====数组排序------ + for (var j = 0; j < moneyArray.length - 1; j++) { + //两两比较,如果前一个比后一个大,则交换位置。 + for (var i = 0; i < moneyArray.length - 1 - j; i++) { + var beginstr = moneyArray[i].moneyname; + var laststr = moneyArray[i + 1].moneyname; + if (beginstr > laststr) { + var temp = moneyArray[i]; + moneyArray[i] = moneyArray[i + 1]; + moneyArray[i + 1] = temp; + } + } + } + for (var i in moneyArray) { + tmp_ys_total = tmp_ys_total + '
' + moneyArray[i].moneyname + ':' + + '' + Math.round(Number(moneyArray[i].amount_ys) * 100) / 100 + '
'; + tmp_yf_total = tmp_yf_total + '
' + moneyArray[i].moneyname + ':' + + '' + Math.round(Number(moneyArray[i].amount_yf) * 100) / 100 + '
'; + tmp_zd_total_c = tmp_zd_total_c + '
' + moneyArray[i].moneyname + ':' + + '' + Math.round(Number(Number(moneyArray[i].amount_ys) - Number(moneyArray[i].amount_yf)) * 100) / 100 + + '
'; + } + document.getElementById('ys_total').innerHTML = tmp_ys_total; + document.getElementById('yf_total').innerHTML = tmp_yf_total; + document.getElementById('lr_total').innerHTML = tmp_zd_total_c; + + var ze_ys = '
' + + '' + Math.round(Number(amount_ze_ys) * 100) / 100 + '
'; + document.getElementById('ys_amount').innerHTML = ze_ys; + + var ze_yf = '
' + + '' + Math.round(Number(amount_ze_yf) * 100) / 100 + '
'; + document.getElementById('yf_amount').innerHTML = ze_yf; + + var mlamount = Number(Math.round((Number(amount_ze_ys) - Number(amount_ze_yf)) * 100) / 100); + var tmp_ze = '
' + + '' + mlamount + '
'; + document.getElementById('lr_amount').innerHTML = tmp_ze; } - }); - } - - - function saveupdatesub(subupdatevalue){ - $.ajax({ - type : 'post', - url : 'jsp/savesubdata.jsp', - cache : false, - data : { - subtable: 'xg_buyin_sub', - subinsertvalue: '[]', - subdelvalue: '[]', - subupdatevalue: subupdatevalue - }, - dataType : 'text', - success : function(result) { - loaddata_detail_sub('subgrid','v_xg_buyin_sub',strid,''); - gridrows=$('#subgrid').datagrid('getData').firstRows || []; - subgridjson=app.jsonToString(gridrows); - //alert('更新箱号成功!'); - }, - error : function(result) { + + + function SetLabelUSD() { + $('#lab_ysusd').text('应收美金'); + $('#lab_yfusd').text('应付美金'); + $('#lab_lrusd').text('美金利润'); } - }); - } - - - function delconno() { - var rows = $('#subgrid').datagrid('getChecked'); - if (rows.length<=0){ - alert('请选择需要撤删的箱子'); - return; - }; - //var rows=$('#subgrid').datagrid('getRows'); - var irow=rows.length; - var subvalue = ""; - var rows1=[]; - $.messager.confirm("操作提示", '您确定要撤删选中的箱子吗?', function (r) { - if (!r) { - return false; - } - else{ - //alert(selectedrows.length); - for (i = 0; i < irow; i++) { - var keyid=rows[i].mx_keyid; - var searchsql=" father='"+strid+"' and ='" +keyid+ "' and mx_hstype_id='买箱入库'"; - //alert(searchsql); - var modrows=loaddatas('xg_cw', searchsql, '', ''); - if(modrows.length>0){ - alert('请先删除该箱子下的费用!'); - return - } - var searchsql=" ='" +keyid+ "' "; - //alert(searchsql); - var modrows=loaddatas('xg_buyout_sub', searchsql, '', ''); - if(modrows.length>0){ - alert('该箱子已使用,不能撤删!'); - return - } - var searchsql=" ='" +keyid+ "' "; - //alert(searchsql); - var modrows=loaddatas('bs_business_container', searchsql, '', ''); - if(modrows.length>0){ - alert('该箱子已使用,不能撤删!'); - return - } - } - for (i = 0; i < irow; i++) { - if (subvalue!=''){ - subvalue+=','; - } - subvalue = subvalue+"{:'" + rows[i].mx_keyid+ - "',subid:'" + rows[i].subid+ - "'}" - } - var subdelvalue = "["+subvalue+"]"; - $.ajax({ - type : 'post', - url : 'jsp/savesubdata.jsp', - cache : false, - data : { - subtable: 'xg_buyin_sub', - subinsertvalue: '[]', - subdelvalue: subdelvalue, - subupdatevalue: '[]' - }, - dataType : 'text', - success : function(result) { - loaddata_detail_sub('subgrid','v_xg_buyin_sub',strid,''); - gridrows=$('#subgrid').datagrid('getData').firstRows || []; - subgridjson=app.jsonToString(gridrows); - alert('撤删成功'); - var rows=$('#subgrid').datagrid('getRows'); - if (rows.length<=0){ - updatefieldvaluebyid('xg_buyin','b_state','草拟','b_id',$('#b_id').val()); - $('#b_state').val('草拟'); - var formobj=app.serializeObject2($('#buyinform')); - delete formobj["bcheck"]; - oldformjson=app.jsonToString(formobj); - $('#btn_delcon').attr('disabled','disabled'); - $('#btn_updatecon').attr('disabled','disabled'); - $(":button[tag*='"+3+"']").removeAttr("disabled"); - $('#btn_save').removeAttr("disabled"); - } - }, - error : function(result) { + + + function calculateAmount(rowIndex) { + //alert('calculateAmount'); + + var priceEditor = $('#feegrid').datagrid('getEditor', { + index: rowIndex, + field: 'mx_price' + }); + var qtyEditor = $('#feegrid').datagrid('getEditor', { + index: rowIndex, + field: 'mx_qty' + }); + var amountEditor = $('#feegrid').datagrid('getEditor', { + index: rowIndex, + field: 'mx_amount_root' + }); + var exrateEditor = $('#feegrid').datagrid('getEditor', { + index: rowIndex, + field: 'mx_exrate' + }); + var amountrmbEditor = $('#feegrid').datagrid('getEditor', { + index: rowIndex, + field: 'mx_amount' + }); + var strprice = priceEditor.target.val(); + var strqty = qtyEditor.target.val(); + var x = /^(\+|-)?\d+($|\.\d+$)/; + if (!x.test(strprice)) { + //priceEditor.target.val('0'); + strprice = 0; + priceEditor.target.val(0); + } + if (!x.test(strqty)) { + //qtyEditor.target.val('0'); + strqty = 0; + qtyEditor.target.val(0); + } + var cost = strprice * strqty; + //priceEditor.target.val() * qtyEditor.target.val(); + amountEditor.target.val(cost); + var amountrmb = cost * exrateEditor.target.val(); + amountrmbEditor.target.val(amountrmb); + calcw(); + + } + + function onClickRow_fee(index, row) { + if (row.mx_sh == '1' || row.alreadyamount > 0) { + //alert('12321'); + //$('#feegrid').datagrid('getEditor', {index: index, field:'mx_sh'}).target.attr("readonly",true); + return; + } + // if (editIndex_fee != index){ + if (endEditing_fee()) { + $('#feegrid').datagrid('beginEdit', index); + editIndex_fee = index; + setEditing(index); + } else { + $('#feegrid').datagrid('selectRow', editIndex_fee); + } + // } + + } + function onClickRow_sub(index, row) { + /*if (endEditing_sub()) { + $('#subgrid').datagrid('beginEdit', index); + editIndex_sub = index; + //setEditing_sub(index); + } else { + $('#subgrid').datagrid('selectRow', editIndex_sub); + }*/ + + loaddata_detail_feesuo('feegridsuo', 'v_xg_buyin_cw', strid, row.subid, row.mx_keyid, ''); + } + + function showfee(i) { + /*if (endEditing_sub()) { + $('#subgrid').datagrid('beginEdit', index); + editIndex_sub = index; + //setEditing_sub(index); + } else { + $('#subgrid').datagrid('selectRow', editIndex_sub); + }*/ + var e = window.event || e; + if (e.stopPropagation) { + e.stopPropagation(); //阻止事件 冒泡传播 + } + var index = $(i).parents("tr:first").attr("datagrid-row-index"); + index = parseInt(index); + console.log(index); + var row = $('#subgrid').datagrid('getRows')[index]; + //console.log(row); + + loaddata_detail_feesuo('feegridsuo', 'v_xg_buyin_cw', strid, row.subid, row.mx_keyid, ''); } - }); - } - }); - } - - function showAllcw(){ - if (!document.getElementById("b_id").readOnly){ - savealert('请先保存数据!'); - return; - } - if (checkchange()){ - savealert('请先保存数据!'); - return; - } - var iread=''; - var ifreadonly=document.getElementById("btn_save").disabled; - if (ifreadonly){ - iread='1'; - } - var keyid = ''; - var conno =''; - var Fxh = ''; - var subid=''; - var strid=$('#b_id').val(); - parent.$('
').dialog({ - title : '整单费用', - width : 850, - height : 570, - id:'viewbuydialog', - top : 80, - content : '', - modal : true, - onClose:function(){ - $(this).remove(); - }, - onBeforeClose: function (event, ui) { - var w=top.frames["cwdialog"]; - if (w.checkchange){ - if (w.checkchange()){ - w.$.sobox.pop({ - cls:'subsidy-box', - title:'远通提示', - width:320, - maskClick : false, - content:'
'+ - '
'+ - '
数据有更改,是否要保存?
'+ - '
'+ - '
', - btn:[ - {text:'是',callback:function () { - var s=w.saveData(); - if (s=='保存成功!'){ - //alert('close'); - mydialog=parent.$('#viewbuydialog'); - mydialog.window('destroy'); - return true; - } - } - }, - {text:'否',cls:'a-sopop-cancel',callback:function () { - mydialog=parent.$('#viewbuydialog'); - mydialog.window('destroy'); - return true; - - }}, - {text:'取消',cls:'a-sopop-cancel',callback:function () { - } - - }] - }) - }else{ - return true; - } - return false; - } - } - }); - } - function showcw(){ - var iread=''; - var ifreadonly=document.getElementById("btn_save").disabled; - if (ifreadonly){ - iread='1'; - } - //alert('000'); - if(strid == ""){ - alert('未保存数据'); - return; - } - var row = $('#subgrid').datagrid('getSelected'); - //alert('111'); - if (!row) return; - var conno =row.mx_conno; - var keyid=row.mx_keyid; - var subid=row.subid; - //subid=subid.replace('{',''); - //subid=subid.replace('}',''); - var Fxh=row.mx_xh; - if ((subid=='')||(subid==null)||(subid==undefined)){ - alert("请先保存!"); - return; - } - - parent.$('
').dialog({ - title : '费用录入', - width : 880, - height : 600, - id:'viewbuydialog', - top : 80, - resizable:true, - content : '', - modal : true, - onClose:function(){ - $(this).remove(); - }, - onBeforeClose: function (event, ui) { - var w=top.frames["cwdialog"]; - if (w.checkchange){ - if (w.checkchange()){ - w.$.sobox.pop({ - cls:'subsidy-box', - title:'远通提示', - width:320, - maskClick : false, - content:'
'+ - '
'+ - '
数据有更改,是否要保存?
'+ - '
'+ - '
', - btn:[ - {text:'是',callback:function () { - var s=w.saveData(); - if (s=='保存成功!'){ - //alert('close'); - mydialog=parent.$('#viewbuydialog'); - mydialog.window('destroy'); - return true; - } - } - }, - {text:'否',cls:'a-sopop-cancel',callback:function () { - mydialog=parent.$('#viewbuydialog'); - mydialog.window('destroy'); - return true; - - }}, - {text:'取消',cls:'a-sopop-cancel',callback:function () { - } - - }] - }) - }else{ - return true; - } - return false; - } - } - }); - } - function removeit_con() { - var checkedRows = $('#subgrid').datagrid('getChecked'); - if (checkedRows.length <= 0) return false; + function loaddata_detail_feesuo(gridname, viewname, strid, subid, conno, options) { + var strid = strid; + if (!subid) { + return + } + //var strtemp=getFeeLevelSQL(userid); + var ssubid = subid.replace('{', ''); + ssubid = subid.replace('}', ''); + var searchcondition = "father = '" + strid + "'" + " and (mx_linkfd_id='" + ssubid + "' or mx_linkfd_id='" + subid + "')"; + if (loginfee == '1') { + searchcondition = searchcondition + " and mx_feetype_id in (select b_feetype_id from b_user_feetype where b_user_id='" + userid + "')"; + } + //var searchcondition = "(father='" + strid + "') and "+strtemp+ "' and mx_linkcon_id= '"+ Fconsubid +"'"; + //alert(searchcondition); + $.ajax({ + type: 'post', + url: 'jsp/loaddata.jsp', + cache: false, + async: false, + data: { + soption: options, + searchcondition: searchcondition, + viewname: viewname, + orderfield: 'mx_xh' + }, + dataType: 'json', // 服务器返回时接收的数据类型 + success: function (result) { + $('#' + gridname).datagrid('loadData', result); + }, + error: function (result) { - $.messager.confirm("操作提示", "您确定要删除选中的数据吗?", function (r) { - if (!r) return false; + } - // 收集 subid 和 keyid - var usedSubids = new Set(); - var usedKeyids = new Set(); - var subids = [], keyids = []; + }); - checkedRows.forEach(row => { - if (row.subid) subids.push(row.subid.replace('{','').replace('}','')); - if (row.keyid) keyids.push(row.keyid); - }); - - // ====== 批量查询 ====== - if(subids.length > 0){ - var searchsql = " father='" + strid + "' and mx_hstype_id='买箱入库' " + - " and mx_linkfd_id in ('" + subids.join("','") + "')"; - var modrows = loaddatas('xg_cw', searchsql, '', ''); - modrows.forEach(r => usedSubids.add(r.mx_linkfd_id)); - } - - if(keyids.length > 0){ - var searchsql1 = " mx_keyid in ('" + keyids.join("','") + "') "; - var modrows1 = loaddatas('xg_buyout_sub', searchsql1, '', ''); - var modrows2 = loaddatas('bs_business_container', searchsql1, '', ''); - modrows1.concat(modrows2).forEach(r => usedKeyids.add(r.mx_keyid)); - } - - // ====== 处理删除 ====== - let canDelete = true; - for (let row of checkedRows) { - let subid = row.subid ? row.subid.replace('{','').replace('}','') : null; - let keyid = row.keyid; - - if (subid && usedSubids.has(subid)) { - alert('请先删除该箱子下的费用!'); - canDelete = false; - break; // 一旦有不允许删除的行,停止检查 - } - - if (keyid && usedKeyids.has(keyid)) { - alert('该箱子已使用,不能撤删!'); - canDelete = false; - break; - } - } - - if (!canDelete) return; // 有问题,不删除任何行 - - // 获取 firstRows - var allData = $('#subgrid').datagrid('getData').firstRows || []; - console.log("firstRows:", allData); - -// 打印选中的行 - console.log("checkedRows:", checkedRows); - -// 根据 mx_xh 找索引 - let indexesToDelete = []; - for (let i = 0; i < allData.length; i++) { - for (let row of checkedRows) { - if (allData[i].mx_xh === row.mx_xh) { - indexesToDelete.push(i); - console.log("匹配到 mx_xh:", row.mx_xh, "索引:", i); - break; - } - } - } - - // 打印准备删除的索引数组 - console.log("indexesToDelete(倒序前):", indexesToDelete); - - // 倒序删除,避免索引错乱 - indexesToDelete.sort((a, b) => b - a).forEach(index => { - console.log("删除索引:", index, "数据:", allData[index]); - $('#subgrid').datagrid('deleteRow', index); - }); - - // 清空选中 - $('#subgrid').datagrid('clearChecked'); - editIndex_sub = undefined; - - }); - } + } - function insertyf(){ - if (checkchange()){ - alert('请先保存,再来导入应付费用!'); - return; - } - var Fbsno=$('#b_id').val(); - var Fdwid=$('#b_customer_id').val(); - var Famount=$('#b_amount').val(); - var Fmoney=$('#b_money_id').val(); - /*if ((Fdwid== '')||(Fmoney== '')||(Famount==0)){ - alert('请选填箱公司、单价、币种后,再来导入应付费用!'); - return; - } */ - - /* var rows = $('#subgrid').datagrid('getChecked'); - if (rows.length<=0){ - var rows=$('#subgrid').datagrid('getRows'); - //return false; - }; */ - //alert(irow); - var rows = $('#subgrid').datagrid('getData').firstRows || []; - var irow = $('#subgrid').datagrid('getData').firstRows || [].length; - for (i = 0; i < irow; i++) { - var subid=rows[i].subid; - // alert(keyid); - if ((subid=='')||(subid==null)||(subid==undefined)){ - alert("请先保存!"); - return; - } - } - - var selarray = new Array(); - var rows = $('#subgrid').datagrid('getChecked'); - //alert(rows.length); - for (var i = rows.length-1; i>=0; i--){ - //for (var i = 0; i <= irow-1; i++){ - if (rows[i].subid!=''){ - selarray.push("'"+rows[i].subid+"'");} - } - var sselarray=selarray.join(","); - var query = {selrows: selarray}; - var keyID='xginsertfee_data'+generateUID(); - localStorage.setItem(keyID, JSON.stringify(query)); - - var datadialog = parent.$('
').dialog({ - title : '费用导入操作', - width : 410, - height :280, - id:'cwdialog', - cache: false, - closeOnEscape: false, - // closable:true, - autoOpen: false, - top : 200, - //resizable:true, - content : '', - modal : true, - onClose:function(){ - $(this).remove(); - loaddata_detail_sub('subgrid','v_xg_buyin_sub',strid,''); - gridrows=$('#subgrid').datagrid('getData').firstRows || []; - subgridjson=app.jsonToString(gridrows); - $('#subgrid').datagrid('unselectAll'); - $('#subgrid').datagrid('uncheckAll'); - // loaddata(Fsubid); - // DoSearch(); - //alert('111'); - //getxzamount(); - } - }); - - } - - - function createcon_pl(){ - if (checkchange()){ - alert('请先保存,再来批量生成箱子!'); - return; - } - if (document.getElementById("b_id").readOnly){ - }else{ - alert('请先保存,再来批量生成箱子!'); - return; - } - var Fbsno=$('#b_id').val(); - var Fdwid=$('#b_customer_id').val(); - var Famount=$('#b_amount').val(); - var Fmoney=$('#b_money_id').val(); - var selarray = new Array(); - var sselarray=selarray.join(","); - var datadialog = parent.$('
').dialog({ - title : '批量生成操作', - width : 450, - height :340, - id:'cwdialog', - cache: false, - closeOnEscape: false, - // closable:true, - autoOpen: false, - top : 200, - //resizable:true, - content : '', - modal : true, - onClose:function(){ - $(this).remove(); - loaddata_detail_sub('subgrid','v_xg_buyin_sub',strid,''); - gridrows=$('#subgrid').datagrid('getData').firstRows || []; - subgridjson=app.jsonToString(gridrows); - $('#subgrid').datagrid('unselectAll'); - $('#subgrid').datagrid('uncheckAll'); - // loaddata(Fsubid); - // DoSearch(); - //alert('111'); - //getxzamount(); - } - }); - - } - - - - - - - function showattach(o){ - var e = window.event || e; - if (e.stopPropagation) { - e.stopPropagation(); //阻止事件 冒泡传播 - } - var selindex = $(o).attr('attr1'); - var gridid='subgrid'; - var rows=$("#"+gridid).datagrid("getRows"); - var row=rows[selindex]; - if(row.mx_conno!='' && row.mx_conno!=undefined){ - getattachfile(row.mx_conno,'xg_containerlib_files',0); - }else{ - alert('请确认箱号!'); - } - } - // var gridname = 'subgrid'; - // var $gridbody = $('#' + gridname).datagrid('getPanel').find('.datagrid-body'); - // $gridbody.on('paste', myevent); + function removeitfee(o) { + var e = window.event || e; + if (e.stopPropagation) { + e.stopPropagation(); //阻止事件 冒泡传播 + } + // var selindex = $(o).attr('attr1'); + // let editIndex=Number(curindex) + 1; + // var gridid = 'feegrid'; - // var input = document.getElementById('auto_sub'); - // input.addEventListener('paste', myevent); + var selid = $(o).attr('attr1'); + var selindex = $("#feegrid").datagrid('getRowIndex', selid); + var curindex = $("#feegrid").datagrid('getRows').length; + if ($("#feegrid").datagrid('getRows')[selindex].alreadyamount == 0) { + $.messager.confirm("操作提示", '您确定要删除选中的数据吗?', function (r) { + if (!r) { + return false; + } else { + $("#feegrid").datagrid('deleteRow', selindex); + $("#feegrid").datagrid('options').editIndex = undefined; + let rows = $("#feegrid").datagrid('getRows'); + for (var i = selindex; i < rows.length; i++) { + rows[i].mx_xh = Number(i) + 1; + } + $("#feegrid").datagrid('loadData', rows); + // computeFooter_fee(); + if (curindex <= 1) { + $('#feegrid').datagrid('appendRow', { + mx_level: 1, + //mx_type_id : '应收', + mx_hstype_id: '买箱入库', + mx_xh: 1, + mx_intputman_id: userid, + mx_inputdate: getnowdate(), + alreadyamount: 0, + notamount: 0, + }); + editIndex_fee = curindex - 1; + //alert(editIndex_fee); + $('#feegrid').datagrid('beginEdit', editIndex_fee); + } + } + }); + } + } + function addfee(o) { + var e = window.event || e; + if (e.stopPropagation) { + e.stopPropagation(); //阻止事件 冒泡传播 + } - function myevent(event) { - event.preventDefault(); + var gridid = 'feegrid'; + if (endEditing_fee()) { + var curindex = $(o).attr('attr1'); + let editIndex = Number(curindex) + 1; + let irow = $('#feegrid').datagrid('getRows').length; + if (editIndex >= irow) { + $('#feegrid').datagrid('appendRow', { + mx_xh: Number(curindex) + 1, + mx_level: 1, + //mx_type_id : '应收', + mx_hstype_id: '买箱入库', + mx_intputman_id: userid, + mx_inputdate: getnowdate(), + alreadyamount: 0, + notamount: 0, + }); + } else { + $('#feegrid').datagrid('insertRow', { + index: editIndex, + row: { + mx_xh: Number(curindex) + 1, + mx_level: 1, + //mx_type_id : '应收', + mx_hstype_id: '买箱入库', + mx_intputman_id: userid, + mx_inputdate: getnowdate(), + alreadyamount: 0, + notamount: 0, + } + }); + } + let rows = $('#feegrid').datagrid('getRows'); + for (var i = editIndex; i < rows.length; i++) { + rows[i].mx_xh = Number(i) + 1; + } + $('#feegrid').datagrid('loadData', rows); + $('#feegrid').datagrid('selectRow', editIndex).datagrid('beginEdit', editIndex); + $('#feegrid').datagrid('options').editIndex = editIndex; + editIndex_fee = editIndex; + } + } + function append_fee() { + if (endEditing_fee()) { + editIndex_fee = $('#feegrid').datagrid('getRows').length; + $('#feegrid').datagrid('appendRow', { + mx_xh: editIndex_fee + 1, + mx_level: 1, + //mx_type_id : '应收', + mx_hstype_id: '买箱入库', + mx_intputman_id: userid, + mx_inputdate: getnowdate(), + alreadyamount: 0, + notamount: 0, + }); - var clipboardData = (event.originalEvent || event).clipboardData; - if (!clipboardData) return; - var gridname = 'subgrid'; - var $grid = $('#' + gridname); - // 获取当前聚焦的列 field - var opts = $grid.datagrid('getColumnFields'); - var fieldname_zx = ''; - var colopts = []; + $('#feegrid').datagrid('beginEdit', editIndex_fee); + } + } - for (var j = 0; j < opts.length; j++) { - var editor = $grid.datagrid('getEditor', { index: editIndex_sub, field: opts[j] }); - if (editor && editor.target.is(':focus')) { - fieldname_zx = opts[j]; // 找到聚焦列 - } + function append_con() { + var contype = $('#b_contype').val(); + var Fdate = ''; + if (orgid != 'shltpn') { + Fdate = $('#b_date').val(); + } - var opt = $grid.datagrid('getColumnOption', opts[j]); - if (!opt.hidden) { - colopts.push(opts[j]); // 可见列 - } - } + if (endEditing_sub()) { + var newRow = { + mx_type: '买箱入库', + mx_contype: contype, + mx_xh: getguid(), + mx_xk: $('#b_xk').val(), + mx_xz: '是', + mx_date: $('#b_date').val(), + mx_zxdate: Fdate, + mx_city_id: $('#b_city_id').val(), + v_mx_city_name: $('#v_cityname').val(), + mx_atwhere: $('#b_atwhere').val(), + v_mx_atwhere_name: $('#v_b_atwhere_name').val(), + mx_txid: $('#b_txid').val() + }; + allRows.push(newRow); + $('#subgrid').datagrid('loadData', allRows); - // 根据 fieldname_zx 找列索引 - var colIndex = -1; - if (fieldname_zx) { - for (var k = 0; k < colopts.length; k++) { - if (colopts[k] === fieldname_zx) { - colIndex = k; - break; - } - } - } + let newIndex = allRows.length - 1; - // 获取当前行索引 - var selrow = $grid.datagrid('getSelected'); - var rowIndex = $grid.datagrid('getRowIndex', selrow); - if (colIndex === -1 || rowIndex === undefined || rowIndex < 0) { - $.messager.alert('提示', '请先点击要粘贴的单元格!'); - return; - } + $('#subgrid').datagrid('selectRow', newIndex); + $('#subgrid').datagrid('beginEdit', newIndex); + editIndex_sub = newIndex; + $('#subgrid').datagrid('scrollTo', newIndex); + } + } - // 获取原始 ClipboardEvent - var clipboardData = event.originalEvent.clipboardData; - if (!clipboardData) return; - var data = clipboardData.getData('Text'); - // 分行并过滤空行(避免最后多插入空行) - var datas = data.split("\n").filter(line => line.trim() !== ""); - // 檢查 - let allRows = $grid.datagrid('getData').firstRows || [] - var selrow = allRows[rowIndex]; + function setxh_fee1() { + var i = 0; + var rows = $("#feegrid").datagrid("getRows"); + var irow = $("#feegrid").datagrid("getRows").length; + //alert(irow); + for (i = 0; i < irow; i++) { + $('#feegrid').datagrid('updateRow', { + index: i, + row: { + mx_xh: i + 1 + } + }); + $('#feegrid').datagrid('refreshRow', i); - if(selrow && selrow.v_checkyx && selrow.v_checkyx === '是'){ - $.messager.alert('提示', '箱号:' + (selrow.mx_conno || '') + ',已使用,不可修改!'); - return; - } + }; + } - // 提示 - $.messager.progress({ title: '导入中', msg: '请稍候...' }); + function setxh_fee() { + var i = 0; + var rows = $("#feegrid").datagrid("getRows"); + var irow = $("#feegrid").datagrid("getRows").length; + for (i = 0; i < irow; i++) { + $('#feegrid').datagrid('beginEdit', i); + editIndex_fee = i; + $('#feegrid').datagrid('getEditor', { + index: i, + field: 'mx_xh' + }).target.val(i + 1); + endEditing_fee(); + } + } - // ------------------------------ - // 5️⃣ 构建 Worker 处理粘贴逻辑 - // ------------------------------ - var workerCode = ` + function insert_fee() { + var index; + if (editIndex_fee == undefined) { + var row = $('#feegrid').datagrid('getSelected'); + if (!row) { + return + }; + index = $('#feegrid').datagrid('getRowIndex', row); + } else { + index = editIndex_fee; + } + + if (endEditing_fee()) { + $('#feegrid').datagrid('insertRow', { + index: index, + row: { + mx_xh: index + 1, + mx_level: 1, + //mx_type_id : '应收', + mx_hstype_id: '买箱入库', + mx_intputman_id: userid, + mx_inputdate: getnowdate() + } + }); + //setxh_fee(); + $('#feegrid').datagrid('selectRow', index).datagrid('beginEdit', index); + editIndex_fee = index; + } + } + + function insert_con() { + var index; + if (editIndex_sub == undefined) { + var row = $('#feegrid').datagrid('getSelected'); + if (!row) { + return + }; + index = $('#subgrid').datagrid('getRowIndex', row); + } else { + index = editIndex_sub; + } + + if (endEditing_sub()) { + $('#subgrid').datagrid('insertRow', { + index: index, + row: { + mx_type: '买箱入库', + mx_date: $('#b_date').val() + } + }); + + $('#subgrid').datagrid('selectRow', index).datagrid('beginEdit', index); + editIndex_sub = index; + } + } + + function copyrecord_fee() { + var rows = $('#feegrid').datagrid('getSelected'); + if (!rows) { + return + }; + var index = $('#feegrid').datagrid('getRowIndex', rows); + index = index + 1; + var rowsjson = app.jsonToString(rows); + var obj = eval('(' + rowsjson + ')'); + delete obj["subid"]; + if (endEditing_fee()) { + $('#feegrid').datagrid('insertRow', { index: index, row: obj }); + $('#feegrid').datagrid('selectRow', index).datagrid('beginEdit', index); + editIndex_fee = index; + } + $('#feegrid').datagrid('selectRow', index).datagrid('beginEdit', index); + editIndex_fee = index; + } + + + + function mx_shClick(o) { + var index = $(o).attr('rowIndex'); + if (editIndex_fee) + $('#feegrid').datagrid('endEdit', editIndex_fee); + $('#feegrid').datagrid('options').onBeginEdit = function () { + return; + }; + $('#feegrid').datagrid('beginEdit', index); + editIndex_fee = index; + canedit = '1'; + if (!$(o).get(0).checked) { + $('#feegrid').datagrid('getEditor', { + index: index, + field: 'mx_sh' + }).target.prop("checked", false); + $('#feegrid').datagrid('getEditor', { + index: index, + field: 'mx_shman_id' + }).target.val(''); + $('#feegrid').datagrid('getEditor', { + index: index, + field: 'mx_shdate' + }).target.val(''); + } else { + $('#feegrid').datagrid('getEditor', { + index: index, + field: 'mx_sh' + }).target.prop("checked", true); + $('#feegrid').datagrid('getEditor', { + index: index, + field: 'mx_shman_id' + }).target.val(userid); + $('#feegrid').datagrid('getEditor', { + index: index, + field: 'mx_shdate' + }).target.val(getnowdate()); + } + $('#feegrid').datagrid('endEdit', editIndex_fee); + $('#feegrid').datagrid('options').onBeginEdit = onBeginEdit_fee; + + } + + function removeit_fee() { + var selectedrows = $('#feegrid').datagrid('getChecked'); + if (selectedrows.length <= 0) { + return false; + }; + $.messager.confirm("操作提示", '您确定要删除选中的数据吗?', function (r) { + if (!r) { + return false; + } + else { + var hassh = false; + for (i = selectedrows.length - 1; i >= 0; i--) { + if (selectedrows[i].mx_sh == '1') { + hassh = true; + } else { + $('#feegrid').datagrid('deleteRow', $('#feegrid').datagrid('getRowIndex', selectedrows[i])); + } + } + if (hassh) + alert('已经审核的费用不能删除'); + //setxh_fee2(); + editIndex_fee = undefined; + } + }); + } + + + + function selecthistory() { + //alert('111'); + if ($('#b_customer_id').val() == '') { + alert('请先选定委托单位,再来选择业务费用!'); + return; + } + var sparams = new Array(); + var desgrid = "feegrid"; + var selectid = "hishtcw_bsys"; + var moduleid = "bs_ht"; + var userid = ""; + var parentfrm = self.name; + var options = "{mx_date:'" + getnowdate() + "',mx_user_id:'" + "'}"; + // alert(options); + + sparams.push($('#b_customer_id').val()); + //sparams.push("ZHOUSHANPENGXIANG"); + var psparams = sparams.join(","); + var url = "jselectdialog/dataSelectMuti.jsp?parentfrm=" + parentfrm + + "&desgrid=" + desgrid + "&selectid=" + selectid + "&moduleid=" + + moduleid + "&psparams=" + psparams + "&userid=" + userid + + "&options=" + options; + + var datadialog = parent.$('
').dialog({ + title: '数据选取', + width: 888, + height: 500, + // left:50, + top: 50, + onClose: function (event, ui) { + updatehl(); + }, + content: '', + modal: true + }); + } + + + function showxzmod() { + var row = $('#feegrid').datagrid('getSelected'); + var url; + if (row != undefined) { + if (row.mx_type_id == '应付') { + url = "jcw/payxzmod.jsp?businessid=" + row.subid; + } else if (row.mx_type_id == '应收') { + url = "jcw/receivexzmod.jsp?businessid=" + row.subid; + } + if (url != undefined) { + var datadialog = parent.$('
').dialog({ + title: '销账明细', + width: 640, + height: 400, + content: '', + modal: true + }); + } + } + } + + function loaddata_detail_fee(gridname, viewname, strid, options) { + var strid = strid; + var strtemp = getFeeLevelSQL(userid); + var searchcondition = "(father='" + strid + "') and " + strtemp; + $.ajax({ + type: 'post', + url: 'jsp/loaddata.jsp', + cache: false, + async: false, + data: { + soption: options, + searchcondition: searchcondition, + viewname: viewname, + orderfield: 'mx_xh' + }, + dataType: 'json', // 服务器返回时接收的数据类型 + success: function (result) { + $('#' + gridname).datagrid('loadData', result); + }, + error: function (result) { + + } + }); + } + + function loaddata_detail_sub(gridname, viewname, strid, options) { + var strid = strid; + + var searchcondition = "(father='" + strid + "') "; + $.ajax({ + type: 'post', + url: 'jsp/loaddata.jsp', + cache: false, + async: false, + data: { + soption: options, + searchcondition: searchcondition, + viewname: viewname, + orderfield: 'mx_xh' + }, + dataType: 'json', // 服务器返回时接收的数据类型 + success: function (result) { + subgridRows = result + subgridjson = app.jsonToString(subgridRows) + + var $grid = $('#' + gridname); + $grid.datagrid('loadData', result); + + $('#subgrid').datagrid('clearSelections'); + $('#subgrid').datagrid('clearChecked'); + }, + error: function (result) { + + } + }); + } + + function savecolumn_con() { + saveColumn('subgrid', 'v_xg_buyin_sub'); + } + + function savecolumn_fee() { + saveColumn('feegrid', 'v_xg_buyin_cw'); + } + + function createcon() { + var qty = parseInt($('#b_qty').val()); + if ($('#b_qty').val() == '' || $('#b_contype').val() == '' || $('#v_b_atwhere_name').val() == '' || $('#b_xk').val() == '') { + alert('数量、箱型、箱况或堆场为空,请检查!'); + return; + } + + var allRows = subgridRows; + var irow = allRows.length; + + var contype = $('#b_contype').val(); + var Fdate = ''; + if (orgid != 'shltpn') { + Fdate = $('#b_date').val(); + } + + for (var i = irow; i < qty; i++) { + allRows.push({ + mx_contype: contype, + mx_xh: getguid(), + mx_xk: $('#b_xk').val(), + mx_xz: '是', + mx_type: '买箱入库', + mx_zxdate: Fdate, + mx_city_id: $('#b_city_id').val(), + v_mx_city_name: $('#v_cityname').val(), + mx_atwhere: $('#b_atwhere').val(), + v_mx_atwhere_name: $('#v_b_atwhere_name').val(), + mx_txid: $('#b_txid').val() + }); + } + + // 更新 datagrid + $('#subgrid').datagrid('loadData', allRows); + $('#subgrid').datagrid('scrollTo', allRows.length - 1); + } + + function canitemidexists() { + var arritem = []; + var canuse = true; + var conno = '' + for (var i = 0; i < subgridRows.length; i++) { + var mxitemid = subgridRows[i].mx_conno; + //alert(mxitemid); + if ((mxitemid == '') || (mxitemid == undefined)) { + continue; + //canuse = false; + //break; + } + if (arritem.indexOf(mxitemid) > -1) { + if (conno != '') { + conno = conno + ";"; + } + conno = conno + mxitemid; + //canuse = false; + continue; + } + arritem.push(mxitemid); + }; + if (conno != '') { + conno = conno + ";"; + alert("箱号:" + conno + "有重复,不能保存"); + canuse = false; + } + + return canuse; + } + + /*function canitemidexists(){ + var itemrows = $('#subgrid').datagrid('getRows'); + var irow = itemrows.length; + var arritem=[]; + var canuse=true; + var conno='' + for (var i = 0; i < irow; i++) { + var mxitemid=itemrows[i].mx_conno; + //alert(mxitemid); + if((mxitemid=='')||(mxitemid==undefined)){ + continue; + //canuse = false; + //break; + } + if(arritem.indexOf(mxitemid)>-1){ + canuse = false; + break; + } + arritem.push(mxitemid); + }; + return canuse; + }*/ + + + function createconno() { + if (checkchange()) { + alert('请先保存,再生成系统箱号!'); + return; + } + var sid = $('#b_id').val(); + var rows = subgridRows; + var irow = subgridRows.length; + var value = ""; + for (i = 0; i < irow; i++) { + var keyid = rows[i].mx_keyid; + // alert(keyid); + if ((keyid == '') || (keyid == null) || (keyid == undefined)) { + alert("请先确认入库!"); + return; + } + //alert(keyid); + var conn = rows[i].mx_conno; + if ((conn != '') && (conn != null) && (conn != undefined)) { + //alert("111"); + continue; + } + + var tmpjson = loaddatas('v_gx_keyrecords', "='" + keyid + "'", 'mx_shdatetime desc', ''); + if (tmpjson.length > 0) { + if (tmpjson[0].father != strid) { + alert("112"); + // alert('该箱子已使用,不能撤删!'); + continue; + } + } + + if (value != '') { + value = value + ',' + } + value = value + "{father:'" + sid + + "',mx_conno:'" + rows[i].mx_keyid + + "',subid:'" + rows[i].subid + + "'}" + } + + if (value == '') { + // alert('费用导入失败,不能重复导入费用!'); + return; + } + + value = "[" + value + "]"; + //alert(value); + $.ajax({ + type: 'post', + url: 'jsp/savesubtable.jsp', + cache: false, + data: { + subtable: 'xg_buyin_sub', + subinsertvalue: '[]', + subdelvalue: '[]', + subupdatevalue: value, + father: sid + }, + dataType: 'text', + success: function (result) { + alert('箱号生成成功!'); + loaddata_detail_sub('subgrid', 'v_xg_buyin_sub', strid, ''); + }, + error: function (result) { + } + }); + + } + + + + function sh() { + $('#btn_check').attr('disabled', 'disabled'); + if (checkchange()) { + alert('请先保存数据!'); + $('#btn_check').removeAttr("disabled"); + return; + } + var Fid = $('#b_id').val(); + var Fdwid = $('#b_customer_id').val(); + if (Fdwid == '') { + alert('箱公司不能为空!'); + $('#btn_check').removeAttr("disabled"); + return; + } + if (!canitemidexists()) { + //alert('箱号有重复,不能更新箱池!'); + return; + } + + var rows = $('#subgrid').datagrid('getChecked'); + if (rows.length <= 0) { + var rows = subgridRows; + //return false; + }; + var tmpjson; + if (!rows) { + alert('未输入买入的箱子'); + $('#btn_check').removeAttr("disabled"); + return; + } + + /* var connoArray=[]; + var Fsql=" mx_type not in('卖箱出库','还箱退租','代管出库')" + if (Fid!=''){ + Fsql=Fsql+" and father<>'"+Fid+"'"; + } + var tmpjson=loaddatas('xg_conmaxtype', Fsql, '', ''); + for(var k in tmpjson){ + if (!(strinArray(connoArray,tmpjson[k].mx_conno))){ + connoArray.push(tmpjson[k].mx_conno); + } + } */ + + // ========= 第一轮循环:收集要批量查询的 key ========= + + var subidList = []; + var connoList = []; + + for (var i = 0; i < rows.length; i++) { + var r = rows[i]; + + if (r.mx_contype == '' || r.mx_contype == null) { + alert('箱型不能为空'); + $('#btn_check').removeAttr("disabled"); + return; + } + if (r.mx_atwhere == '' || r.mx_atwhere == null) { + alert('存放堆场不能为空'); + $('#btn_check').removeAttr("disabled"); + return; + } + if (r.mx_txid == '' || r.mx_txid == null) { + alert('提箱单号不能为空'); + $('#btn_check').removeAttr("disabled"); + return; + } + + // 已确认记录直接跳过,不参与重复确认查询 + if (r.mx_keyid != '' && r.mx_keyid != null && r.mx_keyid != undefined) { + continue; + } + + // subid 批量收集(包含 { } 两种形式) + if (r.subid) { + var s1 = r.subid; + var s2 = r.subid.replace('{', '').replace('}', ''); + subidList.push(s1, s2); + } + + // conno 批量收集 + if (r.mx_conno) { + connoList.push(r.mx_conno); + } + } + + // 去重 + subidList = Array.from(new Set(subidList)); + connoList = Array.from(new Set(connoList)); + // ========= 第二阶段:一次性批量查询 DB ========= + + // ① 已确认的箱(避免重复确认) + var confirmedMap = new Set(); + if (subidList.length > 0) { + var sql1 = " father = '" + Fid + "' AND mx_link_id IN ('" + subidList.join("','") + "')"; + var tmp1 = loaddatas('xg_conmaxtype', sql1, '', ''); + for (var t = 0; t < tmp1.length; t++) { + confirmedMap.add(tmp1[t].mx_link_id); + } + } + + // ② 箱池中已存在的箱号(避免重复输入) + var connoMap = new Set(); + if (connoList.length > 0) { + var sql2 = + " father <> '" + Fid + "' " + + " AND mx_conno IN ('" + connoList.join("','") + "')" + + " AND mx_type NOT IN ('卖箱出库','还箱退租','代管出库')"; + var tmp2 = loaddatas('xg_conmaxtype', sql2, '', ''); + for (var k = 0; k < tmp2.length; k++) { + connoMap.add(tmp2[k].mx_conno); + } + } + + + // ========= 第三轮循环:逐条判断 ========= + for (var i = 0; i < rows.length; i++) { + var r = rows[i]; + + // 跳过已确认记录 + if (!(r.mx_keyid != '' && r.mx_keyid != null && r.mx_keyid != undefined)) { + + // 判断 subid 是否重复确认 + if (r.subid) { + var s1 = r.subid; + var s2 = r.subid.replace('{', '').replace('}', ''); + if (confirmedMap.has(s1) || confirmedMap.has(s2)) { + alert('已确认的箱子不可重复确认!'); + $('#btn_sh').removeAttr("disabled"); + return; + } + } + } + + // 判断箱号是否在箱池中存在 + if (r.mx_conno) { + if (connoMap.has(r.mx_conno)) { + alert('箱号:' + r.mx_conno + '在箱池中已经存在,不可重复输入!'); + $('#btn_check').removeAttr("disabled"); + return; + } + } + } + + + var rows1 = []; + var minid = getAutoID('xg_buyin_autokeyid', 'g3soft'); + if ((minid == '') || (minid == null) || (minid == undefined)) { + alert('系统箱号出错,确认失败,请重新确认!'); + $('#btn_check').removeAttr("disabled"); + return; + } + var Fstrid = $('#b_id').val(); + var Fywid = ''; + Fywid = Fstrid.substr(Fstrid.length - 3, Fstrid.length); + var n = 0; + console.log(Fywid); + // return; + // alert(minid); + + var Fdate = getnowtime(); + + var subdata = []; + var subdata1 = []; + var subdata2 = []; + var subdata3 = []; + var maindata = {}; + var tmpdata = {}; + var tmpdata1 = {}; + var tmpdata2 = {}; + var tmpdata3 = {}; + /////////修改确认xg_buyin////// + maindata = {}; + maindata.b_id = $('#b_id').val(); + maindata.b_sh = '1'; + maindata.b_shman_id = userid; + maindata.b_shdatetime = Fdate; + ////////////////// + + for (var i = 0; i < rows.length; i++) { + var Fkeyid = rows[i].mx_keyid; + if ((Fkeyid != '') && (Fkeyid != null) && (Fkeyid != undefined)) { + continue; + } + var conkeyid = (Number(minid) + n).toString() + '1' + Fywid; + n = n + 1; + + var contype = rows[i].mx_contype; + var txid = rows[i].mx_txid; + var xk = rows[i].mx_xk; + var atwhere = rows[i].mx_atwhere; + var txdate = rows[i].mx_zxdate; + var bz1 = rows[i].mx_bz1; + + if ((contype == undefined) || (contype == null)) { contype = ''; } + if ((txid == undefined) || (txid == null)) { txid = ''; } + if ((xk == undefined) || (xk == null)) { xk = ''; } + if ((atwhere == undefined) || (atwhere == null)) { atwhere = ''; } + if ((txdate == undefined) || (txdate == null)) { txdate = ''; } + if ((bz1 == undefined) || (bz1 == null)) { bz1 = ''; } + + /////////修改确认/xg_buyin_sub////// + tmpdata = {}; + tmpdata.mx_sh = '1'; + tmpdata.mx_shman_id = userid; + tmpdata.mx_shdatetime = Fdate; + tmpdata.mx_keyid = conkeyid; + tmpdata.mx_date = $('#b_date').val(); + tmpdata.mx_dw_id = Fdwid; + tmpdata.subid = rows[i].subid; + subdata.push(tmpdata); + + //////////插入xg_keyrecords////// + tmpdata1 = {}; + tmpdata1.mx_conno = rows[i].mx_conno; + tmpdata1.mx_contype = contype; + tmpdata1.mx_txid = txid; + tmpdata1.mx_xk = xk; + tmpdata1.mx_bz1 = bz1; + tmpdata1.mx_atwhere = atwhere; + tmpdata1.mx_txdate = txdate; + tmpdata1.mx_xgyw = 'xg'; + tmpdata1.father = $('#b_id').val(); + tmpdata1.mx_sh = '1'; + tmpdata1.mx_shman_id = userid; + tmpdata1.mx_shdatetime = Fdate; + tmpdata1.mx_keyid = conkeyid; + tmpdata1.mx_date = $('#b_date').val(); + tmpdata1.mx_dw_id = Fdwid; + tmpdata1.mx_link_id = rows[i].subid; + tmpdata1.mx_type = '买箱入库'; + subdata1.push(tmpdata1); + + //////////插入xg_conmaxtype/////// + tmpdata2 = {}; + tmpdata2.mx_conno = rows[i].mx_conno; + tmpdata2.mx_contype = contype; + tmpdata2.mx_txid = txid; + tmpdata2.mx_xk = xk; + tmpdata2.mx_bz1 = bz1; + tmpdata2.mx_atwhere = atwhere; + tmpdata2.mx_txdate = txdate; + tmpdata2.mx_xgyw = 'xg'; + tmpdata2.father = $('#b_id').val(); + tmpdata2.mx_sh = '1'; + tmpdata2.mx_shman_id = userid; + tmpdata2.mx_shdatetime = Fdate; + tmpdata2.mx_keyid = conkeyid; + tmpdata2.mx_date = $('#b_date').val(); + tmpdata2.mx_dw_id = Fdwid; + tmpdata2.mx_link_id = rows[i].subid; + tmpdata2.mx_type = '买箱入库'; + subdata2.push(tmpdata2); + } + + // ===== 优化 xg_cw 查询 ===== + // 收集所有 subid(包含 {} 形式) + var allSubidList = []; + rows.forEach(r => { + if (r.subid) { + allSubidList.push(r.subid); + allSubidList.push(r.subid.replace('{', '').replace('}', '')); + } + }); + allSubidList = Array.from(new Set(allSubidList)); + + // 一次性批量查询 xg_cw + var xgcwMap = {}; // key: mx_linkfd_id -> 对应 xg_cw 记录数组 + if (allSubidList.length > 0) { + var searchsqlcw = " father ='" + Fid + "' AND (" + + allSubidList.map(sid => "mx_linkfd_id='" + sid + "'").join(" OR ") + + ")"; + var xgcwrows = loaddatas('xg_cw', searchsqlcw, 'subid', ''); + xgcwrows.forEach(r => { + if (!xgcwMap[r.mx_linkfd_id]) xgcwMap[r.mx_linkfd_id] = []; + xgcwMap[r.mx_linkfd_id].push(r); + }); + } + + // 循环 rows,生成 subdata3 + for (var i = 0; i < rows.length; i++) { + var r = rows[i]; + var conkeyid = (Number(minid) + i).toString() + '1' + Fywid; // 保持原 keyid 逻辑 + var contype = r.mx_contype || ''; + var txid = r.mx_txid || ''; + var xk = r.mx_xk || ''; + var atwhere = r.mx_atwhere || ''; + var txdate = r.mx_zxdate || ''; + + var subid = r.subid; + var ssubid = subid.replace('{', '').replace('}', ''); + + var relatedCw = (xgcwMap[subid] || []).concat(xgcwMap[ssubid] || []); + relatedCw.forEach(cw => { + var tmpdata3 = {}; + tmpdata3.mx_keyid = conkeyid; + tmpdata3.mx_shdatetime = Fdate; + tmpdata3.mx_conno = r.mx_conno; + tmpdata3.mx_contype = contype; + tmpdata3.mx_txid = txid; + tmpdata3.mx_xk = xk; + tmpdata3.mx_atwhere = atwhere; + tmpdata3.mx_txdate = txdate; + tmpdata3.subid = cw.subid; + subdata3.push(tmpdata3); + }); + } + + ///////////////////// + //console.log('vcvcvcvcvcvc'); + var subjson = app.jsonToString(subdata); + //console.log('subjson:'+subjson); + var subjson1 = app.jsonToString(subdata1); + //console.log("subjson1:"+subjson1); + var subjson2 = app.jsonToString(subdata2); + //console.log("subjson2:"+subjson2); + var subjson3 = app.jsonToString(subdata3); + //console.log("subjson3:"+subjson3); + //alert(subjson); + ////////////////////////////////////////// + var subtable = new Array(); + var keyid = new Array(); + var subinsertvalue = new Array(); + var subupdatevalue = new Array(); + var subdelvalue = new Array(); + subtable.push('xg_buyin'); + subtable.push('xg_buyin_sub'); + subtable.push('xg_keyrecords'); + subtable.push('xg_conmaxtype'); + subtable.push('xg_cw'); + + var formjson = app.jsonToString(maindata); + //console.log("formjson:"+formjson); + subinsertvalue.push('[]'); + subinsertvalue.push('[]'); + subinsertvalue.push(subjson1); + subinsertvalue.push(subjson2); + subinsertvalue.push('[]'); + + subupdatevalue.push('[' + formjson + ']'); + subupdatevalue.push(subjson); + subupdatevalue.push('[]'); + subupdatevalue.push('[]'); + subupdatevalue.push(subjson3); + + subdelvalue.push('[]'); + subdelvalue.push('[]'); + subdelvalue.push('[]'); + subdelvalue.push('[]'); + subdelvalue.push('[]'); + + keyid.push('b_id'); + keyid.push('subid'); + keyid.push('subid'); + keyid.push('subid'); + keyid.push('subid'); + + // console.log(subtable) + // console.log(subinsertvalue) + // console.log(subdelvalue) + // console.log(subupdatevalue) + // console.log(keyid) + + var sResult = ''; + sResult = saveobjt(subtable, subinsertvalue, subdelvalue, subupdatevalue, keyid); + if (sResult == 'OK') { + alert('确认成功!'); + $('#btn_check').removeAttr("disabled"); + setywwcqty(); + loaddata('buyinform', 'v_xg_buyin', strid, 'main'); + // $('#btn_sh').attr('disabled','disabled'); + //$('#btn_createcon').attr('disabled','disabled'); + var formobj = app.serializeObject2($('#buyinform')); + delete formobj["bcheck"]; + oldformjson = app.jsonToString(formobj); + + loaddata_detail_sub('subgrid', 'v_xg_buyin_sub', strid, ''); + } else { + alert(sResult); + $('#btn_check').removeAttr("disabled"); + } + $('#btn_check').removeAttr("disabled"); + } + + function saveupdatecw(table, subupdatevalue) { + //alert(subupdatevalue); + $.ajax({ + type: 'post', + url: 'jsp/savesubdata.jsp', + cache: false, + data: { + subtable: table, + subinsertvalue: '[]', + subdelvalue: '[]', + subupdatevalue: subupdatevalue + }, + dataType: 'text', + success: function (result) { + + //alert('更新箱号成功!'); + }, + error: function (result) { + } + }); + } + + function savesubtable(rowsjson) { + var sresult = ''; + $.ajax({ + type: 'post', + url: 'jsp/savesubtable.jsp', + cache: false, + async: false, + data: { + subtable: 'xg_buyin_sub', + subinsertvalue: '[]', + subdelvalue: '[]', + subupdatevalue: rowsjson, + father: '' + }, + dataType: 'text', + success: function (result) { + sresult = result; + }, + error: function (result) { + } + + }); + return sresult; + } + + + function canupdateconno(keyid, conno) { + var sstate = getfieldvaluebyid('v_xg_constate', 'b_state', 'b_id', keyid); + if (sstate != '可用') { + alert('key值:' + keyid + '的箱子当前状态为:' + sstate + ',不能更新箱号'); + return false; + } + var tmpjson = loaddatas('v_xg_constate', "mx_conno='" + conno + "' and v_constate not in('卖箱出库','还箱退租')", 'b_id', ''); + //var skeyid=getfieldvaluebyid('xg_container', 'b_id', 'b_conno', conno); + if (tmpjson.length > 0) + if (tmpjson[0].b_id != keyid) { + alert('箱号:' + conno + '箱池里已经存在,不能输入重复的箱号!'); + return false; + } + return true; + } + + function updateconno() { + endEditing_sub(); + var rows1 = []; + var subvalue = ""; + var rows = $('#subgrid').datagrid('getChecked'); + + //alert(rows.length); + // alert(app.jsonToString(rows)); + if (rows.length <= 0) { + alert('请选择要更新箱号的箱子'); + return; + } + if (!canitemidexists()) { + //alert('箱号有重复,不能更新箱池!'); + return; + } + //var rows=$('#subgrid').datagrid('getRows'); + for (var i = 0; i < rows.length; i++) { + if (!canupdateconno(rows[i].mx_keyid, rows[i].mx_conno)) { + return; + } + if (subvalue != '') { + subvalue += ','; + } + subvalue = subvalue + "{mx_conno:'" + rows[i].mx_conno + + //"',:'" + rows[i].+ + "',subid:'" + rows[i].subid + + "'}" + } + + var subdelvalue = "[" + subvalue + "]"; + $.ajax({ + type: 'post', + url: 'jsp/savesubdata.jsp', + cache: false, + data: { + subtable: 'xg_buyin_sub', + subinsertvalue: '[]', + subdelvalue: '[]', + subupdatevalue: subdelvalue + }, + dataType: 'text', + success: function (result) { + loaddata_detail_sub('subgrid', 'v_xg_buyin_sub', strid, ''); + alert('更新箱号成功!'); + }, + error: function (result) { + } + }); + } + + + function saveupdatesub(subupdatevalue) { + $.ajax({ + type: 'post', + url: 'jsp/savesubdata.jsp', + cache: false, + data: { + subtable: 'xg_buyin_sub', + subinsertvalue: '[]', + subdelvalue: '[]', + subupdatevalue: subupdatevalue + }, + dataType: 'text', + success: function (result) { + loaddata_detail_sub('subgrid', 'v_xg_buyin_sub', strid, ''); + //alert('更新箱号成功!'); + }, + error: function (result) { + } + }); + } + + + function delconno() { + var rows = $('#subgrid').datagrid('getChecked'); + if (rows.length <= 0) { + alert('请选择需要撤删的箱子'); + return; + }; + //var rows=$('#subgrid').datagrid('getRows'); + var irow = rows.length; + var subvalue = ""; + var rows1 = []; + $.messager.confirm("操作提示", '您确定要撤删选中的箱子吗?', function (r) { + if (!r) { + return false; + } + else { + //alert(selectedrows.length); + for (i = 0; i < irow; i++) { + var keyid = rows[i].mx_keyid; + var searchsql = " father='" + strid + "' and ='" + keyid + "' and mx_hstype_id='买箱入库'"; + //alert(searchsql); + var modrows = loaddatas('xg_cw', searchsql, '', ''); + if (modrows.length > 0) { + alert('请先删除该箱子下的费用!'); + return + } + var searchsql = " ='" + keyid + "' "; + //alert(searchsql); + var modrows = loaddatas('xg_buyout_sub', searchsql, '', ''); + if (modrows.length > 0) { + alert('该箱子已使用,不能撤删!'); + return + } + var searchsql = " ='" + keyid + "' "; + //alert(searchsql); + var modrows = loaddatas('bs_business_container', searchsql, '', ''); + if (modrows.length > 0) { + alert('该箱子已使用,不能撤删!'); + return + } + } + for (i = 0; i < irow; i++) { + if (subvalue != '') { + subvalue += ','; + } + subvalue = subvalue + "{:'" + rows[i].mx_keyid + + "',subid:'" + rows[i].subid + + "'}" + } + var subdelvalue = "[" + subvalue + "]"; + $.ajax({ + type: 'post', + url: 'jsp/savesubdata.jsp', + cache: false, + data: { + subtable: 'xg_buyin_sub', + subinsertvalue: '[]', + subdelvalue: subdelvalue, + subupdatevalue: '[]' + }, + dataType: 'text', + success: function (result) { + loaddata_detail_sub('subgrid', 'v_xg_buyin_sub', strid, ''); + alert('撤删成功'); + var rows = $('#subgrid').datagrid('getRows'); + if (rows.length <= 0) { + updatefieldvaluebyid('xg_buyin', 'b_state', '草拟', 'b_id', $('#b_id').val()); + $('#b_state').val('草拟'); + var formobj = app.serializeObject2($('#buyinform')); + delete formobj["bcheck"]; + oldformjson = app.jsonToString(formobj); + $('#btn_delcon').attr('disabled', 'disabled'); + $('#btn_updatecon').attr('disabled', 'disabled'); + $(":button[tag*='" + 3 + "']").removeAttr("disabled"); + $('#btn_save').removeAttr("disabled"); + } + }, + error: function (result) { + } + }); + } + }); + } + + function showAllcw() { + if (!document.getElementById("b_id").readOnly) { + savealert('请先保存数据!'); + return; + } + if (checkchange()) { + savealert('请先保存数据!'); + return; + } + var iread = ''; + var ifreadonly = document.getElementById("btn_save").disabled; + if (ifreadonly) { + iread = '1'; + } + var keyid = ''; + var conno = ''; + var Fxh = ''; + var subid = ''; + var strid = $('#b_id').val(); + parent.$('
').dialog({ + title: '整单费用', + width: 850, + height: 570, + id: 'viewbuydialog', + top: 80, + content: '', + modal: true, + onClose: function () { + $(this).remove(); + }, + onBeforeClose: function (event, ui) { + var w = top.frames["cwdialog"]; + if (w.checkchange) { + if (w.checkchange()) { + w.$.sobox.pop({ + cls: 'subsidy-box', + title: '远通提示', + width: 320, + maskClick: false, + content: '
' + + '
' + + '
数据有更改,是否要保存?
' + + '
' + + '
', + btn: [ + { + text: '是', callback: function () { + var s = w.saveData(); + if (s == '保存成功!') { + //alert('close'); + mydialog = parent.$('#viewbuydialog'); + mydialog.window('destroy'); + return true; + } + } + }, + { + text: '否', cls: 'a-sopop-cancel', callback: function () { + mydialog = parent.$('#viewbuydialog'); + mydialog.window('destroy'); + return true; + + } + }, + { + text: '取消', cls: 'a-sopop-cancel', callback: function () { + } + + }] + }) + } else { + return true; + } + return false; + } + } + }); + } + function showcw() { + var iread = ''; + var ifreadonly = document.getElementById("btn_save").disabled; + if (ifreadonly) { + iread = '1'; + } + //alert('000'); + if (strid == "") { + alert('未保存数据'); + return; + } + var row = $('#subgrid').datagrid('getSelected'); + //alert('111'); + if (!row) return; + var conno = row.mx_conno; + var keyid = row.mx_keyid; + var subid = row.subid; + //subid=subid.replace('{',''); + //subid=subid.replace('}',''); + var Fxh = row.mx_xh; + if ((subid == '') || (subid == null) || (subid == undefined)) { + alert("请先保存!"); + return; + } + + parent.$('
').dialog({ + title: '费用录入', + width: 880, + height: 600, + id: 'viewbuydialog', + top: 80, + resizable: true, + content: '', + modal: true, + onClose: function () { + $(this).remove(); + }, + onBeforeClose: function (event, ui) { + var w = top.frames["cwdialog"]; + if (w.checkchange) { + if (w.checkchange()) { + w.$.sobox.pop({ + cls: 'subsidy-box', + title: '远通提示', + width: 320, + maskClick: false, + content: '
' + + '
' + + '
数据有更改,是否要保存?
' + + '
' + + '
', + btn: [ + { + text: '是', callback: function () { + var s = w.saveData(); + if (s == '保存成功!') { + //alert('close'); + mydialog = parent.$('#viewbuydialog'); + mydialog.window('destroy'); + return true; + } + } + }, + { + text: '否', cls: 'a-sopop-cancel', callback: function () { + mydialog = parent.$('#viewbuydialog'); + mydialog.window('destroy'); + return true; + + } + }, + { + text: '取消', cls: 'a-sopop-cancel', callback: function () { + } + + }] + }) + } else { + return true; + } + return false; + } + } + }); + } + + + function removeit_con() { + var checkedRows = $('#subgrid').datagrid('getChecked'); + if (checkedRows.length <= 0) return false; + + $.messager.confirm("操作提示", "您确定要删除选中的数据吗?", function (r) { + if (!r) return false; + + // 收集 subid 和 keyid + var usedSubids = new Set(); + var usedKeyids = new Set(); + var subids = [], keyids = []; + + checkedRows.forEach(row => { + if (row.subid) subids.push(row.subid.replace('{', '').replace('}', '')); + if (row.keyid) keyids.push(row.keyid); + }); + + // ====== 批量查询 ====== + if (subids.length > 0) { + var searchsql = " father='" + strid + "' and mx_hstype_id='买箱入库' " + + " and mx_linkfd_id in ('" + subids.join("','") + "')"; + var modrows = loaddatas('xg_cw', searchsql, '', ''); + modrows.forEach(r => usedSubids.add(r.mx_linkfd_id)); + } + + if (keyids.length > 0) { + var searchsql1 = " mx_keyid in ('" + keyids.join("','") + "') "; + var modrows1 = loaddatas('xg_buyout_sub', searchsql1, '', ''); + var modrows2 = loaddatas('bs_business_container', searchsql1, '', ''); + modrows1.concat(modrows2).forEach(r => usedKeyids.add(r.mx_keyid)); + } + + // ====== 处理删除 ====== + let canDelete = true; + for (let row of checkedRows) { + let subid = row.subid ? row.subid.replace('{', '').replace('}', '') : null; + let keyid = row.keyid; + + if (subid && usedSubids.has(subid)) { + alert('请先删除该箱子下的费用!'); + canDelete = false; + break; // 一旦有不允许删除的行,停止检查 + } + + if (keyid && usedKeyids.has(keyid)) { + alert('该箱子已使用,不能撤删!'); + canDelete = false; + break; + } + } + + if (!canDelete) return; // 有问题,不删除任何行 + + subgridRows = subgridRows.filter(row => + !checkedRows.some(checked => checked.mx_xh === row.mx_xh) + ); + + $('#subgrid').datagrid('loadData', subgridRows) + // 清空选中 + $('#subgrid').datagrid('clearChecked'); + editIndex_sub = undefined; + }); + } + + + function insertyf() { + if (checkchange()) { + alert('请先保存,再来导入应付费用!'); + return; + } + var Fbsno = $('#b_id').val(); + var Fdwid = $('#b_customer_id').val(); + var Famount = $('#b_amount').val(); + var Fmoney = $('#b_money_id').val(); + /*if ((Fdwid== '')||(Fmoney== '')||(Famount==0)){ + alert('请选填箱公司、单价、币种后,再来导入应付费用!'); + return; + } */ + + /* var rows = $('#subgrid').datagrid('getChecked'); + if (rows.length<=0){ + var rows=$('#subgrid').datagrid('getRows'); + //return false; + }; */ + //alert(irow); + var rows = subgridRows; + var irow = subgridRows.length; + for (i = 0; i < irow; i++) { + var subid = rows[i].subid; + // alert(keyid); + if ((subid == '') || (subid == null) || (subid == undefined)) { + alert("请先保存!"); + return; + } + } + + var selarray = new Array(); + var rows = $('#subgrid').datagrid('getChecked'); + //alert(rows.length); + for (var i = rows.length - 1; i >= 0; i--) { + //for (var i = 0; i <= irow-1; i++){ + if (rows[i].subid != '') { + selarray.push("'" + rows[i].subid + "'"); + } + } + var sselarray = selarray.join(","); + var query = { selrows: selarray }; + var keyID = 'xginsertfee_data' + generateUID(); + localStorage.setItem(keyID, JSON.stringify(query)); + + var datadialog = parent.$('
').dialog({ + title: '费用导入操作', + width: 410, + height: 280, + id: 'cwdialog', + cache: false, + closeOnEscape: false, + // closable:true, + autoOpen: false, + top: 200, + //resizable:true, + content: '', + modal: true, + onClose: function () { + $(this).remove(); + loaddata_detail_sub('subgrid', 'v_xg_buyin_sub', strid, ''); + $('#subgrid').datagrid('unselectAll'); + $('#subgrid').datagrid('uncheckAll'); + // loaddata(Fsubid); + // DoSearch(); + //alert('111'); + //getxzamount(); + } + }); + + } + + + function createcon_pl() { + if (checkchange()) { + alert('请先保存,再来批量生成箱子!'); + return; + } + if (document.getElementById("b_id").readOnly) { + } else { + alert('请先保存,再来批量生成箱子!'); + return; + } + var Fbsno = $('#b_id').val(); + var Fdwid = $('#b_customer_id').val(); + var Famount = $('#b_amount').val(); + var Fmoney = $('#b_money_id').val(); + var selarray = new Array(); + var sselarray = selarray.join(","); + var datadialog = parent.$('
').dialog({ + title: '批量生成操作', + width: 450, + height: 340, + id: 'cwdialog', + cache: false, + closeOnEscape: false, + // closable:true, + autoOpen: false, + top: 200, + //resizable:true, + content: '', + modal: true, + onClose: function () { + $(this).remove(); + loaddata_detail_sub('subgrid', 'v_xg_buyin_sub', strid, ''); + $('#subgrid').datagrid('unselectAll'); + $('#subgrid').datagrid('uncheckAll'); + // loaddata(Fsubid); + // DoSearch(); + //alert('111'); + //getxzamount(); + } + }); + + } + + + + + + + function showattach(o) { + var e = window.event || e; + if (e.stopPropagation) { + e.stopPropagation(); //阻止事件 冒泡传播 + } + var selindex = $(o).attr('attr1'); + var gridid = 'subgrid'; + var rows = $("#" + gridid).datagrid("getRows"); + var row = rows[selindex]; + if (row.mx_conno != '' && row.mx_conno != undefined) { + getattachfile(row.mx_conno, 'xg_containerlib_files', 0); + } else { + alert('请确认箱号!'); + } + } + + + // var gridname = 'subgrid'; + // var $gridbody = $('#' + gridname).datagrid('getPanel').find('.datagrid-body'); + // $gridbody.on('paste', myevent); + + // var input = document.getElementById('auto_sub'); + // input.addEventListener('paste', myevent); + + function myevent(event) { + event.preventDefault(); + + var clipboardData = (event.originalEvent || event).clipboardData; + if (!clipboardData) return; + + var gridname = 'subgrid'; + var $grid = $('#' + gridname); + + // 获取当前聚焦的列 field + var opts = $grid.datagrid('getColumnFields'); + var fieldname_zx = ''; + var colopts = []; + + for (var j = 0; j < opts.length; j++) { + var editor = $grid.datagrid('getEditor', { index: editIndex_sub, field: opts[j] }); + if (editor && editor.target.is(':focus')) { + fieldname_zx = opts[j]; // 找到聚焦列 + } + + var opt = $grid.datagrid('getColumnOption', opts[j]); + if (!opt.hidden) { + colopts.push(opts[j]); // 可见列 + } + } + + // 根据 fieldname_zx 找列索引 + var colIndex = -1; + if (fieldname_zx) { + for (var k = 0; k < colopts.length; k++) { + if (colopts[k] === fieldname_zx) { + colIndex = k; + break; + } + } + } + + // 获取当前行索引 + var selrow = $grid.datagrid('getSelected'); + var rowIndex = $grid.datagrid('getRowIndex', selrow); + if (colIndex === -1 || rowIndex === undefined || rowIndex < 0) { + $.messager.alert('提示', '请先点击要粘贴的单元格!'); + return; + } + + // 获取原始 ClipboardEvent + var clipboardData = event.originalEvent.clipboardData; + if (!clipboardData) return; + var data = clipboardData.getData('Text'); + // 分行并过滤空行(避免最后多插入空行) + var datas = data.split("\n").filter(line => line.trim() !== ""); + + // 檢查 + let allRows = $grid.datagrid('getData').firstRows || [] + var selrow = allRows[rowIndex]; + + if (selrow && selrow.v_checkyx && selrow.v_checkyx === '是') { + $.messager.alert('提示', '箱号:' + (selrow.mx_conno || '') + ',已使用,不可修改!'); + return; + } + + // 提示 + $.messager.progress({ title: '导入中', msg: '请稍候...' }); + + // ------------------------------ + // 5️⃣ 构建 Worker 处理粘贴逻辑 + // ------------------------------ + var workerCode = ` function generateUUID() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { const r = Math.random() * 16 | 0; @@ -5491,410 +4970,411 @@ function calcw(){ }; `; - // ------------------------------ - // 6️⃣ 启动 Worker - // ------------------------------ - var blob = new Blob([workerCode], { type: "application/javascript" }); - var worker = new Worker(URL.createObjectURL(blob)); + // ------------------------------ + // 6️⃣ 启动 Worker + // ------------------------------ + var blob = new Blob([workerCode], { type: "application/javascript" }); + var worker = new Worker(URL.createObjectURL(blob)); - worker.postMessage({ datas, colopts, colIndex, rowIndex, allRows }); + worker.postMessage({ datas, colopts, colIndex, rowIndex, allRows }); - worker.onmessage = function(e) { - if (e.data.error) { - $.messager.alert('提示', e.data.error); - $.messager.progress('close'); - worker.terminate(); - return; - } - - var newAllRows = e.data.rows; - - // 更新 datagrid 数据 - $grid.datagrid('loadData', newAllRows); - - // ------------------------------ - // 7️⃣ 恢复编辑状态,处理 textbox/val - // ------------------------------ - // for (var i = 0; i < newAllRows.length; i++) { - // $grid.datagrid('beginEdit', i); - // for (var j = 0; j < colopts.length; j++) { - // var field = colopts[j]; - // var ed = $grid.datagrid('getEditor', { index: i, field: field }); - // if (ed) { - // var val = newAllRows[i][field]; - // if (ed.target.next().attr('class') === 'textbox') { - // ed.target.textbox('setValue', val); - // } else { - // ed.target.val(val); - // } - // } - // } - // } - - $.messager.progress('close'); - worker.terminate(); - }; - } - - function myevent_old(event){ - // 添加到事件对象中的访问系统剪贴板的接口 - //endEditing_sub(); - var gridname='subgrid'; - var clipboardData = event.clipboardData, - i = 0, - items, item, types; - data = clipboardData.getData('Text'); - var datas = data.split("\n"); - var opts = $('#'+gridname).datagrid('getColumnFields'); - var fieldname_zx=''; - var colopts=new Array(); - for(var j=0; j=rowindex+i)&&(rowlen>0)&&(rowindex!=-1)){ - editIndex_sub =rowindex+i; - }else{ - $('#'+gridname).datagrid('appendRow', {}); - editIndex_sub = $('#'+gridname).datagrid('getRows').length - 1; - } - //rows[i].v_checkyx!='是' - var Fcheckyx=rows[editIndex_sub].v_checkyx; - var Fconno=rows[editIndex_sub].mx_conno; - if (Fcheckyx=='是'){ - alert('箱号:'+Fconno+',已使用,不可修改!'); - return; - } - /*$('#'+gridname).datagrid('beginEdit', editIndex_sub); - Fcheckyx=$('#subgrid').datagrid('getRows')[editIndex_sub].v_checkyx; - Fconno=$('#subgrid').datagrid('getRows')[editIndex_sub].mx_conno; - if (Fcheckyx=='是'){ - alert('箱号:'+Fconno+',已使用,不可修改!'); - return; - }*/ - var jobj={}; - for (var j = 0; j < row.length; j++) { - /*var colvalue=row[j]; - var colfieldname=colopts[k+j]; - $('#'+gridname).datagrid('beginEdit', editIndex_sub); - var ed=$('#'+gridname).datagrid('getEditor', {index : editIndex_sub,field : colfieldname}); - if(ed){ - ed.target.val(colvalue); - }*/ - var colvalue=row[j]; - var colfieldname=colopts[k+j]; - strval=app.jsonToString(colvalue); - if(strval.indexOf("\\r\\n")>-1){ - strval=strval.substring(0,strval.length-5)+'"'; - strval=eval('('+strval+')') - colvalue=strval; - } - //jobj[colfieldname]=colvalue; - rows[editIndex_sub][colfieldname]=colvalue; - if (colfieldname=='v_mx_atwhere_name'){ - // console.log(colvalue); - var searchsql=" b_name='"+colvalue+"'" ; - var tmpjson=loaddatas('b_othercompany', searchsql, '', ''); - if (tmpjson.length>0){ - var Fatwhereid=tmpjson[0].b_id - } - //jobj['mx_atwhere']=Fatwhereid; - rows[editIndex_sub].mx_atwhere=Fatwhereid; - } - //if (colfieldname=='mx_keyid'){ - // jobj['mx_keyid']=''; - // rows[editIndex_sub].mx_keyid=''; - //} - // $('#'+gridname).datagrid('beginEdit', editIndex_sub); - - //if (colfieldname=='mx_conno'){ - //Fcheckyx=$('#subgrid').datagrid('getRows')[editIndex_sub].v_checkyx - // Fconno=$('#subgrid').datagrid('getRows')[editIndex_sub].mx_conno - // if (Fcheckyx='是'){ - // alert('箱号:'+Fconno+',已使用,不可修改!'); - // return; - //} - /*var ed=$('#'+gridname).datagrid('getEditor', {index : editIndex_sub,field : colfieldname}); - if(ed){ - if(ed.target.next().attr("class") == "textbox"){ - ed.target.textbox('setValue',colvalue); - }else{ - ed.target.val(colvalue); + + var newAllRows = e.data.rows; + + // 更新 datagrid 数据 + $grid.datagrid('loadData', newAllRows); + + // ------------------------------ + // 7️⃣ 恢复编辑状态,处理 textbox/val + // ------------------------------ + // for (var i = 0; i < newAllRows.length; i++) { + // $grid.datagrid('beginEdit', i); + // for (var j = 0; j < colopts.length; j++) { + // var field = colopts[j]; + // var ed = $grid.datagrid('getEditor', { index: i, field: field }); + // if (ed) { + // var val = newAllRows[i][field]; + // if (ed.target.next().attr('class') === 'textbox') { + // ed.target.textbox('setValue', val); + // } else { + // ed.target.val(val); + // } + // } + // } + // } + + $.messager.progress('close'); + worker.terminate(); + }; + } + + function myevent_old(event) { + // 添加到事件对象中的访问系统剪贴板的接口 + //endEditing_sub(); + var gridname = 'subgrid'; + var clipboardData = event.clipboardData, + i = 0, + items, item, types; + data = clipboardData.getData('Text'); + var datas = data.split("\n"); + var opts = $('#' + gridname).datagrid('getColumnFields'); + var fieldname_zx = ''; + var colopts = new Array(); + for (var j = 0; j < opts.length; j++) { + var editor = $('#' + gridname).datagrid('getEditor', + { + index: editIndex_sub, + field: opts[j] + } + ); + if (editor) { + if (editor.target.is(":focus")) { + fieldname_zx = opts[j]; + } } - }*/ - } - } - /*$('#'+gridname).datagrid('updateRow',{ - index: editIndex_sub, - row: jobj - }); */ - $('#'+gridname).datagrid('refreshRow', editIndex_sub); - } - - } - endEditing_sub(); - //loadcon(); - // $.messager.progress('close'); -} + var opt = $('#' + gridname).datagrid('getColumnOption', opts[j]); + if (!opt.hidden) { + colopts.push(opts[j]); + } + } + var k = 1; + if ((fieldname_zx != '') && (fieldname_zx != undefined)) { + for (k = 0; k < colopts.length; k++) { + if (colopts[k] == fieldname_zx) { + // alert(k); + break; + } + } + } + var selrow = $('#' + gridname).datagrid('getSelected'); + var rowindex = $('#' + gridname).datagrid('getRowIndex', selrow); + // $.messager.progress({ + // title:'导入中', + // msg:'导入中...' + // }); -function printtoexcel(){ - Save_Excel('subgrid'); - } - -function showsortmenu(event){ - var parObj=$("#more"); - var y = parObj.offset().top; - var x = parObj.offset().left; - - $('#sortmenu').menu('show', { - left: x, - top: y+25 - }); - } - -function importcwexcel(){ - var Fbsno=$('#b_id').val(); - if (checkchange()){ - alert('请先保存,再来导入应付费用!'); - return; - } - var rows = $('#subgrid').datagrid('getData').firstRows || []; - var irow = $('#subgrid').data('allRows').length || [].length; - for (i = 0; i < irow; i++) { - var subid=rows[i].subid; - // alert(keyid); - if ((subid=='')||(subid==null)||(subid==undefined)){ - alert("请先保存!"); - return; - } - } - var Vtable='v_tj_xg_sub'; //视图,用来取field(列名)的; - var FTable='bs_business_cw'; //要更新的表 - var PPfield='[mx_conno]'; //粘贴复制的内容和数据库表中的内容 用来匹配的字段 - var importField='[mx_conno,mx_date8,b_shipingdate,mx_bz10,mx_msg,mx_date2,mx_date6,mx_msg_gw,mx_date3,mx_bz11,mx_date4]'; //导入的字段,不包含在内的字段无法导入. - var parentfrm = self.name; - parent.$('
').dialog({ - title : '批量导入费用操作', - width : 1080, - height : 600, - id:'jddialog', - top : 50, - onClose : function() { - $(this).remove(); - //DoSearch(); - }, - content : '', - modal : true - }); - } - - function showconlog() { - var sid=$('#b_id').val(); - Ftype="箱号"; - //Ftype=type; - var url; - url = "jxg/xgcondellog.jsp?businessid=" +sid+'&type='+Ftype; - if (url != undefined) { - var datadialog = parent.$('
').dialog({ - title : '箱子删除日志', - width : 680, - height : 500, - content : '', - modal : true - }); - } - } - - - - function showlog(type,id) { - var url; - url = "jxg/xgconlog.jsp?businessid=" +id; - if (url != undefined) { - var datadialog = parent.$('
').dialog({ - title : '箱子修改日志', - width : 950, - height :600, - content : '', - modal : true - }); - } + for (var i = 0; i < datas.length; i++) { + var row = datas[i].split("\t"); + // alert(row); + if (row != '') { + if (endEditing_sub()) { + var rowlen = $('#' + gridname).datagrid('getRows').length; + var rows = $('#' + gridname).datagrid('getRows'); + // alert(rowlen); + if ((rowlen >= rowindex + i) && (rowlen > 0) && (rowindex != -1)) { + editIndex_sub = rowindex + i; + } else { + $('#' + gridname).datagrid('appendRow', {}); + editIndex_sub = $('#' + gridname).datagrid('getRows').length - 1; + } + //rows[i].v_checkyx!='是' + var Fcheckyx = rows[editIndex_sub].v_checkyx; + var Fconno = rows[editIndex_sub].mx_conno; + if (Fcheckyx == '是') { + alert('箱号:' + Fconno + ',已使用,不可修改!'); + return; + } + /*$('#'+gridname).datagrid('beginEdit', editIndex_sub); + Fcheckyx=$('#subgrid').datagrid('getRows')[editIndex_sub].v_checkyx; + Fconno=$('#subgrid').datagrid('getRows')[editIndex_sub].mx_conno; + if (Fcheckyx=='是'){ + alert('箱号:'+Fconno+',已使用,不可修改!'); + return; + }*/ + var jobj = {}; + for (var j = 0; j < row.length; j++) { + /*var colvalue=row[j]; + var colfieldname=colopts[k+j]; + $('#'+gridname).datagrid('beginEdit', editIndex_sub); + var ed=$('#'+gridname).datagrid('getEditor', {index : editIndex_sub,field : colfieldname}); + if(ed){ + ed.target.val(colvalue); + }*/ + var colvalue = row[j]; + var colfieldname = colopts[k + j]; + strval = app.jsonToString(colvalue); + if (strval.indexOf("\\r\\n") > -1) { + strval = strval.substring(0, strval.length - 5) + '"'; + strval = eval('(' + strval + ')') + colvalue = strval; + } + //jobj[colfieldname]=colvalue; + rows[editIndex_sub][colfieldname] = colvalue; + if (colfieldname == 'v_mx_atwhere_name') { + // console.log(colvalue); + var searchsql = " b_name='" + colvalue + "'"; + var tmpjson = loaddatas('b_othercompany', searchsql, '', ''); + if (tmpjson.length > 0) { + var Fatwhereid = tmpjson[0].b_id + } + //jobj['mx_atwhere']=Fatwhereid; + rows[editIndex_sub].mx_atwhere = Fatwhereid; + } + //if (colfieldname=='mx_keyid'){ + // jobj['mx_keyid']=''; + // rows[editIndex_sub].mx_keyid=''; + //} + // $('#'+gridname).datagrid('beginEdit', editIndex_sub); - } - - function getappendconFrm(){ - $('#CategoryFrm').window({ - width: 260, - height: 200, - left:520, - top:200, - title:'批量选择箱子', - collapsible:false, - minimizable:false, - maximizable:false, - modal:true, - href:'jxg/selectcon_pl.jsp' - }); - } - function selectcon_pl(){ - /*if (checkchange()){ - alert('请先保存,再来生成箱子!'); - return; - } */ - getappendconFrm(); - $("#CategoryFrm").window({ - onLoad:function(){ - /*setAutoCompleteSimple('#mx_con_size',[["20'"],["40'"],["45'"]]); - setAutoComplete('#mx_con_type_id', 'b_con_type', 'b_name','b_id',''); - setAutoCompleteSimple('#mx_cztype',[['过磅称重法M1'],['累计相加称重法M2']]); - setAutoCompleteSimple('#mx_con_kz',[['E'],['F']]); */ - }, - onClose:function(){ - if (CategoryFrmshowmodal){ - var e = window.event || e; - if (e.stopPropagation) { - e.stopPropagation(); //阻止事件 冒泡传播 - } - isSave = true; - var fatherid=$("#b_id").val(); - - var Fcontype=$('#mx_con_type_id').val(); - var Fbegin=Number($('#b_begin').val()); - var Fend=Number($('#b_end').val()); - if ((Fbegin=='')||(Fbegin==0)||(Fend=='')||(Fend==0)){ - alert('该起止不能为空!'); //、箱量 - return; - } + //if (colfieldname=='mx_conno'){ + //Fcheckyx=$('#subgrid').datagrid('getRows')[editIndex_sub].v_checkyx + // Fconno=$('#subgrid').datagrid('getRows')[editIndex_sub].mx_conno + // if (Fcheckyx='是'){ + // alert('箱号:'+Fconno+',已使用,不可修改!'); + // return; + //} + /*var ed=$('#'+gridname).datagrid('getEditor', {index : editIndex_sub,field : colfieldname}); + if(ed){ + if(ed.target.next().attr("class") == "textbox"){ + ed.target.textbox('setValue',colvalue); + }else{ + ed.target.val(colvalue); + } + }*/ + } + } + /*$('#'+gridname).datagrid('updateRow',{ + index: editIndex_sub, + row: jobj + }); */ + $('#' + gridname).datagrid('refreshRow', editIndex_sub); + } - var irow = $('#subgrid').datagrid('getData').firstRows.length || 0; - for (i = Fbegin - 1; i < Fend ; i++) { - if (i').dialog({ + title: '批量导入费用操作', + width: 1080, + height: 600, + id: 'jddialog', + top: 50, + onClose: function () { + $(this).remove(); + //DoSearch(); + }, + content: '', + modal: true + }); + } + + function showconlog() { + var sid = $('#b_id').val(); + Ftype = "箱号"; + //Ftype=type; + var url; + url = "jxg/xgcondellog.jsp?businessid=" + sid + '&type=' + Ftype; + if (url != undefined) { + var datadialog = parent.$('
').dialog({ + title: '箱子删除日志', + width: 680, + height: 500, + content: '', + modal: true + }); + } + } - function checkConNo(conno) { - if (!conno || conno.length !== 11) { - return "集装箱号" + conno + "不正确,请输入11位集装箱号"; - } - const sqz = conno.substring(0, 4); // 前四位字母 - const szz = conno.substring(4, 10); // 中间六位数字 - const shz = conno.substring(10, 11); // 校验位 + function showlog(type, id) { + var url; + url = "jxg/xgconlog.jsp?businessid=" + id; + if (url != undefined) { + var datadialog = parent.$('
').dialog({ + title: '箱子修改日志', + width: 950, + height: 600, + content: '', + modal: true + }); + } - // ===== 前四位必须 A~Z ===== - for (let i = 0; i < 4; i++) { - const code = conno.charCodeAt(i); - if (code < 65 || code > 90) { - return "集装箱号" + conno + "不正确,前四位应该是字符"; - } - } + } - // ===== 后六位必须为数字 ===== - for (let i = 4; i < 10; i++) { - const code = conno.charCodeAt(i); - if (code < 48 || code > 57) { - return "集装箱号" + conno + "不正确,后七位应该是数字"; - } - } + function getappendconFrm() { + $('#CategoryFrm').window({ + width: 260, + height: 200, + left: 520, + top: 200, + title: '批量选择箱子', + collapsible: false, + minimizable: false, + maximizable: false, + modal: true, + href: 'jxg/selectcon_pl.jsp' + }); + } + function selectcon_pl() { + /*if (checkchange()){ + alert('请先保存,再来生成箱子!'); + return; + } */ + getappendconFrm(); + $("#CategoryFrm").window({ + onLoad: function () { + /*setAutoCompleteSimple('#mx_con_size',[["20'"],["40'"],["45'"]]); + setAutoComplete('#mx_con_type_id', 'b_con_type', 'b_name','b_id',''); + setAutoCompleteSimple('#mx_cztype',[['过磅称重法M1'],['累计相加称重法M2']]); + setAutoCompleteSimple('#mx_con_kz',[['E'],['F']]); */ + }, + onClose: function () { + if (CategoryFrmshowmodal) { + var e = window.event || e; + if (e.stopPropagation) { + e.stopPropagation(); //阻止事件 冒泡传播 + } + isSave = true; + var fatherid = $("#b_id").val(); - // ===== 校验位必须数字 ===== - const checkDigit = conno.charCodeAt(10); - if (checkDigit < 48 || checkDigit > 57) { - return "集装箱号" + conno + "不正确,后七位应该是数字"; - } - const checkNum = checkDigit - 48; + var Fcontype = $('#mx_con_type_id').val(); + var Fbegin = Number($('#b_begin').val()); + var Fend = Number($('#b_end').val()); + if ((Fbegin == '') || (Fbegin == 0) || (Fend == '') || (Fend == 0)) { + alert('该起止不能为空!'); //、箱量 + return; + } - // ===== 计算校验值 ===== - let sumValue = 0; + var irow = $('#subgrid').datagrid('getData').firstRows.length || 0; + for (i = Fbegin - 1; i < Fend; i++) { + if (i < irow) { + $('#subgrid').datagrid('checkRow', i); + } + } + $("#subgrid").datagrid('scrollTo', Fbegin) + } + } + }) + } + // 字母 A~Z 的值映射(与 Java 版 ConCharValues 一致) + const ConCharValues = [ + 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, + 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38 + ]; - // 前四位 A-Z - for (let i = 0; i < 4; i++) { - const letterIndex = conno.charCodeAt(i) - 65; // A=0 - sumValue += ConCharValues[letterIndex] * getPow2(i); - } + function getPow2(n) { + // 使用位运算减少开销(比 Math.pow 更快) + return 1 << n; + } - // 后六位数字 - for (let i = 4; i < 10; i++) { - const num = conno.charCodeAt(i) - 48; - sumValue += num * getPow2(i); - } - // ===== 模 11 校验 ===== - const mod = sumValue % 11; + function checkConNo(conno) { + if (!conno || conno.length !== 11) { + return "集装箱号" + conno + "不正确,请输入11位集装箱号"; + } - if (mod !== 10) { - if (mod !== checkNum) { - return "箱号" + conno + "校验不正确"; - } - } else { - if (checkNum !== 0) { - return "箱号" + conno + "校验不正确"; - } - } + const sqz = conno.substring(0, 4); // 前四位字母 + const szz = conno.substring(4, 10); // 中间六位数字 + const shz = conno.substring(10, 11); // 校验位 - return "OK"; - } + // ===== 前四位必须 A~Z ===== + for (let i = 0; i < 4; i++) { + const code = conno.charCodeAt(i); + if (code < 65 || code > 90) { + return "集装箱号" + conno + "不正确,前四位应该是字符"; + } + } - - - + // ===== 后六位必须为数字 ===== + for (let i = 4; i < 10; i++) { + const code = conno.charCodeAt(i); + if (code < 48 || code > 57) { + return "集装箱号" + conno + "不正确,后七位应该是数字"; + } + } + + // ===== 校验位必须数字 ===== + const checkDigit = conno.charCodeAt(10); + if (checkDigit < 48 || checkDigit > 57) { + return "集装箱号" + conno + "不正确,后七位应该是数字"; + } + const checkNum = checkDigit - 48; + + // ===== 计算校验值 ===== + let sumValue = 0; + + // 前四位 A-Z + for (let i = 0; i < 4; i++) { + const letterIndex = conno.charCodeAt(i) - 65; // A=0 + sumValue += ConCharValues[letterIndex] * getPow2(i); + } + + // 后六位数字 + for (let i = 4; i < 10; i++) { + const num = conno.charCodeAt(i) - 48; + sumValue += num * getPow2(i); + } + + // ===== 模 11 校验 ===== + const mod = sumValue % 11; + + if (mod !== 10) { + if (mod !== checkNum) { + return "箱号" + conno + "校验不正确"; + } + } else { + if (checkNum !== 0) { + return "箱号" + conno + "校验不正确"; + } + } + + return "OK"; + } + + + + \ No newline at end of file