1 Star 0 Fork 1

arting87/layui-sku-template

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
sku-product.html 2.80 KB
一键复制 编辑 原始数据 按行查看 历史
晴天莫爱小鸟 提交于 2022-11-12 14:47 . 初始化数据
<!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>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/arting87_admin/layui-sku-template.git
git@gitee.com:arting87_admin/layui-sku-template.git
arting87_admin
layui-sku-template
layui-sku-template
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385