<!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('会员码管理')" />
	<th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" href="#member-gencode-form" data-toggle="modal" shiro:hasPermission="adam:member:code:creation">
					<i class="fa fa-plus"></i> 创建
				</a>
			</div>

			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table"></table>
			</div>

			<div id="member-gencode-form" class="modal fade" aria-hidden="true">
				<div class="modal-dialog" style="width:33%;">
					<div class="modal-content modal-body row">
						<h3 class="m-t-none m-b text-center">创建会员码</h3>

						<form role="form" id="form-member-code-generate">
							<input name="memberId" type="hidden" th:value="${memberId}" readonly>
							<input name="memberPriceId" type="hidden" th:value="${memberPrice.memberPriceId}" readonly>
							<div class="form-group">
								<label class="pull-left">生产数量：</label>
								<input type="number" name="genNum" class="form-control" style="width: 30%;height: 20px;" placeholder="生产数量">
							</div>
							<div class="form-group">
<!--								<label>备注：</label>-->
								<textarea rows="3" name="detail" placeholder="备注描述" class="form-control"></textarea>
							</div>
							<div class="text-center" style="margin-bottom: -15px;margin-top: 10px;">
								<button class="btn btn-sm btn-primary m-t-n-xs" type="button" onclick="memberCodeGenerate()">
									<strong>确认创建</strong>
								</button>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<script th:inline="javascript">
	var viewMemberCodeListFlg = [[${@permission.hasPermi('adam:member:code:list')}]];
	var memberId = [[${memberId}]];
	var prefix = ctx + "adam/mcode";

	$(function() {
		var options = {
			url: prefix + "/mgt/list?memberId=" + memberId,
			createUrl: prefix + "/mgt/creation/{id}",
			exportUrl: prefix + "/export_code",
			detailUrl: ctx + "adam/order/orderList/detail/{id}",
			sortName: "createdAt",
			sortOrder: "desc",
			modalName: "会员码创建记录",
			columns: [{
				checkbox: true
			},
				{
					field: 'memberName',
					title: '会员名称',
					width: 220
				},
				{
					field: 'memberCombo',
					title: '会员套餐名称',
					width: 180
				},
				{
					field: 'genNum',
					title: '生产数量',
					width: 80
				},
				{
					field: 'useNum',
					title: '使用数量',
					width: 80
				},
				{
					field: 'detail',
					title: '备注',
					width: 280
				},
				{
					field: 'operator',
					title: '创建人',
					width: 100
				},
				{
					field: 'createdAt',
					title: '创建时间',
					width: 150,
					formatter: function (value, row, index) {
						return $.common.sprintf("<span>%s</span>", null != value ? value.replace("T"," ").substring(0, 19) : value);
					}
				},
				{
					title: '操作',
					align: 'center',
					formatter: function(value, row, index) {
						var actions = [];
						actions.push('<a class="btn btn-primary btn-xs ' + viewMemberCodeListFlg + '" href="javascript:void(0)" onclick="memberCodeList(\'' + row.batchNo + '\')"><i class="fa fa-list-ul"></i>查看码列表</a> ');
						return actions.join('');
					}
				}]
		};
		$.table.init(options);
	});

	/* 会员码列表 */
	function memberCodeList(batchNo) {
		$.modal.openTab("会员码列表", prefix + '/mgt/code?batchNo=' + batchNo);
	}

	$("#form-member-code-generate").validate({
		onkeyup: false,
		rules:{
			genNum: {
				required: true,
				number: true,
				min: 1,
				max: 100
			},
			detail: {
				required: true,
				minlength: 2,
				maxlength: 100
			}
		},
		messages: {
			genNum: {
				required: "请输入生产数量",
				number: "生产数量必须为数字",
				min: "生产数量不能小于1",
				max: "生产数量不能大于100"
			},
			detail: {
				required: "请输入备注描述",
				minlength: "备注描述不得少于2个字符",
				maxlength: "备注描述不得大于100个字符"
			}

		},
		focusCleanup: true
	});
	function memberCodeGenerate() {
		if ($.validate.form("form-member-code-generate")) {
			$('#member-gencode-form').hide();
			$.operate.saveModal(prefix + "/mgt/creation", $('#form-member-code-generate').serialize(), memberCodeGenerateCallback);
		}
	}
	function memberCodeGenerateCallback(result) {
		if (typeof callback == "function") {
			callback(result);
		}
		if (result.code == web_status.SUCCESS) {
			$.modal.alertSuccess(result.msg);
			setTimeout("refreshTab()", 1500);
		} else if (result.code == web_status.WARNING) {
			$('#member-gencode-form').show();
			$.modal.alertWarning(result.msg);
		} else {
			$('#member-gencode-form').show();
			$.modal.alertError(result.msg);
		}
	}
</script>
</body>
</html>