<!--
	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">

		<article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
			<div class="jarviswidget" id="wid-id-4">
				<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-2">
                                    <div class="input-group">
                                        <label>
                                            <select ug-select2 style="width: 250px;" ng-change="getPurchaseList()" ng-model="queryParam.purchaseStatus" name="purchaseStatus">
                                                <option value="">--请选择--</option>
                                                <option value="0">待采购</option>
                                                <option value="1">已采购</option>
                                            </select>
                                        </label>
                                    </div>
                                </div>
                                <div class="col-sm-2">
                                    <div class="input-group">
                                        <label>
                                            <select ug-select2 style="width: 250px;" ng-change="getPurchaseList()" ng-model="queryParam.sellUnit" name="sellUnit">
                                                <option value="">--销售方式--</option>
                                                <option value="0">计重</option>
                                                <option value="1">计件</option>
                                            </select>
                                        </label>
                                    </div>
                                </div>
                                <div class="col-sm-2">
                                    <div class="input-group">
                                        <input type="text" class="form-control" datepicker-popup="yyyy-MM-dd" datepicker-localdate
                                               placeholder="采购起始日期"
                                               ng-model="queryParam.startTime"
                                               close-text="关闭"
                                               current-text="今日"
                                               clear-text="清除"
                                               is-open="datepickerSetting.startTime.opened"
                                               ng-required="true" />
                                        <div class="input-group-btn">
                                            <button type="button" class="btn btn-default" ng-click="openDatepicker($event, 1)"><i class="glyphicon glyphicon-calendar"></i></button>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-2">
                                    <div class="input-group">
                                        <input type="text" class="form-control" datepicker-popup="yyyy-MM-dd" datepicker-localdate
                                               placeholder="采购截止日期"
                                               ng-model="queryParam.endTime"
                                               close-text="关闭"
                                               current-text="今日"
                                               clear-text="清除"
                                               is-open="datepickerSetting.endTime.opened"
                                               ng-required="true" />
                                        <div class="input-group-btn">
                                            <button type="button" class="btn btn-default" ng-click="openDatepicker($event, 2)"><i class="glyphicon glyphicon-calendar"></i></button>
                                        </div>
                                    </div>
                                </div>

                                <div class="col-sm-3">
                                    <div class="input-group">
                                        <input type="search" placeholder="产品名称" data-ng-keyup="getPurchaseList()" ng-model="queryParam.keyword" class="form-control" aria-controls="dt_basic"></label>
                                    </div>
                                </div>
                            </div>
                            <div class="row margin-top-10">
                                <div class="col-sm-12">
                                    <div class="input-group">
                                        <div class="input-group-btn">
                                            <button class="btn btn-primary margin-right-5" type="button" data-ng-click="getPurchaseList()">
                                                <i class="fa fa-refresh"></i>
                                                刷新
                                            </button>
                                            <button class="btn btn-primary margin-right-5" type="button" ng-click="createPlan()">
                                                <i class="fa fa-plus"></i>
                                                生成今日采购计划
                                            </button>

                                            <button class="btn btn-primary" type="button" ng-click="exportExcel()">
                                                <i class="fa fa-plus"></i>
                                                导出未采购商品
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row margin-top-10 margin-bottom-10">
                                <div class="col-lg-2">
                                    <div class="input-group">
                                        <input type="text" class="form-control" datepicker-popup="yyyy-MM-dd" datepicker-localdate
                                               placeholder="配送起始日期"
                                               ng-model="purchasePlan.appointmentTimeStart"
                                               close-text="关闭"
                                               current-text="今日"
                                               clear-text="清除"
                                               is-open="datepickerSetting.appointmentTimeStart.opened"
                                               ng-required="true" />
                                        <div class="input-group-btn">
                                            <button type="button" class="btn btn-default" ng-click="openDatepicker($event,3)"><i class="glyphicon glyphicon-calendar"></i></button>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-lg-2">
                                    <div class="input-group">
                                        <input type="text" class="form-control" datepicker-popup="yyyy-MM-dd" datepicker-localdate
                                               placeholder="配送截止日期"
                                               ng-model="purchasePlan.appointmentTimeEnd"
                                               close-text="关闭"
                                               current-text="今日"
                                               clear-text="清除"
                                               is-open="datepickerSetting.appointmentTimeEnd.opened"
                                               ng-required="true" />
                                        <div class="input-group-btn">
                                            <button type="button" class="btn btn-default" ng-click="openDatepicker($event, 4)"><i class="glyphicon glyphicon-calendar"></i></button>
                                        </div>
                                    </div>
                                </div>
                                <button class="btn btn-primary" type="button" ng-click="createPlanAppointmenTime()">
                                    <i class="fa fa-plus"></i>
                                    生成指定配送日期的采购计划
                                </button>
                            </div>
						</div>
						<div class="table-responsive">
							<table class="table table-striped table-condensed table-hover smart-form has-tickbox">
								<thead>
								<tr>
									<th></th>
									<th width="80">需求日期</th>
									<th>产品名称</th>
                                    <th>销售方式</th>
									<th>采购状态</th>
									<th>数量</th>
									<th>产品规格</th>
                                    <th>重量</th>
                                    <th>创建时间</th>
									<th>操作</th>
								</tr>
								</thead>
								<tbody>
								<tr ng-repeat="purchase in purchaseList"  ng-if="purchaseList.length > 0" ng-mouseenter="show=true" ng-mouseleave="show=false">
									<td></td>
									<td ng-bind="purchase.purchaseCode"></td>
									<td ng-bind="purchase.itemName"></td>
                                    <td><span ng-if="purchase.sellUnit == 0">计重</span><span ng-if="purchase.sellUnit == 1">计件</span></td>
									<td ng-bind="purchase.purchaseStatusDesc"></td>
									<td ng-bind="purchase.totalItemQty"></td>
                                    <td>{{purchase.spec}}{{purchase.itemUnit}}</td>
									<td>{{purchase.totalWeight}}{{purchase.itemUnit}}</td>
                                    <td ng-bind="purchase.createDate | date: 'yyyy-MM-dd'"></td>
									<td width="180">
										<a ng-show="show" ng-if="purchase.purchaseStatus == 0" href="javascript:void(0);" data-ng-click="finish($index)" title="采购完成">
											<span class="fa fa-edit"></span>
										</a>
										<!--<a ng-show="show" ng-if="purchase.purchaseStatus != 1" href="javascript:void(0);" data-ng-click="cancel($index)" title="取消">-->
											<!--<span class="fa fa-recycle">取消</span>-->
										<!--</a>-->
									</td>
								</tr>
								<tr ng-if="purchaseList == null || purchaseList.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="addPurchase.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="addPurchaseForm" name="addPurchaseForm" novalidate="">

			</form>
		</div>
	</div>
	<div class="modal-footer">
		<button class="btn btn-primary" type="submit" data-ng-click="savePurchase()">
			<i class="fa fa-save"></i>
			保存
		</button>
		<button class="btn btn-warning" ng-click="cancel()">关闭</button>
	</div>
</script>