03853ec019c37d410d897beae5607b60.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <?php /*a:3:{s:67:"D:\project\gyx\gaoyixia\application\mall\view\store_goods\form.html";i:1704700772;s:56:"D:\project\gyx\gaoyixia\application\admin\view\main.html";i:1699858976;s:73:"D:\project\gyx\gaoyixia\application\mall\view\store_goods\form_style.html";i:1699858976;}*/ ?>
  2. <div class="layui-card layui-bg-gray"><?php if(!(empty($title) || (($title instanceof \think\Collection || $title instanceof \think\Paginator ) && $title->isEmpty()))): ?><div class="layui-card-header layui-anim layui-anim-fadein notselect"><span class="layui-icon layui-icon-next font-s10 color-desc margin-right-5"></span><?php echo htmlentities((isset($title) && ($title !== '')?$title:'')); ?><div class="pull-right"></div></div><?php endif; ?><div class="layui-card-body layui-anim layui-anim-upbit"><style> .inner-input {
  3. width: 80px;
  4. height: 14px;
  5. padding: 1px 5px;
  6. line-height: 12px;
  7. }
  8. .goods-spec-box {
  9. position: relative;
  10. margin: 0 10px 10px 0;
  11. vertical-align: middle;
  12. }
  13. .goods-spec-title {
  14. z-index: 2;
  15. width: 40px;
  16. color: #fff;
  17. height: 28px;
  18. position: absolute;
  19. background: #999;
  20. line-height: 28px;
  21. }
  22. .goods-spec-close {
  23. right: 8px;
  24. z-index: 2;
  25. line-height: 28px;
  26. position: absolute;
  27. display: inline-block
  28. }
  29. .goods-spec-btn {
  30. height: 28px;
  31. margin-left: 5px !important;
  32. line-height: 26px !important;
  33. }
  34. .goods-spec-box input {
  35. z-index: 1;
  36. width: 120px;
  37. position: relative;
  38. border: 1px solid #999;
  39. padding: 5px 0 5px 45px;
  40. display: inline-block !important;
  41. }
  42. .goods-spec-box input[type=checkbox] {
  43. z-index: 2;
  44. width: 40px;
  45. height: 28px;
  46. border: none;
  47. cursor: pointer;
  48. appearance: none;
  49. position: absolute;
  50. -webkit-appearance: none;
  51. }
  52. .goods-spec-box input[type=checkbox]:before {
  53. top: 1px;
  54. left: 1px;
  55. width: 40px;
  56. height: 26px;
  57. content: ' ';
  58. position: absolute;
  59. background: #c9c9c9;
  60. }
  61. .goods-spec-box input[type=checkbox]:after {
  62. top: 1px;
  63. left: 1px;
  64. color: #999;
  65. width: 40px;
  66. height: 26px;
  67. content: '\e63f';
  68. font-size: 16px;
  69. line-height: 26px;
  70. position: absolute;
  71. text-align: center;
  72. font-family: 'layui-icon';
  73. }
  74. .goods-spec-box input[type=checkbox]:checked:after {
  75. color: #333;
  76. content: '\e605';
  77. }
  78. </style><style> .layui-form-radio{
  79. margin: 0 !important;
  80. padding-right:0 !important;
  81. }
  82. .layui-form-select{
  83. margin-right: 10px !important;
  84. }
  85. .spec_over_td img{
  86. width: 50px;
  87. height: 50px;
  88. }
  89. </style><form onsubmit="return false;" id="GoodsForm" data-auto="true" method="post" class='layui-form layui-card' autocomplete="off"><div class="layui-card-body think-box-shadow padding-left-40"><div class="layui-tab"><ul class="layui-tab-title"><li class="layui-this">基础设置</li><li>规格设置</li></ul><div class="layui-tab-content"><!--基础设置--><div class="layui-tab-item layui-show"><!--基础设置start--><div class="layui-form-item layui-row layui-col-space15"><label class="layui-col-xs9 relative"><span class="color-green">商品名称</span><input name="name" required class="layui-input" placeholder="请输入商品名称" value="<?php echo htmlentities((isset($vo['name']) && ($vo['name'] !== '')?$vo['name']:'')); ?>"></label></div><div class="layui-form-item layui-row layui-col-space15"><label class="layui-col-xs9 relative"><span class="color-green">副标题</span><input name="desc" required class="layui-input" placeholder="请输入商品副标题" value="<?php echo htmlentities((isset($vo['desc']) && ($vo['desc'] !== '')?$vo['desc']:'')); ?>"></label></div><div class="layui-form-item layui-row layui-col-space15"><label class="layui-col-xs3 relative"><span class="color-green">会员账号</span><input name="phone" class="layui-input" placeholder="请输入会员账号" value="<?php echo htmlentities((isset($vo['phone']) && ($vo['phone'] !== '')?$vo['phone']:'')); ?>"></label><label class="layui-col-xs3 relative"><span class="color-green">热搜阅读量</span><input name="hot_num" class="layui-input" placeholder="请输入热搜阅读量" value="<?php echo htmlentities((isset($vo['hot_num']) && ($vo['hot_num'] !== '')?$vo['hot_num']:'')); ?>"><input name="hot_num_old" type="hidden" value='<?php echo htmlentities((isset($vo['hot_num']) && ($vo['hot_num'] !== '')?$vo['hot_num']:"")); ?>' class="layui-input"></label><label class="layui-col-xs3 relative"><span class="color-green">上架时间</span><input name="release_time" id="release_time" class="layui-input" placeholder="" value="<?php echo htmlentities((isset($vo['release_time']) && ($vo['release_time'] !== '')?$vo['release_time']:'')); ?>"></label></div><div class="layui-form-item layui-row layui-col-space15"><label class="layui-col-xs9 relative"><span class="color-green">标签</span><textarea placeholder="请输入标签" maxlength="100" class="layui-textarea" name="label"><?php echo htmlentities((isset($vo['label']) && ($vo['label'] !== '')?$vo['label']:'')); ?></textarea><span >多个用逗号隔开(半角)</span></label></div><!-- 商品分类--><div class="layui-form-item layui-row layui-col-space15"><label class="layui-col-xs9 relative" style="width: 100%;"><span class="color-green">商品分类</span></label><div style="width: 100%"><div style="width: 15%;float: left;"><select class="layui-select" id="first_classify" name="first_classify" lay-filter="first_classify" lay-search><option selected data-first_key="-1" selected value="0">请选择</option><?php if(!empty($goods_cate)): foreach($goods_cate as $ck=>$cv): if(isset_full_check($vo,'first_classify',$cv['id'])): ?><option selected data-first_key="<?php echo htmlentities($ck); ?>" value="<?php echo htmlentities($cv['id']); ?>"><?php echo htmlentities($cv['title']); ?></option><?php else: ?><option data-first_key="<?php echo htmlentities($ck); ?>" value="<?php echo htmlentities($cv['id']); ?>"><?php echo htmlentities($cv['title']); ?></option><?php endif; ?><?php endforeach; ?><?php endif; ?></select></div><div style="width: 15%;float: left"><select class="layui-select" id="second_classify" name="second_classify" lay-filter="second_classify" lay-search></select></div><div style="width: 15%;float: left"><select class="layui-select" id="third_classify" name="third_classify" lay-filter="third_classify" lay-search></select></div><input type="hidden" id="first" value="<?php echo htmlentities((isset($vo['first_classify']) && ($vo['first_classify'] !== '')?$vo['first_classify']:'-1')); ?>"/><input type="hidden" id="second" value="<?php echo htmlentities((isset($vo['second_classify']) && ($vo['second_classify'] !== '')?$vo['second_classify']:'-1')); ?>"/><input type="hidden" id="third" value="<?php echo htmlentities((isset($vo['third_classify']) && ($vo['third_classify'] !== '')?$vo['third_classify']:'-1')); ?>"/></div></div><div class="layui-form-item"><span class="color-green label-required-prev">商品LOGO及轮播展示图片</span><table class="layui-table"><thead><tr><th class="text-center">LOGO</th><th class="text-left">轮播图</th></tr><tr><td width="90px" class="text-center"><input name="cover" type="hidden" value="<?php echo htmlentities((isset($vo['cover']) && ($vo['cover'] !== '')?$vo['cover']:'')); ?>"></td><td width="auto" class="text-left"><input name="image" type="hidden" value="<?php echo htmlentities((isset($vo['image']) && ($vo['image'] !== '')?$vo['image']:'')); ?>"></td></tr></thead></table><script>$('[name="cover"]').uploadOneImage(), $('[name="image"]').uploadMultipleImage()</script></div><div class="layui-form-item"><span class="color-green label-required-prev">商品详情图</span><textarea name="content"><?php echo htmlentities((isset($vo['content']) && ($vo['content'] !== '')?$vo['content']:"")); ?></textarea><!-- <table class="layui-table">--><!-- <thead>--><!-- <tr>--><!-- <td width="auto" class="text-left"><input name="content" type="hidden" value="<?php echo htmlentities((isset($vo['content']) && ($vo['content'] !== '')?$vo['content']:'')); ?>"></td>--><!-- </tr>--><!-- </thead>--><!-- </table>--><!-- <script>$('[name="content"]').uploadMultipleImage()</script>--></div><!-- 运费设置--><div class="freight_box"><div class="layui-form-item layui-row layui-col-space15"><label class="layui-col-xs9 relative" style="width: 100%;"><span class="color-green">模板开关</span><div class="layui-input-block margin-left-0 margin-top-15"><label ><input type="radio" class="layui-input" value="0" name="freight_type" lay-filter="freight_type" <?php if(!isset($vo['freight_type']) || !$vo['freight_type']): ?>checked<?php endif; ?> ></label><span class="margin-right-10">固定运费</span><label><input type="radio" class="layui-input" value="1" name="freight_type" lay-filter="freight_type" <?php if(isset($vo['freight_type']) && $vo['freight_type']): ?>checked<?php endif; ?> ></label><span class="margin-right-10">运费模板</span></div></label></div><div class="layui-form-item layui-row layui-col-space15 freight_mud" <?php if(!isset($vo['freight_type']) || !$vo['freight_type']): ?>style="display:none"<?php endif; ?>><label class="layui-col-xs9 relative" style="width: 100%;"><span class="color-green">运费模板</span><select name="freight_id" class="layui-select" lay-filter ="freight_id"><option value="0" >请选择</option><?php if(!empty($express)): foreach($express as $tk=>$tv): if(isset($vo['freight_id']) && $vo['freight_id'] ==$tv['id']): ?><option selected value="<?php echo htmlentities($tv['id']); ?>"><?php echo htmlentities($tv['name']); ?></option><?php else: ?><option value="<?php echo htmlentities($tv['id']); ?>"><?php echo htmlentities($tv['name']); ?></option><?php endif; ?><?php endforeach; ?><?php endif; ?></select></label></div><div class="layui-form-item layui-row layui-col-space15 postage" <?php if(isset($vo['freight_type']) && $vo['freight_type']): ?>style="display:none"<?php endif; ?>><label class="layui-col-xs9 relative" style="width: 100%;"><span class="color-green">虚拟销量</span><input type="number" step="1" min="0" name="sale_num" value="<?php echo htmlentities((isset($vo['sale_num']) && ($vo['sale_num'] !== '')?$vo['sale_num']:'')); ?>" class="layui-input"></label><label class="layui-col-xs9 relative" style="width: 100%;"><span class="color-green">运费金额</span><input type="number" step="1" min="0" name="postage" value="<?php echo htmlentities((isset($vo['postage']) && ($vo['postage'] !== '')?$vo['postage']:'')); ?>" class="layui-input"></label><div class="layui-form-mid layui-word-aux" style="margin-left: 10px">不填(或0)表示包邮</div></div></div><!-- 运费设置 end--></div><!--规格设置start--><div class="layui-tab-item"><div class="layui-form-item"><span class="color-green label-required-prev">商品规格及商品SKU绑定<span class="color-red font-s12">(规格填写后不允许再次修改)</span></span><div ng-repeat="x in specs track by $index" style="display:none" class="margin-bottom-10" ng-class="{true:'layui-show'}[isAddMode&&specs.length>0]"><div class="goods-spec-box padding-10 margin-0 relative" style="background:#ddd"><span class="text-center goods-spec-title">分组</span><label class="label-required-null inline-block"><input ng-blur="x.name=trimSpace(x.name)" ng-model="x.name" required placeholder="请输入分组名称"></label><div class="pull-right"><a class="layui-btn layui-btn-sm layui-btn-primary goods-spec-btn" ng-click="addSpecVal(x.list)">增加</a><a class="layui-btn layui-btn-sm layui-btn-primary goods-spec-btn" ng-class="{false:'layui-bg-gray'}[$index>0]" ng-click="upSpecRow(specs,$index)">上移</a><a class="layui-btn layui-btn-sm layui-btn-primary goods-spec-btn" ng-class="{false:'layui-bg-gray'}[$index<specs.length-1]" ng-click="dnSpecRow(specs,$index)">下移</a><a class="layui-btn layui-btn-sm layui-btn-primary goods-spec-btn" ng-click="delSpecRow(specs,$index)" ng-if="specs.length>1">删除</a></div></div><div class="goods-spec-box padding-10 margin-0 layui-bg-gray block relative" ng-if="x.list && x.list.length > 0"><label class="label-required-null inline-block margin-right-10 margin-bottom-5 relative nowrap" ng-repeat="xx in x.list"><input type="checkbox" lay-ignore ng-model="xx.check" ng-click="xx.check=checkListChecked(x.list,$event.target.checked)"><input type="text" ng-blur="xx.name=trimSpace(xx.name)" ng-model="xx.name" ng-keyup="xx.name=$event.target.value" required placeholder="请输入规格"><a ng-if="x.list.length>1" ng-click="x.list=delSpecVal(x.list,$index)" class="layui-icon layui-icon-close font-s12 goods-spec-close"></a></label></div></div><a ng-if="isAddMode&&specs.length<5" class="layui-btn layui-btn-sm layui-btn-primary" ng-click="addSpecRow(specs)">增加分组</a><table class="layui-table margin-top-10"><thead><tr><th ng-repeat="x in specsTreeNava track by $index" class="nowrap" ng-bind="x"></th><th class="text-center nowrap">规格图片</th><th width="10%" class="text-center nowrap">商品SKU <a ng-click="batchSet('sku',null)" data-tips-text="批量设置" class="layui-icon">&#xe63c;</a></th><th width="10%" class="text-center nowrap">市场价格 <a ng-click="batchSet('original_price',2)" data-tips-text="批量设置" class="layui-icon">&#xe63c;</a></th><th width="10%" class="text-center nowrap">销售价格 <a ng-click="batchSet('sell_price',2)" data-tips-text="批量设置" class="layui-icon">&#xe63c;</a></th><th width="10%" class="text-center nowrap" style="display: none">虚拟销量 <a ng-click="batchSet('virtual',0)" data-tips-text="批量设置" class="layui-icon">&#xe63c;</a></th><th width="10%" class="text-center nowrap">重量(KG)<a ng-click="batchSet('weight',2)" data-tips-text="批量设置" class="layui-icon">&#xe63c;</a></th><th width="10%" class="text-center nowrap">销售状态</th></tr></thead><tbody><input type="hidden" id="up_img" value="-1" /><tr ng-repeat="rows in specsTreeData track by $index"><td class="layui-bg-gray" ng-if="td.show" rowspan="{{td.span}}" ng-repeat="td in rows" ng-bind="td.name"></td><td style="width: 60px;height: 60px" class="padding-10 spec_over_td"><img class="up_img" src="{{rows[0].spec_cover}}" alt="sku图片"><input style="display: none" type="file" accept="image/png,image/jpeg,image/gif" name="file" onchange="upload_img(this)"><input type="hidden" name="spec_cover[]" class="layui-input border-0 padding-left-0 text-center" ng-model="rows[0].spec_cover"></td><td class="padding-0"><label class="padding-0 margin-0"><input ng-blur="rows[0].sku=setValue(rows[0].key,'sku',$event.target.value)" class="layui-input border-0 padding-left-0 text-center" ng-model="rows[0].sku"></label></td><td class="padding-0"><label class="padding-0 margin-0"><input ng-blur="rows[0].original_price=setValue(rows[0].key,'original_price',$event.target.value,'(parseFloat(_)||0).toFixed(2)')" class="layui-input border-0 padding-left-0 text-center" ng-model="rows[0].original_price"></label></td><td class="padding-0"><label class="padding-0 margin-0"><input ng-blur="rows[0].sell_price=setValue(rows[0].key,'sell_price',$event.target.value,'(parseFloat(_)||0).toFixed(2)')" class="layui-input border-0 padding-left-0 text-center" ng-model="rows[0].sell_price"></label></td><td class="padding-0" style="display: none"><label class="padding-0 margin-0"><input ng-blur="rows[0].virtual=setValue(rows[0].key,'virtual',$event.target.value,'(parseInt(_)||0)')" class="layui-input border-0 padding-left-0 text-center" ng-model="rows[0].virtual"></label></td><td class="padding-0"><label class="padding-0 margin-0"><input ng-blur="rows[0].weight=setValue(rows[0].key,'weight',$event.target.value,'(parseInt(_)||0).toFixed(2)')" class="layui-input border-0 padding-left-0 text-center" ng-model="rows[0].weight"></label></td><td class="text-center layui-bg-gray"><label class="think-checkbox margin-0 full-width full-height block"><input lay-ignore type="checkbox" ng-model="rows[0].status"></label></td></tr></tbody></table><p class="color-desc">请从仓储平台获取商品SKU与商品条码,请注意尽量不要重复,也不能产生订单后再修改!</p><textarea class="layui-textarea layui-hide" name="specs">{{specs}}</textarea><textarea class="layui-textarea layui-hide" name="lists">{{specsTreeData}}</textarea></div><div class="layui-form-item layui-row layui-col-space15"><label class="layui-col-xs15 relative"><span class="color-green">详情</span><textarea name="detail"><?php echo htmlentities((isset($vo['detail']) && ($vo['detail'] !== '')?$vo['detail']:"")); ?></textarea></label></div><div class="layui-form-item text-center"><?php if(!(empty($vo['id']) || (($vo['id'] instanceof \think\Collection || $vo['id'] instanceof \think\Paginator ) && $vo['id']->isEmpty()))): ?><input type="hidden" name="id" value="<?php echo htmlentities($vo['id']); ?>"><?php endif; ?><button class="layui-btn" type="submit">保存商品</button><button class="layui-btn layui-btn-danger" type='button' onclick="history.go(-1)" data-close>返回</button></div></div></div></div></div></form></div><textarea class="layui-hide" id="goods-specs"><?php echo (isset($vo['specs']) && ($vo['specs'] !== '')?$vo['specs']:''); ?></textarea><textarea class="layui-hide" id="goods-value"><?php echo (isset($defaultValues) && ($defaultValues !== '')?$defaultValues:''); ?></textarea><script> window.form.render();
  90. // $('[name="logo"]').uploadOneImage();
  91. require(['ckeditor', 'angular'], function () {
  92. window.createEditor('[name="content"]', {
  93. });
  94. })
  95. </script><script> window.form.render();
  96. layui.use('form', function () {
  97. var form = layui.form;
  98. //日期时间范围
  99. laydate.render({
  100. elem: '#sell_time'
  101. ,type: 'datetime'
  102. });
  103. laydate.render({
  104. elem: '#release_time'
  105. ,type: 'datetime'
  106. });
  107. //监听指定开关
  108. form.on('radio(freight_type)', function(data) {
  109. if (data.value == 1) {
  110. $(".freight_mud").show();
  111. $(".postage").hide();
  112. } else {
  113. $(".freight_mud").hide();
  114. $(".postage").show();
  115. }
  116. })
  117. //监听指定开关
  118. })
  119. $(document).on("click",'.up_img',function () {
  120. console.log( $(".up_img").index(this))
  121. $("#up_img").val( $(".up_img").index(this));
  122. $(this).siblings('[name="file"]').click();
  123. })
  124. function upload_img(e) {
  125. var file = e.files[0]; //获取图片资源
  126. var index_n = $("#up_img").val();
  127. var fileTypes = ["bmp", "jpg", "png", "jpeg"];
  128. var bTypeMatch = false
  129. for (var i = 0; i < fileTypes.length; i++) {
  130. var start = file.name.lastIndexOf(".");
  131. var fileType = file.name.substring(start + 1);
  132. if (fileType.toLowerCase() == fileTypes[i]) {
  133. bTypeMatch = true;
  134. break;
  135. }
  136. }
  137. if (bTypeMatch) {
  138. if (file.size <= 1024 * 1024 * 50) {
  139. var farmData = new FormData();
  140. farmData.append("file", file)
  141. $.ajax("/api/Upload/upload", {
  142. data: farmData,
  143. processData: false,
  144. contentType: false,
  145. dataType: 'json',
  146. type: 'post', //HTTP请求类型
  147. headers: {
  148. 'zbtoken': localStorage.getItem("token"),
  149. 'enctype': 'multipart/form-data',
  150. },
  151. success: function (data) {
  152. if(data.code == 1) {
  153. $('.up_img').eq(index_n).attr('src',data.data)
  154. $("input[name='spec_cover[]']").eq(index_n).val(data.data)
  155. window.form.render();
  156. }else{
  157. layer.msg(data.msg);
  158. }
  159. console.log(data)
  160. },
  161. error: function (xhr, type, errorThrown) {
  162. console.log(type);
  163. }
  164. });
  165. } else {
  166. alert('仅支持不超过50M的图片');
  167. return false;
  168. }
  169. } else {
  170. alert('仅限bmp,jpg,png,jpeg图片格式');
  171. return false;
  172. }
  173. }
  174. require(['ckeditor', 'angular'], function () {
  175. //window.createEditor('[name="content"]', {height: 500});
  176. var app = angular.module("GoodsForm", []).run(callback);
  177. angular.bootstrap(document.getElementById(app.name), [app.name]);
  178. function getRand(length, prefix) {
  179. return (function (time, code) {
  180. code += parseInt(time.substr(0, 1)) + parseInt(time.substr(1, 1)) + time.substr(2, 8);
  181. while (code.length < length) code += Math.round(Math.random() * 10);
  182. return code;
  183. })(Date.now().toString(), prefix || '' + '')
  184. }
  185. function callback($rootScope) {
  186. $rootScope.isAddMode = parseInt('<?php echo htmlentities((isset($isAddMode) && ($isAddMode !== '')?$isAddMode:0)); ?>');
  187. $rootScope.maps = JSON.parse(angular.element('#goods-value').val() || '[]') || {};
  188. $rootScope.specs = JSON.parse(angular.element('#goods-specs').val() || '[{"name":"默认分组","list":[{"name":"默认规格","check":true}]}]');
  189. // 批量设置数值
  190. $rootScope.batchSet = function (type, fixed) {
  191. layer.prompt({title: '请输入数值', formType: 0}, function (value, index) {
  192. $rootScope.$apply(function () {
  193. var val = (parseFloat(value) || 0).toFixed(fixed);
  194. for (var i in $rootScope.specsTreeData) for (var j in $rootScope.specsTreeData[i]) {
  195. $rootScope.specsTreeData[i][j][type] = val;
  196. }
  197. });
  198. layer.close(index);
  199. });
  200. };
  201. // 返回商品列表
  202. $rootScope.hsitoryBack = function () {
  203. $.msg.confirm('确定要取消编辑吗?', function (index) {
  204. history.back(), $.msg.close(index);
  205. });
  206. };
  207. // 设置默认值
  208. $rootScope.setValue = function (key, type, value, call) {
  209. $rootScope.maps[key] || ($rootScope.maps[key] = {});
  210. return $rootScope.maps[key][type] = eval(call.replace('_', "'" + value + "'"));
  211. };
  212. // 读取默认值
  213. $rootScope.getValue = function (key, callback) {
  214. if (typeof callback === 'function') {
  215. return callback($rootScope.maps[key] || {});
  216. }
  217. return {};
  218. };
  219. // 去除空白字符
  220. $rootScope.trimSpace = function (value) {
  221. return (value + '').replace(/\s*/ig, '');
  222. };
  223. // 生成交叉表格数据
  224. $rootScope.specsTreeData = [];
  225. $rootScope.specsTreeNava = [];
  226. // 当前商品规格发生变化时重新计算规格列表
  227. $rootScope.$watch('specs', function () {
  228. var data = $rootScope.specs, list = [], navs = [], table = [[]];
  229. // 过滤无效记录
  230. for (var i in data) {
  231. var tmp = [];
  232. for (var j in data[i].list) if (data[i].list[j].check && data[i].list[j].name.length > 0) {
  233. data[i].list[j].span = 1, data[i].list[j].show = true, data[i].list[j].group = data[i].name;
  234. tmp.push(data[i].list[j]);
  235. }
  236. list.push(tmp), navs.push(data[i].name);
  237. }
  238. $rootScope.specsTreeNava = navs;
  239. // 表格交叉
  240. for (var i in list) {
  241. var tmp = [];
  242. for (var j in table) for (var k in list[i]) tmp.push(table[j].concat(list[i][k]));
  243. table = tmp;
  244. }
  245. // 表格合并
  246. list = angular.fromJson(angular.toJson(table));
  247. for (var i in list) {
  248. var key = [], _key = '';
  249. for (var td in list[i]) key.push(list[i][td].group + '::' + list[i][td].name);
  250. for (var td in list[i]) if (_key.length === 0) {
  251. list[i][0].key = _key = key.join(';;');
  252. list[i][0].spec_cover = $rootScope.getValue(_key, function (data) {
  253. return data.spec_cover || ''
  254. });
  255. list[i][0].sku = $rootScope.getValue(_key, function (data) {
  256. return data.sku || getRand(14, 'D')
  257. });
  258. list[i][0].virtual = $rootScope.getValue(_key, function (data) {
  259. return data.virtual || '0';
  260. });
  261. list[i][0].express = $rootScope.getValue(_key, function (data) {
  262. return data.express || '1';
  263. });
  264. list[i][0].original_price = $rootScope.getValue(_key, function (data) {
  265. return data.original_price || '0.00';
  266. });
  267. list[i][0].sell_price = $rootScope.getValue(_key, function (data) {
  268. return data.sell_price || '0.00';
  269. });
  270. list[i][0].status = $rootScope.getValue(_key, function (data) {
  271. return !!(typeof data.status !== 'undefined' ? data.status : true);
  272. });
  273. list[i][0].weight = $rootScope.getValue(_key, function (data) {
  274. return data.weight || '0.00';
  275. });
  276. list[i][0].goods_no = $rootScope.getValue(_key, function (data) {
  277. return data.goods_no || '';
  278. });
  279. }
  280. }
  281. $rootScope.specsTreeData = list;
  282. }, true);
  283. // 判断规则是否能取消选择
  284. $rootScope.checkListChecked = function (list, check) {
  285. for (var i in list) if (list[i].check) return check;
  286. return true;
  287. };
  288. // 增加整行规格分组
  289. $rootScope.addSpecRow = function (data) {
  290. data.push({name: '规格分组', list: [{name: '规格属性', check: true}]})
  291. };
  292. // 下移整行规格分组
  293. $rootScope.dnSpecRow = function (data, $index) {
  294. var tmp = [], cur = data[$index];
  295. if ($index > data.length - 2) return false;
  296. for (var i in data) {
  297. (parseInt(i) !== parseInt($index)) && tmp.push(data[i]);
  298. (parseInt(i) === parseInt($index) + 1) && tmp.push(cur);
  299. }
  300. return $rootScope.specs = tmp;
  301. };
  302. // 上移整行规格分组
  303. $rootScope.upSpecRow = function (data, $index) {
  304. var tmp = [], cur = data[$index];
  305. if ($index < 1) return false;
  306. for (var i in data) {
  307. (parseInt(i) === parseInt($index) - 1) && tmp.push(cur);
  308. (parseInt(i) !== parseInt($index)) && tmp.push(data[i]);
  309. }
  310. return $rootScope.specs = tmp;
  311. };
  312. // 移除整行规格分组
  313. $rootScope.delSpecRow = function (data, $index) {
  314. var tmp = [];
  315. for (var i in data) if (parseInt(i) !== parseInt($index)) tmp.push(data[i]);
  316. return $rootScope.specs = tmp;
  317. };
  318. // 增加分组的属性
  319. $rootScope.addSpecVal = function (list) {
  320. list.push({name: '规格属性', check: true});
  321. };
  322. // 移除分组的属性
  323. $rootScope.delSpecVal = function (data, $index) {
  324. var temp = [];
  325. for (var i in data) if (parseInt(i) !== parseInt($index)) temp.push(data[i]);
  326. return temp;
  327. };
  328. }
  329. })
  330. layui.use('element', function(){
  331. var $ = layui.jquery
  332. ,element = layui.element;
  333. var active = {
  334. tabAdd: function(){
  335. element.tabAdd('demo', {
  336. title: '新选项'+ (Math.random()*1000|0)
  337. ,content: '内容'+ (Math.random()*1000|0)
  338. ,id: new Date().getTime()
  339. })
  340. }
  341. ,tabDelete: function(othis){
  342. element.tabDelete('demo', '44');
  343. othis.addClass('layui-btn-disabled');
  344. }
  345. ,tabChange: function(){
  346. element.tabChange('demo', '22');
  347. }
  348. };
  349. $('.site-demo-active').on('click', function(){
  350. var othis = $(this), type = othis.data('type');
  351. active[type] ? active[type].call(this, othis) : '';
  352. });
  353. //Hash地址的定位
  354. var layid = location.hash.replace(/^#test=/, '');
  355. element.tabChange('test', layid);
  356. element.on('tab(test)', function(elem){
  357. location.hash = 'test='+ $(this).attr('lay-id');
  358. });
  359. });
  360. // 分类联动 start
  361. var sel_second = <?php echo isset($vo['second_classify']) ? $vo['second_classify']:0; ?>;
  362. var sel_third = <?php echo isset($vo['third_classify']) ? $vo['third_classify']:0; ?>;
  363. var goods_spec = <?php echo json_encode($goods_cate); ?>;
  364. first(1);
  365. function first(source){
  366. // 将其他选择框置空
  367. var first_key = $("select[name='first_classify']").find("option:selected").data("first_key")
  368. $("#first").val(first_key);
  369. $("select[name='second_classify']").html('');
  370. $("select[name='third_classify']").html('');
  371. // 没有下级不继续
  372. if(first_key == -1 || !("children" in goods_spec[first_key])){
  373. $("#second").val(-1);
  374. $("#third").val(-1);
  375. window.form.render();
  376. return true;
  377. }else{
  378. var second_html = '<option data-second_key="-1" selected value="0">请选择分类</option>';
  379. var to_each = goods_spec[first_key]['children'];
  380. $.each(to_each,function (ck,cv) {
  381. if(source == 1 && sel_second == cv.id){
  382. second_html +='<option selected data-second_key="'+ck+'" value="'+cv.id+'">'+cv.title+'</option>';
  383. $("#second").val(ck);
  384. }else{
  385. second_html +='<option data-second_key="'+ck+'" value="'+cv.id+'">'+cv.title+'</option>';
  386. }
  387. })
  388. $("select[name='second_classify']").html(second_html);
  389. second(source)
  390. window.form.render();
  391. }
  392. }
  393. function second(source){
  394. var first_key = $("select[name='first_classify']").find("option:selected").data("first_key");
  395. var second_key = $("select[name='second_classify']").find("option:selected").data("second_key");
  396. // 将其他选择框置空
  397. $("#second").val(second_key);
  398. $("select[name='third_classify']").html('');
  399. // 没有下级不继续
  400. if(second_key == -1 || !("children" in goods_spec[first_key]['children'][second_key])){
  401. $("#third").val(-1);
  402. window.form.render();
  403. return true;
  404. }
  405. var to_each = goods_spec[first_key]['children'][second_key]['children'];
  406. var third_html = '<option data-third_key="-1" selected value="0">请选择分类</option>';
  407. $.each(to_each,function (ck,cv) {
  408. if(source == 1 && sel_third == cv.id){
  409. third_html +='<option selected data-third_key="'+ck+'" value="'+cv.id+'">'+cv.title+'</option>';
  410. $("#third").val(ck);
  411. }else{
  412. third_html +='<option data-third_key="'+ck+'" value="'+cv.id+'">'+cv.title+'</option>';
  413. }
  414. })
  415. $("select[name='third_classify']").html(third_html);
  416. window.form.render();
  417. }
  418. // 一级分类监听
  419. form.on('select(first_classify)', function(data){
  420. var first_key = data.elem[data.elem.selectedIndex].dataset.first_key;
  421. //与之前选择的一样不处理
  422. if($("#first").val() == first_key){
  423. return true;
  424. }
  425. first(2);
  426. })
  427. // 二级分类监听
  428. form.on('select(second_classify)', function(data){
  429. var second_key = data.elem[data.elem.selectedIndex].dataset.second_key;
  430. //与之前选择的一样不处理
  431. if($("#second").val() == second_key){
  432. return true;
  433. }
  434. second(2)
  435. })
  436. // 分类end
  437. require(['ckeditor', 'angular'], function () {
  438. window.createEditor('[name="detail"]', {
  439. height: 500,
  440. });
  441. })
  442. </script></div>