newMyTemplate.zml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <script>
  2. var sizeMap = new Map();
  3. var typeMap = new Z.HashMap();
  4. Z.onload(function()
  5. {
  6. var data = Z.J.toObject('${sizeMap}');
  7. for(var key in data)
  8. {
  9. sizeMap.set(key, data[key]);
  10. }
  11. Z("#typeData .z-active")[0].click(); //默认触发第一条click
  12. var typeList = Z.J.toObject('${typeList}');
  13. for (var i = 0; i < typeList.length; i++)
  14. {
  15. var type = typeList[i];
  16. typeMap.put(''+type.typeId, type);
  17. }
  18. });
  19. function doSubmitNewMyTemplate()
  20. {
  21. var typeId = Z("#typeId").val();
  22. var type = typeMap.get(typeId);
  23. if (Z.V.isEmpty(typeId) || !type)
  24. {
  25. Z.alert("请选择正确的类型");
  26. return;
  27. }
  28. var width = parseFloat(Z("#width").val() || 0);
  29. var height = parseFloat(Z("#height").val() || 0);
  30. var sizeBleed = parseFloat(Z("#sizeBleed").val() || 0);
  31. var baseWidthMm = type.sizeMWidth;
  32. var baseHeightMm = type.sizeMHeight;
  33. if (width <=0 || height <= 0)
  34. {
  35. Z.alert("请输入设计尺寸");
  36. return;
  37. }
  38. // pvc名片不补位特殊流程
  39. if(typeId == "1806070857392601" || typeId == "1807131630136416"){
  40. if(width == "87" && height == "50"){
  41. baseWidthMm = 90;
  42. baseHeightMm = 53;
  43. sizeBleed = 3;
  44. } else if(width == "85" && height == "54") {
  45. baseWidthMm = 88.5;
  46. baseHeightMm = 57;
  47. width = 85;
  48. height = 53.5;
  49. sizeBleed = 3.5;
  50. } else {
  51. baseWidthMm = 88.5;
  52. baseHeightMm = 57;
  53. sizeBleed = 3.5;
  54. }
  55. }
  56. // 添加 2mm 出血长度
  57. width += sizeBleed;
  58. height += sizeBleed;
  59. if (!type.sizeMWidth || !type.sizeMHeight)
  60. {
  61. Z.alert("模位尺寸不正确,请联系管理员");
  62. return;
  63. }
  64. function getAreaTimes(widthMm, heightMm)
  65. {
  66. var fullWidthMm = baseWidthMm * Math.ceil(widthMm / baseWidthMm);
  67. var fullHeightMm = baseHeightMm * Math.ceil(heightMm / baseHeightMm);
  68. return fullWidthMm * fullHeightMm;
  69. }
  70. // 切换横竖版,减少用纸单位
  71. if (getAreaTimes(height, width) < getAreaTimes(width, height))
  72. {
  73. // width、height 对调
  74. var setWidth = width;
  75. width = height;
  76. height = setWidth;
  77. }
  78. var fullWidth = baseWidthMm * Math.ceil(width / baseWidthMm);
  79. var fullHeight = baseHeightMm * Math.ceil(height / baseHeightMm);
  80. var templateType = Z("#templateType").val();
  81. var oddEven = Z("#oddEven").val();
  82. var pageValue = document.getElementById("pageValues") == null ? Z("#pageValue").val() : document.getElementById("pageValues").value;
  83. var templateName = "";
  84. if(document.getElementById("templateName"))
  85. {
  86. templateName = document.getElementById("templateName").value;
  87. }
  88. //创建新的我的模板
  89. var ajax = new Z.Ajax();
  90. ajax.setClassName("TemplatePresenter");
  91. ajax.setMethodName("doCreateMyTemplate");
  92. ajax.addParam("typeId", typeId);
  93. ajax.addParam("baseWidthMm", baseWidthMm);
  94. ajax.addParam("baseHeightMm", baseHeightMm);
  95. ajax.addParam("width", width);
  96. ajax.addParam("height", height);
  97. ajax.addParam("fullWidth", fullWidth);
  98. ajax.addParam("fullHeight", fullHeight);
  99. ajax.addParam("sizeBleed", sizeBleed);
  100. ajax.addParam("pageValue", pageValue);
  101. ajax.addParam("createMode", 0);
  102. ajax.addParam("isModify", false);
  103. ajax.addParam("createChannel", templateType == 1 ? "out_draft" : "platform_design");
  104. ajax.addParam("oddEven", oddEven);
  105. ajax.addParam("templateName", templateName);
  106. ajax.setFailureAlert();
  107. ajax.setSuccess(function(){
  108. var mediaId = this.responseText;
  109. if(templateType == 2){
  110. var newLink = "/zhiqimMediaEditor/mediaDesign.htm?";
  111. newLink += "mediaId=" + mediaId + "&";
  112. newLink += "designWidth=" + baseWidthMm + "&";
  113. newLink += "designHeight=" + baseHeightMm + "&";
  114. newLink += "bleedSize=" + sizeBleed + "&isTemplateEdit=true";
  115. window.open(newLink);
  116. parent.location.reload();
  117. }else{
  118. window.parent.externalDraftUpload("newTemplate",type.typeName);
  119. parent.Z.Dialog.close();
  120. }
  121. });
  122. ajax.execute();
  123. }
  124. function doSelDesignType(typeId,typeName)
  125. {//选择类型
  126. var list = sizeMap.get("" + typeId) || [];
  127. var html = '';
  128. var typeHtml = '';
  129. var width = 0, height = 0, bleedSize;
  130. for(var i=0; i < list.length;i++)
  131. {
  132. bleedSize = list[i].sizeBleed;
  133. width = list[i].sizeWidth - bleedSize;
  134. height = list[i].sizeHeight - bleedSize;
  135. html += '<button type="button" data-sizeWidth="' + width + '"data-sizeHeight="' + height + '"data-sizeBleed="' + bleedSize;
  136. html += '" class="z-button z-large z-bordered z-blue-bd z-mg-t3 z-mg-r5" onclick="doSelSize(this);">' + width + "X" + height + '</button>';
  137. }
  138. var defaultBleedSize = list[0] ? list[0].sizeBleed : 2;
  139. html += '<button type="button" class="z-button z-large z-bordered z-blue-bd z-mg-t3 z-mg-r5" data-sizeBleed="'+defaultBleedSize+'" onclick="doSelSize(this);">自定义</button>'
  140. if(typeName.indexOf("普通名片") != -1 || typeName.indexOf("代金券") != -1 || typeName.indexOf("彩页") != -1 ){
  141. typeHtml += '<button type="button" data-options="group:templateType" class="z-button z-large z-bordered z-blue-bd z-mg-t3 z-hover z-active" onclick="doType(this,1);">外部稿件</button>'
  142. Z("#templateType").val(1);
  143. }else {
  144. typeHtml += '<button type="button" data-options="group:templateType" class="z-button z-large z-bordered z-blue-bd z-mg-t3 z-hover z-active" onclick="doType(this,1);">外部稿件</button>'
  145. Z("#templateType").val(1);
  146. }
  147. Z("#typeId").val(typeId);
  148. Z("#sizeCont").html(html);
  149. Z("#typeCont").html(typeHtml);
  150. if (typeName.indexOf("画册") != -1) {
  151. var pageValueHtml = "";
  152. pageValueHtml += '<button type="button" class="z-button z-large z-bordered z-blue-bd z-mg-t3 z-mg-r5 z-active" onclick="doSelSize(this);">自定义</button>'
  153. pageValueHtml += '<span><input type="number" id="pageValues" name="pageValues" class="z-input z-w70" value="" class="z-mg-r3" maxlength="3" placeholder="P数" data-options="type:Amount2R;paste:true;"></span>'
  154. Z("#pageValueTd").html(pageValueHtml);
  155. var tb = document.getElementById("templateTable");
  156. var tbody = document.createElement("tbody");
  157. var tr = document.createElement("tr");
  158. var td1 = document.createElement("td");
  159. var td2 = document.createElement("td");
  160. tr.id = "newMyTemplateId";
  161. td2.style.float = "left";
  162. td2.style.paddingLeft = "6px";
  163. td1.innerHTML = "模板版式:";
  164. td2.innerHTML = '<button type="button" data-options="group:oddEven" class="z-button z-large z-bordered z-blue-bd z-mg-t3 z-hover z-active" onclick="doOddEven(this,0);">横版</button>&nbsp;';
  165. td2.innerHTML += '<button type="button" data-options="group:oddEven" class="z-button z-large z-bordered z-blue-bd z-mg-t3 z-hover" onclick="doOddEven(this,1);">竖版</button>';
  166. tr.appendChild(td1);
  167. tr.appendChild(td2);
  168. tbody.append(tr);
  169. tb.appendChild(tbody);
  170. var tr2 = document.createElement("tr");
  171. var td21 = document.createElement("td");
  172. var td22 = document.createElement("td");
  173. tr2.id = "newMyTemplateNameId";
  174. td22.style.float = "left";
  175. td22.style.paddingLeft = "6px";
  176. td21.innerHTML = "模板名称:";
  177. td22.innerHTML = '<span><input id="templateName" name="templateName" type="test" placeholder="模板画册名称" class="z-input z-w300 z-mg-r3" value="" data-options="type:Amount2R;paste:true;"></span>';
  178. tr2.appendChild(td21);
  179. tr2.appendChild(td22);
  180. tbody.append(tr2);
  181. tb.appendChild(tbody);
  182. }else {
  183. var allTemplateTr = document.getElementById("newMyTemplateId");
  184. if (allTemplateTr != null){
  185. var tb = document.getElementById("templateTable");
  186. tb.deleteRow(3);//注意:添加行可能需要修改
  187. tb.deleteRow(3);
  188. }
  189. var pageValueHtml = "";
  190. pageValueHtml += '<button type="button" data-options="group:pageValue" class="z-button z-large z-bordered z-blue-bd z-mg-t3 z-hover" onclick="doPageValues(this,1)">单面</button>&nbsp;';
  191. pageValueHtml += '<button type="button" data-options="group:pageValue" class="z-button z-large z-bordered z-blue-bd z-mg-t3 z-hover z-active" onclick="doPageValues(this,2)">双面</button>';
  192. Z("#pageValueTd").html(pageValueHtml);
  193. }
  194. Z("#sizeCont button")[0].click(); //默认触发第一条click
  195. }
  196. function doPageValues(ele,pageValue){
  197. Z("#pageValue").val(pageValue);
  198. Z(ele).addClass('z-active').siblings("button").removeClass("z-active");
  199. }
  200. function doOddEven(ele,oddEvenId){
  201. Z("#oddEven").val(oddEvenId);
  202. Z(ele).addClass('z-active').siblings("button").removeClass("z-active");
  203. }
  204. function doType(ele,createChannelId) {
  205. Z("#templateType").val(createChannelId);
  206. Z(ele).addClass('z-active').siblings("button").removeClass("z-active");
  207. }
  208. function doSelSize(ele)
  209. {//选择尺寸
  210. Z(ele).addClass('z-active').siblings("button").removeClass("z-active");
  211. Z("#width").val(Z(ele).attr("data-sizeWidth") || "");
  212. Z("#height").val(Z(ele).attr("data-sizeHeight") || "");
  213. Z("#sizeBleed").val(Z(ele).attr("data-sizeBleed") || 2);
  214. }
  215. function diyCardSize()
  216. {
  217. var width = parseFloat(Z("#width").val() || 0);
  218. var height = parseFloat(Z("#height").val() || 0);
  219. var $$btn = Z("#sizeCont button");
  220. var $btnDiy = Z($$btn[$$btn.length-1]);
  221. var flag = false;
  222. if (width > 0 || height > 0)
  223. {
  224. for (var i = 0; i< $$btn.length-1; i++)
  225. {
  226. var btn = $$btn[i];
  227. var sizeWidth = Z(btn).attr("data-sizeWidth");
  228. var sizeHeight = Z(btn).attr("data-sizeHeight");
  229. if (width == sizeWidth && height == sizeHeight)
  230. {
  231. btn.click();
  232. flag = true;
  233. break;
  234. }
  235. }
  236. }
  237. if (!flag)
  238. {
  239. $btnDiy.addClass('z-active').siblings("button").removeClass("z-active");
  240. Z("#sizeBleed").val($btnDiy.attr("data-sizeBleed") || 2);
  241. }
  242. }
  243. </script>
  244. <div class="content">
  245. <form id="theForm" name="theForm" style="overflow: scroll;height:420px;padding-bottom: 20px;">
  246. <input type="hidden" name="mediaId" id="mediaId" value="">
  247. <input type="hidden" name="typeId" id="typeId" value="">
  248. <input type="hidden" name="sizeBleed" id="sizeBleed" value="2">
  249. <input type="hidden" name="pageValue" id="pageValue" value="2">
  250. <input type="hidden" name="templateType" id="templateType" value="2">
  251. <input type="hidden" name="oddEven" id="oddEven" value="0">
  252. <table id="templateTable" class="z-table z-pd6 z-bg-white z-text-center">
  253. <tr class="z-h50">
  254. <td width="100">产品类型:</td>
  255. <td width="*%" align="left" id="typeData">
  256. <#for item : DesignTypeDao.listTemmplate()>
  257. <button type="button" data-options="group:typeId" class="z-button z-large z-bordered z-blue-bd z-mg-t3 z-hover <#if item_index == 0>z-active</#if>" onclick="{Z(this).toggleClass('z-active');doSelDesignType('${item.getTypeId()}','${item.getTypeName()}')};">${item.getTypeName()}</button>
  258. </#for>
  259. </td>
  260. </tr>
  261. <tr class="z-h50">
  262. <td>设计面数:</td>
  263. <td align="left" id="pageValueTd">
  264. <button type="button" data-options="group:pageValue" class="z-button z-large z-bordered z-blue-bd z-mg-t3 z-hover" onclick="{Z(this).toggleClass('z-active');Z('#pageValue').val(1);};">单面</button>
  265. <button type="button" data-options="group:pageValue" class="z-button z-large z-bordered z-blue-bd z-mg-t3 z-hover z-active" onclick="{Z(this).toggleClass('z-active');Z('#pageValue').val(2);};">双面</button>
  266. </td>
  267. </tr>
  268. <tr class="z-h50">
  269. <td>设计尺寸:</td>
  270. <td align="left">
  271. <span class="z-w100p" id="sizeCont">
  272. <button type="button" class="z-button z-large z-bordered z-blue-bd z-mg-t3" onclick="doSelSize(this);">自定义</button>
  273. </span>
  274. <span class="z-w200" >
  275. <input type="text" id="width" name="width" class="z-input z-w70 ${zmr_color_class}" oninput="diyCardSize();" value="" class="z-mg-r3" maxlength="8" placeholder="宽度" data-options="type:Amount2R;paste:true;">&nbsp;X&nbsp;
  276. <input type="text" id="height" name="height" class="z-input z-w70 ${zmr_color_class}" oninput="diyCardSize();" value="" class="z-mg-r3" maxlength="8" placeholder="高度" data-options="type:Amount2R;paste:true;">&nbsp;mm
  277. </span>
  278. </td>
  279. </tr>
  280. </table>
  281. <table class="z-table z-pd6 z-bg-white z-text-center">
  282. <tr class="z-h50">
  283. <td width="100">模板类型:</td>
  284. <td align="left" id="typeCont">
  285. <!--<button type="button" data-options="group:templateType" class="z-button z-large z-bordered z-blue-bd z-mg-t3 z-hover" onclick="{Z(this).toggleClass('z-active');Z('#templateType').val(1);};">外部稿件</button>
  286. <button type="button" data-options="group:templateType" class="z-button z-large z-bordered z-blue-bd z-mg-t3 z-hover z-active" onclick="{Z(this).toggleClass('z-active');Z('#templateType').val(2);};">平台设计</button>-->
  287. </td>
  288. </tr>
  289. </table>
  290. </form>
  291. <div class="z-bg-gray z-absolute z-w100p z-h80 z-text-center z-pd20" style="bottom:0;">
  292. <button type="button" class="z-button z-large z-w100 z-blue" onclick="doSubmitNewMyTemplate();">确定</button>
  293. <button type="button" class="z-button z-large z-w100 z-mg-l10" onclick="parent.Z.Dialog.close();">关闭</button>
  294. </div>
  295. </div>