<!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('兑换券')" />
	<style>
        body .layui-layer-btn {
                display: none !important;
            }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
	<div class="row">
		<div class="col-sm-12 search-collapse">
			<form id="coupon-form">
				<div class="select-list">
					<ul>
						<input type="hidden" name="couType" th:value="${couType}" />
						<li>
							<input type="text" name="keyword" placeholder="搜索"/>
						</li>
						<li>
							类型：<select name="bindType" th:with="type=${@dict.getType('zhengzai_coupon_bind_type')}">
							<option value="">所有</option>
							<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
						</select>
						</li>
						<li>
							适用范围：<select name="busiType" th:with="type=${@dict.getType('zhengzai_coupon_busi_type')}">
							<option value="">所有</option>
							<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
						</select>
						</li>
						<li>
							<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
						</li>
					</ul>
				</div>
			</form>
		</div>

		<div class="btn-group-sm" id="toolbar" role="group">
			<a class="btn btn-success" th:onclick="$.operate.addTab([[${couType}]])" shiro:hasPermission="candy:coupon:mgt:add">
				<i class="fa fa-plus"></i> 新增
			</a>
		</div>

		<div class="col-sm-12 select-table table-striped">
			<table id="bootstrap-table"></table>
		</div>
	</div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
	var prefix = ctx + "candy/coupon/mgt";
	var prefix2 = ctx + "local";
	var viewMgtCouponFlag = [[${@permission.hasPermi('candy:coupon:mgt:detail')}]];
	var cancelMgtCouponFlag = [[${@permission.hasPermi('candy:coupon:mgt:cancel')}]];

	var couType = [[${couType}]];

	$(function() {
		var options = {
			url: prefix + "/list",
			createUrl: prefix + "/add/{id}",
			detailUrl: prefix + "/detail/" + couType + "/{id}",
			removeUrl: prefix + "/cancel/{id}",
			// updateUrl: prefix + "/edit/{id}",
			// exportUrl: prefix + "/export",
			sortName: "createdAt",
			sortOrder: "desc",
			modalName: "优先券",
			columns: [
				{
					checkbox: true
				},
				{
					field: 'couponRuleScopeName',
					title: '适用演出'
				},
				{
					field: 'eventAmt',
					title: '数量'
				},
				{
					field: 'title',
					title: '标题'
				},
				{
					field: 'notice',
					title: '描述'
				},
				{
					field: 'operator',
					title: '创建人'
				},
				{
					field: 'createdAt',
					title: '生成时间',
					sortable: true,
					formatter: function (value, row, index) {
						return $.common.sprintf("<span>%s</span>", null != value ? value.substring(0, 19) : value);
					}
				},
				{
					field: 'expireAt',
					title: '失效时间',
					formatter: function (value, row, index) {
						return $.common.sprintf("<span>%s</span>", value);
					}
				},
				{
					title: '操作',
					// align: 'center',
					formatter: function(value, row, index) {
						var actions = [];
						actions.push('<a class="btn btn-warning btn-xs ' + viewMgtCouponFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.mcouponId + '\')"><i class="fa fa-search"></i>详情</a>');
						actions.push('<a class="btn btn-success btn-xs ' + viewMgtCouponFlag + '" href="javascript:void(0)" onclick="relevancyShow(\'' + row.mcouponId + '\')">关联巡演</a>');
						// if (row.state === 0) {
						//     actions.push('<a class="btn btn-danger btn-xs ' + cancelMgtCouponFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.mcouponId + '\')"><i class="fa fa-remove"></i>取消</a>');
						// }
						if (row.bindType === 0 && row.state === 1) {
							actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="couponCodeList(\'' + row.couponId + '\')"><i class="fa fa-list-ul"></i>码列表</a> ');
						}
						return actions.join('');
					}
				}]
		};
		$.table.init(options);
	});

	/* 查看码列表 */
	function couponCodeList(couponId) {
		var url = 'candy/coupon/code?couponId=' + couponId;
		$.modal.openTab("查看码列表", url);
	}

	// 导出数据
	function relevancyShow(couponId) {
		// console.log(userIds.toString(), 'dataParam')
		$.modal.open('关联巡演', prefix2 + "/relevancyShow?couponId="+couponId, 500, 350, cancel)
	}
	function cancel () {
		console.log('确定按钮？')
	}
</script>
</body>
</html>