Index: ssts-tousse/src/main/java/com/forgon/disinfectsystem/tousse/toussedefinition/service/GoodBindHelper.java =================================================================== diff -u --- ssts-tousse/src/main/java/com/forgon/disinfectsystem/tousse/toussedefinition/service/GoodBindHelper.java (revision 0) +++ ssts-tousse/src/main/java/com/forgon/disinfectsystem/tousse/toussedefinition/service/GoodBindHelper.java (revision 15948) @@ -0,0 +1,66 @@ +package com.forgon.disinfectsystem.tousse.toussedefinition.service; + +import com.forgon.disinfectsystem.goodsBindingConfig.vo.BindGoodVo; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.Predicate; +import org.apache.log4j.Logger; + +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +/** + * Created by zhonghaowen on 2016/11/25. + */ +public class GoodBindHelper { + + private static GoodBindHelper goodBindHelper; + + protected static final Logger logger = Logger.getLogger(GoodBindHelper.class); + + public static GoodBindHelper getInstance() { + if (goodBindHelper == null) { + synchronized (TousseDefinitionHelper.class) { + if (goodBindHelper == null) { + goodBindHelper = new GoodBindHelper(); + } + } + } + return goodBindHelper; + } + + /** + * 处理添加的绑定物品 + * 遍历这个绑定物品vo列表和查询出来的物品,对比两个,如果查询出来的物品跟这个vo列表的物品一样,则添加到reList里 + * + * @param bindGoodVos 需要绑定物品的vo列表 + * @param map 查询出来的物品 + * @return 返回最终需要绑定的列表, 里面有物品的名字, id, 数量等属性 + */ + public List> handleAddBindGood(List bindGoodVos, Map map) { + try { + List> list = (List>) map.get("data"); + List> reList = new LinkedList<>(); + for (BindGoodVo bindGoodVo : bindGoodVos) { + Map m = CollectionUtils.find(list, new Predicate>() { + @Override + public boolean evaluate(Map object) { + //这里id比较一定要用toString() + return bindGoodVo.getGoodId().equals(object.get("id").toString()); + // return object.get("name").equals(bindGoodVo.getGoodName()); + } + }); + if (m != null) { + //如果找到一样的,则设置他的绑定数量 + m.put("amount", bindGoodVo.getBindCount()); + reList.add(m); + } + } + return reList; + } + catch (Exception e) { + logger.error(e, e); + throw new RuntimeException(e); + } + } +} Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/vo/BindGoodVo.java =================================================================== diff -u --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/vo/BindGoodVo.java (revision 0) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/vo/BindGoodVo.java (revision 15948) @@ -0,0 +1,70 @@ +package com.forgon.disinfectsystem.goodsBindingConfig.vo; + +/** + * Created by zhonghaowen on 2016/11/25. + */ +public class BindGoodVo { + + /** + * 绑定物品的名字 + */ + private String goodName; + + /** + * 绑定物品的数量 + */ + private Integer bindCount; + + /** + * 绑定物品的id + */ + private String goodId; + + + /** + * 绑定物品的类型 + */ + private String goodType; + + public String getGoodName() { + return goodName; + } + + public void setGoodName(String goodName) { + this.goodName = goodName; + } + + public Integer getBindCount() { + return bindCount; + } + + public void setBindCount(Integer bindCount) { + this.bindCount = bindCount; + } + + public String getGoodId() { + return goodId; + } + + public void setGoodId(String goodId) { + this.goodId = goodId; + } + + public String getGoodType() { + return goodType; + } + + public void setGoodType(String goodType) { + this.goodType = goodType; + } + + @Override + public String toString() { + return "BindGoodVo{" + + "goodName='" + goodName + '\'' + + ", bindCount=" + bindCount + + ", goodId='" + goodId + '\'' + + ", goodType='" + goodType + '\'' + + '}'; + } +} Index: forgon-tools/src/main/java/com/forgon/tools/json/JSONUtil.java =================================================================== diff -u -r15932 -r15948 --- forgon-tools/src/main/java/com/forgon/tools/json/JSONUtil.java (.../JSONUtil.java) (revision 15932) +++ forgon-tools/src/main/java/com/forgon/tools/json/JSONUtil.java (.../JSONUtil.java) (revision 15948) @@ -6,6 +6,8 @@ import java.util.List; import java.util.Set; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; import net.sf.json.JSONArray; import net.sf.json.JSONNull; import net.sf.json.JSONObject; @@ -41,7 +43,6 @@ import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; import edu.emory.mathcs.backport.java.util.Arrays; @@ -425,5 +426,26 @@ } return jsonElement.getAsInt(); } - + + /** + * 把json的字符串转成对应的类型(可以是po,可以是List) + * @param json 要转的字符串 + * @param token 要转的类型 + * @param + * @return + */ + public static T fromJson(String json, TypeToken token) { + if (StringUtils.isBlank(json)) { + return null; + } + Gson gson = new GsonBuilder().create(); + try { + return gson.fromJson(json, token.getType()); + } + catch (Exception e) { + System.err.println(json + " 无法转换为 " + token.getRawType().getName() + " 对象!"); + e.printStackTrace(); + throw new RuntimeException(e); + } + } } Index: forgon-tools/src/main/java/com/forgon/tools/util/PageUtil.java =================================================================== diff -u -r15924 -r15948 --- forgon-tools/src/main/java/com/forgon/tools/util/PageUtil.java (.../PageUtil.java) (revision 15924) +++ forgon-tools/src/main/java/com/forgon/tools/util/PageUtil.java (.../PageUtil.java) (revision 15948) @@ -46,14 +46,18 @@ * @param pageEntity 分页的实体类 */ public static void outPutResult(PageEntity pageEntity, List list) { + if (pageEntity == null) { + pageEntity = new PageEntity(); + } try { List> reList = PageUtil.startPage(pageEntity.getStart(), pageEntity.getLimit(), list); JSONObject jsonObject = new JSONObject(); Map map = pageEntity.getMap(); if (!map.isEmpty()) { BeanUtils.populate(jsonObject, map); } - if (list.size() > 0) { + if (CollectionUtils.isNotEmpty(list)) { + // if (list.size() > 0) { jsonObject.put("data", reList); jsonObject.put("totalCount", list.size()); String result = jsonObject.toString(); Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/impl/GoodsBindSrvImpl.java =================================================================== diff -u -r15116 -r15948 --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/impl/GoodsBindSrvImpl.java (.../GoodsBindSrvImpl.java) (revision 15116) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/impl/GoodsBindSrvImpl.java (.../GoodsBindSrvImpl.java) (revision 15948) @@ -5,6 +5,7 @@ import com.forgon.disinfectsystem.goodsBindingConfig.enums.BidirectionalStatus; import com.forgon.disinfectsystem.goodsBindingConfig.enums.GoodType; import com.forgon.disinfectsystem.goodsBindingConfig.service.GoodsBindSrv; +import com.forgon.disinfectsystem.goodsBindingConfig.vo.BindGoodVo; import com.forgon.tools.hibernate.ObjectDao; import com.forgon.tools.util.IntegerUtils; import net.sf.json.JSONArray; @@ -82,15 +83,12 @@ @Override - public JSONArray handleBind(String name, Integer count) { - if (count == null || count <= 0) { - throw new ParameterException("请输入大于0的数量!"); - } + public JSONArray handleBind(BindGoodVo bindGoodVo) { JSONArray jsonArray = new JSONArray(); //先用主绑定物名称找出对应的次要绑定物 - this.iterateHandleBindGoods(jsonArray, name, count, GoodType.MAIN); + this.iterateHandleBindGoods(jsonArray, bindGoodVo, GoodType.MAIN); //然后用次要绑定物名称去找双向绑定了的主要绑定物 - this.iterateHandleBindGoods(jsonArray, name, count, GoodType.SECOND); + this.iterateHandleBindGoods(jsonArray, bindGoodVo, GoodType.SECOND); logger.debug(String.format("[jsonArray]:%s", jsonArray)); return jsonArray; } @@ -121,61 +119,74 @@ /** * 迭代查找出来的对应绑定物品,并且计算好他们对应的绑定数量 * - * @param jsonArray 最终需要返回的数组,里面有绑定物品的名字和最终绑定数量 - * @param name 绑定物品的名字 - * @param count 页面填写的对应数量 - * @param type {@link GoodType} 物品绑定的类型 + * @param jsonArray 最终需要返回的数组,里面有绑定物品的名字和最终绑定数量 + * @param bindGoodVo {@link BindGoodVo} + * @param type {@link GoodType} 物品绑定的类型 */ - private void iterateHandleBindGoods(JSONArray jsonArray, String name, Integer count, GoodType type) { - List goods = this.findAllBindBindingConfigByNameAndType(name, type); - logger.debug(String.format("[goods]:%s", goods)); - if (CollectionUtils.isNotEmpty(goods)) { - //迭代查找出来的list,并计算应该绑定的数量 - for (GoodsBindingConfig good : goods) { - JSONObject jsonObject = new JSONObject(); - if (GoodType.MAIN.equals(type)) { - //如果当前数量不能整除主要绑定物 - if (count % good.getMainCount() != 0) { - continue; + private void iterateHandleBindGoods(JSONArray jsonArray, BindGoodVo bindGoodVo, GoodType type) { + Integer count = bindGoodVo.getBindCount(); + if (count == null || count <= 0) { + throw new ParameterException("请输入大于0的数量!"); + } + try { + List goods = this.findAllBindingByCondition(bindGoodVo, type); + logger.debug(String.format("[需要绑定的物品]:%s", goods)); + if (CollectionUtils.isNotEmpty(goods)) { + //迭代查找出来的list,并计算应该绑定的数量 + for (GoodsBindingConfig good : goods) { + JSONObject jsonObject = new JSONObject(); + if (GoodType.MAIN.equals(type)) { + //如果当前数量不能整除主要绑定物 + if (count % good.getMainCount() != 0) { + continue; + } + //计算出比例,次绑定物的数量=当前数量/主绑定物数量*次要绑定物数量 + Integer rate = count / good.getMainCount(); + jsonObject.put("goodName", good.getSecondaryGoodName()); + jsonObject.put("bindCount", rate * good.getSecondaryCount()); + jsonObject.put("goodId", good.getSecondaryGoodId()); + jsonArray.add(jsonObject); } - jsonObject.put("name", good.getSecondaryGoodName()); - //计算出比例,次绑定物的数量=当前数量/主绑定物数量*次要绑定物数量 - Integer rate = count / good.getMainCount(); - jsonObject.put("bindCount", rate * good.getSecondaryCount()); - jsonArray.add(jsonObject); - } - else if (GoodType.SECOND.equals(type)) { - //如果当前数量不能整除次要绑定物 - if (count % good.getSecondaryCount() != 0) { - continue; + else if (GoodType.SECOND.equals(type)) { + //如果当前数量不能整除次要绑定物 + if (count % good.getSecondaryCount() != 0) { + continue; + } + //计算出比例,主绑定物的数量=当前数量/次要绑定物数量*主要绑定物数量 + Integer rate = count / good.getSecondaryCount(); + jsonObject.put("goodName", good.getMainGoodName()); + jsonObject.put("bindCount", rate * good.getMainCount()); + jsonObject.put("goodId", good.getMainGoodId()); + jsonArray.add(jsonObject); } - jsonObject.put("name", good.getMainGoodName()); - //计算出比例,主绑定物的数量=当前数量/次要绑定物数量*主要绑定物数量 - Integer rate = count / good.getSecondaryCount(); - jsonObject.put("bindCount", rate * good.getMainCount()); - jsonArray.add(jsonObject); } } } + catch (Exception e) { + logger.error(e); + throw new RuntimeException(e); + } } + /** * 根据名字和绑定物品类型查找所有对应的绑定物品 * - * @param name 绑定物品的名字 - * @param type 绑定物品的类型,主绑定物品还是次要绑定物品 + * @param bindGoodVo {@link BindGoodVo} + * @param type 绑定物品的类型,主绑定物品还是次要绑定物品 * @return {@link GoodsBindingConfig} */ - private List findAllBindBindingConfigByNameAndType(String name, GoodType type) { + private List findAllBindingByCondition(BindGoodVo bindGoodVo, GoodType type) { try { + String id = bindGoodVo.getGoodId(); StringBuilder hql = new StringBuilder("from GoodsBindingConfig po where 1 = 1"); - hql.append(GoodType.MAIN.equals(type) ? String.format(" and po.mainGoodName = '%s' and po.mainGoodType = '一次性物品'", name) : - String.format(" and po.secondaryGoodName = '%s' and po.secondaryGoodType = '一次性物品' and bidirectionalStatus = %s", name, BidirectionalStatus.IS.getVal())); + hql.append(GoodType.MAIN.equals(type) ? String.format(" and po.mainGoodId = '%s' and po.mainGoodType = '一次性物品'", id) : + String.format(" and po.secondaryGoodId = '%s' and po.secondaryGoodType = '一次性物品' and bidirectionalStatus = %s", id, BidirectionalStatus.IS.getVal())); List result = objectDao.findByHql(hql.toString()); return result; } catch (Exception e) { - logger.error(e, e); + logger.error(e); throw new RuntimeException(e); } } Index: ssts-tousse/src/main/java/com/forgon/disinfectsystem/tousse/toussedefinition/action/TousseDefinitionAction.java =================================================================== diff -u -r15886 -r15948 --- ssts-tousse/src/main/java/com/forgon/disinfectsystem/tousse/toussedefinition/action/TousseDefinitionAction.java (.../TousseDefinitionAction.java) (revision 15886) +++ ssts-tousse/src/main/java/com/forgon/disinfectsystem/tousse/toussedefinition/action/TousseDefinitionAction.java (.../TousseDefinitionAction.java) (revision 15948) @@ -21,7 +21,12 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import com.forgon.disinfectsystem.goodsBindingConfig.vo.BindGoodVo; +import com.forgon.disinfectsystem.tousse.toussedefinition.service.GoodBindHelper; import com.forgon.disinfectsystem.tousse.toussedefinition.service.TousseDefinitionHelper; +import com.forgon.tools.json.JSONUtil; +import com.forgon.tools.util.PageUtil; +import com.google.gson.reflect.TypeToken; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import net.sf.json.JsonConfig; @@ -31,6 +36,7 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Namespace; import org.apache.struts2.convention.annotation.ParentPackage; @@ -91,6 +97,8 @@ private String proxyPriceHidden;//器械包代理灭菌价格 private File upload; + protected final Logger logger = Logger.getLogger(this.getClass()); + private TousseDefinition tousseDefinition; private TousseDefinitionManager tousseDefinitionManager; @@ -1946,4 +1954,21 @@ e.printStackTrace(); } } + + public void searchBindGood(){ + try { + String tousseType = StrutsParamUtils.getPraramValue("tousseType", ""); + String findGood = StrutsParamUtils.getPraramValue("findGood", ""); + List bindGoodVos = JSONUtil.fromJson(findGood, new TypeToken>(){}); + Map map = tousseDefinitionManager.searchComboGoods("", tousseType, true, false, null); + GoodBindHelper goodBindHelper = GoodBindHelper.getInstance(); + List> reList = goodBindHelper.handleAddBindGood(bindGoodVos, map); + PageUtil.outPutResult(null, reList); + } + catch (Exception e) { + logger.error(e, e); + PageUtil.outPutResult(null, null); + throw new RuntimeException(e); + } + } } Index: ssts-web/src/main/webapp/disinfectsystem/recyclingApplication/goodsTemplateApplicationView.js =================================================================== diff -u -r15924 -r15948 --- ssts-web/src/main/webapp/disinfectsystem/recyclingApplication/goodsTemplateApplicationView.js (.../goodsTemplateApplicationView.js) (revision 15924) +++ ssts-web/src/main/webapp/disinfectsystem/recyclingApplication/goodsTemplateApplicationView.js (.../goodsTemplateApplicationView.js) (revision 15948) @@ -26,12 +26,13 @@ if (sstsConfig.invoicePlanPrintButtonName != undefined){ invoicePlanPrintButtonName = sstsConfig.invoicePlanPrintButtonName; } +//判断是否ie和ie7 +var isIE6OrIE7 = top.Ext4.isIE6 || top.Ext4.isIE7; // 遮罩层对象 var objMask = { 'printMask' : null, 'loadMask' : null } -// top.printMask = null; /** * 打开对应的表单 * @param form 对应的表单 @@ -279,7 +280,7 @@ //Ext4 申请科室Store var appDepartJsonStore = new Ext4.data.Store({ //limit参数,每页显示条数,默认为25 - pageSize: 15, + pageSize: isIE6OrIE7 ? 15 : 50, autoLoad:false, proxy : { type : 'ajax', @@ -369,12 +370,12 @@ //物品选择下拉框数据源 var comboGoodsStore = new Ext4.data.JsonStore({ - pageSize:100, + pageSize: isIE6OrIE7 ? 30 : 100, proxy : goodProxy, fields : goodModel, listeners:{ beforeload : function(){ - if (!top.Ext4.isIE6 && !top.Ext4.isIE7){ + if (!isIE6OrIE7){ createExt4Mask.call(objMask,'loadMask','数据处理中,请稍候......',applicationWindow); objMask.loadMask.show(); } @@ -383,7 +384,7 @@ } }, load : function(){ - if (!top.Ext4.isIE6 && !top.Ext4.isIE7){ + if (!isIE6OrIE7){ if(objMask.loadMask){ // loadMask.hide(); objMask.loadMask.destroy(); @@ -399,29 +400,6 @@ }); - -//全部物品选择下拉框数据源,只在申请窗口弹出的时候加载一次,用于缓存所有数据,物品绑定的数据从这里读取 -var allGoodsComboStore = new Ext4.data.JsonStore({ - proxy : goodProxy, - fields : goodModel, - listeners:{ - beforeload : function(){ - //在加载前设定参数,limit要设置成空,这样才会加载到所有的数据 - allGoodsComboStore.proxy.extraParams.cssdOrgUnitCode = ""; - allGoodsComboStore.proxy.extraParams.spell = ""; - allGoodsComboStore.proxy.extraParams.limit = ""; - //暂时只绑定一次性物品,所以type用一次性物品 - allGoodsComboStore.proxy.extraParams.tousseType = "一次性物品"; - }, - load : function () { - // console.log(allGoodsComboStore.getCount()); - } - } -}); - - - - var tousseAndDiposableGoodsStore = new Ext.data.Store({ proxy : new Ext.data.HttpProxy({ url : WWWROOT + '/disinfectSystem/baseData/tousseDefinitionAction!searchInsideTousseData.do', @@ -2665,9 +2643,6 @@ ] }); - if (Ext4.isEmpty(applicationWindow)){ - allGoodsComboStore.reload(); - } applicationWindow = new top.Ext4.window.Window({ @@ -2687,7 +2662,7 @@ // loadMask = new Ext4.LoadMask({msg:'数据处理中,请稍候......',target:applicationWindow}); - if (!top.Ext4.isIE6 && !top.Ext4.isIE7){ + if (!isIE6OrIE7){ createExt4Mask.call(objMask,'loadMask','数据处理中,请稍候......',applicationWindow); } else{ @@ -3249,7 +3224,7 @@ // }); var mask; - if (!top.Ext4.isIE6 && !top.Ext4.isIE7){ + if (!isIE6OrIE7){ createMask.call(objMask,'printMask','正在处理批量打印请求,请稍候...',Ext.getBody(),true); objMask.printMask.show(); } @@ -3261,7 +3236,7 @@ RecyclingApplicationTableManager.findPrintRecyclingGoods(JSON.stringify(printParams) , function(result){ var obj = JSON.parse(result); - if (!top.Ext4.isIE6 && !top.Ext4.isIE7){ + if (!isIE6OrIE7){ objMask.printMask.hide(); } else { Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/ctrl/GoodsBindingCtrl.java =================================================================== diff -u -r15116 -r15948 --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/ctrl/GoodsBindingCtrl.java (.../GoodsBindingCtrl.java) (revision 15116) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/ctrl/GoodsBindingCtrl.java (.../GoodsBindingCtrl.java) (revision 15948) @@ -3,6 +3,7 @@ import com.forgon.disinfectsystem.goodsBindingConfig.entity.GoodsBindingConfig; import com.forgon.disinfectsystem.goodsBindingConfig.enums.BidirectionalStatus; import com.forgon.disinfectsystem.goodsBindingConfig.service.GoodsBindSrv; +import com.forgon.disinfectsystem.goodsBindingConfig.vo.BindGoodVo; import com.forgon.tools.StrutsResponseUtils; import net.sf.json.JSONArray; import net.sf.json.JSONObject; @@ -101,9 +102,9 @@ @ResponseBody @RequestMapping(value = "/handleBind") - public void handleBind(@RequestParam("name") String name, @RequestParam("count") Integer count, HttpServletResponse response) { + public void handleBind(@ModelAttribute("bindGoodVo") BindGoodVo bindGoodVo, HttpServletResponse response) { try { - JSONArray jsonArray = goodsBindSrvImpl.handleBind(name, count); + JSONArray jsonArray = goodsBindSrvImpl.handleBind(bindGoodVo); JSONObject jsonObject = new JSONObject(); jsonObject.put("data", jsonArray); StrutsResponseUtils.output(jsonArray, response); Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/service/GoodsBindSrv.java =================================================================== diff -u -r15116 -r15948 --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/service/GoodsBindSrv.java (.../GoodsBindSrv.java) (revision 15116) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/goodsBindingConfig/service/GoodsBindSrv.java (.../GoodsBindSrv.java) (revision 15948) @@ -2,6 +2,7 @@ import com.forgon.disinfectsystem.goodsBindingConfig.entity.GoodsBindingConfig; +import com.forgon.disinfectsystem.goodsBindingConfig.vo.BindGoodVo; import net.sf.json.JSONArray; import java.util.List; @@ -47,10 +48,9 @@ /** * 处理对应的物品绑定 * - * @param name 页面传进来的物品名字 - * @param count 页面传进来的物品数量 + * @param bindGoodVo {@link BindGoodVo} * @return 最终需要绑定的物品(里面有name和bindCount) */ - JSONArray handleBind(String name, Integer count); + JSONArray handleBind(BindGoodVo bindGoodVo); } Index: ssts-web/src/main/webapp/disinfectsystem/goodsBindingConfig/goodsBindHandler.js =================================================================== diff -u -r15116 -r15948 --- ssts-web/src/main/webapp/disinfectsystem/goodsBindingConfig/goodsBindHandler.js (.../goodsBindHandler.js) (revision 15116) +++ ssts-web/src/main/webapp/disinfectsystem/goodsBindingConfig/goodsBindHandler.js (.../goodsBindHandler.js) (revision 15948) @@ -3,19 +3,76 @@ }; /** - * 迭代从后端得到的需要绑定物品的数据,从comboGoodsStore里按照名字来寻找对应需要绑定的数据 + * 绑定物品的代理属性 + */ +GoodsBindHandler.prototype.bindGoodProxy = { + type: 'ajax', + url: WWWROOT + '/disinfectSystem/baseData/tousseDefinitionAction!searchBindGood.do', + reader: { + type: 'json', + totalProperty: 'totalCount', + idProperty: 'noneExsist', + root: 'data' + } +}; + +/** + * 绑定物品的数据源 + */ +GoodsBindHandler.prototype.bindGoodStore = new Ext4.data.JsonStore({ + proxy: GoodsBindHandler.prototype.bindGoodProxy, + fields: goodModel, + listeners: { + beforeload: function () { + //在加载前设定参数,limit要设置成空,这样才会加载到所有的数据 + //暂时只绑定一次性物品,所以type用一次性物品 + // allGoodsComboStore.proxy.extraParams.tousseType = "一次性物品"; + }, + load: function (a, b, c) { + } + } +}) + + +/** + * + * 向后台发送请求查找出需要绑定的物品,并且加载到bindGoodStore中 * @param records 需要绑定物品记录的数组 - * @param data 里面要寻找的名字和对应的绑定数量 + * @param data 要让服务器查询的物品数据(即需要绑定的物品名字,数量,id) */ GoodsBindHandler.prototype.findBindRecord = function (records, data) { + var me = this; + me.bindGoodStore.reload({ + params: { + tousseType: "一次性物品", + findGood: JSON.stringify(data) + }, + callback: function (r, option, success) { + if (success) { + me.findAndSetBindGood(records, data); + } + } + }); +} + +/** + * 从bindGoodStore数据源中查找对应的物品,设置好对应的数量并添加到表格里 + * @param records 需要绑定物品记录的数组 + * @param data 要寻找的物品的名字和对应的绑定数量 + */ +GoodsBindHandler.prototype.findAndSetBindGood = function (records, data) { + var me = this; top.Ext4.each(data, function (item) { - var record = allGoodsComboStore.findRecord('name', item.name); + // var record = me.bindGoodStore.findRecord('name', item.goodName); + var record = me.bindGoodStore.findRecord('id', item.goodId); if (record != null) { //如果找得到,设置数量为后端传过来的捆绑数量 - record.set('count', item.bindCount); + // record.set('count', item.bindCount); + record.set('count', record.get('amount')); records.push(record); } }); + me.addBindGood(records); } /** @@ -68,9 +125,15 @@ var me = this; var applicationCount = top.Ext4.getCmp('count1').getValue(); var applicationName = top.Ext4.getCmp('package1').getValue(); + var bindGoodVo = { + goodName: applicationName, + bindCount: applicationCount, + goodId: curSelectedGoods.id, + goodType: curSelectedGoods.type + } Ext.Ajax.request({ url: WWWROOT + '/disinfectSystem/goodsBindingConfig/goodsBindingCtrl/handleBind.mhtml', - params: {count: applicationCount, name: applicationName}, + params: bindGoodVo, timeout: 600000, method: 'POST', success: function (response, options) { @@ -79,7 +142,6 @@ var result = Ext.decode(response.responseText); if (!isUndefinedOrNullOrEmpty(result)) { me.findBindRecord(records, result); - me.addBindGood(records); } } catch (e) {