Jelajahi Sumber

批次管理

wangxiaoming 7 tahun lalu
induk
melakukan
561f6782a0

+ 12 - 9
watero-rst-core/src/main/java/com.iamberry.rst.core/pts/PtsBatch.java

@@ -2,6 +2,7 @@ package com.iamberry.rst.core.pts;
 
 import java.io.Serializable;
 import java.util.Date;
+import java.util.List;
 
 /**
  * 生产批次类
@@ -25,7 +26,7 @@ public class PtsBatch implements Serializable{
 
     private Integer batchSoftwareVersionId;//软件版本
 
-    private Integer batchHardwareVersionId;//硬件版本
+    //private Integer batchHardwareVersionId;//硬件版本
 
     private Integer batchStatus;//批次状态:0:停止使用;1:正常使用;
 
@@ -41,6 +42,8 @@ public class PtsBatch implements Serializable{
 
     private String softwareVersionNo; //软件版本号
 
+    private List<PtsBatchColor> ptsBatchColorList; //颜色集合
+
     public Integer getBatchId() {
         return batchId;
     }
@@ -89,14 +92,6 @@ public class PtsBatch implements Serializable{
         this.batchSoftwareVersionId = batchSoftwareVersionId;
     }
 
-    public Integer getBatchHardwareVersionId() {
-        return batchHardwareVersionId;
-    }
-
-    public void setBatchHardwareVersionId(Integer batchHardwareVersionId) {
-        this.batchHardwareVersionId = batchHardwareVersionId;
-    }
-
     public Integer getBatchStatus() {
         return batchStatus;
     }
@@ -168,4 +163,12 @@ public class PtsBatch implements Serializable{
     public void setGeneratedQuantity(Integer generatedQuantity) {
         this.generatedQuantity = generatedQuantity;
     }
+
+    public List<PtsBatchColor> getPtsBatchColorList() {
+        return ptsBatchColorList;
+    }
+
+    public void setPtsBatchColorList(List<PtsBatchColor> ptsBatchColorList) {
+        this.ptsBatchColorList = ptsBatchColorList;
+    }
 }

+ 10 - 0
watero-rst-core/src/main/java/com.iamberry.rst.core/pts/PtsBom.java

@@ -17,6 +17,8 @@ public class PtsBom implements Serializable{
 
     private Integer produceId;//产品id
 
+    private String bomVersion; //版本
+
     private String bomRemarks;//备注
 
     private Date bomCreateTime;//创建时间
@@ -109,4 +111,12 @@ public class PtsBom implements Serializable{
     public void setProduceName(String produceName) {
         this.produceName = produceName;
     }
+
+    public String getBomVersion() {
+        return bomVersion;
+    }
+
+    public void setBomVersion(String bomVersion) {
+        this.bomVersion = bomVersion;
+    }
 }

+ 3 - 1
watero-rst-interface/src/main/java/com/iamberry/rst/faces/pts/PtsBatchService.java

@@ -11,7 +11,7 @@ import java.util.List;
  */
 public interface PtsBatchService {
 
-    //查询bom单列表
+    //查询b批次列表
     PagedResult<PtsBatch> listPtsBatchPage(int pageNO, int pageSize, PtsBatch ptsBatch, boolean isTotalNum);
 
     //添加批次
@@ -22,4 +22,6 @@ public interface PtsBatchService {
 
     //修改批次
     Integer updatePtsBatch(PtsBatch ptsBatch);
+
+
 }

+ 16 - 3
watero-rst-service/src/main/java/com/iamberry/rst/service/pts/PtsBatchServiceImpl.java

@@ -29,16 +29,29 @@ public class PtsBatchServiceImpl implements PtsBatchService {
 
     @Override
     public Integer savePtsBatch(PtsBatch ptsBatch) {
-        return null;
+        if(ptsBatch.getBatchStatus() == 1){
+            PtsBatch pts = new PtsBatch();
+            pts.setBatchStatus(1);
+            pts.setProduceId(ptsBatch.getProduceId());
+            ptsBatchMapper.batchStatusDisabled(ptsBatch);; //修改批次状态
+        }
+        return ptsBatchMapper.savePtsBatch(ptsBatch);
     }
 
     @Override
     public PtsBatch getPtsBatch(PtsBatch ptsBatch) {
-        return null;
+        return ptsBatchMapper.getPtsBatch(ptsBatch);
     }
 
     @Override
     public Integer updatePtsBatch(PtsBatch ptsBatch) {
-        return null;
+        if(ptsBatch.getBatchStatus() == 1){
+            PtsBatch pts = new PtsBatch();
+            pts.setBatchStatus(1);
+            pts.setProduceId(ptsBatch.getProduceId());
+            ptsBatchMapper.batchStatusDisabled(ptsBatch);; //修改批次状态
+        }
+        return ptsBatchMapper.updatePtsBatch(ptsBatch);
     }
+
 }

+ 3 - 0
watero-rst-service/src/main/java/com/iamberry/rst/service/pts/mapper/PtsBatchMapper.java

@@ -17,4 +17,7 @@ public interface PtsBatchMapper {
 
     //修改批次
     Integer updatePtsBatch(PtsBatch ptsBatch);
+
+    //停用其他相同产品的批次
+    Integer batchStatusDisabled(PtsBatch ptsBatch);
 }

+ 69 - 3
watero-rst-service/src/main/java/com/iamberry/rst/service/pts/mapper/ptsBatchMapper.xml

@@ -33,17 +33,83 @@
                 AND t.batch_no like CONCAT('%',#{batchNo},'%')
             </if>
         </where>
+        GROUP BY t.batch_id
+        ORDER BY t.batch_status DESC, t.batch_id DESC
     </select>
 
     <select id="getPtsBatch" parameterType="PtsBatch" resultType="PtsBatch">
-
+        SELECT
+            t.batch_id AS batchId,
+            t.batch_no AS batchNo,
+            t.batch_quantity AS batchQuantity,
+            t.batch_color_quantity AS batchColorQuantity,
+            t.bom_id AS bomId,
+            t.produce_id AS produceId,
+            t.batch_software_version_id AS batchSoftwareVersionId,
+            t.batch_status AS  batchStatus,
+            t.batch_desc AS batchDesc,
+            t.batch_create_time AS batchCreateTime,
+            t.batch_update_time AS batchUpdateTime
+        FROM
+            tb_rst_pts_batch t
+        <where>
+            <if test="produceId !=null">
+                AND t.produce_id = #{produceId}
+            </if>
+            <if test="batchNo !=null and batchNo !=''">
+                AND t.batch_no = #{batchNo}
+            </if>
+            <if test="batchId !=null and batchId !=''">
+                AND t.batch_id = #{batchId}
+            </if>
+        </where>
     </select>
 
     <insert id="savePtsBatch" parameterType="PtsBatch" useGeneratedKeys="true" keyProperty="batchId">
-
+            insert into tb_rst_pts_batch (`batch_no` ,`batch_quantity` ,`batch_color_quantity` ,`bom_id` ,`produce_id` ,`batch_software_version_id` ,`batch_status` ,`batch_desc` )
+            values (#{batchNo},#{batchQuantity},#{batchColorQuantity},#{bomId},#{produceId},#{batchSoftwareVersionId},#{batchStatus},#{batchDesc})
     </insert>
 
-    <update id="updatePtsBatch" parameterType="PtsBatch">
+    <update id="batchStatusDisabled" parameterType="PtsBatch">
+        update
+            tb_rst_pts_batch
+        set
+           batch_status = 0
+        where
+            produce_id = #{produceId}
+            AND batch_status = #{batchStatus}
+    </update>
 
+    <update id="updatePtsBatch" parameterType="PtsBatch">
+        update
+            tb_rst_pts_batch
+        <set>
+            <if test="batchNo !=null and batchNo !=''">
+                batch_no = #{batchNo},
+            </if>
+            <if test="batchQuantity !=null and batchQuantity !=''">
+                batch_quantity = #{batchQuantity},
+            </if>
+            <if test="batchColorQuantity !=null and batchColorQuantity !=''">
+                batch_color_quantity = #{batchColorQuantity},
+            </if>
+            <if test="produceId !=null">
+                produce_id = #{produceId},
+            </if>
+            <if test="bomId !=null  and bomId !=''">
+                bom_id = #{bomId},
+            </if>
+            <if test="batchSoftwareVersionId !=null">
+                batch_software_version_id = #{batchSoftwareVersionId},
+            </if>
+            <if test="batchStatus !=null">
+                batch_status = #{batchStatus},
+            </if>
+            <if test="batchDesc !=null and batchDesc !=''">
+                batch_desc = #{batchDesc}
+            </if>
+        </set>
+        WHERE
+            batch_id = #{batchId}
     </update>
 </mapper>

+ 8 - 3
watero-rst-service/src/main/java/com/iamberry/rst/service/pts/mapper/ptsBomMapper.xml

@@ -7,6 +7,7 @@
         trpb.bom_id AS bomId,
         trpb.bom_name AS bomName,
         trpb.produce_id AS produceId,
+        trpb.bom_version AS bomVersion,
         trpb.bom_remarks AS bomRemarks,
         trpb.bom_create_time AS bomCreateTime,
         trpb.bom_update_time AS bomUpdateTime,
@@ -44,6 +45,7 @@
         trpb.bom_id AS bomId,
         trpb.bom_name AS bomName,
         trpb.produce_id AS produceId,
+        trpb.bom_version AS bomVersion,
         trpb.bom_remarks AS bomRemarks,
         trpb.bom_create_time AS bomCreateTime,
         trpb.bom_update_time AS bomUpdateTime,
@@ -77,8 +79,8 @@
 
 
     <insert id="savePtsBom" parameterType="PtsBom" useGeneratedKeys="true" keyProperty="bomId">
-         insert into tb_rst_pts_bom (bom_name ,produce_id ,bom_remarks  )
-         values (#{bomName},#{produceId},#{bomRemarks})
+         insert into tb_rst_pts_bom (bom_name ,produce_id ,bom_remarks,bom_version  )
+         values (#{bomName},#{produceId},#{bomRemarks},#{bomVersion})
     </insert>
 
     <insert id="savePtsBomComponentsList" parameterType="java.util.List" useGeneratedKeys="true">
@@ -101,7 +103,10 @@
                 produce_id = #{produceId},
             </if>
             <if test="bomRemarks !=null  and bomRemarks !=''">
-                bom_remarks = #{bomRemarks}
+                bom_remarks = #{bomRemarks},
+            </if>
+            <if test="bomVersion !=null  and bomVersion !=''">
+                bom_version = #{bomVersion}
             </if>
         </set>
         where

+ 144 - 24
watero-rst-web/src/main/java/com/iamberry/rst/controllers/pts/AdminPtsBatchController.java

@@ -1,15 +1,14 @@
 package com.iamberry.rst.controllers.pts;
 
 import com.iamberry.rst.core.page.PagedResult;
-import com.iamberry.rst.core.pts.Produce;
-import com.iamberry.rst.core.pts.PtsBatch;
-import com.iamberry.rst.core.pts.PtsBom;
-import com.iamberry.rst.core.pts.PtsMachineVersion;
+import com.iamberry.rst.core.pts.*;
+import com.iamberry.rst.faces.pts.MachineVersionService;
 import com.iamberry.rst.faces.pts.ProduceService;
 import com.iamberry.rst.faces.pts.PtsBatchService;
 import com.iamberry.rst.faces.pts.PtsBomService;
 import com.iamberry.rst.utils.StitchAttrUtil;
 import com.iamberry.wechat.tools.ResponseJson;
+import net.sf.json.JSONArray;
 import org.apache.shiro.authz.annotation.Logical;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -20,6 +19,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.servlet.ModelAndView;
 
 import javax.servlet.http.HttpServletRequest;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -40,6 +40,11 @@ public class AdminPtsBatchController {
     @Autowired
     private PtsBomService ptsBomService;
 
+    @Autowired
+    private MachineVersionService machineVersionService;
+
+    private String[] BATCH_COLOR = {"黑色","白色","红色","蓝色","绿色","橙色","黄色","青色","紫色"};
+
     /**
      * 获取batch单列表
      *
@@ -73,7 +78,7 @@ public class AdminPtsBatchController {
      */
     @RequiresPermissions("batch:add:batch")
     @RequestMapping(value = "/to_add_batch")
-    public ModelAndView toAddBom(HttpServletRequest request) {
+    public ModelAndView toAddbatch(HttpServletRequest request) {
         ModelAndView mv = new ModelAndView("pts/batch/add_batch");
 
         //获取产品集合,用于页面选择产品
@@ -91,25 +96,41 @@ public class AdminPtsBatchController {
     @ResponseBody
     @RequiresPermissions("batch:add:batch")
     @RequestMapping(value = "/save_batch")
-    public ResponseJson saveBom(PtsBatch ptsBatch, String batchComponentJson, HttpServletRequest request) {
+    public ResponseJson saveBatch(PtsBatch ptsBatch, HttpServletRequest request) {
 
-        if (!this.isValiData(ptsBatch) || batchComponentJson == null) {
-            return new ResponseJson(500, "ERROR", 500);
+        if (!this.isValiData(ptsBatch)  ) {
+            return new ResponseJson(500, "请检查表单,再次提交", 500);
         }
+        Integer flag = ptsBatchService.savePtsBatch(ptsBatch);
+        if (flag < 1) {
+            return new ResponseJson(500, "添加失败", 500);
+        } else {
+            return new ResponseJson(200, "添加成功", 200);
+        }
+    }
 
-        return new ResponseJson(200, "添加成功", 200);
-
-//        JSONArray jsonArray = JSONArray.fromObject(batchComponentJson);
-//        List<PtsBatchComponents> ptsBatchComponentsList = (List) JSONArray.toCollection(jsonArray, PtsBatchComponents.class);
-//        ptsBatch.setPtsBatchComponentsList(ptsBatchComponentsList);
-//
-//        Integer flag = ptsBatchService.savePtsBatch(ptsBatch);
-//
-//        if (flag < 1) {
-//            return new ResponseJson(500, "添加失败", 500);
-//        } else {
-//            return new ResponseJson(200, "添加成功", 200);
-//        }
+    /**
+     * 列表,修改批次状态
+     *
+     * @return
+     */
+    @ResponseBody
+    @RequiresPermissions("batch:select:list")
+    @RequestMapping(value = "/update_batch_status")
+    public ResponseJson updateBatchStatus(Integer batchId, Integer batchStatus,Integer produceId) {
+        PtsBatch ptsBatch = new PtsBatch();
+        if(batchId == null ||  batchStatus == null || produceId == null){
+            return new ResponseJson(500, "修改失败", 500);
+        }
+        ptsBatch.setBatchId(batchId);
+        ptsBatch.setBatchStatus(batchStatus);
+        ptsBatch.setProduceId(produceId);
+        Integer flag = ptsBatchService.updatePtsBatch(ptsBatch);
+        if (flag < 1) {
+            return new ResponseJson(500, "修改失败", 500);
+        } else {
+            return new ResponseJson(200, "修改成功", 200);
+        }
     }
 
 
@@ -121,7 +142,7 @@ public class AdminPtsBatchController {
     @ResponseBody
     @RequiresPermissions(value = {"batch:add:batch", "batch:update:batch"}, logical = Logical.OR)
     @RequestMapping(value = "/get_version")
-    public ResponseJson getBom(HttpServletRequest request) {
+    public ResponseJson getVersion(HttpServletRequest request) {
 
         String produceId = request.getParameter("produceId");
         if (produceId == null || "".equals(produceId)) {
@@ -130,7 +151,7 @@ public class AdminPtsBatchController {
 
         PtsMachineVersion ptsMachineVersion = new PtsMachineVersion();
         ptsMachineVersion.setProduceId(Integer.valueOf(produceId));
-        List<PtsMachineVersion> ptsMachineVersionList = null; //ptsBomService.listPtsMachineVersionByPro(ptsMachineVersion);
+        List<PtsMachineVersion> ptsMachineVersionList = machineVersionService.listMachineVersion(ptsMachineVersion);
 
         if (ptsMachineVersionList != null) {
             ResponseJson rj = new ResponseJson(200, "SUCCESS", 200);
@@ -141,6 +162,28 @@ public class AdminPtsBatchController {
         }
     }
 
+    /**
+     * 获取单个批次
+     *
+     * @return
+     */
+    @ResponseBody
+    @RequiresPermissions(value = {"batch:add:batch", "batch:update:batch"}, logical = Logical.OR)
+    @RequestMapping(value = "/is_valiBatchNo")
+    public ResponseJson getIsValiBatchNo(HttpServletRequest request) {
+
+        String batchNo = request.getParameter("batchNo");
+        if (batchNo == null || "".equals(batchNo)) {
+            return new ResponseJson(500, "未获取到批次编号", 500);
+        }
+        PtsBatch ptsBatch = new PtsBatch();
+        ptsBatch.setBatchNo(batchNo);
+        ptsBatch = ptsBatchService.getPtsBatch(ptsBatch);
+
+        ResponseJson rj = new ResponseJson(200, "SUCCESS", 200);
+        rj.addResponseKeyValue("ptsBatch", ptsBatch);
+        return rj;
+    }
 
     /***
      * 验证信息
@@ -149,9 +192,86 @@ public class AdminPtsBatchController {
      */
     public boolean isValiData(PtsBatch ptsBatch) {
         boolean flag = true;
-
+        if(ptsBatch.getBatchNo() == null  || ptsBatch.getBatchNo().length() >= 20){
+            return false;
+        }
+        if (ptsBatch.getBatchQuantity() == null || ptsBatch.getBatchQuantity() == 0){
+            return false;
+        }
+        if (ptsBatch.getBomId() == null){
+            return false;
+        }
+        if (ptsBatch.getProduceId() == null){
+            return false;
+        }
+        if (ptsBatch.getBatchSoftwareVersionId() == null){
+            return false;
+        }
+        if (ptsBatch.getBatchStatus() == null){
+            return false;
+        }
         return flag;
     }
 
+    /**
+     * 跳转到修改批次页面
+     *
+     * @return
+     */
+    @RequiresPermissions("batch:update:batch")
+    @RequestMapping(value = "/to_update_batch")
+    public ModelAndView toUpdateBatch(Integer batchId, HttpServletRequest request) {
+        ModelAndView mv = new ModelAndView("pts/batch/update_batch");
+
+        PtsBatch ptsBatch = new PtsBatch();
+        ptsBatch.setBatchId(batchId);
+        ptsBatch = ptsBatchService.getPtsBatch(ptsBatch);
+
+        //颜色集合
+        JSONArray jsonArray = JSONArray.fromObject(ptsBatch.getBatchColorQuantity());
+        List<PtsBatchColor> ptsBatchColorList = (List) JSONArray.toCollection(jsonArray, PtsBatchColor.class);
+        ptsBatch.setPtsBatchColorList(ptsBatchColorList);
+
+        //bom单
+        PtsBom ptsBom = new PtsBom();
+        ptsBom.setProduceId(ptsBatch.getProduceId());
+        List<PtsBom> ptsBomsList = ptsBomService.listBom(ptsBom);
+
+        //版本
+        PtsMachineVersion ptsMachineVersion = new PtsMachineVersion();
+        ptsMachineVersion.setProduceId(ptsBatch.getProduceId());
+        List<PtsMachineVersion> ptsMachineVersionList = machineVersionService.listMachineVersion(ptsMachineVersion);
+
+        //获取产品集合,用于页面选择产品
+        List<Produce> produceList = produceService.getProduceList();
+
+        mv.addObject("ptsBatch", ptsBatch);
+        mv.addObject("ptsBomsList", ptsBomsList);
+        mv.addObject("produceList", produceList);
+        mv.addObject("ptsMachineVersionList", ptsMachineVersionList);
+        mv.addObject("batchColor", BATCH_COLOR);
+        return mv;
+    }
+
+    /**
+     * 修改批次
+     *
+     * @return
+     */
+    @ResponseBody
+    @RequiresPermissions("batch:add:batch")
+    @RequestMapping(value = "/update_batch")
+    public ResponseJson updateBatch(PtsBatch ptsBatch, String batchColorJson, HttpServletRequest request) {
+
+        if (!this.isValiData(ptsBatch)  ) {
+            return new ResponseJson(500, "请检查表单,再次提交", 500);
+        }
+        Integer flag = ptsBatchService.updatePtsBatch(ptsBatch);
+        if (flag < 1) {
+            return new ResponseJson(500, "修改失败", 500);
+        } else {
+            return new ResponseJson(200, "修改成功", 200);
+        }
+    }
 
 }

+ 17 - 4
watero-rst-web/src/main/java/com/iamberry/rst/controllers/pts/AdminPtsBomController.java

@@ -94,7 +94,7 @@ public class AdminPtsBomController {
     public ResponseJson saveBom(PtsBom ptsBom, String bomComponentJson, HttpServletRequest request) {
 
         if (!this.isValiData(ptsBom) || bomComponentJson == null) {
-            return new ResponseJson(500, "ERROR", 500);
+            return new ResponseJson(500, "请检查表单,再次提交", 500);
         }
 
         JSONArray jsonArray = JSONArray.fromObject(bomComponentJson);
@@ -110,12 +110,22 @@ public class AdminPtsBomController {
         }
     }
 
+    /**
+     * 验证方法
+     * @param ptsBom
+     * @return
+     */
     public boolean isValiData(PtsBom ptsBom) {
         boolean flag = true;
-        if (ptsBom.getBomName() != null && "".equals(ptsBom.getBomName())) {
-
+        if (ptsBom.getBomName() == null || "".equals(ptsBom.getBomName())) {
+            return false;
+        }
+        if(ptsBom.getProduceId() == null){
+            return false;
+        }
+        if(ptsBom.getBomVersion() == null || "".equals(ptsBom.getBomVersion())){
+            return false;
         }
-
         return flag;
     }
 
@@ -246,6 +256,9 @@ public class AdminPtsBomController {
     @RequiresPermissions("bom:add:bom")
     @RequestMapping(value = "/update_bom")
     public ResponseJson updateBom(PtsBom ptsBom, String bomComponentJson, HttpServletRequest request) {
+        if (!this.isValiData(ptsBom) || bomComponentJson == null) {
+            return new ResponseJson(500, "请检查表单,再次提交", 500);
+        }
 
         JSONArray jsonArray = JSONArray.fromObject(bomComponentJson);
         List<PtsBomComponents> ptsBomComponentsList = (List) JSONArray.toCollection(jsonArray, PtsBomComponents.class);

+ 1 - 0
watero-rst-web/src/main/resources/watero-rst-orm.xml

@@ -77,5 +77,6 @@
 		<mapper resource="com/iamberry/rst/service/pts/mapper/machinePartsMapper.xml"/>
 		<mapper resource="com/iamberry/rst/service/pts/mapper/machineSupplierMapper.xml"/>
 		<mapper resource="com/iamberry/rst/service/pts/mapper/machineVersionMapper.xml"/>
+		<mapper resource="com/iamberry/rst/service/pts/mapper/ptsBatchMapper.xml"/>
 	</mappers>
 </configuration>

+ 156 - 39
watero-rst-web/src/main/webapp/WEB-INF/views/pts/batch/add_batch.ftl

@@ -46,14 +46,14 @@
         <div class="row cl">
             <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>批次编号:</label>
             <div class="formControls col-xs-8 col-sm-9">
-				<input type="text" class="input-text" value="" id="batchNo" name="batchNo" placeholder="请输入1-20位的名称,支持字母、数字" datatype="/^[a-zA-Z0-9\u4e00-\u9fa5]{1,20}$/" errormsg="请输入1-20位的名称,支持字母、数字!">
+				<input type="text" class="input-text" value="" id="batchNo" name="batchNo" placeholder="请输入1-20位的名称,支持字母、数字" datatype="/^[a-zA-Z0-9]{1,20}$/" errormsg="请输入1-20位的名称,支持字母、数字!">
             </div>
         </div>
 
         <div class="row cl">
             <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>批次数量:</label>
             <div class="formControls col-xs-8 col-sm-9 components">
-                <input type="hidden" id="batchColorJson" name="batchColorJson">
+                <input type="hidden" id="batchColorQuantity" name="batchColorQuantity">
                 <table class="table table-border table-bordered table-bg table-hover table-sort">
                     <thead>
                     <tr class="text-c">
@@ -67,43 +67,52 @@
                 </table>
             </div>
         </div>
+        <div class="row cl">
+            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
+                <input class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;新增零件&nbsp;&nbsp;" onclick="addBatchColor('','')">
+            </div>
+        </div>
 
         <div class="row cl">
             <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>批次总数量:</label>
             <div class="formControls col-xs-8 col-sm-9">
-				<input type="text" class="input-text" value="" id="batchQuantity" name="batchQuantity" placeholder="该批次的总数量,只能输入数字且不能超过999999" datatype="n1-3" errormsg="批次数量只能输入数字且不能超过999999!">
+				<input type="text" class="input-text" value=""  name="batchQuantity" disabled="disabled"  style="background: #eee;" placeholder="该批次的总数量" datatype="n1-6"  errormsg="批次数量只能输入数字且不能超过999999!">
+                <input type="hidden" class="input-text" value=""  name="batchQuantity" >
             </div>
         </div>
 
         <div class="row cl">
-            <label class="form-label col-xs-4 col-sm-3">软件版本:</label>
+            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>软件版本:</label>
             <div class="formControls col-xs-8 col-sm-9">
                 <span class="select-box">
-				    <select class="select" size="1" name="batchSoftwareVersionId" id="batchSoftwareVersionId">
+				    <select class="select" size="1" name="batchSoftwareVersionId" id="batchSoftwareVersionId"  datatype="*" errormsg="请选择软件版本">
 				    </select>
 				</span>
+                <span id="batchSoftwareVersionIdMsg" style="color: red;"></span>
             </div>
         </div>
 
         <div class="row cl">
-            <label class="form-label col-xs-4 col-sm-3">Bom单:</label>
-            <div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
-				<select class="select" size="1" name="bomId" id="bomId">
-				</select>
+            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>Bom单:</label>
+            <div class="formControls col-xs-8 col-sm-9">
+                <span class="select-box" >
+                    <select class="select" size="1" name="bomId" id="bomId" datatype="*" errormsg="请选择Bom单">
+                    </select>
 				</span>
+                <span id="bomIdMsg" style="color: red;"></span>
             </div>
         </div>
 
 
         <div class="row cl">
-            <label class="form-label col-xs-4 col-sm-3">批次状态:</label>
+            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>批次状态:</label>
             <div class="formControls col-xs-8 col-sm-9">
                 <div class="radio-box">
-                    <input type="radio" id="batchStatus-1" name="batchStatus" checked >
+                    <input type="radio" id="batchStatus-1" name="batchStatus" checked  value="1">
                     <label for="batchStatus-1">立即使用</label>
                 </div>
                 <div class="radio-box">
-                    <input type="radio" id="batchStatus-2" name="batchStatus">
+                    <input type="radio" id="batchStatus-2" name="batchStatus" value="0">
                     <label for="batchStatus-2">暂不使用</label>
                 </div>
             </div>
@@ -132,6 +141,11 @@
     </form>
 </article>
 <script type="text/javascript">
+    /*颜色枚举值*/
+    var colorAll = ['黑色','白色','红色','蓝色','绿色','橙色','黄色','青色','紫色'];
+
+    /*修改批次时,获取之前的批次编号,添加页面为空*/
+    var upBatchNo = null;
 
     $(function(){
         $("#form-batch-add").Validform({
@@ -142,13 +156,7 @@
                 }
             },
             datatype: {//自定义验证类型
-                "select": function (gets, obj, curform, regxp) {
-                    if (gets == "") {
-                        return false;
-                    } else {
-                        return true;
-                    }
-                }
+
             },
             ignoreHidden: true,
             tipSweep: true, //若为true,则只在表单提交时验证
@@ -156,6 +164,27 @@
             beforeCheck: function (curform) {  //验证通过之前执行的函数
             },
             beforeSubmit: function (curform) {  //验证通过之后执行的函数
+                //批次编号不能重复 --   重复为false  不重复(可用)为true
+                var batchNo = $("#batchNo").val();
+                if(upBatchNo == null || typeof(upBatchNo) == "undefined"){
+                    if(!isValiBatchNo(batchNo)){
+                        layer.msg("批次编号重复", {icon: 5, time: 3000});
+                        return false;
+                    }
+                }
+
+                //计算批次数量
+                calculationQuantity();
+
+                //合并 批次颜色信息
+                var colorList =  new Array();
+                $("#batchColorAll").find("tr").each(function(){
+                    var ptsBatchColor  = {};
+                    ptsBatchColor.colorName = $(this).find("[name='colorName']").eq(0).val();
+                    ptsBatchColor.colorQuantity =  $(this).find("[name='colorQuantity']").eq(0).val();
+                    colorList.push(ptsBatchColor);
+                })
+                $("#batchColorQuantity").val(JSON.stringify(colorList));
             },
             callback: function (data) {//异步回调函数
                 if (data) {
@@ -171,24 +200,49 @@
         });
     })
 
-    /*颜色枚举值全局变量*/
-    var colorAll = ['黑','红','橙','黄','绿','青','蓝','紫','白']
 
     $(function () {
         /*添加页面初始化,将根据产品的来获取bom和软件版本*/
-        var produceId =   $("[name='produceId']").val();
+        var produceId = $("[name='produceId']").val();
         getBomByProduce(produceId);
         getVersionByProduce(produceId);
 
         /*初始化一个颜色*/
-        addBatchColor();
+        addBatchColor('','');
 
         /*监听产品选择*/
-//        $("[name='produceId']").change(function(){
-//            var produceId = $(this).val();
-//            getBomByProduce(produceId);
-//        })
+        $("[name='produceId']").change(function(){
+            var produceId = $(this).val();
+            getBomByProduce(produceId);
+            getVersionByProduce(produceId);
+        })
     })
+    
+
+    /*判断batch是否重复   重复为false  不重复(可用)为true */
+    function isValiBatchNo(batchNo) {
+        var boolean = false;
+        $.ajax({
+            type: "POST",
+            data: {
+                batchNo : batchNo
+            },
+            url: "${path}/admin/batch/is_valiBatchNo",
+            async: false,
+            success: function(data){
+                if (data.returnCode == 200 ) {
+                    if(data.returnMsg.ptsBatch == null ){
+                        boolean = true
+                    }
+                }else{
+                    layer.msg(data.resultMsg, {icon: 5, time: 3000});
+                }
+            },
+            error: function(XmlHttpRequest, textStatus, errorThrown){
+            }
+        });
+        return boolean;
+    }
 
     /*根据产品id,获取bom集合*/
     function getBomByProduce(produceId){
@@ -208,7 +262,9 @@
                     }
                 }
                 if(data.returnCode != 200 || data.returnMsg.ptsBomsList <1){
-                    layer.msg('系统没有对应产品的Bom单,请到Bom单管理中添加Bom', {icon: 5, time: 3000});
+                    $("#bomIdMsg").html("系统没有对应产品的Bom单,请到Bom单管理中添加Bom单");
+                }else{
+                    $("#bomIdMsg").html("");
                 }
                 $("[name='bomId']").html(html);
             },
@@ -224,7 +280,7 @@
             data: {
                 produceId : produceId
             },
-            url: "${path}/admin/batch/get_listBatch",
+            url: "${path}/admin/batch/get_version",
             async: false,
             success: function(data){
                 var html = '';
@@ -235,9 +291,11 @@
                     }
                 }
                 if(data.returnCode != 200 || data.returnMsg.ptsMachineVersionList <1){
-                    layer.msg('系统没有对应产品的Bom单,请到Bom单管理中添加Bom', {icon: 5, time: 3000});
+                    $("#batchSoftwareVersionIdMsg").html("系统没有对应产品的软件版本,请到版本管理中添加软件版本");
+                }else{
+                    $("#batchSoftwareVersionIdMsg").html("");
                 }
-                $("[name='bomId']").html(html);
+                $("[name='batchSoftwareVersionId']").html(html);
             },
             error: function(XmlHttpRequest, textStatus, errorThrown){
             }
@@ -245,18 +303,77 @@
     }
 
     /*添加颜色*/
-    function addBatchColor() {
-        //获取颜色枚举值
-        getColorAll();
-
+    function addBatchColor(colorName,colorQuantity) {
+        var notAddColor = colorAll
+        var opHtml = '';
+        for(var i=0;i<notAddColor.length;i++){
+            opHtml += '<option value="'+ notAddColor[i] +'" >'+ notAddColor[i] + '</option>'
+        }
+        var html = '<tr class="text-c">'
+                +'<td>'
+                +'<select class="select" size="1" name="colorName" style="height: 30px;">'
+                + opHtml
+                +'</select>'
+                +'</td>'
+                +'<td>'
+                +'<input type="text" class="input-text colorQuantity" value="" onblur="calculationQuantity()" name="colorQuantity" placeholder="数量" datatype="n1-5" errormsg="零件数量只能为数字且不能超过99999!">'
+                +'</td>'
+                +'<td>'
+                +'<a style="" href="javascript:void(0);" title="删除" onclick="delComponent(this,1)"> '
+                +'<i class="Hui-iconfont">&#xe609;</i>'
+                +'</a>'
+                +'</td> '
+                +'</tr>';
+        $("#batchColorAll").append(html);
     }
 
-    /*获取颜色枚举值*/
-    function getColorAll() {
-        for(var i++; i<colorAll.length;i++){
-
+    /*删除颜色  type=all时删除所有的颜色,但必须要保留一个颜色 */
+    function delComponent(node,type) {
+        if(type == "all"){
+            $("#batchColorAll").find("tr").each(function () {
+                $(this).remove();
+            })
+        }else{
+            //删除零件必须保证还有一个颜色
+            var batchLength = $("#batchColorAll").find("tr").length;
+            if(batchLength > 1){
+                $(node).parent().parent().remove();
+            }else{
+                layer.msg('必须要有一个颜色', {icon: 5, time: 3000});
+            }
         }
+        //删除操作需要计算总数量
+        calculationQuantity();
     }
+
+    /**计算批次总数量*/
+    function calculationQuantity(){
+        var quantity = 0;
+        $("#batchColorAll").find("[name='colorQuantity']").each(function (){
+            var colorQuantity = $(this).val();
+            var myreg = /^[0-9]*$/;
+            if( colorQuantity != null && colorQuantity != "" && typeof(colorQuantity) != "undefined"){
+                if(myreg.test(colorQuantity))
+                {
+                    quantity += parseInt(colorQuantity);
+                }
+            }
+        })
+        $("[name='batchQuantity']").val(quantity);
+    }
+
+    /*获取未被添加的颜色*/
+//    function getNotAddColorAll() {
+//        if($("#batchColorAll").find("tr") != null && $("#batchColorAll").find("tr").length > 0){
+//            $("#batchColorAll").find("tr").each(function (){
+//                for(var i=0; i<colorAll.length;i++){
+//                    colorAll.remove(1);
+//                }
+//            })
+//        }else{
+//            return colorAll;
+//        }
+//    }
 </script>
 <!--/请在上方写此页面业务相关的脚本-->
 </body>

+ 49 - 3
watero-rst-web/src/main/webapp/WEB-INF/views/pts/batch/batch_list.ftl

@@ -81,9 +81,18 @@
                                 <a style="text-decoration:none" href="javascript:void(0);" title="编辑" onclick="admin_update_batch(${batch.batchId!''})">
                                     <i class="Hui-iconfont">&#xe6df;</i>
                                 </a>&nbsp;
-                                <a style="text-decoration:none" href="javascript:void(0);" title="查看batch单详情" onclick="admin_details_batch(${batch.batchId!''})">
-                                    <i class="Hui-iconfont">&#xe665;</i>
-                                </a>
+                                <#if batch.batchStatus??>
+                                    <#if batch.batchStatus == 1>
+                                        <a style="text-decoration:none" href="javascript:void(0);" title="停止使用" onclick="update_batch_status(${batch.batchId!''},${batch.produceId!''},0)">
+                                            <i class="Hui-iconfont">&#xe631;</i>
+                                        </a>
+                                    </#if>
+                                    <#if batch.batchStatus == 0>
+                                        <a style="text-decoration:none" href="javascript:void(0);" title="立即使用" onclick="update_batch_status(${batch.batchId!''},${batch.produceId!''},1)">
+                                            <i class="Hui-iconfont">&#xe615;</i>
+                                        </a>
+                                    </#if>
+                                </#if>
                             </td>
                         </tr>
                     </#list>
@@ -121,6 +130,43 @@
         window.location.href= "${path}/admin/batch/to_details_batch?batchId="+batchId;
     }
 
+    /**
+     * 修改状态
+     * @param batchId
+     * @param status
+     */
+    function update_batch_status(batchId,produceId,status){
+        var statusMsg = '';
+        if(status == 1){
+            statusMsg = '使用该批次将会停止使用其他同产品的批次!';
+        }else{
+            statusMsg = '停用该批次,你需要立即使用同产品的其他批次,否则可能影响机器生产二维码!';
+        }
+
+        layer.confirm(statusMsg, {
+            btn: ['确定','取消'] //按钮
+        }, function(){
+            $.ajax({
+                type: "POST",
+                data: {
+                    batchId : batchId,
+                    produceId : produceId,
+                    batchStatus : status
+                },
+                url: "${path}/admin/batch/update_batch_status",
+                async: false,
+                success: function(data){
+                },
+                error: function(XmlHttpRequest, textStatus, errorThrown){
+                }
+            });
+            location.replace(location.href)
+        }, function(){
+            layer.closeAll();
+            return false;
+        });
+    }
+
 </script>
 </body>
 </html>

+ 394 - 0
watero-rst-web/src/main/webapp/WEB-INF/views/pts/batch/update_batch.ftl

@@ -0,0 +1,394 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+    <meta charset="utf-8">
+    <meta name="renderer" content="webkit|ie-comp|ie-stand">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+    <meta name="viewport"
+          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
+    <meta http-equiv="Cache-Control" content="no-siteapp"/>
+<#include "/base/add_base.ftl">
+    <link href="${path}/common/lib/jquery.ui/jquery-ui.css" rel="stylesheet" type="text/css"/>
+    <style>
+        .add-list>li{margin: 10px 0;}
+        input[type=radio]{-webkit-appearance:none;appearance:none;background: url(/rst/common/images/pts/radio-1.png) center center no-repeat;background-size:auto 100%;width: 20px;height: 20px;margin-right: 10px;}
+        input[type=radio]:checked{-webkit-appearance:none;appearance:none;background: url(/rst/common/images/pts/radio-2.png) center center no-repeat;background-size:auto 100%;width: 20px;height: 20px;margin-right: 10px;}
+    </style>
+    <title>修改批次 - 批次管理 - RST</title>
+</head>
+<body>
+<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
+    <span class="c-gray en">&gt;</span> 批次管理
+    <span class="c-gray en">&gt;</span> 修改批次
+    <a class="btn radius r"
+       style="line-height:1.6em;margin-top:3px;background: #32a3d8;color: #fff;border:1px solid #32a3d8;"
+       href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
+</nav>
+<article class="page-container" style="padding: 10px;width: 600px;margin: 0 auto;">
+    <form action="${path}/admin/batch/update_batch" method="post" class="form form-horizontal" id="form-batch-update">
+
+        <input type="hidden" value="${ptsBatch.batchId}" id="batchId" name="batchId">
+        <input type="hidden" value="${ptsBatch.produceId}" id="produceId" name="produceId">
+
+        <div class="row cl">
+            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>所属产品:</label>
+            <div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
+				<select class="select" size="1" name="produceId" datatype="*" errormsg="请选择产品" disabled="disabled" style="background: #eee;" >
+                <#if produceList?? &&  (produceList?size > 0) >
+                    <#list produceList as produce>
+                        <option value="${produce.produceId}" <#if ptsBatch.produceId??><#if ptsBatch.produceId == produce.produceId >selected="selected" </#if></#if>>${produce.produceName}</option>
+                    </#list>
+                </#if>
+				</select>
+				</span>
+            </div>
+        </div>
+
+        <div class="row cl">
+            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>批次编号:</label>
+            <div class="formControls col-xs-8 col-sm-9">
+				<input type="text" class="input-text" value="${ptsBatch.batchNo}" id="batchNo" name="batchNo" placeholder="请输入1-20位的名称,支持字母、数字" datatype="/^[a-zA-Z0-9]{1,20}$/" errormsg="请输入1-20位的名称,支持字母、数字!">
+            </div>
+        </div>
+
+        <div class="row cl">
+            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>批次数量:</label>
+            <div class="formControls col-xs-8 col-sm-9 components">
+                <input type="hidden" id="batchColorQuantity" name="batchColorQuantity">
+                <table class="table table-border table-bordered table-bg table-hover table-sort">
+                    <thead>
+                    <tr class="text-c">
+                        <th width="150">选择颜色</th>
+                        <th width="60">批次数量</th>
+                        <th width="20">操作</th>
+                    </tr>
+                    </thead>
+                    <tbody id="batchColorAll">
+                        <#if ptsBatch.ptsBatchColorList?? &&  (ptsBatch.ptsBatchColorList?size > 0) >
+                            <#list ptsBatch.ptsBatchColorList as ptsBatchColor>
+                            <tr class="text-c">
+                                <td>
+                                    <select class="select" size="1" name="colorName" style="height: 30px;">
+                                        <#list batchColor as color>
+                                            <option value="${color}" <#if ptsBatchColor.colorName == color >selected="selected" </#if>>${color}</option>
+                                        </#list>
+                                    </select>
+                                </td>
+                                <td>
+                                    <input type="text" class="input-text colorQuantity" value="${ptsBatchColor.colorQuantity}" onblur="calculationQuantity()" name="colorQuantity" placeholder="数量" datatype="n1-5" errormsg="零件数量只能为数字且不能超过99999!"></td>
+                                <td>
+                                    <a style="" href="javascript:void(0);" title="删除" onclick="delComponent(this,1)"> <i class="Hui-iconfont"></i></a>
+                                </td>
+                            </tr>
+                            </#list>
+                        </#if>
+                    </tbody>
+                </table>
+            </div>
+        </div>
+
+        <div class="row cl">
+            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
+                <input class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;新增零件&nbsp;&nbsp;" onclick="addBatchColor('','')">
+            </div>
+        </div>
+
+        <div class="row cl">
+            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>批次总数量:</label>
+            <div class="formControls col-xs-8 col-sm-9">
+				<input type="text" class="input-text" value="${ptsBatch.batchQuantity}"  name="batchQuantity" disabled="disabled"  style="background: #eee;" placeholder="该批次的总数量" datatype="n1-6" errormsg="批次数量只能输入数字且不能超过999999!">
+                <input type="hidden" class="input-text" value="${ptsBatch.batchQuantity}"  name="batchQuantity" >
+            </div>
+        </div>
+
+        <div class="row cl">
+            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>软件版本:</label>
+            <div class="formControls col-xs-8 col-sm-9">
+                <span class="select-box">
+				    <select class="select" size="1" name="batchSoftwareVersionId" id="batchSoftwareVersionId"  datatype="*" errormsg="请选择软件版本">
+                    <#if ptsMachineVersionList?? &&  (ptsMachineVersionList?size > 0) >
+                        <#list ptsMachineVersionList as ptsMachineVersion>
+                            <option value="${ptsMachineVersion.machineVersionId}" <#if ptsBatch.batchSoftwareVersionId == ptsMachineVersion.machineVersionId >selected="selected" </#if>>${ptsMachineVersion.machineVersionName}(${ptsMachineVersion.machineVersionNo})</option>
+                        </#list>
+                    </#if>
+				    </select>
+				</span>
+                <span id="batchSoftwareVersionIdMsg" style="color: red;"></span>
+            </div>
+        </div>
+
+        <div class="row cl">
+            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>Bom单:</label>
+            <div class="formControls col-xs-8 col-sm-9">
+                <span class="select-box" >
+                    <select class="select" size="1" name="bomId" id="bomId" datatype="*" errormsg="请选择Bom单">
+                        <#if ptsBomsList?? &&  (ptsBomsList?size > 0) >
+                            <#list ptsBomsList as ptsBom>
+                                <option value="${ptsBom.bomId}" <#if ptsBatch.bomId == ptsBom.bomId >selected="selected" </#if>>${ptsBom.bomName}</option>
+                            </#list>
+                        </#if>
+                    </select>
+				</span>
+                <span id="bomIdMsg" style="color: red;"></span>
+            </div>
+        </div>
+
+
+        <div class="row cl">
+            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>批次状态:</label>
+            <div class="formControls col-xs-8 col-sm-9">
+                <div class="radio-box">
+                    <input type="radio" id="batchStatus-1" name="batchStatus" value="1"  <#if ptsBatch.batchStatus == 1>checked</#if>>
+                    <label for="batchStatus-1">立即使用</label>
+                </div>
+                <div class="radio-box">
+                    <input type="radio" id="batchStatus-2" name="batchStatus" value="0" <#if ptsBatch.batchStatus == 0>checked</#if>>
+                    <label for="batchStatus-2">暂不使用</label>
+                </div>
+            </div>
+        </div>
+
+        <div class="row cl">
+            <label class="form-label col-xs-4 col-sm-3">批次描述:</label>
+            <div class="formControls col-xs-8 col-sm-9">
+                <textarea name="batchDesc" id="batchDesc" cols="" rows="" class="textarea"
+                          placeholder="批次描述,最多支持100字符" onKeyUp="$.Huitextarealength(this,100)" >${ptsBatch.batchDesc}</textarea>
+                <p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p>
+            </div>
+        </div>
+
+
+
+        <div class="row cl">
+            <label class="form-label col-xs-4 col-sm-3"></label>
+            <span class="c-red">*提示</span><span>:如果设置状态为 使用,将停止使用同一个产品的其他批次!</span>
+        </div>
+        <div class="row cl">
+            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
+                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
+            </div>
+        </div>
+    </form>
+</article>
+<script type="text/javascript">
+    /*颜色枚举值*/
+    var colorAll = ['黑色','白色','红色','蓝色','绿色','橙色','黄色','青色','紫色'];
+
+    /*修改批次时,获取之前的批次编号,添加页面为空*/
+    var upBatchNo = '${ptsBatch.batchNo}';
+
+    $(function(){
+        $("#form-batch-update").Validform({
+            tiptype: function (msg, o, cssctl) {
+                if (o.type == 3) {//失败
+                    layer.msg(msg, {icon: 5, time: 3000});
+                    $(window).scrollTop(o.obj.offset().top - 40);
+                }
+            },
+            datatype: {//自定义验证类型
+
+            },
+            ignoreHidden: true,
+            tipSweep: true, //若为true,则只在表单提交时验证
+            ajaxPost: true, //异步提交
+            beforeCheck: function (curform) {  //验证通过之前执行的函数
+            },
+            beforeSubmit: function (curform) {  //验证通过之后执行的函数
+                //批次编号不能重复 --   重复为false  不重复(可用)为true
+                var batchNo = $("#batchNo").val();
+                if(upBatchNo == null || typeof(upBatchNo) == "undefined"){
+                    if(!isValiBatchNo(batchNo)){
+                        layer.msg("批次编号重复", {icon: 5, time: 3000});
+                        return false;
+                    }
+                }else{
+                    if(upBatchNo != batchNo){
+                        if(!isValiBatchNo(batchNo)){
+                            layer.msg("批次编号重复", {icon: 5, time: 3000});
+                            return false;
+                        }
+                    }
+                }
+                //合并 批次颜色信息
+                var colorList =  new Array();
+                $("#batchColorAll").find("tr").each(function(){
+                    var ptsBatchColor  = {};
+                    ptsBatchColor.colorName = $(this).find("[name='colorName']").eq(0).val();
+                    ptsBatchColor.colorQuantity =  $(this).find("[name='colorQuantity']").eq(0).val();
+                    colorList.push(ptsBatchColor);
+                })
+                $("#batchColorQuantity").val(JSON.stringify(colorList));
+            },
+            callback: function (data) {//异步回调函数
+                if (data) {
+                    var index = layer.alert(data.resultMsg, function () {
+                        if (data.resultCode == 200) {
+                            location.href = "${path}/admin/batch/_batch_list";
+                        } else {
+                            layer.close(index);
+                        }
+                    });
+                }
+            }
+        });
+    })
+
+    /*判断batch是否重复   重复为false  不重复(可用)为true */
+    function isValiBatchNo(batchNo) {
+        var boolean = false;
+        $.ajax({
+            type: "POST",
+            data: {
+                batchNo : batchNo
+            },
+            url: "${path}/admin/batch/is_valiBatchNo",
+            async: false,
+            success: function(data){
+                if (data.returnCode == 200 ) {
+                    if(data.returnMsg.ptsBatch == null ){
+                        boolean = true
+                    }
+                }else{
+                    layer.msg(data.resultMsg, {icon: 5, time: 3000});
+                }
+            },
+            error: function(XmlHttpRequest, textStatus, errorThrown){
+            }
+        });
+        return boolean;
+    }
+
+    /*根据产品id,获取bom集合*/
+    function getBomByProduce(produceId){
+        $.ajax({
+            type: "POST",
+            data: {
+                produceId : produceId
+            },
+            url: "${path}/admin/bom/get_listBom",
+            async: false,
+            success: function(data){
+                var html = '';
+                if (data.returnCode == 200) {
+                    var bomList = data.returnMsg.ptsBomsList;
+                    for(var i=0;i<bomList.length;i++){
+                        html += '<option value="'+ bomList[i].bomId +'">'+ bomList[i].bomName +'</option>';
+                    }
+                }
+                if(data.returnCode != 200 || data.returnMsg.ptsBomsList <1){
+                    $("#bomIdMsg").html("系统没有对应产品的Bom单,请到Bom单管理中添加Bom单");
+                }else{
+                    $("#bomIdMsg").html("");
+                }
+                $("[name='bomId']").html(html);
+            },
+            error: function(XmlHttpRequest, textStatus, errorThrown){
+            }
+        });
+    }
+
+    /*根据产品获取软件版本*/
+    function getVersionByProduce(produceId) {
+        $.ajax({
+            type: "POST",
+            data: {
+                produceId : produceId
+            },
+            url: "${path}/admin/batch/get_version",
+            async: false,
+            success: function(data){
+                var html = '';
+                if (data.returnCode == 200) {
+                    var versionList = data.returnMsg.ptsMachineVersionList;
+                    for(var i=0;i<versionList.length;i++){
+                        html += '<option value="'+ versionList[i].machineVersionId +'">'+ versionList[i].machineVersionName +'('+ versionList[i].machineVersionNo +')</option>';
+                    }
+                }
+                if(data.returnCode != 200 || data.returnMsg.ptsMachineVersionList <1){
+                    $("#batchSoftwareVersionIdMsg").html("系统没有对应产品的软件版本,请到版本管理中添加软件版本");
+                }else{
+                    $("#batchSoftwareVersionIdMsg").html("");
+                }
+                $("[name='batchSoftwareVersionId']").html(html);
+            },
+            error: function(XmlHttpRequest, textStatus, errorThrown){
+            }
+        });
+    }
+
+    /*添加颜色*/
+    function addBatchColor(colorName,colorQuantity) {
+        var notAddColor = colorAll
+        var opHtml = '';
+        for(var i=0;i<notAddColor.length;i++){
+            opHtml += '<option value="'+ notAddColor[i] +'" >'+ notAddColor[i] + '</option>'
+        }
+        var html = '<tr class="text-c">'
+                +'<td>'
+                +'<select class="select" size="1" name="colorName" style="height: 30px;">'
+                + opHtml
+                +'</select>'
+                +'</td>'
+                +'<td>'
+                +'<input type="text" class="input-text colorQuantity" value="" onblur="calculationQuantity()" name="colorQuantity" placeholder="数量" datatype="n1-5" errormsg="零件数量只能为数字且不能超过99999!">'
+                +'</td>'
+                +'<td>'
+                +'<a style="" href="javascript:void(0);" title="删除" onclick="delComponent(this,1)"> '
+                +'<i class="Hui-iconfont">&#xe609;</i>'
+                +'</a>'
+                +'</td> '
+                +'</tr>';
+        $("#batchColorAll").append(html);
+    }
+
+    /*删除颜色  type=all时删除所有的颜色,但必须要保留一个颜色 */
+    function delComponent(node,type) {
+        if(type == "all"){
+            $("#batchColorAll").find("tr").each(function () {
+                $(this).remove();
+            })
+        }else{
+            //删除零件必须保证还有一个颜色
+            var batchLength = $("#batchColorAll").find("tr").length;
+            if(batchLength > 1){
+                $(node).parent().parent().remove();
+            }else{
+                layer.msg('必须要有一个颜色', {icon: 5, time: 3000});
+            }
+        }
+        //删除操作需要计算总数量
+        calculationQuantity();
+    }
+
+    /**计算批次总数量*/
+    function calculationQuantity(){
+        var quantity = 0;
+        $("#batchColorAll").find("[name='colorQuantity']").each(function (){
+            var colorQuantity = $(this).val();
+            var myreg = /^[0-9]*$/;
+            if( colorQuantity != null && colorQuantity != "" && typeof(colorQuantity) != "undefined"){
+                if(myreg.test(colorQuantity))
+                {
+                    quantity += parseInt(colorQuantity);
+                }
+            }
+        })
+        $("[name='batchQuantity']").val(quantity);
+    }
+
+    /*获取未被添加的颜色*/
+//    function getNotAddColorAll() {
+//        if($("#batchColorAll").find("tr") != null && $("#batchColorAll").find("tr").length > 0){
+//            $("#batchColorAll").find("tr").each(function (){
+//                for(var i=0; i<colorAll.length;i++){
+//                    colorAll.remove(1);
+//                }
+//            })
+//        }else{
+//            return colorAll;
+//        }
+//    }
+</script>
+<!--/请在上方写此页面业务相关的脚本-->
+</body>
+</html>

+ 15 - 8
watero-rst-web/src/main/webapp/WEB-INF/views/pts/bom/add_bom.ftl

@@ -28,9 +28,9 @@
     <form action="${path}/admin/bom/save_bom" method="post" class="form form-horizontal" id="form-bom-add">
 
         <div class="row cl">
-            <label class="form-label col-xs-4 col-sm-3">所属产品:</label>
+            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>所属产品:</label>
             <div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
-				<select class="select" size="1" name="produceId">
+				<select class="select" size="1" name="produceId" datatype="*" errormsg="请选择产品">
                 <#if produceList?? &&  (produceList?size > 0) >
                     <#list produceList as produce>
                         <option value="${produce.produceId}" <#if produceId??><#if produceId ==produce.produceId >selected="selected"</#if></#if>>${produce.produceName}</option>
@@ -44,7 +44,7 @@
         </div>
 
         <div class="row cl">
-            <label class="form-label col-xs-4 col-sm-3">修改基础</label>
+            <label class="form-label col-xs-4 col-sm-3">修改基础:</label>
             <div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
 				<select class="select" size="1" name="bomId">
 				</select>
@@ -53,14 +53,21 @@
         </div>
 
         <div class="row cl">
-            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>Bom名称</label>
+            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>Bom名称:</label>
             <div class="formControls col-xs-8 col-sm-9">
                 <input type="text" class="input-text" value="" id="bomName" name="bomName" placeholder="请输入1-20位的名称,支持中文、字母、数字" datatype="/^[a-zA-Z0-9\u4e00-\u9fa5]{1,20}$/" errormsg="请输入1-20位的名称,支持中文、字母、数字!">
             </div>
         </div>
 
         <div class="row cl">
-            <label class="form-label col-xs-4 col-sm-3">备注:</label>
+            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>版本:</label>
+            <div class="formControls col-xs-8 col-sm-9">
+                <input type="text" class="input-text" value="" id="bomVersion" name="bomVersion" placeholder="请输入1-10位的版本号" datatype="*1-10" errormsg="请输入1-10位的版本号!">
+            </div>
+        </div>
+
+        <div class="row cl">
+            <label class="form-label col-xs-4 col-sm-3">备注:</label>
             <div class="formControls col-xs-8 col-sm-9">
                 <textarea name="bomRemarks" id="bomRemarks" cols="" rows="" class="textarea"
                           placeholder="Bom单备注,最多支持100字符" onKeyUp="$.Huitextarealength(this,100)" ></textarea>
@@ -69,7 +76,7 @@
         </div>
 
         <div class="row cl">
-            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>Bom零件清单</label>
+            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>Bom零件清单:</label>
             <div class="formControls col-xs-8 col-sm-9 components">
                 <input type="hidden" id="bomComponentJson" name="bomComponentJson">
                 <table class="table table-border table-bordered table-bg table-hover table-sort">
@@ -96,7 +103,7 @@
 
         <div class="row cl">
             <label class="form-label col-xs-4 col-sm-3"></label>
-            <span class="c-red">*提示</span><span>新增的Bom,需要批次选中该Bom单,才会生效!</span>
+            <span class="c-red">*提示</span><span>:新增的Bom,需要批次选中该Bom单,才会生效!</span>
         </div>
         <div class="row cl">
             <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
@@ -201,7 +208,7 @@
                 +'</select> '
                 +'</td> '
                 +'<td> '
-                +'<input type="text" class="input-text" value="'+ number +'" id="" name="comNumber" placeholder="零件数量" datatype="n1-3" errormsg="零件数量不能超过999件!"> '
+                +'<input type="text" class="input-text" value="'+ number +'" id="" name="comNumber" placeholder="零件数量" datatype="n1-3" errormsg="零件数量只能为数字且不能超过999件!"> '
                 +'</td> '
                 +'<td> '
                 +'<a style="" href="javascript:void(0);" title="删除" onclick="delComponent(this,1)"> '

+ 13 - 6
watero-rst-web/src/main/webapp/WEB-INF/views/pts/bom/update_bom.ftl

@@ -28,9 +28,9 @@
         <input type="hidden" value="${ptsBom.produceId}" id="produceId" name="produceId">
 
         <div class="row cl">
-            <label class="form-label col-xs-4 col-sm-3">所属产品</label>
+            <label class="form-label col-xs-4 col-sm-3">所属产品:</label>
             <div class="formControls col-xs-8 col-sm-9" > <span class="select-box">
-				<select class="select" disabled="disabled" style="background: #eee;">
+				<select class="select" disabled="disabled" style="background: #eee;" datatype="*" errormsg="请选择产品">
                 <#if produceList?? &&  (produceList?size > 0) >
                     <#list produceList as produce>
                         <option value="${produce.produceId}" <#if ptsBom.produceId??><#if ptsBom.produceId == produce.produceId >selected="selected" </#if></#if>>${produce.produceName}</option>
@@ -42,14 +42,21 @@
         </div>
 
         <div class="row cl">
-            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>Bom名称</label>
+            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>Bom名称:</label>
             <div class="formControls col-xs-8 col-sm-9">
                 <input type="text" class="input-text" value="${ptsBom.bomName}" id="bomName" name="bomName" placeholder="请输入1-20位的名称,支持中文、字母、数字" datatype="/^[a-zA-Z0-9\u4e00-\u9fa5]{1,20}$/" errormsg="请输入1-20位的名称,支持中文、字母、数字!">
             </div>
         </div>
 
         <div class="row cl">
-            <label class="form-label col-xs-4 col-sm-3">备注:</label>
+            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>版本:</label>
+            <div class="formControls col-xs-8 col-sm-9">
+                <input type="text" class="input-text" value="${ptsBom.bomVersion}" id="bomVersion" name="bomVersion" placeholder="请输入1-10位的版本号" datatype="*1-10" errormsg="请输入1-10位的版本号!">
+            </div>
+        </div>
+
+        <div class="row cl">
+            <label class="form-label col-xs-4 col-sm-3">备注:</label>
             <div class="formControls col-xs-8 col-sm-9">
                 <textarea name="bomRemarks" id="bomRemarks" cols="" rows="" class="textarea"
                           placeholder="Bom单备注,最多支持100字符" onKeyUp="$.Huitextarealength(this,100)" >${ptsBom.bomRemarks ! ''}</textarea>
@@ -58,7 +65,7 @@
         </div>
 
         <div class="row cl">
-            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>Bom零件清单</label>
+            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>Bom零件清单:</label>
             <div class="formControls col-xs-8 col-sm-9 components">
                 <input type="hidden" id="bomComponentJson" name="bomComponentJson">
                 <table class="table table-border table-bordered table-bg table-hover table-sort">
@@ -102,7 +109,7 @@
 
         <div class="row cl">
             <label class="form-label col-xs-4 col-sm-3"></label>
-            <span class="c-red">*提示</span><span>新增的Bom,需要批次选中该Bom单,才会生效!</span>
+            <span class="c-red">*提示</span><span>:新增的Bom,需要批次选中该Bom单,才会生效!</span>
         </div>
         <div class="row cl">
             <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">