Index.js 3.85 KB
'use strict';
var $ = require('jquery'),
	common = require('../../common/common');


var ENUM = {
	checkStatus: {
		100: '暂存',
		200: '待审核',
		300: '审核通过',
		900: '驳回'
	}
};

var g = new common.grid({
	el: '#basicTable',
	parms: function() {
		return {
			shopsId: common.util.__input("shop-name"),
			checkStatus: common.util.__input("status"),
			supplierId: common.util.__input("supplier-name"),
			brandId: common.util.__input("brand-name")
		};
	},
	columns: [{
		display: "店铺ID",
		name: "shopsId"
	}, {
		display: "店铺名称",
		name: "shopsName"
	}, {
		display: "包含品牌",
		name: "brands",
		render: function(item) {
			console.log(item);
			if (item.brands instanceof Array && item.brands.length > 0) {
				var brandArr = [];
				$.each(item.brands, function(i, value) {
					if($.inArray(value.brandName, brandArr) === -1) {
						brandArr.push(value.brandName);
					}
				});

				return '<p>' + brandArr.join('</p><p>') + '</p>';
			} else {
				return '';
			}
		}
	}, {
		display: "更新时间",
		name: "updateTime",
		render: function(item) {
			if (item.updateTime) {
				return common.util.__dateFormat(new Date(item.updateTime * 1000), "yyyy-MM-dd hh:mm:ss");
			} else {
				return '';
			}
		}
	}, {
		display: "开店时间",
		render: function(item) {
			var htmArr = [];
			if(item.openTime && item.openTime != 0) {
				htmArr.push("<p>有货店铺: " + common.util.__dateFormat(new Date(item.openTime * 1000), "yyyy-MM-dd hh:mm:ss") + "</p>");
			}
			
			if(item.blkOpenTime && item.blkOpenTime != 0) {
				htmArr.push("<p>BLK店铺: " + common.util.__dateFormat(new Date(item.blkOpenTime * 1000), "yyyy-MM-dd hh:mm:ss") + "</p>");
			}

			return htmArr.join(' ');
		}
	}, {
		display: "状态",
		name: "checkStatus",
		render: function(item) {
			if (item.checkStatus) {
				return ENUM.checkStatus[item.checkStatus]
			} else {
				return '待装修';
			}
		}
	}, {
		display: "操作",
		render: function(item) {
			var HtmArr = [];

			if(+item.checkStatus == 200){
				HtmArr.push('<a href="/supplier/shop/decorationDetail/'+item.shopsId+'/'+item.shopsType+'/view/'+item.id+'/" class="btn btn-info btn-xs">装修查看</a>');
			}else {
				HtmArr.push('<a href="/supplier/shop/decorationDetail/'+item.shopsId+'/'+item.shopsType+'/editor/'+item.id+'/" class="btn btn-success btn-xs">装修编辑</a>');
			}

			if(item.passStatus && +item.passStatus == 1){
				if(+item.shopStatus == 1){
					// 1开启 0 关闭
					HtmArr.push('<a data-index="'+item.__index+'" href="javascript:void(0);" class="closeshops btn btn-danger btn-xs">关店</a>');
				}else{
					HtmArr.push('<a data-index="'+item.__index+'" href="javascript:void(0);" class=" openshops btn btn-success btn-xs">开店</a>');
				}
			}

			if (+item.checkStatus == 900) {
				HtmArr.push('<a href="javascript:void(0)" class="btn btn-warning btn-xs commentBtn" data-comment="'+item.comment+'">驳回理由</a>');
			}

			return HtmArr.join('');
		}
	}]
});

g.init($("#gridurl").val());

// 筛选
$(document).on('click', "#filter-btn", function() {
	g.reload();
});

//查看驳回理由
$(document).on('click', ".commentBtn", function() {
	var comment = $(this).attr("data-comment");
	common.dialog.confirm(
		"查看驳回理由",
		comment,
		function(){},
		function(){}
	);
});

var Bll={
	toast:function(content,url,id){
		common.dialog.confirm("温馨提示",content,function(){
			common.util.__ajax({
				url:url,
				data:{shopsId:id}
			},function(){
				g.reload();
			});
		});
	}
}

//关闭店铺
$('#basicTable').on('click', '.closeshops', function() {
	var item=g.rows[$(this).data("index")];
	Bll.toast("确定要关闭此店铺吗?","/supplier/shop/closeShops",item.shopsId);
});

//开启店铺
$('#basicTable').on('click', '.openshops', function() {
	var item=g.rows[$(this).data("index")];
	Bll.toast("确定要开启此店铺吗?","/supplier/shop/openShops",item.shopsId);
});