Browse Source

开发运费模板模块,修复省市区域选择js加载问题,安装vue插件

wechat_public_accounts
linyaostalker 5 years ago
parent
commit
ba138ebf1f
  1. 61
      backend/controllers/ExpressTemplateController.php
  2. 7
      backend/views/express-template/create.php
  3. 40
      backend/views/express-template/update.php
  4. 7
      backend/views/layouts/main.php
  5. 4
      common/models/ars/ExpressTemplate.php
  6. 4
      composer.json

61
backend/controllers/ExpressTemplateController.php

@ -2,12 +2,17 @@
namespace backend\controllers;
use common\models\ars\City;
use common\models\ars\Province;
use Yii;
use common\models\ars\ExpressTemplate;
use common\models\searchs\ExpressTemplateSearch;
use yii\caching\Cache;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\Response;
use yii\widgets\ActiveForm;
/**
* ExpressTemplateController implements the CRUD actions for ExpressTemplate model.
@ -67,12 +72,39 @@ class ExpressTemplateController extends Controller
{
$model = new ExpressTemplate();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
if (Yii::$app->request->isPost) {
$data = Yii::$app->request->post('ExpressTemplate');
if (Yii::$app->request->isAjax) {
$model->load($data, '');
Yii::$app->response->format = Response::FORMAT_JSON;
$data = ActiveForm::validate($model);
$data['status'] = 2;
return $data;
}
if (Yii::$app->request->post('area') == null) {
return $this->redirect(Yii::$app->request->referrer . '?status=1');
}
$cityIds = array_keys(Yii::$app->request->post('area'));
$data['city'] = implode(',', $cityIds);
$model->load($data, '');
$model->save();
return $this->redirect('index');
}
$data = [];
$provinces = Province::find()->cache(0)->all();
foreach ($provinces as $k => $v) {
$data[$k]['province'] = $v->name;
$cities = City::find()->cache(0)
->where(['province_id' => $v->province_id])
->all();
foreach ($cities as $city) {
$data[$k]['city'][] = ['id' => $city->city_id, 'name' => $city->name];
}
}
return $this->render('create', [
'model' => $model,
'data' => $data
]);
}
@ -86,13 +118,30 @@ class ExpressTemplateController extends Controller
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect('index');
$data = Yii::$app->request->post('ExpressTemplate');
if ($data) {
if (Yii::$app->request->post('area') == null) {
return $this->redirect(Yii::$app->request->referrer . '&status=1');
}
$cityIds = array_keys(Yii::$app->request->post('area'));
$data['city'] = implode(',', $cityIds);
$model->load($data, '');
$model->save();
return $this->render('view', ['model' => ExpressTemplate::findOne($model->id)]);
}
$data = [];
$provinces = Province::find()->cache(0)->all();
foreach ($provinces as $k => $v) {
$data[$k]['province'] = $v->name;
$cities = City::find()->cache(0)
->where(['province_id' => $v->province_id])
->all();
foreach ($cities as $city) {
$data[$k]['city'][] = ['id' => $city->city_id, 'name' => $city->name];
}
}
return $this->render('update', [
'model' => $model,
'model' => $model, 'data' => $data, 'cities' => explode(',', $model->city)
]);
}

7
backend/views/express-template/create.php

@ -7,7 +7,7 @@ use kartik\tabs\TabsX;
/* @var $this yii\web\View */
/* @var $model common\models\ars\ExpressTemplate */
$this->title = '创建 Express Template';
$this->title = '创建运费模板';
$this->params['breadcrumbs'][] = ['label' => 'Express Templates', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
Yii::$app->params['bsVersion'] = '4.x';
@ -28,6 +28,11 @@ Yii::$app->params['bsVersion'] = '4.x';
'form' => $form,
]),
],
[
'label' => '<i class="fas fa-globe"></i> 选择配送区域',
'content' => $this->render('area', ['data' => $data, 'form' => $form, 'cities' => []
]),
],
],
'position' => TabsX::POS_ABOVE,
'encodeLabels' => false

40
backend/views/express-template/update.php

@ -1,19 +1,51 @@
<?php
use yii\helpers\Html;
use yii\bootstrap4\Html;
use yii\bootstrap4\ActiveForm;
use kartik\tabs\TabsX;
/* @var $this yii\web\View */
/* @var $model common\models\ars\ExpressTemplate */
$this->title = '编辑 Express Template: ' . $model->name;
$this->title = '编辑运费模板: ' . $model->name;
$this->params['breadcrumbs'][] = ['label' => 'Express Templates', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Update ';
Yii::$app->params['bsVersion'] = '4.x';
?>
<div class="express-template-update">
<div class="express-template-form">
<?= $this->render('_form', [
<?php
$form = ActiveForm::begin(['options' => ['class' => 'container-fluid']]);
echo TabsX::widget([
'bordered' => true,
'items' => [
[
'label' => '<i class="fas fa-user"></i> 基本信息',
'content' => $this->render('_form', [
'model' => $model,
]) ?>
'form' => $form,
]),
],
[
'label' => '<i class="fas fa-globe"></i> 选择配送区域',
'content' => $this->render('area', ['data' => $data, 'form' => $form, 'cities' => $cities
]),
],
],
'position' => TabsX::POS_ABOVE,
'encodeLabels' => false
]);
?>
<div class="form-group">
<?= Html::submitButton('保存', ['class' => 'btn btn-success']) ?>
<?= Html::a('返回', ['index'], ['class' => 'btn btn-info']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>

7
backend/views/layouts/main.php

@ -19,6 +19,13 @@ AppAsset::register($this);
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<?php $this->registerCsrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title>
<?php if (YII_ENV == 'dev'){?>
<!-- 开发环境版本,包含了有帮助的命令行警告 -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<?php } else {?>
<!-- 生产环境版本,优化了尺寸和速度 -->
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<?php } ?>
<?php $this->head() ?>
</head>
<body class="hold-transition skin-blue-light sidebar-mini">

4
common/models/ars/ExpressTemplate.php

@ -17,7 +17,7 @@ use yii\behaviors\TimestampBehavior;
* @property int $basic_price 基本运费
* @property int $basic_amount 基本数量
* @property int $extra_price 续重运费
* @property int $extra_amount 续重运费
* @property int $extra_amount 续重数量
* @property int $updated_at 更新时间
* @property int $created_at 创建时间
*/
@ -67,7 +67,7 @@ class ExpressTemplate extends \yii\db\ActiveRecord
'basic_price' => '基本运费',
'basic_amount' => '基本数量',
'extra_price' => '续重运费',
'extra_amount' => '续重运费',
'extra_amount' => '续重数量',
'updated_at' => '更新时间',
'created_at' => '创建时间',
];

4
composer.json

@ -18,7 +18,9 @@
"moonlandsoft/yii2-phpexcel": "*",
"kartik-v/yii2-tabs-x": "^1.2@dev",
"kartik-v/yii2-editable": "^1.7@dev",
"kartik-v/yii2-widget-depdrop": "dev-master"
"kartik-v/yii2-widget-depdrop": "dev-master",
"antkaz/yii2-vue": "dev-master",
"xj/yii2-babel": "dev-master"
},
"repositories": {
"asset_packagist": {

Loading…
Cancel
Save