|
|
//商家管理
|
|
|
'use strict';
|
|
|
var $ = require('jquery'),
|
|
|
Handlebars = require('yoho.handlebars');
|
|
|
Handlebars = require('yoho.handlebars');
|
|
|
|
|
|
var dropDown=require('../common/dropDown');
|
|
|
var dropDown = require('../common/dropDown');
|
|
|
require('../util/jquery.gritter');
|
|
|
var grid=require('../common/grid');
|
|
|
var edit=require('../common/edit');
|
|
|
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(){
|
|
|
});
|
|
|
if($('#shopsId').val()>0){
|
|
|
var submit=function(callback){
|
|
|
e.submit('/store/update',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);
|
|
|
});
|
|
|
}
|
|
|
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-bottom:15px;" placeholder="官方网址">';
|
|
|
break;
|
|
|
case 1:
|
|
|
inputAdd = '<input type="text" name="homeurl" class="form-control" style="margin-bottom:15px;" placeholder="其他平台网址">';
|
|
|
break;
|
|
|
case 2:
|
|
|
inputAdd = '<input type="text" name="homeaddresslist" class="form-control" style="margin-bottom: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 = $('#shopsType').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() {});
|
|
|
if ($('#shopsId').val() > 0) {
|
|
|
var submit = function(callback) {
|
|
|
e.submit('/store/update',
|
|
|
function(option) {
|
|
|
option.success = function(res) {
|
|
|
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);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
}else{
|
|
|
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 shopsId =$('#shopsId').val();
|
|
|
console.log(shopsId);
|
|
|
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;
|
|
|
data.shopsId=shopsId;
|
|
|
});
|
|
|
return false;
|
|
|
});
|
|
|
$(function(){
|
|
|
if($('#otherUrl').val().split(',').length>1){
|
|
|
var homepage=$('#otherUrl').val().split(',');
|
|
|
$.each(homepage,function(){
|
|
|
$('#homepage').append('<input value="'+this+'" type="text" name="homepage" class="form-control" style="margin-buttom:15px;">')
|
|
|
})
|
|
|
} else {
|
|
|
var submit = function(callback) {
|
|
|
e.submit('/store/add',
|
|
|
function(option) {
|
|
|
option.success = function(res) {
|
|
|
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);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if($('#websiteUrl').val().split(',').length>1){
|
|
|
var websiteUrl=$('#websiteUrl').val().split(',');
|
|
|
$.each(websiteUrl,function(){
|
|
|
$('#homeurl').append('<input value="'+this+'" type="text" name="homeurl" class="form-control" style="margin-buttom:15px;">')
|
|
|
})
|
|
|
}
|
|
|
$(".check").click(function() {
|
|
|
var shopsId = $('#shopsId').val();
|
|
|
var onCheck = $(this).data('oncheck');
|
|
|
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);
|
|
|
});
|
|
|
var updateBrand =$('#updateBrand tbody tr');
|
|
|
var shopRelation=[];
|
|
|
shopRelation.push('[')
|
|
|
$.each(updateBrand,function (index) {
|
|
|
shopRelation.push('{')
|
|
|
shopRelation.push('"agreementEndTime":'+$('#updateBrand tbody tr').eq(index).find('td').eq(1).find('.agreementendtime').val()+',');
|
|
|
shopRelation.push('"brandId":'+$('#updateBrand tbody tr').eq(index).find('td').eq(1).find('.brandid').val()+',');
|
|
|
shopRelation.push('"supplierId":'+$('#updateBrand tbody tr').eq(index).find('td').eq(1).find('.supplierid').val());
|
|
|
console.log(index,updateBrand.length-1);
|
|
|
if(index==updateBrand.length-1){
|
|
|
shopRelation.push('}')
|
|
|
}else{
|
|
|
shopRelation.push('},')
|
|
|
}
|
|
|
});
|
|
|
shopRelation.push(']')
|
|
|
console.log(shopRelation.join(''));
|
|
|
submit(function(data) {
|
|
|
data.websiteUrl = hplist.toString();
|
|
|
data.otherUrl = homeurlist.toString();
|
|
|
data.shopAddress = homeaddresslist.toString();
|
|
|
data.onCheck = onCheck;
|
|
|
data.shopsId = shopsId;
|
|
|
data.shopRelation = shopRelation.join('');
|
|
|
});
|
|
|
return false;
|
|
|
});
|
|
|
$(function() {
|
|
|
if ($('#otherUrl').val().split(',').length > 1) {
|
|
|
var homepage = $('#otherUrl').val().split(',');
|
|
|
$.each(homepage,
|
|
|
function() {
|
|
|
$('#homepage').append('<input value="' + this + '" type="text" name="homepage" class="form-control" style="margin-buttom:15px;">')
|
|
|
})
|
|
|
}
|
|
|
|
|
|
if ($('#websiteUrl').val().split(',').length > 1) {
|
|
|
var websiteUrl = $('#websiteUrl').val().split(',');
|
|
|
$.each(websiteUrl,
|
|
|
function() {
|
|
|
$('#homeurl').append('<input value="' + this + '" type="text" name="homeurl" class="form-control" style="margin-buttom:15px;">')
|
|
|
})
|
|
|
}
|
|
|
|
|
|
if($('#shopAddress').val().split(',').length>1){
|
|
|
var shopAddress=$('#shopAddress').val().split(',');
|
|
|
$.each(shopAddress,function(){
|
|
|
$('#homeaddress').append('<input value="'+this+'" type="text" name="homeaddresslist" class="form-control" style="margin-buttom:15px;">')
|
|
|
if ($('#shopAddress').val().split(',').length > 1) {
|
|
|
var shopAddress = $('#shopAddress').val().split(',');
|
|
|
$.each(shopAddress,
|
|
|
function() {
|
|
|
$('#homeaddress').append('<input value="' + this + '" type="text" name="homeaddresslist" class="form-control" style="margin-buttom:15px;">')
|
|
|
})
|
|
|
}
|
|
|
});
|
|
|
$('#brand-name').on('change',function() {
|
|
|
$.ajax({
|
|
|
url: '/supplier/storeadmin/supplierlist',
|
|
|
dataType: "json",
|
|
|
type: 'POST',
|
|
|
data: {
|
|
|
brandId: $('#brand-name').val()
|
|
|
},
|
|
|
success: function(data) {
|
|
|
var savebrandlist = [];
|
|
|
var brandselelt = $('#brand-name').find("option:selected").text();
|
|
|
$.each(data.data.data,function(index) {
|
|
|
savebrandlist.push('<tr>');
|
|
|
savebrandlist.push('<td><input class="checkbox" type="checkbox"></td>');
|
|
|
savebrandlist.push('<td>' + brandselelt + '</td>');
|
|
|
savebrandlist.push('<td>' + data.data.data[index].supplierName);
|
|
|
savebrandlist.push('<input type="hidden" class="agreementendtime" value="'+data.data.data[index].agreementEndTime+'">');
|
|
|
savebrandlist.push('<input type="hidden" class="brandid" value="'+data.data.data[index].brandId+'">');
|
|
|
savebrandlist.push('<input type="hidden" class="supplierid" value="'+data.data.data[index].supplierId+'">');
|
|
|
savebrandlist.push('</td>');
|
|
|
savebrandlist.push('</tr>')
|
|
|
});
|
|
|
$('#savebrand tbody').html(savebrandlist.join(''));
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
|
|
|
})
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|