Bladeren bron

商品资料part2

Aslee 3 jaren geleden
bovenliggende
commit
6dc28b7085

+ 6 - 0
src/main/java/com/caimei/modules/archive/dao/CmProductArchiveContentDao.java

@@ -1,9 +1,11 @@
 package com.caimei.modules.archive.dao;
 
+import com.caimei.modules.archive.entity.CmOrderArchiveFile;
 import com.caimei.modules.archive.entity.CmProductArchiveFile;
 import com.thinkgem.jeesite.common.persistence.CrudDao;
 import com.thinkgem.jeesite.common.persistence.annotation.MyBatisDao;
 import com.caimei.modules.archive.entity.CmProductArchiveContent;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -20,4 +22,8 @@ public interface CmProductArchiveContentDao extends CrudDao<CmProductArchiveCont
     void deleteFile(String archiveContentId);
 
     void insertFile(CmProductArchiveFile file);
+
+    void updateFile(@Param("fileId") Integer fileId, @Param("archiveContentId") Integer archiveContentId);
+
+    Integer getDbFileId(String id);
 }

+ 14 - 5
src/main/java/com/caimei/modules/archive/entity/CmProductArchiveContent.java

@@ -21,7 +21,8 @@ public class CmProductArchiveContent extends DataEntity<CmProductArchiveContent>
 	private Integer type;		// 资料类型:1图片资料,2视频资料,3文件资料
 	private Date addTime;		// 添加时间
 
-	private List<CmProductArchiveFile> imageList;	//图片列表
+	private List<CmProductArchiveFile> fileList;	//图片列表
+    private Integer fileId;                 //上传的文件id
 
 	public CmProductArchiveContent() {
 		super();
@@ -65,11 +66,19 @@ public class CmProductArchiveContent extends DataEntity<CmProductArchiveContent>
 		this.addTime = addTime;
 	}
 
-	public List<CmProductArchiveFile> getImageList() {
-		return imageList;
+    public Integer getFileId() {
+        return fileId;
+    }
+
+    public void setFileId(Integer fileId) {
+        this.fileId = fileId;
+    }
+
+	public List<CmProductArchiveFile> getFileList() {
+		return fileList;
 	}
 
-	public void setImageList(List<CmProductArchiveFile> imageList) {
-		this.imageList = imageList;
+	public void setFileList(List<CmProductArchiveFile> fileList) {
+		this.fileList = fileList;
 	}
 }

+ 5 - 5
src/main/java/com/caimei/modules/archive/entity/CmProductArchiveFile.java

@@ -18,7 +18,7 @@ public class CmProductArchiveFile extends DataEntity<CmProductArchiveFile> {
 	private String fileName;		// 文件名称
 	private String ossName;		// oss名称
 	private String ossUrl;		// oss链接
-	private Date uploadTme;		// 上传时间
+	private Date uploadTime;		// 上传时间
 
 	public CmProductArchiveFile() {
 		super();
@@ -60,11 +60,11 @@ public class CmProductArchiveFile extends DataEntity<CmProductArchiveFile> {
 		this.ossUrl = ossUrl;
 	}
 
-	public Date getUploadTme() {
-		return uploadTme;
+	public Date getUploadTime() {
+		return uploadTime;
 	}
 
-	public void setUploadTme(Date uploadTme) {
-		this.uploadTme = uploadTme;
+	public void setUploadTime(Date uploadTime) {
+		this.uploadTime = uploadTime;
 	}
 }

+ 61 - 4
src/main/java/com/caimei/modules/archive/service/CmProductArchiveContentService.java

@@ -1,9 +1,12 @@
 package com.caimei.modules.archive.service;
 
-import java.util.List;
+import java.io.File;
+import java.util.*;
 
 import com.caimei.dfs.image.beens.ImageUploadInfo;
+import com.caimei.modules.archive.entity.CmOrderArchiveFile;
 import com.caimei.modules.archive.entity.CmProductArchiveFile;
+import com.caimei.modules.archive.utils.OssArchiveUtil;
 import com.caimei.modules.common.utils.UploadUtils;
 import com.caimei.modules.sys.utils.UploadImageUtils;
 import com.thinkgem.jeesite.common.config.Global;
@@ -16,6 +19,7 @@ import com.thinkgem.jeesite.common.persistence.Page;
 import com.thinkgem.jeesite.common.service.CrudService;
 import com.caimei.modules.archive.entity.CmProductArchiveContent;
 import com.caimei.modules.archive.dao.CmProductArchiveContentDao;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 
@@ -45,12 +49,12 @@ public class CmProductArchiveContentService extends CrudService<CmProductArchive
 	@Transactional(readOnly = false)
 	public void save(CmProductArchiveContent cmProductArchiveContent) {
 		super.save(cmProductArchiveContent);
-		cmProductArchiveContentDao.deleteFile(cmProductArchiveContent.getId());
 		if (1 == cmProductArchiveContent.getType()) {
+			cmProductArchiveContentDao.deleteFile(cmProductArchiveContent.getId());
 			//保存图片
-			List<CmProductArchiveFile> imageList = cmProductArchiveContent.getImageList();
+			List<CmProductArchiveFile> imageList = cmProductArchiveContent.getFileList();
 			//上传图片
-			imageList.forEach(image->{
+			imageList.forEach(image -> {
 				if (StringUtils.isNotEmpty(image.getOssUrl())) {
 					if (!image.getOssUrl().startsWith("http")) {
 						image.setOssUrl(getImageUrl(image.getOssUrl()));
@@ -59,6 +63,14 @@ public class CmProductArchiveContentService extends CrudService<CmProductArchive
 					cmProductArchiveContentDao.insertFile(image);
 				}
 			});
+		} else {
+			// 更新文件的archiveContentId
+			Integer fileId = cmProductArchiveContent.getFileId();
+			Integer dbFileId = cmProductArchiveContentDao.getDbFileId(cmProductArchiveContent.getId());
+			if (null != fileId && !fileId.equals(dbFileId)) {
+				cmProductArchiveContentDao.deleteFile(cmProductArchiveContent.getId());
+				cmProductArchiveContentDao.updateFile(fileId, Integer.valueOf(cmProductArchiveContent.getId()));
+			}
 		}
 
 	}
@@ -94,4 +106,49 @@ public class CmProductArchiveContentService extends CrudService<CmProductArchive
 		}
 		return imageUrl;
 	}
+
+    @Transactional(readOnly = false)
+    public Map<String, Object> upload(MultipartFile multipartFile, String fileName) {
+        Map<String, Object> map = new HashMap<>();
+        String fileAllName = multipartFile.getOriginalFilename();
+        String fileType = fileAllName.substring(fileAllName.lastIndexOf(".") + 1);
+        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
+        String filePath = uuid + "." + fileType;
+        String contentType = OssArchiveUtil.getContentType(fileAllName);
+        try {
+            //保存本地
+            File file = OssArchiveUtil.ossUpload(multipartFile);
+            logger.info("默认路径>>>" + file.getAbsolutePath());
+            //上传oss
+            String url = OssArchiveUtil.ossUpload(filePath, "archiveFile/", file, contentType);
+            //删除本地文件
+            OssArchiveUtil.deleteFile(file);
+            //保存关联关系
+            CmProductArchiveFile archiveFile = new CmProductArchiveFile();
+            archiveFile.setFileName(fileName);
+            archiveFile.setOssName(filePath);
+            archiveFile.setOssUrl(url);
+            archiveFile.setUploadTime(new Date());
+            cmProductArchiveContentDao.insertFile(archiveFile);
+            map.put("success", true);
+            map.put("msg", "操作成功");
+            map.put("archiveFile", archiveFile);
+        } catch (Exception e) {
+            e.printStackTrace();
+            map.put("success", false);
+            map.put("msg", "操作失败");
+            logger.info("上传异常!!!");
+        }
+        return map;
+    }
+
+    /*@Transactional(readOnly = false)
+    public void deleteFile(Integer fileId) {
+        CmOrderArchiveFile archiveFile = cmOrderArchiveDao.getArchiveFileById(fileId);
+        if (archiveFile != null) {
+            //删除oss服务器上的文件
+            OssArchiveUtil.deleteSingleFile("archiveFile/", archiveFile.getOssName());
+            cmOrderArchiveDao.deleteArchiveFile(fileId);
+        }
+    }*/
 }

+ 16 - 8
src/main/java/com/caimei/modules/archive/web/CmProductArchiveContentController.java

@@ -11,6 +11,8 @@ import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.servlet.mvc.support.RedirectAttributes;
 
 import com.thinkgem.jeesite.common.config.Global;
@@ -21,6 +23,7 @@ import com.caimei.modules.archive.entity.CmProductArchiveContent;
 import com.caimei.modules.archive.service.CmProductArchiveContentService;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 商品资料内容Controller
@@ -57,18 +60,17 @@ public class CmProductArchiveContentController extends BaseController {
 	@RequestMapping(value = "form")
 	public String form(CmProductArchiveContent cmProductArchiveContent, Model model) {
 		model.addAttribute("cmProductArchiveContent", cmProductArchiveContent);
-		List<CmProductArchiveFile> imageList = null;
 		Integer type = cmProductArchiveContent.getType();
-		if (StringUtils.isNotEmpty(cmProductArchiveContent.getId()) && 1 == type) {
-			imageList = cmProductArchiveContentService.getImageList(cmProductArchiveContent.getId());
+		if (StringUtils.isNotEmpty(cmProductArchiveContent.getId())) {
+			List<CmProductArchiveFile> fileList = cmProductArchiveContentService.getImageList(cmProductArchiveContent.getId());
+			cmProductArchiveContent.setFileList(fileList);
 		}
-		cmProductArchiveContent.setImageList(imageList);
 		if (1 == type) {
 			return "modules/archive/cmProductArchiveContentForm";
 		} else if (2 == type) {
-			return "modules/archive/addVedioForm";
+			return "modules/archive/addVideoForm";
 		}else {
-			return "modules/archive/addFileForm";
+ 			return "modules/archive/addFileForm";
 		}
 	}
 
@@ -79,13 +81,19 @@ public class CmProductArchiveContentController extends BaseController {
 		}
 		cmProductArchiveContentService.save(cmProductArchiveContent);
 		addMessage(redirectAttributes, "保存资料成功");
-		return "redirect:" + Global.getAdminPath() + "/archive/cmProductArchiveContent/?repage&type=" + cmProductArchiveContent.getType();
+        return "redirect:" + Global.getAdminPath() + "/archive/cmProductArchiveContent/?repage&type=" + cmProductArchiveContent.getType() + "&productArchiveId=" + cmProductArchiveContent.getProductArchiveId();
 	}
 
 	@RequestMapping(value = "delete")
 	public String delete(CmProductArchiveContent cmProductArchiveContent, RedirectAttributes redirectAttributes) {
 		cmProductArchiveContentService.delete(cmProductArchiveContent);
 		addMessage(redirectAttributes, "删除资料成功");
-		return "redirect:" + Global.getAdminPath() + "/archive/cmProductArchiveContent/?repage&type=" + cmProductArchiveContent.getType();
+		return "redirect:" + Global.getAdminPath() + "/archive/cmProductArchiveContent/?repage&type=" + cmProductArchiveContent.getType() + "&productArchiveId=" + cmProductArchiveContent.getProductArchiveId();
 	}
+
+    @ResponseBody
+    @RequestMapping(value = "upload")
+    public Map<String, Object> upload(@RequestParam("file") MultipartFile file, @RequestParam("fileName") String fileName) {
+        return cmProductArchiveContentService.upload(file, fileName);
+    }
 }

+ 14 - 3
src/main/resources/mappings/modules/archive/CmProductArchiveContentMapper.xml

@@ -37,6 +37,9 @@
 			<if test="type != null">
 				and a.type = #{type}
 			</if>
+		    <if test="productArchiveId != null">
+                and a.productArchiveId = #{productArchiveId}
+            </if>
 		</where>
 		<choose>
 			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
@@ -66,8 +69,11 @@
     <select id="getImageList" resultType="com.caimei.modules.archive.entity.CmProductArchiveFile">
         select * from cm_product_archive_file where archiveContentId = #{id}
     </select>
+	<select id="getDbFileId" resultType="java.lang.Integer">
+		select id from cm_product_archive_file where archiveContentId = #{id} limit 1
+	</select>
 
-    <insert id="insert" parameterType="CmProductArchiveContent"  keyProperty="id" useGeneratedKeys="true">
+	<insert id="insert" parameterType="CmProductArchiveContent"  keyProperty="id" useGeneratedKeys="true">
 		INSERT INTO cm_product_archive_content(
 			productArchiveId,
 			title,
@@ -80,7 +86,7 @@
 			now()
 		)
 	</insert>
-	<insert id="insertFile">
+	<insert id="insertFile" parameterType="CmProductArchiveFile" keyProperty="id" useGeneratedKeys="true">
 		insert into cm_product_archive_file(archiveContentId, fileName, ossName, ossUrl, uploadTime)
 		values (#{archiveContentId}, #{fileName}, #{ossName}, #{ossUrl}, now())
 	</insert>
@@ -90,7 +96,12 @@
 			title = #{title}
 		WHERE id = #{id}
 	</update>
-	
+	<update id="updateFile">
+		update cm_product_archive_file
+		set archiveContentId = #{archiveContentId}
+		where id = #{fileId}
+	</update>
+
 	<delete id="delete">
 		DELETE FROM cm_product_archive_content
 		WHERE id = #{id}

+ 277 - 0
src/main/webapp/WEB-INF/views/modules/archive/addFileForm.jsp

@@ -0,0 +1,277 @@
+<%@ page contentType="text/html;charset=UTF-8" %>
+<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
+<html>
+<head>
+    <title>添加视频资料</title>
+    <meta name="decorator" content="default"/>
+    <style>
+        .controls .new-tag {
+            display: inline-block;
+            width: 78px;
+            height: 30px;
+            border: 1px solid #e5e5e5;
+            border-radius: 5px;
+            margin: 7px;
+            text-align: center;
+            line-height: 30px;
+            font-size: 14px;
+            overflow: hidden;
+            text-overflow: ellipsis;
+            white-space: nowrap;
+            cursor: pointer;
+        }
+
+        .controls .new-tag.active {
+            border-color: #e15616;
+            color: #e15616;
+        }
+
+        #tagInput {
+            width: 263px;
+            margin: 7px;
+            display: inline-block;
+            height: 30px;
+        }
+
+        .controls .tags-operate .tag-add {
+            height: 40px;
+            line-height: 40px;
+            vertical-align: middle;
+        }
+
+        .upload {
+            position: relative;
+            display: inline-block;
+            background: #D0EEFF;
+            border: 1px solid #99D3F5;
+            border-radius: 4px;
+            padding: 4px 12px;
+            color: #1E88C7;
+            text-decoration: none;
+            text-indent: 0;
+            line-height: 20px;
+            margin-left: 20px;
+            cursor: pointer;
+            width: 52px;
+            height: 20px;
+        }
+
+        .upload input {
+            position: absolute;
+            width: 170px;
+            font-size: 20px;
+            right: 0;
+            top: 0;
+            opacity: 0;
+            cursor: pointer;
+        }
+
+        .upload:hover {
+            background: #AADFFD;
+            border-color: #78C3F3;
+            color: #004974;
+            text-decoration: none;
+        }
+
+        .add-submit {
+            position: relative;
+            display: inline;
+            background: #D0EEFF;
+            border: 1px solid #99D3F5;
+            border-radius: 4px;
+            padding: 4px 12px;
+            color: #1E88C7;
+            text-decoration: none;
+            text-indent: 0;
+            line-height: 20px;
+            margin-left: 20px;
+            cursor: pointer;
+            width: 52px;
+            height: 30px;
+        }
+
+        .add-submit input {
+            position: absolute;
+            width: 50px;
+            font-size: 20px;
+            right: 0;
+            top: 0;
+            opacity: 0;
+            cursor: pointer;
+        }
+
+        .add-submit:hover {
+            background: #AADFFD;
+            border-color: #78C3F3;
+            color: #004974;
+            text-decoration: none;
+        }
+
+        .upload-loading{
+            display: none;
+            width: 32px;
+            height: 32px;
+            margin-left: 10px;
+        }
+        .upload-loading img{
+            width: 16px;
+            height: 16px;
+            margin: 0 auto 0;
+        }
+
+        #file-list-display {
+            width: 600px;
+            height: auto;
+            float: left;
+            margin-left: 20px;
+        }
+
+        #file-list-display p {
+            line-height: 30px;
+            font-size: 14px;
+            color: #333333;
+            margin: 0;
+        }
+
+        #file-list-display p .del {
+            color: #2fa4e7;
+            font-size: 12px;
+            cursor: pointer;
+            margin-left: 20px;
+        }
+
+        .Main-content{
+            height: 100px;
+        }
+
+        .control-group{
+            margin-top: 40px;
+        }
+    </style>
+
+    <script type="text/javascript">
+        $(document).ready(function () {
+            $("#searchForm").validate({
+                submitHandler: function (form) {
+                    var isSubMitFlag = true;
+                    var productID = $("#productID").val();
+                    if (isNaN(productID) || productID.indexOf('0') == 0 ) {
+                        alertx("请输入正确的商品ID");
+                        isSubMitFlag = false;
+                        return false;
+                    }
+                    if (isSubMitFlag) {
+                        form.submit();
+                    }
+                }
+            })
+        });
+    </script>
+</head>
+<body>
+<form:form id="inputForm" modelAttribute="cmProductArchiveContent" action="${ctx}/archive/cmOrderArchiveContent/save" method="post" class="form-horizontal">
+    <form:hidden path="id"/>
+    <form:hidden path="type" value="3"/>
+    <sys:message content="${message}"/>
+    <div class="control-group">
+        <label class="control-label"><font color="red">*</font>标题:</label>
+        <div class="controls">
+            <form:input path="title" htmlEscape="false" maxlength="50" class="input-xlarge "  style="position:relative"/>
+        </div>
+    </div>
+    <div class="control-group">
+        <label class="control-label"><font color="red">*</font>文件路径:</label>
+        <input id="uploadFileName" type="text" style="display: inline;margin-left:20px" disabled="true" class="input-xlarge required" />
+        <div class="upload">
+            <input type="file" name="file" id="archiveFile" accept=".pdf,.doc,.docx,.ppt">选择文件
+        </div>
+        <div class="add-submit">
+            <input id="addSubmit" type="button" value="上传" style="cursor: pointer"/>上传&nbsp;
+        </div>
+        <div class="upload-loading">
+            <img alt="gif" src="/static/images/upload.gif" width="32px" border="none">
+        </div>
+        <div style="margin:5px 0 0 180px">
+            <font color="red">支持上传pdf丶word丶pptx文件格式</font>
+        </div>
+    </div>
+</form:form>
+
+<script>
+    var fileId = '';
+
+    function getCheckedItems() {
+        var items = new Array();
+        items.push({
+            id: $("#id").val(),
+            title: $("#title").val(),
+            fileId: fileId
+        })
+        return items;
+    }
+
+    $(function () {
+        //初始化文件名称
+        if (${cmProductArchiveContent.id ne null}) {
+            var fileName = '${cmProductArchiveContent.fileList[0].fileName}';
+            var id = '${cmProductArchiveContent.fileList[0].id}';
+            $("#uploadFileName").val(fileName);
+            fileId = id;
+        }
+
+        //点击上传按钮后上传文件
+        $('#addSubmit').click(function () {
+            var filesById = document.getElementById('archiveFile');
+            var files = $('#archiveFile');
+            var fileList = files.prop('files');
+            var fileName = $('#uploadFileName').val();
+            if (files === '' || files.length == 0 || fileName == '') {
+                alertx('请选择上传文件');
+                return;
+            }
+            var data = new FormData();
+            data.append('file', fileList[0]);
+            data.append('fileName', fileName);
+            $('.upload-loading').css("display", "inline");
+            $.ajax({
+                url: "${ctx}/archive/cmProductArchiveContent/upload",
+                data: data,
+                type: "POST",
+                processData: false,
+                contentType: false,
+                dataType: "json",
+                success: function (res) {
+                    if (res.success) {
+                        debugger
+                        filesById.value = '';
+                        fileId = res.archiveFile.id;
+                        $('.upload-loading').hide();
+                        $.jBox.tip('上传成功', 'info');
+                    } else {
+                        $.jBox.tip(res.msg, 'error');
+                        $('.upload-loading').hide();
+                    }
+                },
+                error: function (json) {
+
+                }
+            });
+        });
+
+
+        var fileList = [];
+        var fileIds = '';
+        var files = document.getElementById("archiveFile");
+        //选择上传文件后显示文件名称
+        files.addEventListener("change", function (event) {
+            var name = event.target.files[0].name;
+            $('#uploadFileName').val(name);
+            fileId = '';
+        });
+    })
+
+
+</script>
+</body>
+</html>
+

+ 87 - 9
src/main/webapp/WEB-INF/views/modules/archive/addVedioForm.jsp → src/main/webapp/WEB-INF/views/modules/archive/addVideoForm.jsp

@@ -143,6 +143,10 @@
         .Main-content{
             height: 100px;
         }
+
+        .control-group{
+            margin-top: 40px;
+        }
     </style>
 
     <script type="text/javascript">
@@ -165,9 +169,9 @@
     </script>
 </head>
 <body>
-<form:form id="inputForm" modelAttribute="cmOrderArchiveContent" action="${ctx}/archive/cmOrderArchiveContent/save" method="post" class="form-horizontal">
+<form:form id="inputForm" modelAttribute="cmProductArchiveContent" action="${ctx}/archive/cmOrderArchiveContent/save" method="post" class="form-horizontal">
     <form:hidden path="id"/>
-    <form:hidden path="type" value="1"/>
+    <form:hidden path="type" value="2"/>
     <sys:message content="${message}"/>
     <div class="control-group">
         <label class="control-label"><font color="red">*</font>标题:</label>
@@ -176,23 +180,97 @@
         </div>
     </div>
     <div class="control-group">
-        <label class="control-label">视频路径:</label>
-        <input id="uploadFileName" type="text" style="display: inline;margin-left:20px" placeholder="视频大小不超过50M" class="input-xlarge required" />
+        <label class="control-label"><font color="red">*</font>视频路径:</label>
+        <input id="uploadFileName" type="text" style="display: inline;margin-left:20px" disabled="true" class="input-xlarge required" />
         <div class="upload">
             <input type="file" name="file" id="archiveFile" accept=".mp4">选择文件
         </div>
         <div class="add-submit">
-            <input id="addSubmit" type="button" value="上传"/>上传&nbsp;
+            <input id="addSubmit" type="button" value="上传" style="cursor: pointer"/>上传&nbsp;
         </div>
         <div class="upload-loading">
             <img alt="gif" src="/static/images/upload.gif" width="32px" border="none">
         </div>
-    </div>
-    <div class="form-actions">
-        <input id="btnCancel" class="btn" type="button" value="取 消" onclick="history.go(-1)"/>
-        <input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;
+        <div style="margin:5px 0 0 180px">
+            <font color="red">视频大小不超过50M</font>
+        </div>
     </div>
 </form:form>
+
+<script>
+    var fileId = '';
+
+    function getCheckedItems() {
+        var items = new Array();
+        items.push({
+            id: $("#id").val(),
+            title: $("#title").val(),
+            fileId: fileId
+        })
+        return items;
+    }
+
+    $(function () {
+        //初始化文件名称
+        if (${cmProductArchiveContent.id ne null}) {
+            var fileName = '${cmProductArchiveContent.fileList[0].fileName}';
+            var id = '${cmProductArchiveContent.fileList[0].id}';
+            $("#uploadFileName").val(fileName);
+            fileId = id;
+        }
+
+        //点击上传按钮后上传文件
+        $('#addSubmit').click(function () {
+            var filesById = document.getElementById('archiveFile');
+            var files = $('#archiveFile');
+            var fileList = files.prop('files');
+            var fileName = $('#uploadFileName').val();
+            if (files === '' || files.length == 0 || fileName == '') {
+                alertx('请选择上传文件');
+                return;
+            }
+            var data = new FormData();
+            data.append('file', fileList[0]);
+            data.append('fileName', fileName);
+            $('.upload-loading').css("display", "inline");
+            $.ajax({
+                url: "${ctx}/archive/cmProductArchiveContent/upload",
+                data: data,
+                type: "POST",
+                processData: false,
+                contentType: false,
+                dataType: "json",
+                success: function (res) {
+                    if (res.success) {
+                        filesById.value = '';
+                        fileId = res.archiveFile.id;
+                        $('.upload-loading').hide();
+                        $.jBox.tip('上传成功', 'info');
+                    } else {
+                        $.jBox.tip(res.msg, 'error');
+                        $('.upload-loading').hide();
+                    }
+                },
+                error: function (json) {
+
+                }
+            });
+        });
+
+
+        var fileList = [];
+        var fileIds = '';
+        var files = document.getElementById("archiveFile");
+        //选择上传文件后显示文件名称
+        files.addEventListener("change", function (event) {
+            var name = event.target.files[0].name;
+            $('#uploadFileName').val(name);
+            fileId = '';
+        });
+    })
+
+
+</script>
 </body>
 </html>
 

+ 6 - 26
src/main/webapp/WEB-INF/views/modules/archive/cmProductArchiveContentForm.jsp

@@ -163,13 +163,12 @@
 </head>
 <body>
 	<ul class="nav nav-tabs">
-		<li><a href="${ctx}/archive/cmProductArchiveContent/?type=1">资料列表</a></li>
+		<li><a href="${ctx}/archive/cmProductArchiveContent/?type=1&productArchiveId=${cmProductArchiveContent.productArchiveId}">资料列表</a></li>
 		<li class="active"><a href="${ctx}/archive/cmProductArchiveContent/form?id=${cmProductArchiveContent.id}">资料${not empty cmProductArchiveContent.id?'编辑':'添加'}</a></li>
 	</ul><br/>
-
-
 	<form:form id="inputForm" modelAttribute="cmProductArchiveContent" action="${ctx}/archive/cmProductArchiveContent/save" method="post" class="form-horizontal">
 		<form:hidden path="id"/>
+		<form:hidden path="productArchiveId"/>
 		<form:hidden path="type" value="1"/>
 		<sys:message content="${message}"/>		
 		<div class="control-group">
@@ -182,10 +181,10 @@
 			<label class="control-label"><font color="red">*</font>图片:</label>
 <%--				<c:if test="${not empty cmProductArchiveContent.imageList}">--%>
 			<div class="upload-image-list" style="display: flex;flex-wrap: wrap">
-				<c:forEach items="${cmProductArchiveContent.imageList}" var="image" varStatus="index">
+				<c:forEach items="${cmProductArchiveContent.fileList}" var="image" varStatus="index">
 					<div class="controls upload-content iconBox" id="imageBox${index.index}">
 						<div class="conList">
-							<form:hidden id="pImage${index.index}" path="imageList[${index.index}].ossUrl" htmlEscape="false"
+							<form:hidden id="pImage${index.index}" path="fileList[${index.index}].ossUrl" htmlEscape="false"
 										 maxlength="255"
 										 class="input-xlarge required"/>
 							<sys:ckfinder input="pImage${index.index}" type="images" uploadPath="/photo"
@@ -194,11 +193,11 @@
 						</div>
 					</div>
 				</c:forEach>
-				<c:set var="size" value="${empty cmProductArchiveContent.imageList?0:cmProductArchiveContent.imageList.size()}"/>
+				<c:set var="size" value="${empty cmProductArchiveContent.fileList?0:cmProductArchiveContent.fileList.size()}"/>
 				<c:forEach var="emptyIndex" begin="${size}" end="${11}">
 					<div class="controls upload-content iconBox conList ${emptyIndex eq 0?'':'hide-pic'}" id="imageBox${emptyIndex}" >
 						<div class="conList">
-							<form:hidden id="pImage${emptyIndex}" path="imageList[${emptyIndex}].ossUrl" htmlEscape="false"
+							<form:hidden id="pImage${emptyIndex}" path="fileList[${emptyIndex}].ossUrl" htmlEscape="false"
 										 maxlength="255"
 										 class="input-xlarge required"/>
 							<sys:ckfinder input="pImage${emptyIndex}" type="images" uploadPath="/photo"
@@ -223,16 +222,7 @@
 		</div>
 	</form:form>
 <script>
-    var imageSize = 0;
-    var imageList = [];
 	$(function () {
-		<c:forEach items="${cmProductArchiveContent.imageList}" var="floorImage" varStatus="index">
-		imageList.push({
-			id: "${floorImage.id}",
-			ossUrl: "${floorImage.ossUrl}"
-		});
-		</c:forEach>
-		imageSize = imageList.length
 		$('.upload-content .conList .btn:nth-of-type(1)').html('<div><span>+</span><h5>选择图片</h5></div>');
 		$('.upload-content .conList .btn:nth-of-type(2)').after('<img class="cancel-upload" src="/static/images/close-btn1.png">').remove();
 		$('.upload-content .conList').find('.cancel-upload').hide();
@@ -303,16 +293,6 @@
 		});
 	});
 
-    function showImage() {
-    	var html = '';
-		imageList.forEach(function (item,index) {
-			html += appendImage(item, index);
-		})
-    }
-
-	function appendImage(item, index) {
-    	alert(1)
-	}
 
 </script>
 </body>

+ 26 - 22
src/main/webapp/WEB-INF/views/modules/archive/cmProductArchiveContentList.jsp

@@ -23,7 +23,7 @@
 <body>
 	<ul class="nav nav-tabs">
 		<li><a href="${ctx}/archive/cmProductArchive/">商品资料列表</a></li>
-		<li class="active"><a href="${ctx}/archive/cmProductArchiveContent/?type=${cmProductArchiveContent.type}">${cmProductArchiveContent.type eq 1?'图片资料':cmProductArchiveContent.type eq 2?'视频资料':'文件资料'}</a></li>
+		<li class="active"><a href="${ctx}/archive/cmProductArchiveContent/?type=${cmProductArchiveContent.type}&productArchiveId=${cmProductArchiveContent.productArchiveId}">${cmProductArchiveContent.type eq 1?'图片资料':cmProductArchiveContent.type eq 2?'视频资料':'文件资料'}</a></li>
 	</ul>
 	<form:form id="searchForm" modelAttribute="cmProductArchiveContent" action="${ctx}/archive/cmProductArchiveContent/" method="post" class="breadcrumb form-search">
 		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
@@ -34,7 +34,7 @@
 				<form:input path="title" htmlEscape="false" maxlength="50" class="input-medium"/>
 			&nbsp;&nbsp;<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
 			&nbsp;&nbsp;<input class="btn btn-primary" style="width: 50px"
-							   onclick="showAddForm(${cmProductArchiveContent.type})" value="添加"/>
+							   onclick="showAddForm('', ${cmProductArchiveContent.type},${cmProductArchiveContent.productArchiveId})" value="添加"/>
 			<div class="clearfix"></div>
 		</div>
 	</form:form>
@@ -59,7 +59,7 @@
 					<fmt:formatDate value="${cmProductArchiveContent.addTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
 				</td>
 				<td>
-    				<a href="${ctx}/archive/cmProductArchiveContent/form?id=${cmProductArchiveContent.id}">编辑</a>
+    				<a onclick="showAddForm(${cmProductArchiveContent.id},${cmProductArchiveContent.type},${cmProductArchiveContent.productArchiveId})">编辑</a>
 					<a href="${ctx}/archive/cmProductArchiveContent/delete?id=${cmProductArchiveContent.id}" onclick="return confirmx('确认要删除该资料吗?', this.href)">删除</a>
 				</td>
 			</tr>
@@ -68,23 +68,22 @@
 	</table>
 	<div class="pagination">${page}</div>
 <script>
-	function showAddForm(type) {
-		debugger
+	function showAddForm(id,type,productArchiveId) {
 		if (type == 1) {
-			window.location='${ctx}/archive/cmProductArchiveContent/form?type=1';
+			window.location = '${ctx}/archive/cmProductArchiveContent/form?type=1&productArchiveId=' + productArchiveId + '&id=' + id;
 		}else {
 			//添加视频资料
 			var url = '';
 			var title = '';
-			url = "${ctx}/archive/cmProductArchiveContent/form?type=" + type;
+			url = "${ctx}/archive/cmProductArchiveContent/form?type=" + type + "&productArchiveId=" + productArchiveId + '&id=' + id;
 			title = type == 2?"添加视频文件":"添加文件资料";
 			top.$.jBox("iframe:" + url, {
 				iframeScrolling: 'yes',
-				width: $(top.document).width() - 600,
-				height: $(top.document).height() - 160,
+				width: 800,
+				height: 300,
 				persistent: true,
 				title: title,
-				buttons: {"取消": '-1', "保存": '1'},
+				buttons: {"保存": '1', "取消": '-1'},
 				submit: function (v, h, f) {
 					//确定
 					var $jboxFrame = top.$('#jbox-iframe');
@@ -93,20 +92,25 @@
 						var items = $jboxFrame[0].contentWindow.getCheckedItems(0);
 						if (items.length > 0) {
 							console.log(items)
-							var productId = items[0].productId;
-							var mainImage = items[0].mainImage;
-							var productName = items[0].productName;
-							var productType = items[0].commodityType;
-							$("#mainImage").attr("src", mainImage).show();
-							$("#productName").text(productName);
-							$("#productId").val(productId);
-							$("#name").val(productName);
-							$(".productInfo").show();
-							if ('' == productType ) {
-								$(".productType").show();
+							var archiveContentId = items[0].id;
+							var title = items[0].title;
+							var fileId = items[0].fileId;
+							if (title == '') {
+								top.$.jBox.tip("标题不能为空");
+								return false;
 							}
+							if (fileId == '') {
+								top.$.jBox.tip("请先上传文件");
+								return false;
+							}
+							$.post("${ctx}/archive/cmProductArchiveContent/save?type="+type+"&id=" + archiveContentId + "&title=" + title + "&fileId=" + fileId+"&productArchiveId=" + productArchiveId, function (data) {
+								top.$.jBox.tip("保存资料成功");
+								setTimeout(function () {
+									window.location.href = "${ctx}/archive/cmProductArchiveContent/?type="+type+"&productArchiveId=" + productArchiveId;
+								}, 200);
+							});
 						} else {
-							top.$.jBox.tip("请先勾选商品...");
+							top.$.jBox.tip("请先上传视频...");
 							return false;
 						}
 					}

+ 3 - 3
src/main/webapp/WEB-INF/views/modules/archive/cmProductArchiveList.jsp

@@ -103,9 +103,9 @@
 				<td>
     				<a href="${ctx}/archive/cmProductArchive/form?id=${cmProductArchive.id}">编辑</a>
 					<a href="${ctx}/archive/cmProductArchive/delete?id=${cmProductArchive.id}" onclick="return confirmx('确认要删除该商品资料吗?', this.href)">删除</a>
-					<a href="${ctx}/archive/cmProductArchiveContent/?type=1">图片资料</a>
-					<a href="${ctx}/archive/cmProductArchiveContent/?type=2">视频资料</a>
-					<a href="${ctx}/archive/cmProductArchiveContent/?type=3">文件资料</a>
+					<a href="${ctx}/archive/cmProductArchiveContent/?productArchiveId=${cmProductArchive.id}&type=1">图片资料</a>
+					<a href="${ctx}/archive/cmProductArchiveContent/?productArchiveId=${cmProductArchive.id}&type=2">视频资料</a>
+					<a href="${ctx}/archive/cmProductArchiveContent/?productArchiveId=${cmProductArchive.id}&type=3">文件资料</a>
 				</td>
 			</tr>
 		</c:forEach>