<?php

use home\assets\MainAsset;
use yii\widgets\ActiveForm;
use yii\helpers\Html;
use yii\helpers\Url;
use home\modules\customer\models\District;
use common\components\Tool;

/* @var $this \yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \home\modules\customer\models\Area */

$attrLabels = $model->attributeLabels();
$asset = MainAsset::register($this);
?>

<?php
$form = ActiveForm::begin([
        'id' => 'main-form',
        'options' => ['class' => 'informationform f14'],
        'action' => $action,
        'fieldConfig' => [
            'options' => ['tag' => 'td'],
            'template' => "{input}{hint}{error}",
            'errorOptions' => ["class" => "error"]
        ]
    ]);
?>

<table cellpadding="0" cellspacing="10" width="100%">
    <tbody>

        <tr>
            <td align="right" width="90"><?= $model->getAttributeLabel('name') ?>：</td>
                <?= $form->field($model, 'name')->textInput(['class' => 'form-control']) ?>
            <td><span class="redstar">*</span></td> <!--如果不需要*号,可以删除*号，请勿删除td标签,以此保留原来的格式-->
            <td align="right"><?= $model->getAttributeLabel('code') ?>：</td>
                <?= $form->field($model, 'code')->textInput(['class' => 'form-control']) ?>
            <td><span class="redstar">*</span></td> 
        </tr>
        <tr>
            <td align="right">父级：</td>
            <td>
                <select class="form-control" name="District[parent_id]" id="area-parent-id">
                    <option value="0" <?php if ($model->parent_id == 0) echo "selected='selected'" ?>>-----顶级类别-----</option>
                    <?php echo District::getDropDownTree($model->parent_id, $model->district_id); ?>
                </select>
                <div class="error"></div>
            </td>
            <td><span class="redstar">*</span></td>
            <td align="right">
                <?= $model->getAttributeLabel('leader_name') ?>：</td>
                <?= $form->field($model, 'leader_name')->textInput(['class' => 'form-control select-single-user', 'placeholder' => '请选择负责人', 'data-hidden-id' => 'leader-id', 'data-url' => Url::to(['/link/single-user']), 'data-title' => '选择负责人']) ?>
                <?= $form->field($model, 'leader_id')->hiddenInput(['id' => 'leader-id']) ?>
                <td><span class="c6"><a href="javascript:;" class="clear-input" data-input-id="district-leader_name" data-hidden-id="leader-id" style="color:#888;">清除</a></span></td>
            <td><span class="redstar"></span></td>
        </tr>
        <tr>
            <td align="right"><?= $model->getAttributeLabel('sort') ?>：</td>
                <?= $form->field($model, 'sort')->textInput(['class' => 'form-control']) ?>
            <td><span class="redstar"></span></td>
            <td align="right"><?= $model->getAttributeLabel('status') ?>：</td>
                <?= $form->field($model, 'status')->radioList(District::getStatusList(), ['itemOptions' => ['labelOptions' => ['class' => 'radio-inline']]]) ?>
            <td></td>
        </tr>
    </tbody>
</table>

<div class="modal-window" >
    <table class="table task-table dialog-table">
        <tbody>
            <tr>
                <th>省/市/区</th>
                <th>操作</th>
            </tr>
            <?php if (!empty($model['district'])) : ?>
                <span id="only-district" data-set-num="<?= $model['num'] ?>" ></span>
                <?php foreach ($model['district'] as $k => $v) : ?>
                    <input type="hidden" id="only-<?= $k ?>" data-set-province="<?= $v['province_id'] ?>" data-set-city="<?= $v['city_id'] ?>"  data-set-area="<?= $v['area_id'] ?>" />
                <?php endforeach; ?>
            <?php endif; ?>
        </tbody>
    </table>
    <p style="text-align:right; padding-right:115px;">
        <button type="button" class="add-district-link">+新增负责区域</button>
    </p>
</div>

<?= ($model->isNewRecord) ? '' : Html::hiddenInput('id', $model->district_id); ?>
<?php ActiveForm::end(); ?>