<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增产品')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-product-add">
        	<input name="supplierId" type="hidden" id="supplierId" />
        	<input name="productCatogoryId" type="hidden" id="treeId"/>
            <div class="form-group">    
                <label class="col-sm-3 control-label">供应商名称：</label>
                <div class="col-sm-8">
                	<div class="input-group">
	                    <input name="supplierName" onclick="selectSupplier()" id="supplierName" type="text" placeholder="请选择供应商 " class="form-control" readonly>
	                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>                    
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">产品分类：</label>
                <div class="col-sm-8">
                	<div class="input-group">
	                    <input name="catogoryName" onclick="selectCatogory()" id="treeName" type="text" placeholder="请选择产品分类 " class="form-control" required readonly>
	                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>                    
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">产品名称：</label>
                <div class="col-sm-8">
                    <input name="productName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">产品规格：</label>
                <div class="col-sm-8">
                    <input name="productSpec" 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="incomePrice" 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="salePrice" class="form-control" type="text" >
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">产品类别：</label>
                <div class="col-sm-8">
                    <select name="productCategory" class="form-control m-b" th:with="type=${@dict.getType('product_category')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">货号：</label>
                <div class="col-sm-8">
                    <input name="productNo" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">计量单位：</label>
                <div class="col-sm-8">
                    <select name="productUnit" class="form-control m-b" th:with="type=${@dict.getType('product_unit')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">产品状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('product_status')}">
                        <input type="radio" th:id="${'prodcutStatus_' + dict.dictCode}" name="prodcutStatus" th:value="${dict.dictValue}" th:checked="${dict.default}" required>
                        <label th:for="${'prodcutStatus_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-3 control-label">备注：</label>
                <div class="col-xs-8">
                    <textarea name="remark" maxlength="500" class="form-control"
                        rows="3"></textarea>
                </div>
			</div>
            <div>
                <p onclick="tableChange()"><a href="javascript:;">添加</a></p>
                <table class="table table-bordered" id="tables">
                    <thead>
                    <tr>
                        <th>名称</th>
                        <th>值</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="tbody">
                    </tbody>
                </table>
                <script type="text/javascript">
                    //添加表格
                    function tableChange() {
                        var length = $("#tbody tr").length;
                        var tableHtml ="";
                        tableHtml += '<tr>'
                            +'<td align="center"><input type="text" name="wmsProductAttributes['+length+'].name" style="line-height: 24px;border:none;border-radius: 4px;border:1px solid #e5e6e7"/> </td>'
                            +'<td align="center"><input type="text" name="wmsProductAttributes['+length+'].attrVal" style="line-height: 24px;border-radius: 4px;border:none;border:1px solid #e5e6e7"/></td>'
                            +'<td><input type="button" onClick="deltr(this)" value="删行"></td>'
                            +'</tr>';
                        $("#tbody").append(tableHtml) ;   //在表格后面添加一行

                    }
                    function deltr(opp) {
                        var length = $("#tbody tr").length;
                        if (length <= 1) {
                            alert("至少保留一行");
                        } else {
                            $(opp).parent().parent().remove();//移除当前行
                        }
                    }
                </script>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "crm/product"
        $("#form-product-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-product-add').serialize());
            }
        }
        
        /* 产品管理-新增-选择供应商  */
        function selectSupplier() {
        	 var url = ctx + "crm/supplier/selectSupplier";
        	 /* var options = {
				title: '选择客户',
				width: "780",
				url: url
			};
			$.modal.openOptions(options);
        	*/
        	 $.modal.open("选择供应商", url);
		}
        
        /*产品管理-新增-选择产品分类树*/
        function selectCatogory() {
        	var treeId = $("#treeId").val();
        	var productCatogoryId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        	var url = ctx + "crm/productCatogory/selectProductCatogoryTree/" + productCatogoryId;
			var options = {
				title: '选择产品分类',
				width: "380",
				url: url,
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}
		
		function doSubmit(index, layero){
			var tree = layero.find("iframe")[0].contentWindow.$._tree;
			if ($.tree.notAllowParents(tree)) {
				var body = layer.getChildFrame('body', index);
    			$("#treeId").val(body.find('#treeId').val());
    			$("#treeName").val(body.find('#treeName').val());
    			layer.close(index);
			}
		}

    </script>
</body>
</html>