<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改客户')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-customer-edit" th:object="${sysCustomer}">
            <h4 class="form-header h4">客户信息</h4>
            <input name="customerId" th:field="*{customerId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">客户id：</label>
                <div class="col-sm-8">
                    <input name="customerId" th:field="*{customerId}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">客户姓名：</label>
                <div class="col-sm-8">
                    <input name="customerName" th:field="*{customerName}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">手机号码：</label>
                <div class="col-sm-8">
                    <input name="phonenumber" th:field="*{phonenumber}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">客户性别：</label>
                <div class="col-sm-8">
                    <select name="sex" class="form-control m-b" th:with="type=${@dict.getType('sys_user_sex')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{sex}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">客户生日：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="birthday" th:value="${#dates.format(sysCustomer.birthday, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <h4 class="form-header h4">商品信息</h4>
            <div class="row">
                <div class="col-sm-12">
                    <button type="button" class="btn btn-white btn-sm" onclick="addColumn()"><i class="fa fa-plus"> 增加</i></button>
                    <button type="button" class="btn btn-white btn-sm" onclick="sub.delColumn()"><i class="fa fa-minus"> 删除</i></button>
                    <div class="col-sm-12 select-table table-striped">
                        <table id="bootstrap-table"></table>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/customer";
        var typeDatas = [[${@dict.getType('sys_yes_no')}]];
        $("#form-customer-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-customer-edit').serialize());
            }
        }

        $("input[name='birthday']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(function() {
            var options = {
                data: [[${sysCustomer.sysGoodsList}]],
                pagination: false,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                columns: [{
                    checkbox: true
                },
                {
                    field: 'index',
                    align: 'center',
                    title: "序号"
                },
                {
                    field: 'goodsId',
                    align: 'center',
                    title: '商品id',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sysGoodsList[%s].goodsId' value='%s'>", index, value);
                        return html;
                    }
				},
                {
                    field: 'name',
                    align: 'center',
                    title: '商品名称',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sysGoodsList[%s].name' value='%s'>", index, value);
                        return html;
                    }
				},
                {
                    field: 'weight',
                    align: 'center',
                    title: '商品重量',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sysGoodsList[%s].weight' value='%s'>", index, value);
                        return html;
                    }
				},
                {
                    field: 'price',
                    align: 'center',
                    title: '商品价格',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='sysGoodsList[%s].price' value='%s'>", index, value);
                        return html;
                    }
				},
                {
                    field: 'type',
                    align: 'center',
                    title: '商品种类',
                    formatter: function(value, row, index) {
                        var name = $.common.sprintf("sysGoodsList[%s].type", index);
                        return $.common.dictToSelect(typeDatas, value, name);
                    }
                
                }]
            };
            $.table.init(options);
            sub.resetIndex();
        });

        function addColumn() {
            var count = $("#" + table.options.id).bootstrapTable('getData').length;
            sub.editColumn();
        	
            $("#" + table.options.id).bootstrapTable('insertRow', {
                index: count,
                row: {
                    index: $.table.serialNumber(count),
                    goodsId: "",
                    name: "",
                    weight: "",
                    price: "",
                    type: ""
        	    }
            });
            sub.resetIndex();
        }
    </script>
</body>
</html>