{% extends '__base__.html' %}

{% block title %}创建账户{% endblock %}

{% block beforehead %}
<script>

var
    action = '{{ action }}';

function initVM(account) {
    var vm = new Vue({
        el: '#vm',
        data: account,
        methods: {
            submit: function (event) {
                this.$data.date = $('#date').val();
                event.preventDefault();
                var $form = $('#vm').find('form');
                $form.postJSON(action, this.$data, function (err, r) {
                    if (err) {
                        $form.showFormError(err);
                    }
                    else {
                        return location.assign('/account/' + r.id);
                    }
                });
            }
        }
    });
    $('#vm').show();
}

$(function () {
    $('#loading').hide();
    initVM({
        name: '',
        buy_strategy: '',
        sell_strategy: '',
        commission_rate: 0.0002,
        initial_funding: 0,
        initial_bank_funding: 0,
        initial_security_funding: 0,
        date: getTodayString()
    });
});

</script>
{% endblock %}

{% block content %}

    <div id="error" class="uk-width-1-1">
    </div>

    <div id="loading" class="uk-width-1-1 uk-text-center">
        <span><i class="uk-icon-spinner uk-icon-medium uk-icon-spin"></i> 正在加载...</span>
    </div>

    <div id="vm" class="uk-width-1-1">
        <form v-on="submit: submit" class="uk-form uk-form-stacked">
            <div class="uk-alert uk-alert-danger uk-hidden"></div>
            <div class="uk-form-row">
                <label class="uk-form-label">账户名称:</label>
                <div class="uk-form-controls">
                    <input v-model="name" name="name" type="text" placeholder="账户名称" class="uk-width-1-1">
                </div>
            </div>
            <div class="uk-form-row">
                <label class="uk-form-label">买入策略:</label>
                <div class="uk-form-controls">
                    <input v-model="buy_strategy" name="buy_strategy" type="text" placeholder="买入策略" class="uk-width-1-1">
                </div>
            </div>
            <div class="uk-form-row">
                <label class="uk-form-label">卖出策略:</label>
                <div class="uk-form-controls">
                    <input v-model="sell_strategy" name="sell_strategy" type="text" placeholder="卖出策略" class="uk-width-1-1">
                </div>
            </div>
            <div class="uk-form-row">
                <label class="uk-form-label">手续费率:</label>
                <div class="uk-form-controls">
                    <input v-model="commission_rate" name="commission_rate" type="text" placeholder="手续费率" class="uk-width-1-1">
                </div>
            </div>
            <div class="uk-form-row">
                <label class="uk-form-label">初始本金:</label>
                <div class="uk-form-controls">
                    <input v-model="initial_funding" name="initial_funding" type="text" placeholder="初始本金" class="uk-width-1-1">
                </div>
            </div>
            <div class="uk-form-row">
                <label class="uk-form-label">现有银行资金:</label>
                <div class="uk-form-controls">
                    <input v-model="initial_bank_funding" name="initial_bank_funding" type="text" placeholder="现有银行资金" class="uk-width-1-1">
                </div>
            </div>
            <div class="uk-form-row">
                <label class="uk-form-label">现有银证资金:</label>
                <div class="uk-form-controls">
                    <input v-model="initial_security_funding" name="initial_security_funding" type="text" placeholder="现有银证资金" class="uk-width-1-1">
                </div>
            </div>
            <div class="uk-form-row">
                <label class="uk-form-label">起始日期:</label>
                <div class="uk-form-controls">
                    <input id="date" v-model="date" name="date" type="text" data-uk-datepicker="{format:'YYYY-MM-DD'}" class="uk-width-1-1">
                </div>
            </div>
            <div class="uk-form-row">
                <button type="submit" class="uk-button uk-button-primary"><i class="uk-icon-save"></i> 保存</button>
                <a href="/account/create" class="uk-button"><i class="uk-icon-compress"></i> 基本选项</a>
                <a href="/" class="uk-button"><i class="uk-icon-times"></i> 取消</a>
            </div>
        </form>
    </div>

{% endblock %}
