<?php

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

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

$this->title = Yii::t('common', 'Interviews');
$this->params['breadcrumbs'][] = $this->title;
?>
<?php $this->beginBlock('content-header') ?>
<?= $this->title . ' ' . Html::a(Yii::t('common', 'Create Interview'), ['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',
                [
                    'attribute' => 'compere_id',
                    'format' => 'raw',
                    'value' => function ($model) {
                        if (!empty($model->compere)) {
                            return Html::a($model->compere->name, \yii\helpers\Url::to(['/compere/view', 'id' => $model->compere_id]), ['title' => '详情', 'target' => '_blank']);
                        } else {
                            return '无';
                        }
                    },
                ],

                [
                    'attribute' => 'master_id',
                    'format' => 'raw',
                    'value' => function ($model) {
                        if (!empty($model->master)) {
                            return Html::a($model->master->name, \yii\helpers\Url::to(['/master/view', 'id' => $model->master_id]), ['title' => '详情', 'target' => '_blank']);
                        } else {
                            return '无';
                        }
                    },
                ],
                'title',
                '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',
                 'created_at:datetime',
                 'updated_at:datetime',
                [
                    'attribute' => 'status',
                    'value' => function ($model) {
                        return  Interview::getStatusList($model->status);
                    },
                ],

                ['class' => 'common\helpers\DiyActionColumn',
                    'template' => ' {log} {goods} {view} {update} {delete}',
                    'buttons' => [
                        'log' => function ($url, $model, $key) {
                            return Html::a('添加记录', Url::to(['/interview-log/create', 'interview_id' => $model->id,'origin'=>Yii::$app->request->url]), [
                                'class' => 'btn btn-success btn-xs',
                                'title'=>Yii::t('common', 'Create Interview Log'),
                                'target'=>'_blank'
                            ]);
                        },
                        'goods' => function ($url, $model, $key) {
                            return Html::a('商品设置', Url::to(['/goods-index/create', 'entity' => Interview::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(['/interview/view', 'id' => $model->id]), [
                                'class' => 'btn btn-success btn-xs',
                                'title'=>$model->title.'详情',
                                'target'=>'_blank'
                            ]);
                        },
                    ]
                ],
            ],
        ]); ?>
    </div>
</div>
