info.js 3.42 KB
//商家管理
'use strict';
var $ = require('jquery'),
    Handlebars = require('yoho.handlebars');

var dropDown=require('../common/dropDown');
require('../util/jquery.gritter');
var grid=require('../common/grid');
var edit=require('../common/edit');

exports.init=function(){
		$('.urlAdd').on('click',function(){
		var type = $(this).data('type'),
			inputAdd = '';
			switch(type)
			{
			case 0:		
				inputAdd = '<input type="text" name="homepage" class="form-control" style="margin-top:15px;" placeholder="官方网址">';
			  break;
			case 1:
				inputAdd = '<input type="text" name="homeurl" class="form-control" style="margin-top:15px;" placeholder="其他平台网址">';
			  break;
			case 2:
				inputAdd = '<input type="text" name="homeaddresslist" class="form-control" style="margin-top:15px;" placeholder="代表实体店">';
			  break;
			}
			$('.Add').eq(type).append(inputAdd);
	});
	new dropDown({el:"#store-type"});
	new dropDown({el:"#store-model"});
	new dropDown({el:"#brand-name",ajax:"brand"});
	$('#addBrand').on('click',function(){
		var storeModel = $('#store-model').val();
		if(storeModel==1&&$('#updateBrand tbody tr').length<1){
			$('#savebrand .checkbox').each(function(){
				if($(this).prop('checked')){
					var check = $(this).closest('tr').html();
					var brand=check.split('<td>')[check.split('<td>').length-2];
					var supplier=check.split('<td>')[check.split('<td>').length-1];
					var table = '<tr><td>'+brand+'<td>'+supplier+'<td><button type="button" class="btn btn-danger btn-xs">删除</button></td></tr>'
					$('#updateBrand tbody').append(table);
				}
			})
		}else{
			$('#savebrand .checkbox').each(function(){
				if($(this).prop('checked')){
					var check = $(this).closest('tr').html();
					var brand=check.split('<td>')[check.split('<td>').length-2];
					var supplier=check.split('<td>')[check.split('<td>').length-1];
					var table = '<tr><td>'+brand+'<td>'+supplier+'<td><button type="button" class="btn btn-danger btn-xs">删除</button></td></tr>'
					$('#updateBrand tbody').append(table);
				}
			})
		}
	});
	var e=new edit("#storeForm");
	    e.on("validate",function(){
	    });
	    var submit=function(callback){
	        e.submit('/store/add',function(option){
	            option.success=function(res){
	            	console.log(res.data.code);
	                if(res.data.code=="200"){
	                    // location.href="/supplier/store/index";
	                }else{
	                    e.$tip("提交失败");
	                }
	                return false;
	            },
	            option.error=function(res){
	                e.$tip("提交失败");
	            }
	            callback&&callback(option.data);
	        });
	    }

	    
	    $("#btn1").click(function(){
	    var homepage=$("input[name='homepage']");
		var hplist=[];
	 	homepage.each(function(index){
	 		hplist.push(homepage[index].value);
	 	})
	 	var homeurl=$("input[name='homeurl']");
		var homeurlist=[];
	 	homeurl.each(function(index){
	 		homeurlist.push(homepage[index].value);
	 	})
	 	var homeaddress=$("input[name='homeaddresslist']");
		var homeaddresslist=[];
	 	homeaddress.each(function(index){
	 		homeaddresslist.push(homeaddress[index].value);
	 	})
	        submit(function(data){
	        	data.websiteUrl=hplist.toString();
	        	data.otherUrl=homeurlist.toString();
	        	data.shopAddress=homeaddresslist.toString();
	            data.onCheck=1;
	        });
	        return false;
	    });

}