diff --git a/vendor/antgoods/goods/src/controllers/GoodsController.php b/vendor/antgoods/goods/src/controllers/GoodsController.php index 39e69a2..33a5ff7 100644 --- a/vendor/antgoods/goods/src/controllers/GoodsController.php +++ b/vendor/antgoods/goods/src/controllers/GoodsController.php @@ -180,6 +180,24 @@ class GoodsController extends Controller $model->alias = $data['alias']; $model->path = $data['path']; $model->save(); + return $model->id; } } + + /** + * @return string + * 点击删除按钮时同时删除字符串中的id + */ + public function actionImgIdDel() + { + $alias = Yii::$app->request->get('data')['alias']; + $imgid = Yii::$app->request->get('imgid'); + $imgidarr = explode(',', $imgid); + $temfile = TemFile::findOne(['alias' => $alias]); + if ($temfile) { + $imgidarr = array_diff($imgidarr, [$temfile->id]); + } + $imgidstr = implode(',', $imgidarr); + return $imgidstr; + } } diff --git a/vendor/antgoods/goods/src/models/ars/Goods.php b/vendor/antgoods/goods/src/models/ars/Goods.php index 85c68dc..ab00598 100644 --- a/vendor/antgoods/goods/src/models/ars/Goods.php +++ b/vendor/antgoods/goods/src/models/ars/Goods.php @@ -44,6 +44,7 @@ use yii\behaviors\TimestampBehavior; */ class Goods extends \yii\db\ActiveRecord { + public $imagePath; //是否删除is_delete const IS_DELETE_NO = 0;//未删除 const IS_DELETE_YES = 1;//已删除 diff --git a/vendor/antgoods/goods/src/views/goods/_form.php b/vendor/antgoods/goods/src/views/goods/_form.php index 07366ef..0d262c0 100644 --- a/vendor/antgoods/goods/src/views/goods/_form.php +++ b/vendor/antgoods/goods/src/views/goods/_form.php @@ -68,11 +68,33 @@ use antgoods\goods\models\ars\Supplier; field($model, 'express_template')->textInput() ?> - field($model, 'image')->widget(\iron\widgets\Upload::className(), [ + field($model, 'image')->textInput() ?> + field($model, 'imagePath')->widget(\iron\widgets\Upload::className(), [ 'url' => 'upload', 'deleteUrl' => 'imageDel', 'dragdropWidth'=> 800, - 'afterSave' => 'savefile' + 'afterSave' => 'savefile', + 'successScript' => " + success: function(data) + { + var imageval = $('#goods-image').val(); + if(imageval == ''){ + $('#goods-image').val(data); + }else{ + $('#goods-image').val($('#goods-image').val()+','+data); + } + } + ", + 'deleteScript' => " + $.ajax({ + url: 'img-id-del', + data: {data: data, imgid: $('#goods-image').val()}, + success: function(data) + { + $('#goods-image').val(data); + }, + }); + ", ]) ?>
diff --git a/vendor/iron/widgets/Upload.php b/vendor/iron/widgets/Upload.php index 5c8f546..3486a4b 100644 --- a/vendor/iron/widgets/Upload.php +++ b/vendor/iron/widgets/Upload.php @@ -96,6 +96,16 @@ class Upload extends InputWidget * 拉拽框大小 */ public $dragdropWidth; + /** + * @var javascript + * 图片上传成功回调方法 + */ + public $successScript; + /** + * @var + * 删除图片触发方法 + */ + public $deleteScript; /** * @throws NotFoundHttpException @@ -164,6 +174,7 @@ class Upload extends InputWidget url: "{$this->afterSave}", dataType: "json", data: {data: data, fileName: files}, + {$this->successScript}, }); }, onLoad:function(obj) @@ -182,6 +193,7 @@ class Upload extends InputWidget }); }, deleteCallback: function (data, pd) { + {$this->deleteScript} for (var i = 0; i < data.length; i++) { $.post("{$this->deleteUrl}", {op: "delete",name: data[i]}, function (resp,textStatus, jqXHR) {