<!--
	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="col-sm-4">
								<div class="dataTables_filter">
									<label>
										<span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>
										<input type="search" placeholder="活动名称" data-ng-keyup="getActivityList()" ng-model="queryParam.keyword" class="form-control" aria-controls="dt_basic"></label>
								</div>
							</div>
							<div class="col-sm-2">
								<button class="btn btn-primary" type="button" data-ng-click="getActivityList()">
									<i class="fa fa-refresh"></i>
									刷新
								</button>
								<button class="btn btn-primary" type="button" data-ng-click="open()">
									<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>
										<label class="checkbox">
											<input type="checkbox" name="checkbox-inline">
											<i></i>
										</label>
									</th>
									<th width="120">活动名称</th>
                                    <th>有效时间</th>
                                    <th>活动描述</th>
                                    <th>类型</th>
                                    <th>最低赠送金额</th>
									<th width="80">操作</th>
								</tr>
								</thead>
								<tbody>
								<tr ng-repeat="activity in activityList"  ng-if="activityList.length > 0" ng-mouseenter="show=true" ng-mouseleave="show=false">
									<td>
										<label class="checkbox">
											<input type="checkbox" name="checkbox-inline">
											<i></i>
										</label>
									</td>
                                    <td ng-bind="activity.activityName"></td>
                                    <td>{{activity.activityBeginTime | date: 'yyyy-MM-dd'}} 至 {{activity.activityEndTime | date: 'yyyy-MM-dd'}}</td>
									<td ng-bind="activity.activityDescribe"></td>
                                    <td><span ng-if="activity.activityType == 1">按卡类型</span><span ng-if="activity.activityType == 2">按消费金额</span></td>
                                    <td ng-bind="activity.lowestPrice"></td>
									<td>
										<div ng-show="show">
											<a href="javascript:void(0);" data-ng-click="removeActivity($index)" title="删除：{{activity.activityName}}">
												<span class="glyphicon glyphicon-remove-circle"></span>
											</a>
											<span> | </span>
											<a href="javascript:void(0);" data-ng-click="updateActivity($index)" title="编辑：{{activity.activityName}}">
												<span class="fa fa-pencil"></span>
											</a>
										</div>
									</td>
								</tr>
								<tr ng-if="activityList == null || activityList.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="addActivity.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="addActivityForm" name="addActivityForm" novalidate="">

				<fieldset>

					<div class="form-group">
						<label class="col-md-2 control-label">活动名称<span class="vaild">*</span></label>
						<div class="col-md-10 input-group">
							<input class="form-control"  ng-model="activity.id" name="id" type="hidden">
							<input class="form-control" required="" ng-model="activity.activityName" name="activityName" placeholder="活动名称" type="text">
						</div>
					</div>

                    <div class="form-group">
                        <label class="col-md-2 control-label">活动描述</label>
                        <div class="col-md-10 input-group">
                            <textarea ng-model="activity.activityDescribe" placeholder="活动描述" rows="5" cols="100">
                            </textarea>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-2 control-label">类型<span class="vaild">*</span></label>
                        <div class="col-md-10 input-group">
                            <label class="radio radio-inline">
                                <input type="radio" class="radiobox" required="" ng-model="activity.activityType" value="1" ng-checked="activity.activityType == 1" name="activityType">
                                <span>按卡类型</span>
                            </label>
                            <label class="radio radio-inline">
                                <input type="radio" class="radiobox" required="" ng-model="activity.activityType" value="2" ng-checked="activity.activityType == 2" name="activityType">
                                <span>按订单金额</span>
                            </label>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-2 control-label">最低赠送金额<span class="vaild">*</span></label>
                        <div class="col-md-10 input-group">
                            <input class="form-control" required="" ng-model="activity.lowestPrice" name="lowestPrice" placeholder="最低赠送金额" type="text">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-2 control-label">卡类型<span class="vaild">*</span></label>
                        <div class="col-md-10 input-group">
                            <select ug-select2 ug-select2-config="ugSelect2Config" style="width: 100%;" required="true" ng-model="activity.couponCategory" name="couponCategory" >
                                <option value="">--请选择--</option>
                                <option value="{{category.id}}" ng-repeat="category in categoryList">{{category.categoryName}}</option>
                            </select>
                        </div>
                    </div>

					<div class="form-group">
						<label class="col-md-2 control-label">起始时间<span class="vaild">*</span></label>
						<div class="col-md-10 input-group">
							<input type="text" class="form-control"
								   datepicker-popup="yyyy-MM-dd"
								   placeholder="起始日期"
								   ng-model="activity.activityBeginTime"
								   close-text="关闭"
								   current-text="今日"
								   clear-text="清除"
								   is-open="datepickerSetting.beginTime.opened"
								   ng-required="true" />
							<span class="input-group-btn">
                                <button type="button" class="btn btn-default" ng-click="open($event, 0)"><i class="glyphicon glyphicon-calendar"></i></button>
							</span>
						</div>
					</div>
					<div class="form-group">
						<label class="col-md-2 control-label">截止日期<span class="vaild">*</span></label>
						<div class="col-md-10 input-group">
							<input type="text" class="form-control" datepicker-popup="yyyy-MM-dd"
								   placeholder="截止日期"
								   ng-model="activity.activityEndTime"
								   close-text="关闭"
								   current-text="今日"
								   clear-text="清除"
								   is-open="datepickerSetting.endTime.opened"
								   ng-required="true" />
							<span class="input-group-btn">
                                <button type="button" class="btn btn-default" ng-click="open($event, 1)"><i class="glyphicon glyphicon-calendar"></i></button>
							</span>
						</div>
					</div>

					<div class="form-group">
						<label class="col-md-2 control-label">是否启用<span class="vaild">*</span></label>
						<div class="col-md-10 input-group">
							<label class="radio radio-inline">
								<input type="radio" class="radiobox" required="" ng-model="activity.available" value="1" ng-checked="activity.available== 1" name="available">
								<span>启用</span>
							</label>
							<label class="radio radio-inline">
								<input type="radio" class="radiobox" required="" ng-model="activity.available" value="0" ng-checked="activity.available== 0" name="available">
								<span>禁用</span>
							</label>
						</div>
					</div>

                    <!--<div class="form-group">-->
                        <!--<label class="col-md-2 control-label">赠送时间(满足活动之后多久赠送)<span class="vaild">*</span></label>-->
                        <!--<div class="col-md-2">-->
                            <!--<input class="form-control" required="" ng-model="activity.activityDay" name="activityDay" placeholder="天数" type="text">-->
                        <!--</div>-->
                        <!--<label class="col-md-1 control-label">天</label>-->
                    <!--</div>-->

                    <fieldset class="demo-switcher-1">
                        <legend>赠送产品</legend>
                        <div class="row">
                            <div class="row">
                                <div class="col-xs-11 col-sm-10">
                                    <div class="dataTables_filter" style="width : 35%;">
                                        <label>
                                            <span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>
                                            <input type="search" placeholder="产品类别/编号/名称" data-ng-keyup="getChildItemList()" ng-model="queryChildParam.keyword" class="form-control" aria-controls="dt_basic">
                                        </label>
                                    </div>
                                </div>
                            </div>
                            <div class="table-responsive col-md-6">

                                <table class="table table-bordered">
                                    <thead>
                                    <tr>
                                        <th colspan="4">可选择产品</th>
                                    </tr>
                                    </thead>
                                    <thead>
                                    <tr>
                                        <th>类别</th>
                                        <th>编号</th>
                                        <th>名称</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr data-ng-repeat="childItem in childItemList">
                                        <td>{{childItem.categoryName}}</td>
                                        <td>{{childItem.itemCode}}</td>
                                        <td>{{childItem.itemName}}</td>
                                        <td>
                                            <div>
                                                <a href="javascript:void(0);" data-ng-click="openItemNumber($index)" title="选择：{{childItem.itemName}}">
                                                    <span class="fa fa-plus"></span>
                                                </a>
                                            </div>
                                        </td>
                                    </tr>
                                    </tbody>
                                    <!--<tfoot>-->
                                    <!--<tr>-->
                                    <!--<td colspan="4">-->
                                    <!--<ug-pagination page-info="pageInfoSetting" ></ug-pagination>-->
                                    <!--</td>-->
                                    <!--</tr>-->
                                    <!--</tfoot>-->
                                </table>

                            </div>
                            <div class="table-responsive col-md-6">
                                <table class="table table-bordered">
                                    <thead>
                                    <tr>
                                        <th colspan="5">已选择产品</th>
                                    </tr>
                                    <tr>
                                        <th>类别</th>
                                        <th>编号</th>
                                        <th>名称</th>
                                        <th>份数</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr ng-repeat="choseItem in choseChildItemList">
                                        <td>{{choseItem.categoryName}}</td>
                                        <td>{{choseItem.itemCode}}</td>
                                        <td>{{choseItem.itemName}}</td>
                                        <td>{{choseItem.count}}</td>
                                        <td>
                                            <div>
                                                <a href="javascript:void(0);" data-ng-click="removeChildItem($index)" title="移除：{{choseItem.itemName}}">
                                                    <span class="glyphicon glyphicon-trash"></span>
                                                </a>
                                            </div>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </fieldset>
					<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" type="submit" data-ng-click="saveActivity()">
			<i class="fa fa-save"></i>
			保存
		</button>
		<button class="btn btn-warning" ng-click="cancel()">关闭</button>
	</div>
</script>

<script type="text/ng-template" id="addItemNumber.html">
    <div class="modal-header">
        <h3 class="modal-title">【{{orderItem.itemName}}】</h3>
    </div>
    <div class="modal-body">
        <div class="widget-body">

            <form class="form-horizontal" ug-validate="addItemNumberForm" name="addItemNumberForm" 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" required data-rule-number="true" ng-model="orderItem.number" name="number" 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" type="submit" data-ng-click="saveItemNumber()">
            <i class="fa fa-save"></i>
            确定
        </button>
        <button class="btn btn-warning" ng-click="cancel()">取消</button>
    </div>
</script>