2026-05-29 19:54:56 +08:00

155 lines
5.3 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!-- 新手礼包设置-->
<?php
?>
<section class="content-header">
</section>
<!-- Main content -->
<section class="content">
<div class="box box-success">
<div class="box-header with-border">
<h3 class="box-title">新手礼包设置</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-block btn-primary btn-flat" onclick="addItem();">添加</button>
</div>
</div>
<div class="box-body" id="listHtml">
<?php foreach ($list as $item): ?>
<div>
<div class="row">
<div class="col-lg-1"></div>
<div class="col-lg-5">
<div class="input-group">
<span class="input-group-addon">物品</span>
<select class="form-control" data-item-select="1">
<?php foreach ($configItemList as $configItem): ?>
<option value="<?= $configItem['id'] ?>" <?= $configItem['id'] == $item['item_id'] ? 'selected="selected"' : '' ?> ><?= $configItem['name'] ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="col-lg-5">
<div class="input-group">
<span class="input-group-addon">数量</span>
<input type="number" class="form-control" data-item-select-num="1" value="<?= $item['goods_num'] ?>">
</div>
</div>
<button type="button" class="btn" onclick="removeItem(this);"><i class="fa fa-remove"></i></button>
</div>
<br>
</div>
<?php endforeach; ?>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-info pull-right" onclick="submitData();">提交修改</button>
</div>
<!-- /.box-body -->
</div>
</section>
<!-- /.content -->
<script type="text/javascript">
//添加一项
function addItem() {
var listHtml = $("#listHtml");
var html = listHtml.children().last();
listHtml.append(html.clone());
}
//删除一项
function removeItem(target) {
if ($("#listHtml").children().length == 1) {
alert('不能删除最后一个');
return;
}
target.parentNode.parentNode.remove();
}
var LG = (function (lg) {
var objURL = function (url) {
this.ourl = url || window.location.href;
this.href = "";//?前面部分
this.params = {};//url参数对象
this.jing = "";//#及后面部分
this.init();
}
//分析url,得到?前面存入this.href,参数解析为this.params对象#号及后面存入this.jing
objURL.prototype.init = function () {
var str = this.ourl;
var index = str.indexOf("#");
if (index > 0) {
this.jing = str.substr(index);
str = str.substring(0, index);
}
index = str.indexOf("?");
if (index > 0) {
this.href = str.substring(0, index);
str = str.substr(index + 1);
var parts = str.split("&");
for (var i = 0; i < parts.length; i++) {
var kv = parts[i].split("=");
this.params[kv[0]] = kv[1];
}
}
else {
this.href = this.ourl;
this.params = {};
}
}
//只是修改this.params
objURL.prototype.set = function (key, val) {
this.params[key] = val;
}
//只是设置this.params
objURL.prototype.remove = function (key) {
this.params[key] = undefined;
}
//根据三部分组成操作后的url
objURL.prototype.url = function () {
var strurl = this.href;
var objps = [];//这里用数组组织,再做join操作
for (var k in this.params) {
if (this.params[k]) {
objps.push(k + "=" + this.params[k]);
}
}
if (objps.length > 0) {
strurl += "?" + objps.join("&");
}
if (this.jing.length > 0) {
strurl += this.jing;
}
return strurl;
}
//得到参数值
objURL.prototype.get = function (key) {
return this.params[key];
}
lg.URL = objURL;
return lg;
}(LG || {}));
//提交修改
function submitData() {
var str = "";
var i = 0;
var numList = $("[data-item-select-num]");
$("[data-item-select]").each(function () {
str += $(this).val() + ":" + numList.eq(i).val() + ",";
i++;
});
str = str.substring(0, str.length - 1);
var url = "<?=\yii\helpers\Url::to(['config/gift-edit'])?>";
var myurl = new LG.URL(url);
myurl.set('item_str', str);
self.location.href = myurl.url();
}
</script>