<?php

use yii\helpers\Url;
use common\assets\TagitsAsset;
use home\assets\LinkAsset;
use yii\helpers\ArrayHelper;
use common\api\User;
use home\models\TagLink;
use home\modules\customer\models\Customer;

LinkAsset::register($this);
TagitsAsset::register($this);

/* @var $this yii\web\View */

$this->title = '添加客户';

//默认值
if ($model->isNewRecord) {
    $model->sort = 0;
    $model->status = 1;
    $model->attention = 0;
    $model->customer_no =  Customer::getNo();
    $model->leader_name = Yii::$app->user->identity->realname;
    $model->leader_id = Yii::$app->user->identity->user_id;
} else {
    $model->leader_name = empty($model->leader_id)?'':ArrayHelper::getValue(User::getOne($model->leader_id), 'realname');
    $model->share_user_names = empty($model->share_user_ids)?'':implode(',', ArrayHelper::getColumn(common\models\User::getUserByDot($model->share_user_ids), 'realname'));
    $model->tag_names = empty($model->customer_id)?'':TagLink::selectNames($model->customer_id, 'customer');
}
?>

<div class="modal-window">
<?= \home\widgets\Alert::widget(); ?>
<?= $this->render('_form', ['model' => $model, 'action' => $action]); ?>
</div>

<script>
    var availableTags = <?= Customer::getName() ?>;
    var projectParams = {
        selectDistrictUrl : "<?= Url::to(['district/select-customer']) ?>",
        cityUrl : "<?= Url::to(['district/select-city']) ?>",
        areaUrl : "<?= Url::to(['district/select-area']) ?>",
        dateType : "1"
    }
</script>
