').text(v == null ? '' : v).html()
}
function val(n, v) {
$('#configForm [name=' + n + ']').val(v == null ? '' : v)
}
window.reloadAppGuide = function() {
$.get(Feng.ctxPath + '/appGuide/data', function(d) {
var c = d.config || {};
['id', 'apkUrl', 'iosStoreUrl'].forEach(function(k) {
val(k, c[k])
});
$('#bannerRows').html((d.banners || []).map(function(x) {
return '
 + ') | ' + esc(x.title) + ' | ' + esc(x.sort) + ' | ' + ((x.enabled === 1) ? '启用' : '停用') + ' | |
'
}).join(''));
$('#linkRows').html((d.links || []).map(function(x) {
var id = String(x.id),
q = Feng.ctxPath + '/appGuide/siteQr/' + encodeURIComponent(id) + '.png';
return '
| ' + esc(x.name) + ' | ' + esc(x.pageName) + ' | ' + x.storeId + ' / ' + x.siteId + ' |  | ' + esc(x.guideUrl) + ' | ' + ((x.enabled === 1) ? '启用' : '停用') + ' | |
'
}).join(''))
})
};
window.saveConfig = function() {
$.post(Feng.ctxPath + '/appGuide/config', $('#configForm').serialize(), function() {
Feng.success('保存成功');
reloadAppGuide()
})
};
window.uploadBanner = function() {
var f = $('#bannerFile')[0].files[0];
if (!f) {
Feng.info('请选择图片');
return
}
var d = new FormData();
d.append('file', f);
$.ajax({
url: Feng.ctxPath + '/mgr/uploadFile',
data: d,
type: 'POST',
contentType: false,
processData: false,
success: function(url) {
$('#bannerUrl').val(url);
$('#uploadTip').text('上传成功')
}
})
};
window.addBanner = function() {
if (!$('#bannerUrl').val()) {
Feng.info('请先上传图片');
return
}
$.post(Feng.ctxPath + '/appGuide/banner', {
imageUrl: $('#bannerUrl').val(),
title: $('#bannerTitle').val(),
sort: $('#bannerSort').val() || 0,
enabled: 1
}, function() {
reloadAppGuide();
$('#bannerUrl,#bannerTitle,#bannerSort,#bannerFile').val('')
})
};
window.deleteBanner = function(id) {
$.post(Feng.ctxPath + '/appGuide/banner/delete', {
id: id
}, reloadAppGuide)
};
window.createQr = function() {
var o = $('#siteSelect option:selected'),
pageName = 'com.sinata.wepark.ui.home.PlaceDetailActivity';
if (!o.val()) {
Feng.info('请选择场地');
return
}
$.post(Feng.ctxPath + '/appGuide/siteQr', {
storeId: o.data('store'),
siteId: o.val(),
name: o.text(),
pageName: pageName
}, function(r) {
if (!r.success) {
Feng.error(r.message);
return
}
Feng.success('已生成');
reloadAppGuide()
})
};
window.changeQr = function(id, enabled) {
$.post(Feng.ctxPath + '/appGuide/siteQr/status', {
id: id,
enabled: enabled
}, reloadAppGuide)
};
$.get(Feng.ctxPath + '/appGuide/sites', function(s) {
$('#siteSelect').append((s || []).map(function(x) {
return '
'
}).join(''))
});
$(reloadAppGuide);
window.deleteQr = function(id) {
if (!confirm('确认删除该场地订场二维码?')) return;
$.post(Feng.ctxPath + '/appGuide/siteQr/delete', {
id: id
}, reloadAppGuide)
};
})();