operations.subject.Index.js 9.06 KB
webpackJsonp([135],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	var $ = __webpack_require__(1),
		common = __webpack_require__(2),
		util = __webpack_require__(13);
	datepicker = __webpack_require__(9);

	new common.dropDown({el: "#subject-type"});
	new common.dropDown({el: "#subject-paltform"});
	new common.dropDown({el: "#subject-status"});
	new common.dropDown({el: "#subject-isShow"});
	var yhChannelArr = ["男生", "女生", "儿童", "创意生活"];

	var g = new common.grid({
		el: "#subject-manage",
		parms: function () {
			return {
				sort: common.util.__input('subject-type'),
				plateform: common.util.__input('subject-paltform'),
				status: common.util.__input('subject-status'),
				isShow: common.util.__input('subject-isShow'),
				startTimeStr:common.util.__input('subject-startTimeStr'),
				endTimeStr:common.util.__input('subject-endTimeStr'),
				title:common.util.__input('subject-title'),
			};
		},
		columns: [
			{display: "ID", name: "id"},
			{display: "分类", name: "sort", render: function (item) {
				if(item.sort == "1") return "奥莱";
				else if(item.sort == "2") return "SALE";
			}},
			{display: "排序", name: "orderNum"},
			{display: "标题", name: "title", width:"200px"},
			{display: "手机端封面图", name: "coverUrl", height:"102px", render: function (item) {
				if(item.coverUrl) {
					return '<img src="' + item.coverUrl + '" height="100px" />';
				}
			}},
			{display: "web封面图", name: "webCoverUrl", height:"102px", render: function (item) {
				if(item.webCoverUrl) {
					return '<img src="' + item.webCoverUrl + '" height="100px" />';
				}
			}},
			{display: "促销形式", name: "promotionName"},
			{display: "平台", name: "plateform", render: function (item) {

				if(item.plateform != null && item.plateform.trim() != "") {
					var paltform = item.plateform;
					var temp = paltform.replace("1", "WEB").replace("2", "APP").replace("3", "WAP").replace("4", "IPAD");
					return temp;
				}
			}},
			{display:"频道", name:"yhChannel", render: function (item) {
				if(item.yhChannel) {
					item.yhChannel = item.yhChannel.replace(/,/g,"|");
					var arr = [];
					var yhChannels = item.yhChannel.split("|");
					for(var i = 0; i < yhChannels.length; i++) {
						arr.push(yhChannelArr[yhChannels[i]-1]);
					}
					return arr.join(",");
				}
			}},
			{display: "状态", name: "status", render: function (item) {
				if(item.status == 1) return "未定时";
				else if(item.status == 2) return "未发布";
				else if(item.status == 3) return "已发布";
				else if(item.status == 4) return "已结束";
			}},
			{display: "创建时间", name: "createTime", render: function (item) {
				if(!item.createTime) return "";
				item.createTime = common.util.__dateFormat(new Date(item.createTime*1000), "yyyy-MM-dd hh:mm:ss");
				return item.createTime;
			}},
			{display: "活动时间", render: function (item) {
				// return new Date(item.startTime).toStri34ng() + "~" + new Date(item.endTime).tostring();
				if(!item.startTime || !item.endTime) return "";
				item.startTime = common.util.__dateFormat(new Date(item.startTime*1000), "yyyy-MM-dd hh:mm:ss");
				item.endTime = common.util.__dateFormat(new Date(item.endTime*1000), "yyyy-MM-dd hh:mm:ss");
				return item.startTime + "~<br>" + item.endTime;
			}},
			{display: "前端展示",name:"isShow", render: function (item) {
				if(item.isShow == 1) return "是";
				else if(item.isShow == 0) return "否";
			}},
			{
				display: "操作", name: "", render: function (item) {
				var arr = [];
				arr.push('<a style="margin-bottom: 10px" class="btn btn-xs btn-info add2" data-index="' + item.__index + '">编辑</a>');
				arr.push("<br>");
				arr.push('<a style="margin-bottom: 10px" class="btn btn-xs btn-danger delbtn" data-index="' + item.__index + '">删除</a>');
				arr.push("<br>");
				arr.push('<a class="btn btn-xs btn-primary showLink" data-index="' + item.__index + '">查看链接</a>');
				return arr.join("");
			}
			}

		]
	});
	/**
	 * 日期插件
	 */
	$.timepicker.datetimeRange($('#subject-startTimeStr'), $('#subject-endTimeStr'));

	g.init('/runManage/subjectManage/subjectList');

	var Bll = {
		getLocalTime:function(nS) {
			var date = new Date(parseInt(nS) * 1000);
			var mm = date.getMonth() + 1;
			var dd = date.getDate();
			return date.getFullYear() + "-" + (mm < 10 ? "0" + mm : mm) + "-" + (dd < 10 ? "0" + dd : dd);
		},
		toast:function(url, item, hint) {
			var e = new common.edit("#baseform", {bucket:"activity"});

			e.on("validate",function() {
				var startTime=$("#startTime").val();
				var endTime=$("#endTime").val();
				if((startTime==""&&endTime=="") || (startTime!=""&&endTime!="")){}else{
					return "开始时间和结束时间必须同时存在";
				}
			});
			e.on("validate", function() {
				var temp = $("#productPoolId").val();
				if(!temp || temp == -1) {
					return "请填写商品池";
				}
			});

			e.on("validate", function() {
				if(($("#promotion1").is(":checked") && !$("#promotionName1").val())
					|| ($("#promotion2").is(":checked") && (!$("#promotionName2").val() || !$("#promotionName3").val()))
					|| ($("#promotion4").is(":checked") && !$("#promotionName4").val())
					|| ($("#promotion5").is(":checked") && !$("#promotionName5").val())) {
					return "请将折扣形式填写完整";
				}
			});

			var dialog=common.dialog.confirm(hint,
				common.util.__template2($("#template").html(), item),

				function() {
					e.submit(url,function(option){
						//option.data;
						if(typeof option.data.startTime == "string") {
							option.data.startTime=new Date(option.data.startTime).getTime() / 1000;
							option.data.endTime=new Date(option.data.endTime).getTime() / 1000;
						}

						var val=$('input:radio[name="promotionName"]:checked').val();
						if(val == 1) {
							option.data.promotionName = $("#promotionName1").val() + "折起";
						}else if(val == 2) {
							option.data.promotionName = $("#promotionName2").val() + "~" + $("#promotionName3").val() + "折";
						}else if(val == 4) {
							option.data.promotionName = $("#promotionName4").val() + "元起";
						}else if(val == 5) {
							option.data.promotionName = $("#promotionName5").val() + "%Off";
						}
						option.data.yhChannel = option.data.yhChannel.replace(/\|/g, ",");
						option.data.plateform = option.data.plateform.replace(/\|/g, ",");

						option.success=function(res){
							dialog.close();
							util.__tip(res.message, 'success');
							g.reload();
						};
						option.error=function(res){
							dialog.close();
							util.__tip(res.message);
						}
					});
					return false;
				});
			//提取折扣信息
			if(item.promotionName) {
				if(item.promotionName.indexOf("折起") != -1) {
					$('#promotionName1').val(item.promotionName.replace(/折起/g, ""));
					$("#promotion1").attr("checked","checked");
				} else if(item.promotionName.indexOf("折") != -1) {
					var name2 = item.promotionName.replace(/折/g, "");
					$('#promotionName2').val(name2.split("~")[0]);
					$('#promotionName3').val(name2.split("~")[1]);
					$("#promotion2").attr("checked","checked");
				} else if(item.promotionName.indexOf("元起") != -1) {
					$('#promotionName4').val(item.promotionName.replace(/元起/g, ""));
					$("#promotion4").attr("checked","checked");
				} else if(item.promotionName.indexOf("%") != -1) {
					var promotionName5 = $("#promotionName5");
					var temp = item.promotionName.replace(/%/g, "");
					temp = temp.replace(/off/ig, "");
					promotionName5.val(temp);
					$("#promotion5").attr("checked","checked");
				}
			}

			e.init();
			new common.dropDown({el: "#productPoolId"});

			// if(hint == "专题编辑") {
			// 	common.util.__ajax({
			// 		async:false,
			// 		url:'/runManage/subjectManage/queryBaseProductPoolListByName',
			// 		data:{idName:item.productPoolId}
			// 	},function(res) {
			// 		$("#select2-productPoolId-container").html(res.data[0].text);
			// 	},true);
			// }
		}
	};

	$('#add-subject').on('click', function() {
		var item = {};
		Bll.toast('/runManage/subjectManage/addSubject', item, "专题添加");
	});

	$(document).on('click', '.add2', function() {
		var item = g.rows[$(this).data("index")];
		Bll.toast('/runManage/subjectManage/modify', item, "专题编辑");
	});

	$(document).on('click', '.delbtn', function() {
		var item=g.rows[$(this).data("index")];
		common.dialog.confirm("警告",
			"确认删除?",
			function() {
				common.util.__ajax({
					url:'/runManage/subjectManage/delSubject',
					data:{id:item.id}
				},function() {
					g.reload();
				});
			});
	});

	$(document).on("click","#filter-btn",function () {
		g.reload(1);
	});

	$(document).on("click", ".copy", function() {
		var Url2=document.getElementById($(this).data("link"));
		Url2.select(); // 选择对象
		document.execCommand("Copy"); // 执行浏览器复制命令
		common.util.__tip("链接复制成功", "success");
	});

	$(document).on("click", ".showLink", function () {
		var item = g.rows[$(this).data("index")];
		var a=new common.dialog({
			title:"\""+item.title + "\"链接",
			width:"80%",
			content:common.util.__template2($("#links-template").html(), item)
		});
	});

/***/ }
]);