guang.brandConcern.Index.js 7.13 KB
webpackJsonp([61],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	/**
	 * Created by wangqianjun on 16/3/30.
	 */

	var $ = __webpack_require__(1);
	common = __webpack_require__(2);

	var imgArr = [];

	var ENUM = {
	    HotEnum: {
	        '1': '是',
	        '0': '否',
	    },

	    StatusEnum: {
	        1:'可用',
	        2:'不可用',
	    },

	    GenderEnum: {
	        1:'男',
	        2:'女',
	        3:'通用',
	    },
	}

	//下拉框
	new common.dropDown({
	    el: "#g-brandId",
	    ajax: 'brand',
	    params : {
	        status: 1
	    }
	});

	var g = new common.grid({
	    el: '#basicTable',
	    size: 10,
	    parms: function () {

	        return {
	            brandId: common.util.__input('g-brandId'),
	        };
	    },
	    columns: [
	        {
	            display: 'ID',
	            name: "id"
	        }, {
	            display: '品牌名称',
	            name: "brandName"
	        }, {
	            display: '新品',
	            render: function (item) {
	                var value = (item.brandType == 1) ? "是" : "否";

	                return "<p>" + value + "</p>";
	            }
	        },{
	            display: '折扣',
	            render: function (item) {
	                var value = (item.brandType == 2) ? "是" : "否";

	                return "<p>" + value + "</p>";
	            }
	        },{
	            display: '推荐',
	            render: function (item) {
	                var value = (item.brandType == 3) ? "是" : "否";

	                return "<p>" + value + "</p>";
	            }
	        },{
	            display: '活动',
	            render: function (item) {
	                var value = (item.brandType == 4) ? "是" : "否";

	                return "<p>" + value + "</p>";
	            }
	        },{
	            display: '折扣价',
	            name: "discount"
	        }, {
	            display: '时间',
	            render: function (item) {
	                var t = new Date(item.createTime * 1000);
	                var formatted = common.util.__dateFormat(t, "yyyy-MM-dd hh:mm:ss");
	                return "<p>" + formatted + "</p>";
	            }
	        },

	        {
	            display: '操作',
	            //}
	            name: "status",
	            render: function (items) {
	                var HtmArr = [];

	                HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-primary btn-xs info-modify">编辑</a>');
	                HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-danger btn-xs info-del">删除</a>');

	                return HtmArr.join('');
	            }
	        }]
	});
	g.init('/guang/relationship/getList');

	//==================== 按钮点击事件 =====================//

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

	//添加
	$(document).on('click', '#add-btn', function() {
	    plusStarOP("新增", '/guang/relationship/addRel', {});

	});

	//编辑
	$(document).on('click', '.info-modify', function() {
	    var item = g.rows[$(this).data("index")];
	    plusStarOP("编辑", '/guang/relationship/updateRel', item);
	});

	//删除
	$(document).on('click', '.info-del', function() {
	    var item = g.rows[$(this).data("index")];

	    common.dialog.confirm("温馨提示","确定要删除该品牌?" , function() {
	        common.util.__ajax({
	            url: '/guang/relationship/delRel',
	            data: {
	                id: item.id,
	            }
	        }, function(res) {
	            if (res.code == 200) {
	                g.reload();
	            }
	        });
	    });
	});


	// 根据选择的类型来动态展示页面
	$(document).on('click', 'input[name="brandType"]', function () {
	    console.log();
	    var val = $(this).val();

	    $('#discount').css('display', 'none');
	    $('#activity').css('display', 'none');
	    $('#activity-name').css('display', 'none');
	    switch (val) {
	        // 折扣
	        case '2':
	        {
	            $('#discount').css('display', 'inline');

	        }
	            break;

	        // 活动
	        case '4':
	        {
	            $('#activity').css('display', 'block');
	            $('#activity-name').css('display', 'block');
	        }
	            break;

	        default :
	            break;
	    }

	})

	function plusStarOP(prefix, url, item) {

	     var a = new common.edit('#templete-top');
	    common.dialog.confirm(prefix+'品牌', common.util.__template2($("#template").html(), item), function () {

	        console.log('type' +  $('#brandType').val());
	        var type = $('#brandType').val();
	        if(type) {
	            return a.submit(url,function(option){
	                //设置图片
	                if(imgArr.length) {
	                    option.data.activityImg = imgArr.toString();
	                }
	                imgArr = [];
	                option.success=function(res){
	                    if(res.code=="200"){
	                        a.$tip("提交成功", function() {
	                            g.reload();
	                        }, 'growl-success');
	                    }else{
	                        a.$tip(res.message);
	                    }
	                    return false;
	                };
	                option.error=function(res){
	                    a.$tip(res.message);
	                }
	            });
	        } else {
	            a.$tip('类型不能为空');
	            return;
	        }


	    });

	    a.init();

	    var val = $('#brandType').val();
	    $('#discount').css('display', 'none');
	    $('#activity').css('display', 'none');
	    $('#activity-name').css('display', 'none');
	    $('input[name="brandType"][value="' + val + '"]').trigger('click');

	    if(prefix == "编辑") {
	        imgArr = item.activityImg||[];
	        $('#brandId').attr('disabled', true);
	    } else {
	        imgArr = [];
	        $('#brandId').attr('disabled',false);
	    }

	    rendBoList(imgArr);


	    // 图片上传
	    uploadImage();

	    new common.dropDown({
	        el: "#brandId",
	        ajax: 'brand',
	        params : {
	            status: 1
	        }

	    });

	}

	function rendBoList (pictureBoList) {
	    $(".image-list").html('');
	    $("#addPic").append(common.util.__template2($("#imgeUpload").html(),
	        {
	            pictureBoList: pictureBoList
	        }
	    ));
	}

	function uploadImage() {
	    common.edit.ajaxfileupload(".picfile", {
	        params: {
	            __type: "upload",
	            bucket: "relationship"
	        },
	        valid_extensions: ['png', 'jpg', 'jpeg'],
	        onComplete: function (response) {

	            if (response.status && response.code == 200) {
	                console.log("response", response);

	                if(response.data) {
	                    imgArr.push(response.data);
	                    rendBoList(imgArr);
	                }

	            }
	            else {
	                common.util.__tip(response.message, 'warning');
	            }
	        }
	    });
	}

	//删除单张图片
	$(document).on('click', '.remove1', function () {
	    var index = $(this).data("index");
	    imgArr.splice(index, 1);
	    rendBoList(imgArr);
	});

/***/ }
]);