代码拉取完成,页面将自动刷新
同步操作将从 晴天莫爱小鸟/layui-sku-template 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link href="layui/css/layui.css" rel="stylesheet" />
</head>
<body>
<div class="layui-container">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
<legend>总价</legend>
</fieldset>
<div id="price">0</div>
<div id="view"></div>
</div>
<script id="demo" type="text/html">
<ul>
{{# layui.each(d.list, function(index, item){ }}
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
<legend>{{item.lable}}</legend>
</fieldset>
{{# layui.each(item.detail, function(idx, chil){ }}
<button type="button" class="layui-btn layui-btn-primary sku-{{index}}" data-index="{{index+'-'+idx}}">{{chil.lable}}</button>
{{# }); }}
{{# }); }}
{{# if(d.list.length === 0){ }}
无数据
{{# } }}
</ul>
</script>
</body>
<script src="layui/layui.js"></script>
<script>
layui.use(['table', 'dropdown'], function() {
var table = layui.table,
$ = layui.$,
upload = layui.upload,
form = layui.form,
util = layui.util,
layer = layui.layer,
laytpl = layui.laytpl;
var skuPrice = [];
$.ajax({
url: 'http://127.0.0.1:82/sku/showProduct',
type: "post",
data:{
},
async: true,
dataType:'json',
success: function(res) {
console.log("res=>",res)
var jsonTermArray = res.jsonTermArray;
var jsonSkuArray = res.jsonSkuArray;
var data = {
list:jsonTermArray
}
var getTpl = demo.innerHTML
,view = document.getElementById('view');
laytpl(getTpl).render(data, function(html){
view.innerHTML = html;
$("#view").on("click","button",function(obj){
console.log(obj);
var index = obj.currentTarget.dataset.index
console.log(index);
var indexArray = index.split("-");
$(".sku-"+indexArray[0]).addClass("layui-btn-primary");
$(this).removeClass("layui-btn-primary")
skuPrice[indexArray[0]] = jsonTermArray[indexArray[0]].detail[indexArray[1]].lable;
console.log(skuPrice)
var length = 0;
for (var i = 0; i < skuPrice.length; i++) {
if( skuPrice[i]){
length++;
}
}
console.log(length,jsonTermArray.length)
if(length == jsonTermArray.length){
var objXX = {};
for (var i = 0; i < jsonSkuArray.length; i++) {
objXX[JSON.parse(jsonSkuArray[i].sku).join(",")] = jsonSkuArray[i];
}
var sku = skuPrice.join(",");
console.log(objXX,sku,objXX[sku])
if(objXX[sku]){
$("#price").html(objXX[sku].curPrice)
}
}
})
});
}
});
})
</script>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。