<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('选择库存商品列表-盘点')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>产品名称：</p>
                                <input type="text" id="productName"  name="params[productName]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
		var columnId=[[${columnId}]];
        var productCategoryDatas = [[${@dict.getType('product_category')}]];
        var productUnitDatas = [[${@dict.getType('product_unit')}]];
		var storageId=[[${storageId}]];
        var prefix = ctx + "crm/stock";

        $(function() {
            var options = {
                url: prefix + "/list",
		        showSearch: false,
		        showRefresh: false,
		        showToggle: false,
		        showColumns: false,
		        clickToSelect: true,
		        sortName: "createTime",
		        sortOrder: "desc",
                modalName: "库存产品",
	            queryParams:{
	            	'storageId':storageId
	            },
                columns: [{
                    radio: true
                },
                {
                    field : 'stockId', 
                    title : '库存ID',
                    visible: false,
		            sortable: true
                },
                {
                    field : 'storageId', 
                    title : '仓库ID',
                    visible: false,
		            sortable: true
                },
                {
                    field : 'productId', 
                    title : '产品ID',
                    visible: false,
		            sortable: true
                },
                {
                    field : 'storage.storageName', 
                    title : '仓库名称',
		            sortable: true
                },
                {
                    field : 'product.productName', 
                    title : '产品名称',
		            sortable: true
                },
                {
                    field : 'product.productNo', 
                    title : '货号',
		            sortable: true
                },
                {
                    field : 'stockNum', 
                    title : '库存数量',
		            sortable: true
                }]
            };
            $.table.init(options);
        });
		
		/* 选择库存产品-提交 */
		function submitHandler() {
			var productId = $.table.selectColumns("productId");
			var stockNum=$.table.selectColumns("stockNum");
			var productName = $.table.selectColumns("product.productName");
			if (productId.length == 0) {
       			$.modal.alertWarning("请选择一条记录");
       			return;
       		}
			$.modal.close();
			parent.$('#productId_'+columnId).val('');
			parent.$('#productName_'+columnId).val('');
			parent.$('#productNum1_'+columnId).val('');
			parent.$('#productId_'+columnId).val(productId);
			parent.$('#productName_'+columnId).val(productName);
			parent.$('#productNum1_'+columnId).val(stockNum);
		}
    </script>
</body>
</html>