<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('提交演出退款')" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-post-add">
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">演出id：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="targetId" id="targetId" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">演出名称：</label>
				<div class="col-sm-8">
					<span id="performanceTitle"></span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">演出统计：</label>
				<div class="col-sm-8">
					<div class="col-sm-12 select-table table-bordered">
						<table id="bootstrap-table"></table>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label layui-required is-required">备注：</label>
				<div class="col-sm-8">
					<textarea name="reason" maxlength="500" class="form-control layui-required" rows="3"></textarea>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<script type="text/javascript">
		var prefix = ctx + "kylin/refundBatch";

		$("#form-post-add").validate({
			onkeyup: false,
			rules:{
				targetId:{
					submitHandler: function(form) {
						var config = {
							url: prefix + "/applyPerformance",
							type: "post",
							dataType: "json",
							data: {
								"targetId" : function() {
									return $.common.trim($("#targetId").val());
								}
							},
							beforeSend: function () {
								$.modal.loading("正在查询演出，请稍后...");
							},
							success: function(result) {
								if (result.code > 0) {
									$.modal.closeLoading();
									layer.msg(result.msg);
									return false;
								}
								$("#performanceTitle").text(result.data.title);
								var options = {
									data: result.data.performanceOrderStatisticalDao,
									pagination: false,
									columns: [
										{
											field: 'title',
											title: '票种名'
										},
										{
											field: 'type',
											title: '类型',
											formatter: function (value, row, index) {
												var typeName = "";
												switch (value) {
													case 1:
														typeName = "单日票";
														break;
													case 2:
														typeName = "通票";
														break;
												}
												return typeName;
											}
										},
										{
											field: 'useStart',
											title: '适用时间'
										},
										{
											field: 'price',
											title: '单价'
										},
										{
											field: 'saleGeneral',
											title: '销售总数量'
										},
										{
											field: 'totalMemberNumber',
											title: '会员销售数量'
										},
										{
											field: 'totalPayingNumber',
											title: '正在支付数量'
										},
										{
											field: 'totalRefundGeneral',
											title: '退票数量'
										},
										{
											field: 'totalSalePrice',
											title: '销售额（元）'
										},
										{
											field: 'surplusGeneral',
											title: '库存数量'
										},
										{
											field: 'totalExchange',
											title: '兑换数量'
										},
									]
								};
								$.table.init(options);
								$.modal.closeLoading();
							}
						};
						$.ajax(config)
					}
				},
			},
		    focusCleanup: true
		});

		function submitHandler() {
			var reason = $('#form-post-add').find("[name='reason']").val();
			var targetId = $('#form-post-add').find("[name='targetId']").val();
			if (!targetId) {
				layer.msg("演出id有误");
				return false;
			}
			if (!reason) {
				layer.msg("请填写备注");
				return false;
			}
			if ($.validate.form()) {
				var data = $('#form-post-add').serializeArray();
				$.operate.save(prefix + "/apply", data);
			}
		}
	</script>
</body>
</html>
