<?php include _include(ADMIN_PATH.'view/htm/header.inc.htm');?>

<div class="row">

	<div class="col-lg-10 mx-auto">

		<div class="card">

			<div class="card-body">

				<form action="<?php echo url('plugin-setting-zaesky_discovery_looppic');?>" method="post" id="form">

					<div class="alert alert-warning">建议选取图片宽高为785 * 445</div>

					<div class="table-responsive arrlist">

						<table class="table" style="min-width: 800px">

							<thead>

								<tr align="center">

									<th width="40">ID</th>

									<th>名称</th>

									<th>链接</th>

									<th width="200">图片地址</th>

									<th>删除</th>

								</tr>

								<thead>

									<tbody>

										<?php foreach($slidelist as $arr) { ?>

										<?php $rowid = $arr['slideid'];?>

										<tr align="center" rowid="<?php echo $rowid; ?>">

											<td><input type="text" class="form-control text-center" style="width: 30px;" name="rowid[<?php echo $rowid;?>]" value="<?php echo $rowid; ?>" placeholder="ID" /></td>

											<td><input type="text" class="form-control" name="name[<?php echo $rowid;?>]" value="<?php echo $arr['name']; ?>" placeholder="名称" /></td>

											<td><input type="text" class="form-control" name="url[<?php echo $rowid;?>]" value="<?php echo $arr['url']; ?>" placeholder="链接" /></td>

											<td><input type="text" class="form-control" style="width: 200px;" name="slidepic[<?php echo $rowid;?>]" value="<?php echo $arr['slidepic']; ?>" placeholder="图片地址" /></td>
					

											<td><a class="btn row_delete  text-center"  role="btn">删除</a></td>

										</tr>

										<?php } ?>

										<tr align="center" rowid="<?php echo !empty($rowid) ? $rowid : 0; ?>" class="d-none">

											<td><input type="text" class="form-control text-center" style="width: 30px;" name="rowid[0]" value="" placeholder="ID" /></td>

											<td><input type="text" class="form-control" name="name[0]" value="" placeholder="名称" /></td>

											<td><input type="text" class="form-control" name="url[0]" value="" placeholder="链接" /></td>

											<td><input type="text" class="form-control" style="width: 200px;" name="slidepic[0]" value="" placeholder="图片地址" /></td>

											<td><a class="btn row_delete" role="btn">删除</a></td>

										</tr>

									</tbody>

						</table>

					</div>

					<p><a role="button" class="btn row_add">[+]增加一行</a></p>

					<p class="text-center">

						<button type="submit" class="btn btn-primary" id="submit" data-loading-text="<?php echo lang('submiting');?>..."><?php echo lang('confirm');?></button>

					</p>

				</form>

			</div>

		</div>

	</div>

</div>


<?php include _include(ADMIN_PATH.'view/htm/footer.inc.htm');?>


<script>

	var maxid = <?php echo $maxid;?>;



	var jform = $("#form");

	var jsubmit = $("#submit");

	var jarrlist = $('.arrlist');

	jform.base64_encode_file(); // 对文件进行 base64 编码，处理文件上传，很方便



	jform.on('submit', function() {

		jform.reset();

		var postdata = jform.serialize();

		jsubmit.button('loading');

		$.xpost(jform.attr('action'), postdata, function(code, message) {

			if (code == 0) {

				$.alert(message);

				jsubmit.text(message).delay(3000).location();

				return;

			} else {

				alert(message);

				jsubmit.button('reset');

			}

		});

		return false;

	});



	// 删除

	var jdelete = $('a.row_delete');

	jarrlist.on('click', 'a.row_delete', function() {

		var jthis = $(this);

		var jtr = jthis.parents('tr');

		var rowid = jtr.attr('rowid');

		if (jform.find('tbody').find('tr').length <= 2) {

			$.alert('不能删除全部，请修改！');

			return;

		}

		jtr.remove();

		return false;

	});

	// 增加

	var jadd = $('a.row_add');

	jadd.on('click', function() {

		var jclone = jarrlist.find('tr').last().clone();

		jclone.insertAfter(jarrlist.find('tr').last()).removeClass('d-none');

		var jrowid = jclone.find('input[name^="rowid"]');

		//var rowid = xn.intval(jrowid.val()) + 1;

		var rowid = ++maxid;

		jrowid.val(rowid);

		jclone.attr('rowid', rowid);



		// 清空值

		jclone.find('input').not('[name^="rowid"]').val('');



		// 修改 [] 中的值为 rowid

		jclone.find('input').attr_name_index(rowid);



		return false;

	});



	$('#nav_pc li.plugin, #nav_mobile li.plugin').addClass('active');

</script>