Commit 18ddc65b authored by ZhuChunYang's avatar ZhuChunYang

update

parent 46d148d8
......@@ -164,10 +164,17 @@ class ApplicationController extends BaseController
{
if(Yii::$app->request->isAjax){
$id = Yii::$app->request->get('id');
$image_category = Yii::$app->request->get('image_category',1);
Yii::$app->response->format = 'json';
$applicate = CoinApplication::getApplicate($id);
if($applicate){
$data = CoinImage::getItemsByImageIds($applicate->image_ids);
if($image_category == 1){
$data = CoinImage::getItemsByImageIds($applicate->image_ids);
}else if($image_category == 2){
$data = CoinImage::getItemsByImageIds($applicate->h5_image_ids);
}else{
$data = ['code' => 0,'data' => []];
}
}else{
$data = ['code' => 0,'data' => []];
}
......@@ -194,9 +201,10 @@ class ApplicationController extends BaseController
Yii::$app->response->format = 'json';
$id = Yii::$app->request->post('applicate_id',0);
$image_id = Yii::$app->request->post('image',0);
$image_category = Yii::$app->request->post('image_category',1);
if($id && $image_id){
$coin_applicate_form = new CoinApplicationForm();
return $coin_applicate_form->addImage($id,$image_id);
return $coin_applicate_form->addImage($id,$image_id,$image_category);
}else{
return ['code' => 1,'msg'=> '图片添加失败'];
}
......@@ -208,9 +216,10 @@ class ApplicationController extends BaseController
Yii::$app->response->format = 'json';
$id = Yii::$app->request->get('id');
$applicate_id = Yii::$app->request->get('applicate_id');
$image_category = Yii::$app->request->get('image_category',1);
if ($id && $applicate_id) {
$coin_applicateion_form = new CoinApplicationForm();
return $coin_applicateion_form->delImage($id,$applicate_id);
return $coin_applicateion_form->delImage($id,$applicate_id,$image_category);
}
return ['code' => 1, 'msg' => 'failed'];
}
......
......@@ -210,11 +210,16 @@ class CoinApplicationForm extends BaseForm
}
}
public function addImage($id,$image_id)
public function addImage($id,$image_id,$image_category)
{
$coin_applicate = CoinApplication::getApplicate($id);
if($coin_applicate){
$image_ids = $coin_applicate->image_ids;
if($image_category == 1){ //app图片
$image_ids_field = 'image_ids';
}else if($image_category == 2){ //h5图片
$image_ids_field = 'h5_image_ids';
}
$image_ids = $coin_applicate->$image_ids_field;
if($image_ids){
$image_items = explode(',',$image_ids);
array_push($image_items,$image_id);
......@@ -222,7 +227,7 @@ class CoinApplicationForm extends BaseForm
}else{
$image_ids = $image_id;
}
$coin_applicate->image_ids = $image_ids;
$coin_applicate->$image_ids_field = $image_ids;
$coin_applicate->save();
return ['code' => 0,'msg' => '图片添加成功'];
}else{
......@@ -230,11 +235,16 @@ class CoinApplicationForm extends BaseForm
}
}
public function delImage($image_id,$id)
public function delImage($image_id,$id,$image_category)
{
$coin_applicate = CoinApplication::getApplicate($id);
if($coin_applicate){
$image_ids = $coin_applicate->image_ids;
if($image_category == 1){ //app图片
$image_ids_field = 'image_ids';
}else if($image_category == 2){ //h5图片
$image_ids_field = 'h5_image_ids';
}
$image_ids = $coin_applicate->$image_ids_field;
$image_items = explode(',',$image_ids);
$image_items = array_diff($image_items,[$image_id]);
if($image_items){
......@@ -242,7 +252,7 @@ class CoinApplicationForm extends BaseForm
}else{
$image_ids = '';
}
$coin_applicate->image_ids = $image_ids;
$coin_applicate->$image_ids_field = $image_ids;
$coin_applicate->save();
return ['code' => 0,'msg' => '图片删除成功'];
}else{
......
......@@ -13,20 +13,30 @@
</style>
<h4>所属应用---<?= $applicate->name ?></h4>
<div class="layui-row" style="padding: 5px;">
<div class="layui-col-md1">
<button class="layui-btn layui-btn-default" id="add">添加应用图片</button>
<div class="layui-tab layui-tab-card">
<ul class="layui-tab-title">
<li class="layui-this">APP应用</li>
<li>H5应用</li>
</ul>
<div class="layui-tab-content">
<div class="layui-tab-item layui-show">
<button class="layui-btn layui-btn-default add_image" image_category="1">添加APP图片</button>
<table class="layui-table" id="table1" lay-filter="table1"></table>
</div>
<div class="layui-tab-item">
<button class="layui-btn layui-btn-default add_image" image_category="2">添加H5图片</button>
<table class="layui-table" id="table2" lay-filter="table2"></table>
</div>
</div>
</div>
</div>
<div class="layui-col-md10">
<table class="layui-table" id="table1" lay-filter="table1"></table>
</div>
<div class="layui-row add" style="display: none;padding: 5px;" id="_form">
<div class="layui-col-xs6 layui-col-sm6 layui-col-md11">
<form class="layui-form" action="javascript:void(0)" id="form1" method="post" lay-filter="form1">
<input type="hidden" name="_csrf" value="<?= Yii::$app->request->getCsrfToken() ?>">
<input id="applicate_id" name="applicate_id" type="hidden" value="<?= $applicate->id ?>">
<input id="image_category" name="image_category" type="hidden" value="">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">图标</label>
......@@ -58,7 +68,7 @@
var applicate_id = $("#applicate_id").val();
table.render({
elem: '#table1',
url: '/admin/application/image-index?id='+applicate_id,
url: '/admin/application/image-index?id='+applicate_id+"&image_category=1",
cols: [[
{
field: 'id',
......@@ -78,13 +88,34 @@
},
]],
});
table.render({
elem: '#table2',
url: '/admin/application/image-index?id='+applicate_id+"&image_category=2",
cols: [[
{
field: 'id',
title: '图片ID'
},
{
field: 'image_url',
title: '图片链接',
templet: function(d){
return "<a href='"+d.image_url+"' target='_blank'>"+d.image_url+"</a>";
}
},
{
title: '操作',
templet: '#operationTpl',
width: 300
},
]],
});
table.on('tool(table1)', function(obj) {
var data = obj.data;
var event = obj.event;
if (event === 'del') {
var index = layer.confirm("确认删除?", {icon: 3, title: '删除'}, function () {
$.get('/admin/application/delete-image', {id: data.id,applicate_id:applicate_id}, function (rev) {
$.get('/admin/application/delete-image', {id: data.id,applicate_id:applicate_id,image_category:1}, function (rev) {
layer.msg(rev.msg);
if (0==rev.code) {
table.reload('table1');
......@@ -93,8 +124,24 @@
});
}
});
table.on('tool(table2)', function(obj) {
var data = obj.data;
var event = obj.event;
if (event === 'del') {
var index = layer.confirm("确认删除?", {icon: 3, title: '删除'}, function () {
$.get('/admin/application/delete-image', {id: data.id,applicate_id:applicate_id,image_category:2}, function (rev) {
layer.msg(rev.msg);
if (0==rev.code) {
table.reload('table2');
}
});
});
}
});
$('#add').click(function () {
$('.add_image').click(function () {
var image_category = $(this).attr('image_category');
$('#image_category').val(image_category);
var index = layer.open({
title: '添加图片',
area: '800px',
......@@ -110,7 +157,7 @@
if (0 == rev.code) {
layer.close(index);
$("#_form").css('display', 'none');
table.reload('table1');
table.reload('table'+image_category);
}
});
},
......@@ -132,7 +179,17 @@
uploader.render({
elem: "#upload1",
url: '/admin/image/upload',
data: {_csrf: $_csrf,image_type:3},
before: function(input){
var data = {};
var image_category = $('#image_category').val();
data._csrf = $_csrf;
if(image_category == 1 ){
data.image_type = 3 ;
}else if(image_category == 2){
data.image_type = 6 ;;
}
this.data=data;
},
done: function (res) {
if(res.code == 0){
$("input[name='image']").val(res.data.image_id);
......@@ -149,4 +206,5 @@
});
$("#image1").attr('src', '');
}
</script>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment