option.blade.php 21 KB

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