12option.blade.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <style type="text/css">
  2. .spectable td,.spectable th {border:1px solid #ccc; vertical-align: middle;text-align:center;}
  3. .spectable th { font-weight: bold;}
  4. .spectableinput { text-align: center;}
  5. .f {border-color: #b94a48;-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);-moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);}
  6. .table.table-bordered tr th,.table.table-bordered tr td{overflow:hidden; text-overflow:ellipsis;}
  7. </style>
  8. <div class="form-group">
  9. <label class="col-xs-12 col-sm-3 col-md-2 control-label">是否启用{{$lang['shopoption']}}</label>
  10. <div class="col-sm-9 col-xs-12">
  11. <label class="checkbox-inline">
  12. <input type="checkbox" id="hasoption" value="1" name="hasoption" @if ($goods['hasoption']==1)checked @endif />启用{{$lang['shopoption']}}
  13. </label>
  14. <span class="help-block">启用{{$lang['shopoption']}}后,商品的价格及库存以商品规格为准,库存设置为0则不显示,-1为不限制</span>
  15. </div>
  16. <label class="col-xs-12 col-sm-3 col-md-2 control-label">是否启用新规格模板</label>
  17. <div class="col-sm-9 col-xs-12">
  18. <label class="checkbox-inline">
  19. <input type="checkbox" id="opt_switch" value="1" name="opt_switch" @if ($goods['opt_switch']==1)checked @endif />启用规格模板
  20. </label>
  21. <span class="help-block">新规格模板只在设置2组规格及不支持线下核销时显示</span>
  22. </div>
  23. </div>
  24. <div id='tboption' style="@if ($goods['hasoption']!=1)display:none @endif">
  25. <div class="alert alert-info">
  26. 1. 拖动规格可调整规格显示顺序, 更改规格及规格项后请点击下方的【刷新规格项目表】来更新数据。<br/>
  27. 2. 每一种规格代表不同型号,例如颜色为一种规格,尺寸为一种规格,如果设置多规格,手机用户必须每一种规格都选择一个规格项,才能添加购物车或购买。<br/>
  28. 3. 前端规格项按添加倒序显示。
  29. </div>
  30. <div id='specs'>
  31. @foreach ($allspecs as $spec)
  32. @include('goods.tpl.spec')
  33. @endforeach
  34. </div>
  35. <table class="table">
  36. <tr>
  37. <td>
  38. <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>
  39. <a href="javascript:;" onclick="calc()" title="刷新规格项目表" class="btn btn-primary"><i class="fa fa-refresh"></i> 刷新规格项目表</a>
  40. </h4>
  41. </td>
  42. </tr>
  43. </table>
  44. <div class="panel-body table-responsive" id="options" style="padding:0;">
  45. {!! $html !!}
  46. </div>
  47. </div>
  48. <div id="modal-module-chooestemp" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" style="width:600px;margin:0px auto;">
  49. <div class="modal-dialog">
  50. <div class="modal-content">
  51. <div class="modal-header">
  52. <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
  53. <h3>选择虚拟物品模板</h3>
  54. </div>
  55. <div class="modal-body">
  56. <div class="form-group">
  57. <label class="col-xs-12 col-sm-3 col-md-2 control-label" style='width: 150px'>选择模板:</label>
  58. <div class="col-sm-9 col-xs-12" style='width: 380px'>
  59. <select class="form-control tpl-category-parent">
  60. @foreach ($virtual_types as $virtual_type)
  61. <option value="{{$virtual_type['id']}}">{{$virtual_type['usedata']}}/{{$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. $('#specs').sortable({
  77. stop: function(){
  78. window.optionchanged = true;
  79. }
  80. });
  81. $('.spec_item_items').sortable(
  82. {
  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 = "{php echo $this->createWebUrl('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. $('#specs').append(data);
  106. var len = $(".add-specitem").length -1;
  107. $(".add-specitem:eq(" +len+ ")").focus();
  108. window.optionchanged = true;
  109. }
  110. });
  111. }
  112. function addSpec(){
  113. var len = $(".spec_item").length;
  114. if(type==3 && virtual==0 && len>=1){
  115. util.message('您的商品类型为:虚拟物品(卡密)的多规格形式,只能添加一种规格!');
  116. return;
  117. }
  118. $("#add-spec").html("正在处理...").attr("disabled", "true").toggleClass("btn-primary");
  119. var url = "{php echo $this->createWebUrl('goods.goods.getSpecTpl',array('tpl'=>'spec'))}";
  120. $.ajax({
  121. "url": url,
  122. success:function(data){
  123. $("#add-spec").html('<i class="fa fa-plus"></i> 添加规格').removeAttr("disabled").toggleClass("btn-primary"); ;
  124. $('#specs').append(data);
  125. var len = $(".add-specitem").length -1;
  126. $(".add-specitem:eq(" +len+ ")").focus();
  127. window.optionchanged = true;
  128. }
  129. });
  130. }
  131. function removeSpec(specid){
  132. if (confirm('确认要删除此规格?')){
  133. $("#spec_" + specid).remove();
  134. window.optionchanged = true;
  135. }
  136. }
  137. function addSpecItem(specid){
  138. $("#add-specitem-" + specid).html("正在处理...").attr("disabled", "true");
  139. var url = "{php echo$this->createWebUrl('goods.goods.getSpecItemTpl',array('tpl'=>'specitem'))}" + "&specid=" + specid;
  140. $.ajax({
  141. "url": url,
  142. success:function(data){
  143. $("#add-specitem-" + specid).html('<i class="fa fa-plus"></i> 添加规格项').removeAttr("disabled");
  144. $('#spec_item_' + specid).append(data);
  145. var len = $("#spec_" + specid + " .spec_item_title").length -1;
  146. $("#spec_" + specid + " .spec_item_title:eq(" +len+ ")").focus();
  147. window.optionchanged = true;
  148. if(type==3 && virtual==0){
  149. $(".choosetemp").show();
  150. }
  151. }
  152. });
  153. }
  154. function removeSpecItem(obj){
  155. $(obj).parent().parent().parent().remove();
  156. }
  157. function calc(){
  158. window.optionchanged = false;
  159. var html = '<table class="table table-bordered table-condensed"><thead><tr class="active">';
  160. var specs = [];
  161. if($('.spec_item').length<=0){
  162. $("#options").html('');
  163. return;
  164. }
  165. $(".spec_item").each(function(i){
  166. var _this = $(this);
  167. var spec = {
  168. id: _this.find(".spec_id").val(),
  169. title: _this.find(".spec_title").val()
  170. };
  171. var items = [];
  172. _this.find(".spec_item_item").each(function(){
  173. var __this = $(this);
  174. var item = {
  175. id: __this.find(".spec_item_id").val(),
  176. title: __this.find(".spec_item_title").val(),
  177. virtual: __this.find(".spec_item_virtual").val(),
  178. show:__this.find(".spec_item_show").get(0).checked?"1":"0"
  179. }
  180. items.push(item);
  181. });
  182. spec.items = items;
  183. specs.push(spec);
  184. });
  185. specs.sort(function(x,y){
  186. if (x.items.length > y.items.length){
  187. return 1;
  188. }
  189. if (x.items.length < y.items.length) {
  190. return -1;
  191. }
  192. });
  193. var len = specs.length;
  194. var newlen = 1;
  195. var h = new Array(len);
  196. var rowspans = new Array(len);
  197. for(var i=0;i<len;i++){
  198. html+="<th style='width:8%;'>" + specs[i].title + "</th>";
  199. var itemlen = specs[i].items.length;
  200. if(itemlen<=0) { itemlen = 1 };
  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;">{{$lang[marketprice]}}</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;">{{$lang[shopnumber]}}</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]={title: specs[m].items[kid].title, virtual: specs[m].items[kid].virtual,html: "<td rowspan='" +rowspan + "'>"+ specs[m].items[kid].title+"</td>\r\n",id: specs[m].items[kid].id};
  227. }
  228. else{
  229. h[m][j]={title:specs[m].items[kid].title,virtual: specs[m].items[kid].virtual, html: "",id: specs[m].items[kid].id};
  230. }
  231. n++;
  232. if(n==rowspan){
  233. kid++; if(kid>specs[m].items.length-1) { kid=0; }
  234. n=0;
  235. }
  236. }
  237. }
  238. var hh = "";
  239. for(var i=0;i<newlen;i++){
  240. hh+="<tr>";
  241. var ids = [];
  242. var titles = [];
  243. var virtuals = [];
  244. for(var j=0;j<len;j++){
  245. hh+=h[j][i].html;
  246. ids.push( h[j][i].id);
  247. titles.push( h[j][i].title);
  248. virtuals.push( h[j][i].virtual);
  249. }
  250. ids =ids.join('_');
  251. titles= titles.join('+');
  252. var val ={ id : "",title:titles, stock : "",costprice : "",productprice : "",marketprice : "",weight:"",productsn:"",goodssn:"",virtual:virtuals,redprice:"" };
  253. if( $(".option_id_" + ids).length>0){
  254. val ={
  255. id : $(".option_id_" + ids+":eq(0)").val(),
  256. title: titles,
  257. stock : $(".option_stock_" + ids+":eq(0)").val(),
  258. costprice : $(".option_costprice_" + ids+":eq(0)").val(),
  259. productprice : $(".option_productprice_" + ids+":eq(0)").val(),
  260. marketprice : $(".option_marketprice_" + ids +":eq(0)").val(),
  261. goodssn : $(".option_goodssn_" + ids +":eq(0)").val(),
  262. productsn : $(".option_productsn_" + ids +":eq(0)").val(),
  263. weight : $(".option_weight_" + ids+":eq(0)").val(),
  264. virtual : virtuals,
  265. redprice : $(".option_redprice_" + ids+":eq(0)").val(),
  266. }
  267. }
  268. hh += '<td class="info">'
  269. hh += '<input name="option_stock_' + ids +'[]"type="text" class="form-control option_stock option_stock_' + ids +'" value="' +(val.stock=='undefined'?'':val.stock )+'"/></td>';
  270. hh += '<input name="option_id_' + ids+'[]"type="hidden" class="form-control option_id option_id_' + ids +'" value="' +(val.id=='undefined'?'':val.id )+'"/>';
  271. hh += '<input name="option_ids[]"type="hidden" class="form-control option_ids option_ids_' + ids +'" value="' + ids +'"/>';
  272. hh += '<input name="option_title_' + ids +'[]"type="hidden" class="form-control option_title option_title_' + ids +'" value="' +(val.title=='undefined'?'':val.title )+'"/></td>';
  273. hh += '<input name="option_virtual_' + ids +'[]"type="hidden" class="form-control option_title option_title_' + ids +'" value="' +(val.virtual=='undefined'?'':val.virtual )+'"/></td>';
  274. hh += '</td>';
  275. 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 )+'"/>';
  276. hh += '</td>';
  277. 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>';
  278. 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>';
  279. 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>';
  280. 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>';
  281. 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>';
  282. 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>';
  283. hh += "</tr>";
  284. }
  285. html+=hh;
  286. html+="</table>";
  287. $("#options").html(html);
  288. }
  289. function setCol(cls){
  290. $("."+cls).val( $("."+cls+"_all").val());
  291. }
  292. function showItem(obj){
  293. var show = $(obj).get(0).checked?"1":"0";
  294. $(obj).next().val(show);
  295. }
  296. function nofind(){
  297. var img=event.srcElement;
  298. img.src="./resource/image/module-nopic-small.jpg";
  299. img.onerror=null;
  300. }
  301. function choosetemp(id){
  302. $('#modal-module-chooestemp').modal();
  303. $('#modal-module-chooestemp').data("temp",id);
  304. }function addtemp(){
  305. var id = $('#modal-module-chooestemp').data("temp");
  306. var temp_id = $('#modal-module-chooestemp').find("select").val();
  307. var temp_name = $('#modal-module-chooestemp option[value='+temp_id+']').text();
  308. //alert(temp_id+":"+temp_name);
  309. $("#temp_name_"+id).val(temp_name);
  310. $("#temp_id_"+id).val(temp_id);
  311. $('#modal-module-chooestemp .close').click();
  312. window.optionchanged = true;
  313. }
  314. </script>