/**
@Name: 案例
*/
layui.define(['laypage', 'fly'], function(exports){
var $ = layui.jquery;
var layer = layui.layer;
var util = layui.util;
var laytpl = layui.laytpl;
var form = layui.form;
var laypage = layui.laypage;
var upload = layui.upload;
var fly = layui.fly;
var device = layui.device();
//求解管理
var active = {
//提交案例
push: function(div){
layer.open({
type: 1
,id: 'LAY_pushcase'
,title: '提交案例'
,area: (device.ios || device.android) ? ($(window).width() + 'px') : '660px'
,content: ['
'].join('')
,success: function(layero, index){
var image = layero.find('.fly-case-image')
,preview = $('#preview');
upload.render({
url: '/api/upload/case/'
,elem: '#caseUpload'
,size: 30
,done: function(res){
if(res.status == 0){
image.val(res.url);
preview.html('封面已上传,点击可预览');
} else {
layer.msg(res.msg, {icon: 5});
}
}
});
form.render('checkbox').on('submit(pushCase)', function(data){
if(!data.field.agree){
return layer.tips('你需要同意才能提交', $('#agree').next(), {tips: 1});
}
fly.json('/case/push/', data.field, function(res){
layer.close(index);
layer.alert(res.msg, {
icon: 1
})
});
});
}
});
}
//点赞
,praise: function(othis){
var li = othis.parents('li')
,PRIMARY = 'layui-btn-primary'
,unpraise = !othis.hasClass(PRIMARY)
,numElem = li.find('.fly-case-nums')
fly.json('/case/praise/', {
id: li.data('id')
,unpraise: unpraise ? true : null
}, function(res){
numElem.html(res.praise);
if(unpraise){
othis.addClass(PRIMARY).html('点赞');
layer.tips('少了个赞囖', numElem, {
tips: 1
});
} else {
othis.removeClass(PRIMARY).html('已赞');
layer.tips('成功获得个赞', numElem, {
tips: [1, '#FF5722']
});
}
});
}
//查看点赞用户
,showPraise: function(othis){
var li = othis.parents('li');
if(othis.html() == 0) return layer.tips('该项目还没有收到赞', othis, {
tips: 1
});
fly.json('/case/praise_user/', {
id: li.data('id')
}, function(res){
var html = '';
layer.open({
type: 1
,title: '项目【'+ res.title + '】获得的赞'
,id: 'LAY_showPraise'
,shade: 0.8
,shadeClose: true
,area: '305px'
,skin: 'layer-ext-case'
,content: function(){
layui.each(res.data, function(_, item){
html += ''
});
return '';
}()
})
});
}
};
$('body').on('click', '.fly-case-active', function(){
var othis = $(this), type = othis.data('type');
active[type] && active[type].call(this, othis);
});
exports('case', {});
});