{extend name="base"}

{block name="content"}
<div class="row">
	<div class="col-sm-12">
		<div class="card-box">
			<div class="row">
				<div class="col-sm-6">
					<form class="form-inline" role="form" action="" method="get">
						<div class="form-group">
							<select name="status" class="form-control">
								<option value="" {if $Think.get.status==''}selected{/if}>全部状态</option>
								<option value="1" {if $Think.get.status=='1'}selected{/if}>已读取</option>
								<option value="2" {if $Think.get.status=='2'}selected{/if}>未读取</option>
							</select>
						</div>
						<button type="submit" class="btn btn-purple waves-effect waves-light"><i class="fa fa-search"></i> 搜索</button>
					</form>
				</div>
			</div>
			<!-- end row -->
			<div class="row">
				<table class="table table-striped m-0">
					<thead>
						<tr>
							<th>发件人</th>
							<th>标题</th>
							<th>内容</th>
							<th>读取状态</th>
							<th>发送时间</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
						{foreach $messages as $v}
						<tr>
							<td>{if $v.from_id==0}系统{else/}{$v.fromUser.username}{/if}</td>
							<td>{$v.title}</td>
							<td>{$v.content}</td>
							<td>
								<input onchange="change_status(this,{$v.id})" type="checkbox" data-plugin="switchery" data-color="#2bb309" data-size="small" data-switchery="true" style="display: none;" {if $v.status==1}checked{/if}>
							</td>
							<td>{$v.create_at|date="Y-m-d H:i:s",###}</td>
							<td>
                                <a href="javascript:void(0);" onclick="del(this,{$v.id})">删除</a>
							</td>
						</tr>
						{/foreach}
					</tbody>
				</table>
			</div>
			<!-- end row -->
		</div>
		{$page}
	</div>
</div>
{/block}

{block name="appendJS"}

<script>
	function change_status(obj,id)
	{
		var status=$(obj).prop('checked');
		if(status){
			status=1;
		}else{
			status=0;
		}
		$.post('/merchant/message/changeStatus',{
			id:id,
			status:status
		},function(res){
			if(res.code!=0){
				alert(res.msg);
			}
		});
	}

	function del(obj,id)
	{
		swal({
			title: "确定删除吗？",
			text: "你将无法恢复该操作！",
			type: "warning",
			showCancelButton: true,
			confirmButtonColor: "#DD6B55",
			confirmButtonText: "确定删除！",
			closeOnConfirm: false
		},
		function(){
			$.post('/merchant/message/del',{
				id:id
			},function(res){
				if(res.code!=0){
					swal('删除失败', res.msg, "error");
				}else{
					swal('删除成功', '', "success");
					setTimeout(function(){
						location.reload();
					},200);
				}
			});
		});
	}
</script>

{/block}
