<?php

use common\models\Master;
use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\search\MasterSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('common', 'Masters');
$this->params['breadcrumbs'][] = $this->title;
?>
<?php $this->beginBlock('content-header') ?>
<?= $this->title . ' ' . Html::a(Yii::t('common', 'Create Master'), ['create'], ['class' => 'btn btn-success']) ?>
<?php $this->endBlock() ?>
<?php echo $this->render('_search', ['model' => $searchModel]); ?>

<div class="box box-success">
    <div class="box-body">
        <?= GridView::widget([
            'dataProvider' => $dataProvider,
            //'filterModel' => $searchModel,
            'columns' => [
                'id',
                'name',
                'desc',
                [
                    'attribute' => 'province',
                    'format' => 'raw',
                    'value' => function ($model) {
                        return \common\models\Region::getNameById($model->province);
                    },
                ],
                [
                    'attribute' => 'city',
                    'format' => 'raw',
                    'value' => function ($model) {
                        return \common\models\Region::getNameById($model->city);
                    },
                ],
                [
                    'attribute' => 'area',
                    'format' => 'raw',
                    'value' => function ($model) {
                        return \common\models\Region::getNameById($model->area);
                    },
                ],

                // 'address',
                 'fields',
                 'works',
                 'tel',
                 'created_at:datetime',
                 'updated_at:datetime',
                [
                    'attribute' => 'status',
                    'value' => function ($model) {
                        return  Master::getStatusList($model->status);
                    },
                ],

                ['class' => 'common\helpers\DiyActionColumn',
                    'template' => '{goods} {view} {update} {delete}',
                    'buttons' => [
                        'goods' => function ($url, $model, $key) {
                            return Html::a('商品设置', Url::to(['/goods-index/create', 'entity' => Master::className(),'entity_id'=>$model->id,'origin'=>Yii::$app->request->url]), [
                                'class' => 'btn btn-success btn-xs',
                                'title'=>Yii::t('common', 'Create Goods Index'),
                                'target'=>'_blank'
                            ]);
                        },

                        'view' => function ($url, $model, $key) {
                            return Html::a('查看', Url::to(['/master/view', 'id' => $model->id]), [
                                'class' => 'btn btn-success btn-xs',
                                'title'=>$model->name.'详情',
                                'target'=>'_blank'
                            ]);
                        },
                    ]
                ],
            ],
        ]); ?>
    </div>
</div>
