<!--
	The ID "widget-grid" will start to initialize all widgets below 
	You do not need to use widgets if you dont want to. Simply remove 
	the <section></section> and you can use wells or panels instead 
	-->
<!-- widget grid -->
<section id="widget-grid" class="">

    <!-- row -->
    <div class="row">

        <!-- NEW WIDGET START -->
        <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">

            <!-- Widget ID (each widget will need unique ID)-->
            <div class="jarviswidget" id="wid-id-4">
                <!-- widget options:
                usage: <div class="jarviswidget" id="wid-id-0" data-widget-editbutton="false">

                data-widget-colorbutton="false"
                data-widget-editbutton="false"
                data-widget-togglebutton="false"
                data-widget-deletebutton="false"
                data-widget-fullscreenbutton="false"
                data-widget-custombutton="false"
                data-widget-collapsed="true"
                data-widget-sortable="false"

                -->
                <header>
                    <span class="widget-icon"> <i class="fa fa-table"></i> </span>
                    <h2>库存列表</h2>
                </header>
                <!-- widget div-->
                <div>
                    <!-- widget edit box -->
                    <div class="jarviswidget-editbox">
                        <!-- This area used as dropdown edit box -->
                    </div>
                    <!-- end widget edit box -->
                    <!-- widget content -->
                    <div class="widget-body no-padding">
                        <div class="dt-toolbar">
                            <div class="row">
                                <div class="col-sm-6">
                                    <div class="dataTables_filter">
                                        <span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>
                                        <input type="search" placeholder="商品编号/商品名称" data-ng-keyup="getStockList()" ng-model="queryParam.keyword" class="form-control" aria-controls="dt_basic">
                                    </div>
                                </div>
                                <div class="col-sm-6">
                                    <button class="btn btn-primary" type="button" data-ng-click="getStockList()">
                                        <i class="fa fa-refresh"></i>
                                        刷新
                                    </button>
                                    <button class="btn btn-primary" type="button" data-ng-click="saveStock()">
                                        <i class="fa fa-plus"></i>
                                        新增库存
                                    </button>
                                </div>
                            </div>
                        </div>
                        <div class="table-responsive">
                            <table class="table table-striped table-condensed table-hover smart-form has-tickbox">
                                <thead>
                                <tr>
                                    <th>序号</th>
                                    <th>商品名称</th>
                                    <th>商品编号</th>
                                    <th>库存数</th>
                                    <th>预警数量</th>
                                    <th width="80">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <tr ng-repeat="stock in stockList" ng-if="stockList.length > 0" ng-mouseenter="show=true" ng-mouseleave="show=false">
                                    <td ng-bind="($index+1) +((pageInfoSetting.pageNum -1) * pageInfoSetting.pageSize)"></td>
                                    <td ng-bind="stock.itemName"></td>
                                    <td ng-bind="stock.itemCode"></td>
                                    <td>{{stock.stockNum}}<span ng-if="stock.stockNum < stock.warningNum" style="color: red;">(库存不足)</span></td>
                                    <td ng-bind="stock.warningNum"></td>
                                    <td width="180">
                                        <a ng-show="show" href="javascript:void(0);" data-ng-click="saveStock($index)" title="编辑">
                                            编辑
                                        </a>
                                        <div ng-show="show" title="调整库存">
                                            <a href="javascript:void(0);" data-ng-click="changeStock($index)" >调整库存</a>
                                        </div>
                                    </td>
                                </tr>
                                <tr ng-if="stockList == null || stockList.length == 0">
                                    <td colspan="11">
                                        <div>暂无数据</div>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                        <div class="dt-toolbar-footer">
                            <div class="col-xs-12 col-sm-12">
                                <ug-pagination page-info="pageInfoSetting"></ug-pagination>
                            </div>
                        </div>
                    </div>
                    <!-- end widget content -->
                </div>
                <!-- end widget div -->
            </div>
            <!-- end widget -->

        </article>
        <!-- WIDGET END -->

    </div>

    <!-- end row -->

</section>
<!-- end widget grid -->

<script type="text/ng-template" id="saveStock.html">
    <div class="modal-header">
        <h3 class="modal-title">库存信息</h3>
    </div>
    <div class="modal-body">
        <div class="widget-body">

            <form class="form-horizontal" ug-validate="stockForm" name="stockFormName" novalidate="">

                <fieldset>

                    <div class="form-group">
                        <label class="col-md-2 control-label">商品名称</label>
                        <div class="col-md-10 input-group">
                            <input class="form-control" ng-model="stock.itemId" name="id" type="hidden">
                            <!--<input class="form-control" ng-model="stock.itemName" name="stockDesc" placeholder="商品名称" type="text">-->
                            <select ug-select2 ug-select2-config="ugSelect2Config" ng-disabled="stock.id" required="true" style="width: 100%" ng-change="getCouponList()" ng-model="stock.itemId" name="itemId" >
                                <option value="">--请选择商品--</option>
                                <option value="{{item.id}}" ng-repeat="item in itemList">{{item.itemName}}</option>
                            </select>
                        </div>
                    </div>

                    <!--<div class="form-group">-->
                        <!--<label class="col-md-2 control-label">商品编号</label>-->
                        <!--<div class="col-md-10 input-group">-->
                            <!--<input class="form-control" ng-model="stock.itemNo" name="itemNo" placeholder="商品编号" type="text">-->
                        <!--</div>-->
                    <!--</div>-->

                    <div class="form-group">
                        <label class="col-md-2 control-label">库存数</label>
                        <div class="col-md-10 input-group">
                            <input class="form-control" required="true" data-rule-positiveInteger="true" ng-disabled="stock.id" ng-model="stock.stockNum" name="stockNum" placeholder="库存数" type="text">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-2 control-label">预警数量</label>
                        <div class="col-md-10 input-group">
                            <input class="form-control" required="true" data-rule-positiveInteger="true" ng-model="stock.warningNum" name="warningNum" placeholder="预警数量" type="text">
                        </div>
                    </div>

                    <div class="form-group" ng-if="errors">
                        <label class="col-md-2 control-label"></label>
                        <div class="col-md-10 error">
                            {{errors.message}}
                        </div>
                    </div>
                </fieldset>
            </form>
        </div>
    </div>
    <div class="modal-footer">
        <button class="btn btn-primary" btn-loading="saveBtnLoading" type="submit" data-ng-click="save()">
            <i class="fa fa-save"></i>
            保存
        </button>
        <button class="btn btn-warning" ng-click="cancel()">关闭</button>
    </div>
</script>

<script type="text/ng-template" id="changeStock.html">
    <div class="modal-header">
        <h3 class="modal-title">库存信息</h3>
    </div>
    <div class="modal-body">
        <div class="widget-body">

            <form class="form-horizontal" ug-validate="stockForm" name="stockFormName" novalidate="">

                <fieldset>

                    <div class="form-group">
                        <label class="col-md-2 control-label">商品名称</label>
                        <div class="col-md-10 input-group">
                            <input class="form-control" ng-model="stock.id" name="id" type="hidden">
                            <!--<input class="form-control" ng-model="stock.itemName" name="stockDesc" placeholder="商品名称" type="text">-->
                            <select ug-select2 ug-select2-config="ugSelect2Config" disabled required="true" style="width: 100%" ng-model="stock.itemId" name="itemId" >
                                <option value="">--请选择商品--</option>
                                <option value="{{item.id}}" ng-repeat="item in itemList">{{item.itemName}}</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label">变更类型：</label>
                        <div class="col-md-10">
                            <label class="radio radio-inline">
                                <input type="radio" class="radiobox" required value="1" ng-model="stock.type" ng-checked="stock.type==1" name="type">
                                <span>入库</span>
                            </label>
                            <label class="radio radio-inline">
                                <input type="radio" class="radiobox" required value="2" ng-model="stock.type" ng-checked="stock.type==2" name="type">
                                <span>破损</span>
                            </label>
                            <label class="radio radio-inline">
                                <input type="radio" class="radiobox" required value="3" ng-model="stock.type" ng-checked="stock.type==3" name="type">
                                <span>核销</span>
                            </label>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-2 control-label">数量</label>
                        <div class="col-md-10 input-group">
                            <input class="form-control" required="true" data-rule-positiveInteger="true" ng-model="stock.number" name="stockNum" placeholder="数量" type="number">
                        </div>
                    </div>

                    <div class="form-group" ng-if="errors">
                        <label class="col-md-2 control-label"></label>
                        <div class="col-md-10 error">
                            {{errors.message}}
                        </div>
                    </div>
                </fieldset>
            </form>
        </div>
    </div>
    <div class="modal-footer">
        <button class="btn btn-primary" btn-loading="saveBtnLoading" type="submit" data-ng-click="save()">
            <i class="fa fa-save"></i>
            保存
        </button>
        <button class="btn btn-warning" ng-click="cancel()">关闭</button>
    </div>
</script>