Authored by LiQZ

新增编辑功能完成

@@ -16,15 +16,23 @@ module.exports = function (app) { @@ -16,15 +16,23 @@ module.exports = function (app) {
16 16
17 }); 17 });
18 18
19 - // app.get("/product/bundle/:id", "product.productBundle.Edit", productBundle_findProductBundleByID, function(apiReq, req, res) {  
20 - // this.$extend = {  
21 - // moduleName: "营销管理",  
22 - // pageName: "编辑套餐",  
23 - // action: "/product/bundle/save",  
24 - // data: apiReq.data  
25 - // }  
26 - //  
27 - // }); 19 + app.get("/product/bundle/:id", "product.productBundle.Edit", "productBundle_findProductBundleByID", function(apiReq) {
  20 +
  21 + // 日期处理
  22 + apiReq.data.beginTimeStr = toDate(apiReq.data.startTime);
  23 + apiReq.data.endTimeStr = toDate(apiReq.data.endTime);
  24 +
  25 + if (apiReq.data.productSkn) {
  26 + apiReq.data.skns = apiReq.data.productSkn.split("/");
  27 + }
  28 +
  29 + this.$extend = {
  30 + moduleName: "营销管理",
  31 + pageName: "编辑套餐",
  32 + action: "/product/bundle/save",
  33 + data: apiReq.data
  34 + }
  35 + });
28 36
29 app.post("/product/bundle/list", "productBundle_productBundleList"); 37 app.post("/product/bundle/list", "productBundle_productBundleList");
30 38
@@ -34,3 +42,13 @@ module.exports = function (app) { @@ -34,3 +42,13 @@ module.exports = function (app) {
34 42
35 43
36 } 44 }
  45 +
  46 +function toDate(seconds) {
  47 + if (!seconds || seconds <= 0) { return ''; }
  48 + var date = new Date(seconds * 1000);
  49 + return fixTwo(date.getFullYear()) + '-' + fixTwo((date.getMonth() + 1)) + '-' + fixTwo(date.getDate()) + ' ' + fixTwo(date.getHours()) + ':' + fixTwo(date.getMinutes()) + ':' + fixTwo(date.getSeconds());
  50 +}
  51 +
  52 +function fixTwo(number) {
  53 + return number < 10? "0" + number: number;
  54 +}
@@ -36,11 +36,11 @@ @@ -36,11 +36,11 @@
36 <div class="form-group"> 36 <div class="form-group">
37 <label class="col-sm-2 control-label">有效时间:</label> 37 <label class="col-sm-2 control-label">有效时间:</label>
38 <div class="col-sm-2"> 38 <div class="col-sm-2">
39 - <input id="beginTimeStr" data-time="" value="<%if data%><% data.beginTimeStr %><%/if%>" type="text" class="form-control" jsaction="time" placeholder="开始时间" readonly required> 39 + <input id="beginTimeStr" data-time="" value="<%if data%><% data.beginTimeStr %><%/if%>" type="text" class="form-control" jsaction="time:end:endTimeStr" placeholder="开始时间" readonly required>
40 </div> 40 </div>
41 <div class="col-sm-1" style="width: 28px;">~</div> 41 <div class="col-sm-1" style="width: 28px;">~</div>
42 <div class="col-sm-2"> 42 <div class="col-sm-2">
43 - <input id="endTimeStr" data-time="" value="<%if data%><% data.endTimeStr %><%/if%>" type="text" class="form-control" jsaction="time" placeholder="结束时间" readonly required> 43 + <input id="endTimeStr" data-time="" value="<%if data%><% data.endTimeStr %><%/if%>" type="text" class="form-control" jsaction="time:begin:beginTimeStr" placeholder="结束时间" readonly required>
44 </div> 44 </div>
45 </div> 45 </div>
46 <div class="form-group"> 46 <div class="form-group">
@@ -56,13 +56,13 @@ @@ -56,13 +56,13 @@
56 </thead> 56 </thead>
57 <tbody> 57 <tbody>
58 <tr> 58 <tr>
59 - <td> <input type="text" name="productSkn" class="form-control" maxlength="10" style="width: 150px;" value="<% if data%><% data.productSkn1 %><%/if%>"> </td> 59 + <td> <input type="text" name="productSkn" class="form-control" maxlength="10" style="width: 150px;" value="<% if data%><% data.skns[0]%><%/if%>"> </td>
60 <td> 60 <td>
61 <button type="button" class="btn btn-default btn-sm btn-down"><span class="glyphicon glyphicon-chevron-down"></span></button> 61 <button type="button" class="btn btn-default btn-sm btn-down"><span class="glyphicon glyphicon-chevron-down"></span></button>
62 </td> 62 </td>
63 </tr> 63 </tr>
64 <tr> 64 <tr>
65 - <td> <input type="text" name="productSkn" class="form-control" maxlength="10" style="width: 150px;" value="<% if data%><% data.productSkn2 %><%/if%>"> </td> 65 + <td> <input type="text" name="productSkn" class="form-control" maxlength="10" style="width: 150px;" value="<% if data%><% data.skns[1]%><%/if%>"> </td>
66 <td> 66 <td>
67 <div class="btn-group"> 67 <div class="btn-group">
68 <button type="button" class="btn btn-default btn-sm btn-up"><span class="glyphicon glyphicon-chevron-up"></span></button> 68 <button type="button" class="btn btn-default btn-sm btn-up"><span class="glyphicon glyphicon-chevron-up"></span></button>
@@ -71,7 +71,7 @@ @@ -71,7 +71,7 @@
71 </td> 71 </td>
72 </tr> 72 </tr>
73 <tr> 73 <tr>
74 - <td> <input type="text" name="productSkn" class="form-control" maxlength="10" style="width: 150px;" value="<% if data%><% data.productSkn3 %><%/if%>"> </td> 74 + <td> <input type="text" name="productSkn" class="form-control" maxlength="10" style="width: 150px;" value="<% if data%><% data.skns[2]%><%/if%>"> </td>
75 <td> 75 <td>
76 <div class="btn-group"> 76 <div class="btn-group">
77 <button type="button" class="btn btn-default btn-sm btn-up"><span class="glyphicon glyphicon-chevron-up"></span></button> 77 <button type="button" class="btn btn-default btn-sm btn-up"><span class="glyphicon glyphicon-chevron-up"></span></button>
@@ -80,7 +80,7 @@ @@ -80,7 +80,7 @@
80 </td> 80 </td>
81 </tr> 81 </tr>
82 <tr> 82 <tr>
83 - <td> <input type="text" name="productSkn" class="form-control" maxlength="10" style="width: 150px;" value="<% if data%><% data.productSkn4 %><%/if%>"> </td> 83 + <td> <input type="text" name="productSkn" class="form-control" maxlength="10" style="width: 150px;" value="<% if data%><% data.skns[3]%><%/if%>"> </td>
84 <td><button type="button" class="btn btn-default btn-sm btn-up"><span class="glyphicon glyphicon-chevron-up"></span></button> 84 <td><button type="button" class="btn btn-default btn-sm btn-up"><span class="glyphicon glyphicon-chevron-up"></span></button>
85 </td> 85 </td>
86 </tr> 86 </tr>
@@ -4,24 +4,25 @@ var e = new common.edit('#editor-group'); @@ -4,24 +4,25 @@ var e = new common.edit('#editor-group');
4 4
5 e.on("validate", function () { 5 e.on("validate", function () {
6 6
7 - if (new Date($("#beginTimeStr").val()).getTime() >= new Date($("#endTimeStr").val()).getTime()) {  
8 - return "开始时间必须小于结束时间";  
9 - }  
10 -  
11 var discount = $("#discount").val(); 7 var discount = $("#discount").val();
12 8
13 - if (!/^1|0\.[0-9][0-9]$/.test(discount) || discount > 1.0) { 9 + if (!/^1|0\.[0-9]{0,2}$/.test(discount) || discount > 1.0 || discount <= 0.0) {
14 return "折扣格式不正确"; 10 return "折扣格式不正确";
15 } 11 }
16 12
17 -  
18 var skns = ''; 13 var skns = '';
19 - $("input[name='productSkn']").each(function (index) {  
20 - var skn = $(this).val();  
21 - if (skn && skn.length > 1) { 14 +
  15 + var iptSkns = $("input[name='productSkn']");
  16 +
  17 + for (var i = 0, l = iptSkns.length; i < l; i++) {
  18 + var $thiz = $(iptSkns[i]);
  19 + var skn = $.trim($thiz.val());
  20 + if (/^[1-9][0-9]{4,10}$/.test(skn)) {
22 skns = skns + skn + "/"; 21 skns = skns + skn + "/";
  22 + } else if(skn.length != 0) {
  23 + return "第 " + (i + 1) + " 个 SKN 格式错误";
23 } 24 }
24 - }); 25 + }
25 26
26 var lio = skns.lastIndexOf("/"); 27 var lio = skns.lastIndexOf("/");
27 28
@@ -45,8 +46,6 @@ $('#add-btn').click(function(option) { @@ -45,8 +46,6 @@ $('#add-btn').click(function(option) {
45 data.startTime = toSeconds(data.beginTimeStr); 46 data.startTime = toSeconds(data.beginTimeStr);
46 data.endTime = toSeconds(data.endTimeStr); 47 data.endTime = toSeconds(data.endTimeStr);
47 48
48 - data.popupPic = $("#popupPic").parent().find("img").attr("src");  
49 -  
50 option.beforeSend = function() { 49 option.beforeSend = function() {
51 $('#add-btn').addClass('disabled'); 50 $('#add-btn').addClass('disabled');
52 }; 51 };
@@ -54,7 +53,7 @@ $('#add-btn').click(function(option) { @@ -54,7 +53,7 @@ $('#add-btn').click(function(option) {
54 option.success = function(res) { 53 option.success = function(res) {
55 if (res.code == "200") { 54 if (res.code == "200") {
56 e.$tip('提交成功', function() { 55 e.$tip('提交成功', function() {
57 - location.href = "/activity/yohocoin/index"; 56 + location.href = "/product/bundle/index";
58 }, 'growl-success'); 57 }, 'growl-success');
59 } else { 58 } else {
60 $('#add-btn').removeClass('disabled'); 59 $('#add-btn').removeClass('disabled');
@@ -91,7 +90,3 @@ function toSeconds(strDate) { @@ -91,7 +90,3 @@ function toSeconds(strDate) {
91 var seconds = new Date(strDate).getTime() / 1000; 90 var seconds = new Date(strDate).getTime() / 1000;
92 return seconds; 91 return seconds;
93 } 92 }
94 -  
95 -$("#set_default_img").click(function() {  
96 - $("#popupPic").parent().find("img").attr("src", default_img);  
97 -});  
@@ -39,6 +39,10 @@ var tableGird = new common.grid({ @@ -39,6 +39,10 @@ var tableGird = new common.grid({
39 return items.discount; 39 return items.discount;
40 }}, 40 }},
41 { display: "状态", render: function(items) { 41 { display: "状态", render: function(items) {
  42 + if (items.status != 1) {
  43 + return "已终止";
  44 + }
  45 +
42 return ''; 46 return '';
43 }}, 47 }},
44 { display: "操作信息", render: function(items) { 48 { display: "操作信息", render: function(items) {
@@ -46,7 +50,7 @@ var tableGird = new common.grid({ @@ -46,7 +50,7 @@ var tableGird = new common.grid({
46 }}, 50 }},
47 { display: "操作", render: function(items) { 51 { display: "操作", render: function(items) {
48 var HtmArr = []; 52 var HtmArr = [];
49 - HtmArr.push('<a href="/activity/yohocoin/update/' + items.id + '" data-id="' + items.id + '" class="btn btn-primary btn-xs">编辑</a>'); 53 + HtmArr.push('<a href="/product/bundle/' + items.id + '" data-id="' + items.id + '" class="btn btn-primary btn-xs">编辑</a>');
50 HtmArr.push('<a href="javascript:void(0);" data-id="' + items.id + '" class="btn btn-danger btn-xs delete">删除</a>'); 54 HtmArr.push('<a href="javascript:void(0);" data-id="' + items.id + '" class="btn btn-danger btn-xs delete">删除</a>');
51 return HtmArr.join(''); 55 return HtmArr.join('');
52 } 56 }