skus.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport"
  6. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  7. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8. <link rel="stylesheet" href="../css/sku_style.css"/>
  9. <title>sku</title>
  10. <script type="text/javascript" src="../js/sku/jquery.min.js"></script>
  11. <script type="text/javascript" src="../js/sku/createSkuTable.js?v16"></script>
  12. <!--<script type="text/javascript" src="../js/sku/customSku.js"></script>-->
  13. <!--<script type="text/javascript" src="../js/plugins/layer/layer.js"></script>-->
  14. <script src="../lib/layui-v2.5.4/layui.js" charset="utf-8"></script>
  15. </head>
  16. <body>
  17. <ul class="SKU_TYPE">
  18. <li is_required='1' propid='3' sku-type-name="颜色">颜色:</li>
  19. </ul>
  20. <ul>
  21. <li><label><input type="checkbox" class="sku_value" propvalid='31' value="土豪金"/>土豪金</label></li>
  22. <li><label><input type="checkbox" class="sku_value" propvalid='32' value="银白色"/>银白色</label></li>
  23. <li><label><input type="checkbox" class="sku_value" propvalid='33' value="深空灰"/>深空灰</label></li>
  24. <li><label><input type="checkbox" class="sku_value" propvalid='34' value="黑色"/>黑色</label></li>
  25. <li><label><input type="checkbox" class="sku_value" propvalid='33' value="玫瑰金"/>玫瑰金</label></li>
  26. </ul>
  27. <div class="clear"></div>
  28. <ul class="SKU_TYPE">
  29. <li is_required='1' propid='1' sku-type-name="存储"><em>*</em>型号:</li>
  30. </ul>
  31. <ul>
  32. <li><label><input type="checkbox" class="sku_value" propvalid='11' value="16G"/>16G</label></li>
  33. <li><label><input type="checkbox" class="sku_value" propvalid='12' value="32G"/>32G</label></li>
  34. <li><label><input type="checkbox" class="sku_value" propvalid='13' value="64G"/>64G</label></li>
  35. <li><label><input type="checkbox" class="sku_value" propvalid='14' value="128G"/>128G</label></li>
  36. <li><label><input type="checkbox" class="sku_value" propvalid='15' value="256G"/>256G</label></li>
  37. </ul>
  38. <div class="clear"></div>
  39. <ul class="SKU_TYPE">
  40. <li is_required='1' propid='2' sku-type-name="版本"><em>*</em>版本:</li>
  41. </ul>
  42. <ul>
  43. <li><label><input type="checkbox" class="sku_value" propvalid='21' value="中国大陆版"/>中国大陆版</label></li>
  44. <li><label><input type="checkbox" class="sku_value" propvalid='22' value="港版"/>港版</label></li>
  45. <li><label><input type="checkbox" class="sku_value" propvalid='23' value="韩版"/>韩版</label></li>
  46. <li><label><input type="checkbox" class="sku_value" propvalid='24' value="美版"/>美版</label></li>
  47. <li><label><input type="checkbox" class="sku_value" propvalid='25' value="日版"/>日版</label></li>
  48. </ul>
  49. <!--<div class="clear"></div>-->
  50. <!--<div class="clear"></div>-->
  51. <!--<ul class="SKU_TYPE">-->
  52. <!--<li is_required='1' propid='4' sku-type-name="类型"><em>*</em>类型:</li>-->
  53. <!--</ul>-->
  54. <!--<ul>-->
  55. <!--<li><label><input type="checkbox" class="sku_value" propvalid='41' value="儿童" />儿童</label></li>-->
  56. <!--<li><label><input type="checkbox" class="sku_value" propvalid='42' value="成人" />成人</label></li>-->
  57. <!--</ul>-->
  58. <div class="clear"></div>
  59. <!--<button class="cloneSku">添加自定义sku属性</button>-->
  60. <!--sku模板,用于克隆,生成自定义sku-->
  61. <div id="skuCloneModel" style="display: none;">
  62. <div class="clear"></div>
  63. <ul class="SKU_TYPE">
  64. <li is_required='0' propid='' sku-type-name="">
  65. <a href="javascript:void(0);" class="delCusSkuType">移除</a>
  66. <input type="text" class="cusSkuTypeInput"/>:
  67. </li>
  68. </ul>
  69. <ul>
  70. <li>
  71. <input type="checkbox" class="model_sku_val" propvalid='' value=""/>
  72. <input type="text" class="cusSkuValInput"/>
  73. </li>
  74. <!--<button class="cloneSkuVal">添加自定义属性值</button>-->
  75. </ul>
  76. <div class="clear"></div>
  77. </div>
  78. <!--单个sku值克隆模板-->
  79. <!--<li style="display: none;" id="onlySkuValCloneModel">-->
  80. <!--<input type="checkbox" class="model_sku_val" propvalid='' value="" />-->
  81. <!--<input type="text" class="cusSkuValInput" />-->
  82. <!--<a href="javascript:void(0);" class="delCusSkuVal">删除</a>-->
  83. <!--</li>-->
  84. <div class="clear"></div>
  85. <div id="skuTable">
  86. <table class="skuTable">
  87. <tbody>
  88. </tbody>
  89. </table>
  90. </div>
  91. <button class="layui-btn btn">获取json 数据</button>
  92. <script type="text/javascript" src="../js/sku/getSetSkuVals.js?1"></script>
  93. <script>
  94. // 模拟后台数据
  95. let moke = [{
  96. color: "土豪金", size: "64G", version: "港版", price: "6767", store: "57",
  97. propvalnames:{propvalids: "31,13,22", skuStock: "57", skuPrice: "6767"}},
  98. {
  99. color: "土豪金", size: "128G", version: "港版", price: "5675", store: "67",
  100. propvalnames:{
  101. propvalids: "31,14,22", skuStock: "67", skuPrice: "5675"}
  102. }
  103. ]
  104. for(let item of moke){
  105. console.log(item, '657657')
  106. let propvalids = item['propvalnames']['propvalids'].split(',')
  107. $(".sku_value").each(function (i, item) {
  108. let propvalid =$(this).attr('propvalid')
  109. if(propvalids.includes(propvalid) ){
  110. $(this).attr('checked', true)
  111. }
  112. })
  113. alreadySetSkuVals[item['propvalnames']['propvalids']] = {
  114. "skuPrice" : item['propvalnames']['skuPrice'],
  115. "skuStock" : item['propvalnames']['skuStock']
  116. }
  117. }
  118. createTab()
  119. $('.btn').on('click', () => {
  120. let tabTitles = ['color', 'size', 'version','price','store'];
  121. let arrJson = []
  122. let alreadySetSkuVals = [];
  123. //获取设置的SKU属性值
  124. $("tr[class*='sku_table_tr']").each(function (i, item) {
  125. let newObj = {}
  126. var skuPrice = $(this).find("input[type='text'][class*='setting_sku_price']").val() || 0;//SKU价格
  127. var skuStock = $(this).find("input[type='text'][class*='setting_sku_stock']").val() || 0;//SKU库存
  128. // if(skuPrice || skuStock){//已经设置了全部或部分值
  129. let propvalids = $(this).attr('propvalids')// 31,13,22
  130. let propvalnames = $(this).attr('propvalnames') // 土豪金;64G;港版
  131. let names = propvalnames.split(';')
  132. for (let j = 0; j < names.length; j++) {
  133. newObj[tabTitles[j]] = names[j]
  134. }
  135. newObj[tabTitles[names.length]] = skuPrice
  136. newObj[tabTitles[names.length + 1]] = skuStock
  137. newObj['propvalnames'] = {propvalids,skuStock, skuPrice}
  138. alreadySetSkuVals.push(newObj)
  139. });
  140. console.log(alreadySetSkuVals, '获取已经设置的SKU值')
  141. getAlreadySetSkuVals();//获取已经设置的SKU值
  142. })
  143. </script>
  144. </body>
  145. </html>