option.blade.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <link href="{{static_url('yunshop/goods/goods.css')}}" media="all" rel="stylesheet" type="text/css"/>
  2. <div class="form-group">
  3. <label class="col-xs-12 col-sm-3 col-md-2 control-label">是否启用{{$lang['shopoption']}}</label>
  4. <div class="col-sm-9 col-xs-12">
  5. <label class="checkbox-inline">
  6. <input type="checkbox" id="hasoption" value="1" name="goods[has_option]"
  7. @if($goods['has_option']==1) checked @endif />启用{{$lang['shopoption']}}
  8. </label>
  9. <span class="help-block">启用{{$lang['shopoption']}}后,商品的价格及库存以商品规格为准,库存设置为0则不显示,-1为不限制</span>
  10. </div>
  11. {{--<label class="col-xs-12 col-sm-3 col-md-2 control-label">是否启用新规格模板</label>
  12. <div class="col-sm-9 col-xs-12">
  13. <label class="checkbox-inline">
  14. <input type="checkbox" id="opt_switch" value="1" name="opt_switch"
  15. @if( $goods['opt_switch']==1) checked @endif />启用规格模板
  16. </label>
  17. <span class="help-block">新规格模板只在设置2组规格及不支持线下核销时显示</span>
  18. </div>--}}
  19. </div>
  20. <div id='tboption' style="@if( $goods['has_option']!=1) display:none @endif">
  21. <div class="alert alert-info">
  22. 1. 拖动规格可调整规格显示顺序, 更改规格及规格项后请点击下方的【刷新规格项目表】来更新数据。<br/>
  23. 2. 每一种规格代表不同型号,例如颜色为一种规格,尺寸为一种规格,如果设置多规格,手机用户必须每一种规格都选择一个规格项,才能添加购物车或购买。
  24. </div>
  25. <div id='specs'>
  26. @foreach ($allspecs as $spec)
  27. @include('goods.tpl.spec')
  28. @endforeach
  29. </div>
  30. <table class="table">
  31. <tr>
  32. <td>
  33. <h4><a href="javascript:;" class='btn btn-primary' id='add-spec' onclick="addSpec()" style="margin-top:10px;margin-bottom:10px;" title="添加规格"><i class='fa fa-plus'></i> 添加规格</a>
  34. <a href="javascript:;" onclick="calc()" title="刷新规格项目表" class="btn btn-primary"><i class="fa fa-refresh"></i> 刷新规格项目表</a>
  35. </h4>
  36. </td>
  37. </tr>
  38. </table>
  39. <div class="panel-body table-responsive" id="options" style="padding:0;">
  40. {!! $html !!}
  41. </div>
  42. </div>
  43. <div id="modal-module-chooestemp" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" style="width:600px;margin:0px auto;">
  44. <div class="modal-dialog">
  45. <div class="modal-content">
  46. <div class="modal-header">
  47. <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
  48. <h3>选择虚拟物品模板</h3>
  49. </div>
  50. <div class="modal-body">
  51. <div class="form-group">
  52. <label class="col-xs-12 col-sm-3 col-md-2 control-label" style='width: 150px'>选择模板:</label>
  53. <div class="col-sm-9 col-xs-12" style='width: 380px'>
  54. <select class="form-control tpl-category-parent">
  55. @foreach ($virtual_types as $virtual_type)
  56. <option value="{{$virtual_type['id']}}">{{$virtual_type['usedata']}}/{{$virtual_type['alldata']}} | {{$virtual_type['title']}}</option>
  57. @endforeach
  58. </select>
  59. </div>
  60. </div>
  61. </div>
  62. <div class="modal-footer">
  63. <span class="btn btn-primary span2" onclick="addtemp()">确认选择</span>
  64. <a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a>
  65. </div>
  66. </div>
  67. </div>
  68. </div>
  69. <script language="javascript">
  70. $(function () {
  71. /*$('#specs').sortable({
  72. stop: function(){
  73. window.optionchanged = true;
  74. }
  75. });
  76. $('.spec_item_items').sortable(
  77. {
  78. handle:'.fa-arrows',
  79. stop: function(){
  80. window.optionchanged = true;
  81. }
  82. }
  83. );*/
  84. $("#hasoption").click(function () {
  85. var obj = $(this);
  86. if (obj.get(0).checked) {
  87. $("#tboption").show();
  88. } else {
  89. $("#tboption").hide();
  90. }
  91. });
  92. })
  93. function addDataSpec() {
  94. $("#add-spec").html("正在处理...").attr("disabled", "true").toggleClass("btn-primary");
  95. var url = "{!! yzWebUrl('shop/tpl',array('tpl'=>'spec_data')) !!}";
  96. $.ajax({
  97. "url": url,
  98. success: function (data) {
  99. $("#add-spec").html('<i class="fa fa-plus"></i> 添加规格').removeAttr("disabled").toggleClass("btn-primary");
  100. ;
  101. $('#specs').append(data);
  102. var len = $(".add-specitem").length - 1;
  103. $(".add-specitem:eq(" + len + ")").focus();
  104. window.optionchanged = true;
  105. }
  106. });
  107. }
  108. function addSpec() {
  109. var len = $(".spec_item").length;
  110. if (type == 3 && virtual == 0 && len >= 1) {
  111. util.message('您的商品类型为:虚拟物品(卡密)的多规格形式,只能添加一种规格!');
  112. return;
  113. }
  114. $("#add-spec").html("正在处理...").attr("disabled", "true").toggleClass("btn-primary");
  115. var url = "{!! yzWebUrl('goods.goods.getSpecTpl',array('tpl'=>'spec')) !!}";
  116. $.ajax({
  117. "url": url,
  118. success: function (data) {
  119. $("#add-spec").html('<i class="fa fa-plus"></i> 添加规格').removeAttr("disabled").toggleClass("btn-primary");
  120. ;
  121. $('#specs').append(data);
  122. var len = $(".add-specitem").length - 1;
  123. $(".add-specitem:eq(" + len + ")").focus();
  124. window.optionchanged = true;
  125. }
  126. });
  127. }
  128. function removeSpec(specid) {
  129. if (confirm('确认要删除此规格?')) {
  130. $("#spec_" + specid).remove();
  131. window.optionchanged = true;
  132. }
  133. }
  134. function addSpecItem(specid) {
  135. $("#add-specitem-" + specid).html("正在处理...").attr("disabled", "true");
  136. var url = "{!! yzWebUrl('goods.goods.getSpecItemTpl',array('tpl'=>'specitem')) !!}" + "&specid=" + specid;
  137. $.ajax({
  138. "url": url,
  139. success: function (data) {
  140. $("#add-specitem-" + specid).html('<i class="fa fa-plus"></i> 添加规格项').removeAttr("disabled");
  141. $('#spec_item_' + specid).append(data);
  142. var len = $("#spec_" + specid + " .spec_item_title").length - 1;
  143. $("#spec_" + specid + " .spec_item_title:eq(" + len + ")").focus();
  144. window.optionchanged = true;
  145. if (type == 3 && virtual == 0) {
  146. $(".choosetemp").show();
  147. }
  148. }
  149. });
  150. }
  151. function removeSpecItem(obj) {
  152. $(obj).parent().parent().parent().remove();
  153. }
  154. function calc() {
  155. window.optionchanged = false;
  156. var html = '<table class="table table-bordered table-condensed"><thead><tr class="active">';
  157. var specs = [];
  158. if ($('.spec_item').length <= 0) {
  159. $("#options").html('');
  160. return;
  161. }
  162. $(".spec_item").each(function (i) {
  163. var _this = $(this);
  164. var spec = {
  165. id: _this.find(".spec_id").val(),
  166. title: _this.find(".spec_title").val()
  167. };
  168. var items = [];
  169. _this.find(".spec_item_item").each(function () {
  170. var __this = $(this);
  171. var item = {
  172. id: __this.find(".spec_item_id").val(),
  173. title: __this.find(".spec_item_title").val(),
  174. virtual: __this.find(".spec_item_virtual").val(),
  175. show: __this.find(".spec_item_show").get(0).checked ? "1" : "0"
  176. }
  177. items.push(item);
  178. });
  179. spec.items = items;
  180. specs.push(spec);
  181. });
  182. specs.sort(function (x, y) {
  183. if (x.items.length > y.items.length) {
  184. return 1;
  185. }
  186. if (x.items.length < y.items.length) {
  187. return -1;
  188. }
  189. });
  190. var len = specs.length;
  191. var newlen = 1;
  192. var h = new Array(len);
  193. var rowspans = new Array(len);
  194. for (var i = 0; i < len; i++) {
  195. html += "<th style='width:8%;'>" + specs[i].title + "</th>";
  196. var itemlen = specs[i].items.length;
  197. if (itemlen <= 0) {
  198. itemlen = 1
  199. }
  200. ;
  201. newlen *= itemlen;
  202. h[i] = new Array(newlen);
  203. for (var j = 0; j < newlen; j++) {
  204. h[i][j] = new Array();
  205. }
  206. var l = specs[i].items.length;
  207. rowspans[i] = 1;
  208. for (j = i + 1; j < len; j++) {
  209. rowspans[i] *= specs[j].items.length;
  210. }
  211. }
  212. html += '<th class="info" style="width:13%;"><div><div style="padding-bottom:10px;text-align:center;font-size:16px;">库存</div><div class="input-group"><input type="text" class="form-control option_stock_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_stock\');"></a></span></div></div></th>';
  213. html += '<th class="success" style="width:30%;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">市场价格</div><div class="input-group"><input type="text" class="form-control option_marketprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_marketprice\');"></a></span></div></div></th>';
  214. html += '<th class="warning" style="width:13%;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">现价</div><div class="input-group"><input type="text" class="form-control option_productprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_productprice\');"></a></span></div></div></th>';
  215. html += '<th class="danger" style="width:13%;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">成本价格</div><div class="input-group"><input type="text" class="form-control option_costprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_costprice\');"></a></span></div></div></th>';
  216. html += '<th class="warning" style="width:13%;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">红包价格</div><div class="input-group"><input type="text" class="form-control option_redprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_redprice\');"></a></span></div></div></th>';
  217. html += '<th class="primary" style="width:13%;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">商品编码</div><div class="input-group"><input type="text" class="form-control option_goodssn_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_goodssn\');"></a></span></div></div></th>';
  218. html += '<th class="danger" style="width:13%;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">商品条码</div><div class="input-group"><input type="text" class="form-control option_productsn_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_productsn\');"></a></span></div></div></th>';
  219. html += '<th class="info" style="width:13%;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">重量(克)</div><div class="input-group"><input type="text" class="form-control option_weight_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_weight\');"></a></span></div></div></th>';
  220. html += '</tr></thead>';
  221. for (var m = 0; m < len; m++) {
  222. var k = 0, kid = 0, n = 0;
  223. for (var j = 0; j < newlen; j++) {
  224. var rowspan = rowspans[m];
  225. if (j % rowspan == 0) {
  226. h[m][j] = {
  227. title: specs[m].items[kid].title,
  228. virtual: specs[m].items[kid].virtual,
  229. html: "<td rowspan='" + rowspan + "'>" + specs[m].items[kid].title + "</td>\r\n",
  230. id: specs[m].items[kid].id
  231. };
  232. }
  233. else {
  234. h[m][j] = {
  235. title: specs[m].items[kid].title,
  236. virtual: specs[m].items[kid].virtual,
  237. html: "",
  238. id: specs[m].items[kid].id
  239. };
  240. }
  241. n++;
  242. if (n == rowspan) {
  243. kid++;
  244. if (kid > specs[m].items.length - 1) {
  245. kid = 0;
  246. }
  247. n = 0;
  248. }
  249. }
  250. }
  251. var hh = "";
  252. for (var i = 0; i < newlen; i++) {
  253. hh += "<tr>";
  254. var ids = [];
  255. var titles = [];
  256. var virtuals = [];
  257. for (var j = 0; j < len; j++) {
  258. hh += h[j][i].html;
  259. ids.push(h[j][i].id);
  260. titles.push(h[j][i].title);
  261. virtuals.push(h[j][i].virtual);
  262. }
  263. ids = ids.join('_');
  264. titles = titles.join('+');
  265. var val = {
  266. id: "",
  267. title: titles,
  268. stock: "",
  269. costprice: "",
  270. productprice: "",
  271. marketprice: "",
  272. weight: "",
  273. productsn: "",
  274. goodssn: "",
  275. virtual: virtuals,
  276. redprice: ""
  277. };
  278. if ($(".option_id_" + ids).length > 0) {
  279. val = {
  280. id: $(".option_id_" + ids + ":eq(0)").val(),
  281. title: titles,
  282. stock: $(".option_stock_" + ids + ":eq(0)").val(),
  283. costprice: $(".option_costprice_" + ids + ":eq(0)").val(),
  284. productprice: $(".option_productprice_" + ids + ":eq(0)").val(),
  285. marketprice: $(".option_marketprice_" + ids + ":eq(0)").val(),
  286. goodssn: $(".option_goodssn_" + ids + ":eq(0)").val(),
  287. productsn: $(".option_productsn_" + ids + ":eq(0)").val(),
  288. weight: $(".option_weight_" + ids + ":eq(0)").val(),
  289. virtual: virtuals,
  290. redprice: $(".option_redprice_" + ids + ":eq(0)").val(),
  291. }
  292. }
  293. hh += '<td class="info">'
  294. hh += '<input name="option_stock_' + ids + '[]"type="text" class="form-control option_stock option_stock_' + ids + '" value="' + (val.stock == 'undefined' ? '' : val.stock ) + '"/></td>';
  295. hh += '<input name="option_id_' + ids + '[]"type="hidden" class="form-control option_id option_id_' + ids + '" value="' + (val.id == 'undefined' ? '' : val.id ) + '"/>';
  296. hh += '<input name="option_ids[]"type="hidden" class="form-control option_ids option_ids_' + ids + '" value="' + ids + '"/>';
  297. hh += '<input name="option_title_' + ids + '[]"type="hidden" class="form-control option_title option_title_' + ids + '" value="' + (val.title == 'undefined' ? '' : val.title ) + '"/></td>';
  298. hh += '<input name="option_virtual_' + ids + '[]"type="hidden" class="form-control option_title option_title_' + ids + '" value="' + (val.virtual == 'undefined' ? '' : val.virtual ) + '"/></td>';
  299. hh += '</td>';
  300. hh += '<td class="success"><input name="option_marketprice_' + ids + '[]" type="text" class="form-control option_marketprice option_marketprice_' + ids + '" value="' + (val.marketprice == 'undefined' ? '' : val.marketprice ) + '"/>';
  301. hh += '</td>';
  302. hh += '<td class="warning"><input name="option_productprice_' + ids + '[]" type="text" class="form-control option_productprice option_productprice_' + ids + '" " value="' + (val.productprice == 'undefined' ? '' : val.productprice ) + '"/></td>';
  303. hh += '<td class="danger"><input name="option_costprice_' + ids + '[]" type="text" class="form-control option_costprice option_costprice_' + ids + '" " value="' + (val.costprice == 'undefined' ? '' : val.costprice ) + '"/></td>';
  304. hh += '<td class="warning"><input name="option_redprice_' + ids + '[]" type="text" class="form-control option_redprice option_redprice_' + ids + '" " value="' + (val.redprice == 'undefined' ? '' : val.redprice ) + '"/></td>';
  305. hh += '<td class="primary"><input name="option_goodssn_' + ids + '[]" type="text" class="form-control option_goodssn option_goodssn_' + ids + '" " value="' + (val.goodssn == 'undefined' ? '' : val.goodssn ) + '"/></td>';
  306. hh += '<td class="danger"><input name="option_productsn_' + ids + '[]" type="text" class="form-control option_productsn option_productsn_' + ids + '" " value="' + (val.productsn == 'undefined' ? '' : val.productsn ) + '"/></td>';
  307. hh += '<td class="info"><input name="option_weight_' + ids + '[]" type="text" class="form-control option_weight option_weight_' + ids + '" " value="' + (val.weight == 'undefined' ? '' : val.weight ) + '"/></td>';
  308. hh += "</tr>";
  309. }
  310. html += hh;
  311. html += "</table>";
  312. $("#options").html(html);
  313. }
  314. function setCol(cls) {
  315. $("." + cls).val($("." + cls + "_all").val());
  316. }
  317. function showItem(obj) {
  318. var show = $(obj).get(0).checked ? "1" : "0";
  319. $(obj).next().val(show);
  320. }
  321. function nofind() {
  322. var img = event.srcElement;
  323. img.src = "./resource/image/module-nopic-small.jpg";
  324. img.onerror = null;
  325. }
  326. function choosetemp(id) {
  327. $('#modal-module-chooestemp').modal();
  328. $('#modal-module-chooestemp').data("temp", id);
  329. }
  330. function addtemp() {
  331. var id = $('#modal-module-chooestemp').data("temp");
  332. var temp_id = $('#modal-module-chooestemp').find("select").val();
  333. var temp_name = $('#modal-module-chooestemp option[value=' + temp_id + ']').text();
  334. //alert(temp_id+":"+temp_name);
  335. $("#temp_name_" + id).val(temp_name);
  336. $("#temp_id_" + id).val(temp_id);
  337. $('#modal-module-chooestemp .close').click();
  338. window.optionchanged = true;
  339. }
  340. calc();//酒店的商品规格中,规格项目列表的图片列不需要,但是页面第一次加载的时候会出现,所以在这里添加该方法,冲刷掉后台传出的html
  341. </script>