<#assign title="我的账号"/>
<#include "/cust/frag.head.ftl" />

<header class="demos-header">
    <h1 class="demos-title">${title}</h1>
</header>

<div class="weui-cells weui-cells_form" id="bindForm">
    <input type="hidden" id="userType" value="${user.userType}">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">姓名</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="staffName" value="${user.staffName}"/>
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd">
            <label class="weui-label">手机号</label>
        </div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="phone" type="tel" value="${user.phone}"/>
        </div>
    </div>
</div>


<div class="weui-btn-area">
    <a id="btnOk" class="weui-btn weui-btn_primary" href="javascript:">更新信息</a>
</div>


<#include "/cust/frag.foot.ftl" />
<script>

    var userId = '${user.userId}';
    (function ($) {
        var userType = '${user.userType}';

        var userPlaceList = ${userPlaceList}.userPlaceList;
        if (userType === 1 || userType === '1') {
            $('#userTypeName').val('一级分销');
        }
        else if (userType === 2 || userType === '2') {
            $('#userTypeName').val('二级分销');
        }

        userPlaceList.forEach(function (v) {
            bindCell(v);
        })

        $('#btnOk').on('click', function () {
            var phone = $('#phone').val();
            var staffName = $('#staffName').val();

            if (staffName === null || staffName === '') {
                $.alert('请填写姓名');
                return;
            }
            if (phone === null || phone === '') {
                $.alert('请填写手机号');
                return;
            }

            var data = {
                'staffName': staffName,
                'phone': phone,
                'userId': userId
            };

            // $.ajax({
            //     url: '/cust/update_account.json',
            //     contentType: "application/json; charset=utf-8",
            //     data: JSON.stringify(data),
            //     type: 'post',
            //     success: function (data) {
            //         if (data.success) {
            //             window.location.replace('/prompt/prompt.html?title=修改成功&message=');
            //             // window.location.reload();
            //         } else {
            //             $.alert(data.msg);
            //         }
            //     },
            //     error: function () {
            //         $.alert("网络异常");
            //     }
            // });

        });

    })(jQuery)

    function bindCell(v) {
        $('#bindForm').append($('<div class="weui-cell">\n' +
                '        <div class="weui-cell__hd"><label class="weui-label">'+v.placeName+'</label></div>\n' +
                '        <div class="weui-cell__bd">\n' +
                '            <a href="javascript:modifyBind(\''+v.placeId+'\')" class="weui-btn weui-btn_default">解除绑定</a>\n' +
                '        </div>\n' +
                '    </div>'));
    }

    function modifyBind(v) {
        // $.ajax({
        //     url: '/cust/modify_bind.json?userId='+userId + '&placeId=' + v,
        //     type: 'get',
        //     success: function (data) {
        //         if (data.success) {
        //             window.location.replace('/prompt/prompt.html?title=解绑成功&message=');
        //             // window.location.reload();
        //         } else {
        //             $.alert(data.msg);
        //         }
        //     },
        //     error: function () {
        //         $.alert("网络异常");
        //     }
        // });
    }

</script>