截流自动化的商城平台
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

add.html 42KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  1. {layout name="layout2" /}
  2. <link rel="stylesheet" href="/static/admin/css/goods.css" media="all">
  3. <link href="__PUBLIC__/static/lib/layui/layeditor/layedit.css" rel="stylesheet"/>
  4. <script src="__PUBLIC__/static/lib/layui/layeditor/index.js"></script>
  5. <script src="__PUBLIC__/static/lib/layui/layeditor/ace/ace.js"></script>
  6. <div class="layui-tab layui-tab-card">
  7. <!--顶部切换页-->
  8. <ul class="layui-tab-title">
  9. <li class="goods-tab layui-this" style="color: #6a6f6c">基础设置</li>
  10. <li class="goods-tab" style="color: #6a6f6c">规格型号</li>
  11. <li class="goods-tab" style="color: #6a6f6c">商品详情</li>
  12. <li class="goods-tab" style="color: #6a6f6c">销售设置</li>
  13. <!-- <li class="goods-tab" style="color: #6a6f6c">分销设置</li>-->
  14. </ul>
  15. <!--切换内容-->
  16. <div class="layui-tab-content layui-form">
  17. <!--基础信息-->
  18. {include file="goods/goods/goods_base" /}
  19. <!--规格型号-->
  20. {include file="goods/goods/goods_spec" /}
  21. <!--商品详情-->
  22. {include file="goods/goods/goods_content" /}
  23. <!--销售设置-->
  24. {include file="goods/goods/goods_sale_setting" /}
  25. <div class="layui-form-item layui-hide">
  26. <input type="button" lay-submit lay-filter="goods-submit" id="goods-submit" value="确认">
  27. </div>
  28. </div>
  29. </div>
  30. <script src="__PUBLIC__/static/common/js/array.js"></script>
  31. <script>
  32. var dragstart = 0;
  33. var swop_element_ed = -1;
  34. var create_table_by_spec = null;
  35. var spec_table_data = [];
  36. var spec_value_temp_id_number = 0;
  37. layui.config({
  38. version:"{$front_version}",
  39. base: '/static/lib/'
  40. }).extend({
  41. likeedit: 'likeedit/likeedit'
  42. }).use(['table', 'form', 'element', 'likeedit'], function() {
  43. var form = layui.form
  44. ,$ = layui.$
  45. , element = layui.element
  46. , layEditor = layui.layEditor;
  47. //---------------------------------------平台分类联动 begin ----------------------------------
  48. var categorys = {$category_lists | raw};
  49. setSelectFirst();
  50. function setSelectFirst(default_id) {
  51. var category_select_html = '<option value="">请选择分类</option>';
  52. for (var i in categorys) {
  53. if (categorys[i]['pid'] == 0) {
  54. category_select_html += '<option value="' + categorys[i]['id'] + '">' + categorys[i]['name'] + '</option>';
  55. }
  56. }
  57. $('select[name="first_cate_id"]').html(category_select_html);
  58. $('select[name="first_cate_id"]').val(default_id);
  59. form.render('select');
  60. }
  61. function setSelectSecond(default_id, pid) {
  62. pid = pid === undefined ? $('select[name="first_cate_id"]').val() : pid;
  63. $('select[name="second_cate_id"]').html('<option value="">请选择分类</option>');
  64. $('select[name="third_cate_id"]').html('<option value="">请选择分类</option>');
  65. var category_select_html = '<option value="">请选择分类</option>';
  66. for (var i in categorys) {
  67. if (categorys[i]['pid'] == pid) {
  68. category_select_html += '<option value="' + categorys[i]['id'] + '">' + categorys[i]['name'] + '</option>';
  69. }
  70. }
  71. $('select[name="second_cate_id"]').html(category_select_html);
  72. $('select[name="second_cate_id"]').val(default_id);
  73. form.render('select');
  74. }
  75. function setSelectThird(default_id, pid) {
  76. pid = pid === undefined ? $('select[name="second_cate_id"]').val() : pid;
  77. $('select[name="third_cate_id"]').html('<option value="">请选择分类</option>');
  78. var first_cate_id = $('select[name="first_cate_id"]').val();
  79. var category_select_html = '<option value="">请选择分类</option>';
  80. for (var i in categorys) {
  81. if (categorys[i]['pid'] == pid) {
  82. category_select_html += '<option value="' + categorys[i]['id'] + '">' + categorys[i]['name'] + '</option>';
  83. }
  84. }
  85. $('select[name="third_cate_id"]').html(category_select_html);
  86. $('select[name="third_cate_id"]').val(default_id);
  87. form.render('select');
  88. }
  89. // 监听一级分类选择
  90. form.on('select(first_category)', function (data) {
  91. setSelectSecond('', data.value);
  92. });
  93. // 监听二级分类选择
  94. form.on('select(second_category)', function (data) {
  95. setSelectThird('', data.value);
  96. });
  97. //---------------------------------------平台分类联动 end ----------------------------------
  98. // -------------------------------------- 下拉菜单渲染 begin -------------------------------
  99. var shop_category_lists = {$shop_category_lists | raw}; // 店铺商品分类
  100. var unit = {$unit_lists | raw};
  101. var brands = {$brand_lists | raw};
  102. var supplier = {$supplier_lists | raw};
  103. var freight = {$freight_lists | raw};
  104. //渲染商家分类
  105. like.setSelect('', shop_category_lists, "shop_cate_id", '分类');
  106. //渲染单位
  107. like.setSelect('', unit, "unit_id", '单位');
  108. //渲染品牌
  109. like.setSelect('', brands, "brand_id", '品牌');
  110. //渲染供应商
  111. like.setSelect('', supplier, "supplier_id", '供应商');
  112. //渲染运费模板
  113. like.setSelect('', freight, "express_template_id", '运费模板');
  114. // -------------------------------------- 下拉菜单渲染 end ---------------------------------
  115. // ----------------------------------------图片/视频上传 begin -----------------------------
  116. // // 监听图片删除
  117. // like.delUpload();
  118. // // 商品封面图
  119. // $(document).on("click", "#image", function () {
  120. // like.imageUpload({
  121. // limit: 1,
  122. // field: "image",
  123. // that: $(this),
  124. // content: '{:url("file/lists")}?type=10'
  125. // });
  126. // })
  127. // // 商品分享海报
  128. // $(document).on("click", "#poster", function () {
  129. // like.imageUpload({
  130. // limit: 1,
  131. // field: "poster",
  132. // that: $(this),
  133. // content: '{:url("file/lists")}?type=10'
  134. // });
  135. // })
  136. // // 商品轮播图
  137. // $(document).on("click", "#goodsimage", function () {
  138. // like.imageUpload({
  139. // limit: 5,
  140. // field: "goods_image[]",
  141. // that: $(this),
  142. // content: '/shop/file/lists?type=10'
  143. // });
  144. // })
  145. // // 商品视频
  146. // $(document).on("click", "#video", function () {
  147. // like.videoUpload({
  148. // limit: 1,
  149. // field: "video",
  150. // that: $(this),
  151. // content: '/shop/file/videoList'
  152. // });
  153. // })
  154. // // 统一规格-规格图片
  155. // $(document).on("click", "#one_spec_image", function () {
  156. // like.imageUpload({
  157. // limit: 1,
  158. // field: "one_spec_image",
  159. // that: $(this),
  160. // content: '/shop/file/lists?type=10'
  161. // });
  162. // })
  163. // // 多规格-规格图片
  164. // $(document).on("click", ".more_spec_image", function () {
  165. // like.imageUpload({
  166. // limit: 1,
  167. // field: "spec_image[]",
  168. // that: $(this),
  169. // content: '/shop/file/lists?type=10'
  170. // });
  171. // })
  172. // // 监听编辑时多规格图片删除按钮
  173. // $(document).on('mouseenter', '.goods-spec-img-div', function () {
  174. // $(this).find('.goods-spec-img-del-x').show();
  175. // });
  176. // $(document).on('mouseleave', '.goods-spec-img-div', function () {
  177. // $(this).find('.goods-spec-img-del-x').hide();
  178. // });
  179. // $(document).on('click', '.goods-spec-img-del-x', function () {
  180. // var key = 'spec_image[]' + $(this).parent().parent().parent().attr('spec-value-temp-ids');
  181. // $(this).parent().html('<div class="like-upload-image goods-spec-img-div"><div class="upload-image-elem"><a class="add-upload-image more_spec_image"> + 添加图片</a></div></div>');
  182. // spec_table_data[key] = '';
  183. //
  184. // });
  185. // 放大图片
  186. $(document).on('click', 'img',function(){
  187. like.showImg($(this).attr('src'),600);
  188. });
  189. // 查看视频
  190. $(document).on('click', 'video',function(){
  191. var src = $(this).attr('src');
  192. layer.open({
  193. type: 1,
  194. title: '查看视频',
  195. content: '<div style="text-align:center;"><video style="width:60%;margin:15px auto;" src="'+ src +'" autoplay controls></video></div>',
  196. area: ['60%', '60%']
  197. });
  198. });
  199. // ----------------------------------------图片/视频上传 end -----------------------------
  200. //------------------------------------------数据验证 begin -------------------------------
  201. function switchTab(number) {
  202. $('.goods-tab').removeClass('layui-this');
  203. $('.goods-content').removeClass('layui-show');
  204. $('.goods-tab').eq(number).addClass('layui-this');
  205. $('.goods-content').eq(number).addClass('layui-show');
  206. }
  207. form.verify({
  208. custom_required: function (value, item) {
  209. if (!$.trim(value)) {
  210. switchTab($(item).attr('switch-tab'));
  211. return $(item).attr('verify-msg');
  212. }
  213. },
  214. status:function(value,item){
  215. if(!$('input[name="status"]:checked').val()){
  216. return $(item).attr('verify-msg');
  217. }
  218. },
  219. one_spec_required: function (value, item) {
  220. if ($('input[name="spec_type"]:checked').val() == 1) {
  221. if (!value) {
  222. switchTab($(item).attr('switch-tab'));
  223. return $(item).attr('verify-msg');
  224. }
  225. }
  226. },
  227. add_more_spec: function (value, item) {
  228. if ($('input[name="spec_type"]:checked').val() == 2) {
  229. if ($('#more-spec-lists-table tbody tr').length == 0) {
  230. switchTab($(item).attr('switch-tab'));
  231. return $(item).attr('verify-msg');
  232. }
  233. }
  234. },
  235. more_spec_required: function (value, item) {
  236. if ($('input[name="spec_type"]:checked').val() == 2) {
  237. if (!value) {
  238. switchTab($(item).attr('switch-tab'));
  239. return $(item).attr('verify-msg');
  240. }
  241. }
  242. },
  243. one_volume: function (value, item) {
  244. if ($('input[name="spec_type"]:checked').val() == 1) {
  245. if (value && value < 0) {
  246. switchTab($(item).attr('switch-tab'));
  247. return '体积必须大于0';
  248. }
  249. }
  250. },
  251. one_weight: function (value, item) {
  252. if ($('input[name="spec_type"]:checked').val() == 1) {
  253. if (value && value < 0) {
  254. switchTab($(item).attr('switch-tab'));
  255. return '重量必须大于0';
  256. }
  257. }
  258. },
  259. one_market_price: function (value, item) {
  260. if ($('input[name="spec_type"]:checked').val() == 1) {
  261. if (value && value <= 0) {
  262. switchTab($(item).attr('switch-tab'));
  263. return '市场价必须大于0';
  264. }
  265. }
  266. },
  267. one_price: function (value, item) {
  268. if ($('input[name="spec_type"]:checked').val() == 2) {
  269. if (value && value <= 0) {
  270. switchTab($(item).attr('switch-tab'));
  271. return '价格必须大于0';
  272. }
  273. }
  274. },
  275. one_chengben_price: function (value, item) {
  276. if ($('input[name="spec_type"]:checked').val() == 2) {
  277. if (value && value <= 0) {
  278. switchTab($(item).attr('switch-tab'));
  279. return '成本价必须大于0';
  280. }
  281. }
  282. },
  283. more_market_price:function (value, item) {
  284. if ($('input[name="spec_type"]:checked').val() == 2) {
  285. if (value && value <= 0) {
  286. switchTab($(item).attr('switch-tab'));
  287. return '市场价必须大于0';
  288. }
  289. }
  290. },
  291. more_price:function (value, item) {
  292. if ($('input[name="spec_type"]:checked').val() == 2) {
  293. if (value && value < 0.01) {
  294. switchTab($(item).attr('switch-tab'));
  295. return '价格必须大于或等于0.01';
  296. }
  297. }
  298. },
  299. more_chengben_price:function (value, item) {
  300. if ($('input[name="spec_type"]:checked').val() == 2) {
  301. if (value && value <= 0) {
  302. switchTab($(item).attr('switch-tab'));
  303. return '成本价格必须大于0';
  304. }
  305. }
  306. },
  307. more_stock: function (value, item) {
  308. if ($('input[name="spec_type"]:checked').val() == 2) {
  309. if (value && value < 0) {
  310. switchTab($(item).attr('switch-tab'));
  311. return '库存必须大于0';
  312. }
  313. }
  314. },
  315. more_weight: function (value, item) {
  316. if ($('input[name="spec_type"]:checked').val() == 2) {
  317. if (value && value < 0) {
  318. switchTab($(item).attr('switch-tab'));
  319. return '重量必须大于0';
  320. }
  321. }
  322. },
  323. more_volume: function (value, item) {
  324. if ($('input[name="spec_type"]:checked').val() == 2) {
  325. if (value && value < 0) {
  326. switchTab($(item).attr('switch-tab'));
  327. return '体积必须大于0';
  328. }
  329. }
  330. },
  331. repetition_spec_name: function (value, item) {
  332. if ($('input[name="spec_type"]:checked').val() == 2) {
  333. var spec_names = [];
  334. $('.spec_name').each(function () {
  335. spec_names.push($(this).val());
  336. });
  337. if ((new Set(spec_names)).size != spec_names.length) {
  338. switchTab($(item).attr('switch-tab'));
  339. return '规格名称重复';
  340. }
  341. }
  342. },
  343. repetition_spec_value: function (value, item) {
  344. if ($('input[name="spec_type"]:checked').val() == 2) {
  345. var spec_values = [];
  346. $(item).find('.goods-spec-value-input').each(function () {
  347. spec_values.push($(this).val());
  348. });
  349. if ((new Set(spec_values)).size != spec_values.length) {
  350. switchTab($(item).attr('switch-tab'));
  351. return '同一规格中,规格值不能重复';
  352. }
  353. }
  354. },
  355. distribution:function (value,item) {
  356. var first_ratio = parseFloat($('.first_ratio').val());
  357. var second_ratio = parseFloat($('.second_ratio').val());
  358. var three_ratio = parseFloat(value);
  359. if(first_ratio + second_ratio + three_ratio > 100){
  360. return '分销比例不可超过100';
  361. }
  362. }
  363. });
  364. //------------------------------------------数据验证 end ----------------------------------
  365. //------------------------------------------规格型号 begin --------------------------------
  366. //监听多规格/单规格按钮
  367. form.on('radio(spec-type)', function (data) {
  368. switchSpecType(data.value);
  369. });
  370. // 统一规格与多规格切换事件
  371. function switchSpecType(value) {
  372. var goods_spec_project = $('#goods-spec-project'); // 规格项区域
  373. if (value == 2) { // 多规格
  374. $('#add-spec').parent().show(); // 显示添加规格项目按钮
  375. if (goods_spec_project.children().length > 0) { // 判断规格项区域是否有子元素
  376. goods_spec_project.parent().show(); // 显示规格项区域
  377. $('#more-spec-lists').show(); // 显示多规格明细
  378. }
  379. $('#one-spec-lists').hide(); // 隐藏统一规格规格明细
  380. } else {
  381. $('#add-spec').parent().hide(); // 隐藏 添加规格项目 按钮
  382. goods_spec_project.parent().hide(); // 隐藏规格项区域
  383. $('#more-spec-lists').hide(); // 隐藏多规格明细
  384. $('#one-spec-lists').show(); // 显示单规格明细
  385. }
  386. }
  387. //监听添加规格项按钮
  388. // $(document).on('click', '#add-spec', function () {
  389. // addSpec();
  390. // });
  391. //添加规格项
  392. function addSpec(value) {
  393. value = value === undefined ? ' ' : value;
  394. var element_spec = $('#goods-spec-project'); // 规格项区域
  395. var count = $('.goods-spec').length; // 规格项数量
  396. if (count > 2) {
  397. layer.msg('最多添加3个规格项目');
  398. return;
  399. }
  400. var template_spec = $('#template-spec').html(); // 获取规格项目模板
  401. // 使用value值替换规格项目模板中{value}占位符,并追加至规格项区域中
  402. element_spec.append(template_spec.replace('{value}', value));
  403. $('#goods-spec-project').parent().show();
  404. form.render('checkbox');
  405. }
  406. // 鼠标移入显示删除规格项按钮
  407. // $(document).on('mouseenter', '.goods-spec', function () {
  408. // $(this).find('.goods-spec-del-x').show();
  409. // });
  410. // 鼠标移出隐藏删除规格项按钮
  411. $(document).on('mouseleave', '.goods-spec', function () {
  412. $(this).find('.goods-spec-del-x').hide();
  413. });
  414. // 监听删除规格项目按钮
  415. $(document).on('click', '.goods-spec-del-x', function () {
  416. $(this).parent().remove(); // 移除当前规格项目
  417. var goods_spec_project = $('#goods-spec-project');
  418. if (goods_spec_project.children().length == 0) { // 规格项区域中若没有子元素则隐藏
  419. goods_spec_project.parent().hide();
  420. }
  421. // 触发生成表格函数
  422. triggerCreateTableBySepc();
  423. });
  424. // 监听规格项输入
  425. $(document).on('input', '.goods-spec input', function () {
  426. triggerCreateTableBySepc();
  427. specValueLater();
  428. });
  429. // 触发生成规格明细表格
  430. function triggerCreateTableBySepc() {
  431. clearTimeout(create_table_by_spec);
  432. create_table_by_spec = setTimeout(createTableBySepc, 1000);
  433. }
  434. // 生成规格明细表格
  435. function createTableBySepc() {
  436. if ($('.goods-spec').length <= 0) { // 没有规格项目,隐藏多规格明细
  437. $('#more-spec-lists').hide();
  438. return;
  439. }
  440. $('#more-spec-lists').show(); // 显示多规格明细
  441. var table_title = []; // 用于保存 规格项的值
  442. var table_data = []; // 规格项数据
  443. var spec_value_temp_arr = []; // 规格值临时数组
  444. var i = 0;
  445. var table_html = '';
  446. var th_html = $('#template-spec-table-th').html(); // 多规格表头模板
  447. var tr_html = $('#template-spec-table-tr').html(); // 多规格行模板
  448. //遍历规格项目
  449. $('.goods-spec').each(function () {
  450. var spec_name = $(this).find('.spec_name').first().val(); // 规格项的值 例:颜色
  451. if (isEmptyString(spec_name)) {
  452. return true;
  453. }
  454. table_title[i] = spec_name; // 保存 规格项的值 例:['颜色']
  455. table_data[i] = []; // 例: [[]]
  456. spec_value_temp_arr[i] = []; // 例:[[]]
  457. var j = 0;
  458. // 遍历 当前规格项目 下的所有 规格值
  459. $(this).find('.goods-spec-value .goods-spec-value-input').each(function () {
  460. var spec_value = $(this).val(); // 规格值 例:
  461. var spec_value_temp_id = $(this).attr('spec-value-temp-id'); // 规格值临时id
  462. if (isEmptyString(spec_value)) {
  463. return true;
  464. }
  465. table_data[i][j] = spec_value; // 将 规格值 保存至 规格项 中
  466. spec_value_temp_arr[i][j] = spec_value_temp_id; // 将 规格值临时id 保存至 规格值临时数组 中
  467. j++;
  468. });
  469. i++;
  470. });
  471. //表格头部组装
  472. spec_th_html = '';
  473. for (var i in table_title) {
  474. spec_th_html += '<th>' + table_title[i] + '</th>';
  475. }
  476. table_html = th_html.replace('{spec_th}', spec_th_html);
  477. // 笛卡尔积, 组装SKU 例:[['颜色', 'S码'], ['颜色', 'M码']]
  478. spec_value_temp_arr = cartesianProduct(spec_value_temp_arr);
  479. table_data = cartesianProduct(table_data);
  480. for (var i in table_data) {
  481. var spec_tr_html = '';
  482. var tr_name_arr = [];
  483. var specs = '';
  484. if (Array.isArray(table_data[i])) {
  485. //根据规格创建tr
  486. var spec_value_temp_ids = '';
  487. for (var j in spec_value_temp_arr[i]) {
  488. spec_value_temp_ids += spec_value_temp_arr[i][j] + ',';
  489. }
  490. spec_value_temp_ids = spec_value_temp_ids.substring(0, spec_value_temp_ids.lastIndexOf(','));
  491. spec_tr_html += '<tr spec-value-temp-ids="' + spec_value_temp_ids + '">';
  492. for (var j in table_data[i]) {
  493. spec_tr_html += '<td>' + table_data[i][j] + '</td>';
  494. tr_name_arr[j] = table_data[i][j];
  495. specs += table_data[i][j].replace(',', '') + ',';
  496. }
  497. } else {
  498. var spec_value_temp_ids = spec_value_temp_arr[i];
  499. spec_tr_html = '<tr spec-value-temp-ids="' + spec_value_temp_ids + '">';
  500. spec_tr_html += '<td>' + table_data[i] + '</td>';
  501. specs += table_data[i].replace(',', '') + ',';
  502. }
  503. specs = specs.substring(0, specs.lastIndexOf(','));
  504. spec_table_data["spec_value_str[]" + spec_value_temp_ids] = specs;
  505. spec_tr_html += '<td style="display: none"><input type="hidden" name="spec_value_str[]" value="' + specs + '"><input type="hidden" name="item_id[]" value=""></td>';
  506. table_html += tr_html.replace('{spec_td}', spec_tr_html);
  507. }
  508. $('#more-spec-lists-table').html(table_html);
  509. setTableValue();
  510. };
  511. //动态渲染已保存的值
  512. function setTableValue() {
  513. $('#more-spec-lists-table').find('input').each(function () {
  514. var key = $(this).attr('name') + $(this).parent().parent().attr('spec-value-temp-ids');
  515. if (spec_table_data[key] !== undefined) {
  516. $(this).val(spec_table_data[key]);
  517. }
  518. });
  519. $('.goods-spec-img-div').each(function () {
  520. var key = $(this).parent().parent().attr('spec-value-temp-ids');
  521. if (spec_table_data["spec_image[]" + key]) {
  522. $(this).html('<input name="spec_image[]" type="hidden" value="' + spec_table_data["spec_image[]" + key] + '"><a class="goods-spec-img-del-x">x</a><img class="goods-spec-img" src="' + spec_table_data["spec_image[]" + key] + '">');
  523. }
  524. });
  525. }
  526. // 监听添加规格值链接被点击: 弹出多行输出框,处理输入的规格值数据,遍历每个规格值并生成相应的html
  527. // $(document).on('click', '.add-spec-value', function () {
  528. // var add_spec_value = $(this);
  529. // layer.prompt({title: '输入规格值,多个请换行', formType: 2}, function (text, index) {
  530. // layer.close(index);
  531. // var specs = text.split('\n');
  532. // for (var i in specs) {
  533. // specs[i] = specs[i].trim();
  534. // }
  535. // specs = unique(specs);
  536. // var added_specs = [];
  537. // add_spec_value.parent().parent().find('.goods-spec-value-input').each(function () {
  538. // added_specs.push($(this).val().trim());
  539. // });
  540. // for (var i in specs) {
  541. // var spec = specs[i].trim();
  542. // if (spec == '' || in_array(spec, added_specs)) {
  543. // //已存或为空的不添加
  544. // continue;
  545. // }
  546. // addSpecvalue(add_spec_value, spec, 0);
  547. // }
  548. // specValueLater();
  549. // });
  550. // });
  551. // 添加规格值: 将【数据】填充至【规格值模板】,并将【规格值模板】追加至【添加规格值】链接前
  552. function addSpecvalue(add_spec_value, spec, spec_id) {
  553. var template_spec_value = $('#template-spec-value').html();
  554. var template_spec_value_html = template_spec_value.replace('{spec_value_temp_id}', spec_value_temp_id_number--);
  555. template_spec_value_html = template_spec_value_html.replace('{spec_value_id}', spec_id);
  556. template_spec_value_html = template_spec_value_html.replace('{spec_value}', spec)
  557. add_spec_value.parent().before(template_spec_value_html);
  558. }
  559. //处理每项规格值
  560. function specValueLater() {
  561. $('.add-spec-value').each(function () {
  562. add_spec_value = $(this);
  563. var spec_values = '';
  564. add_spec_value.parent().parent().find('.goods-spec-value-input').each(function () {
  565. spec_values += $(this).val() + ',';
  566. });
  567. add_spec_value.parent().find('.spec_values').val(spec_values.substring(0, spec_values.lastIndexOf(',')));
  568. var spec_value_ids = '';
  569. add_spec_value.parent().parent().find('.goods-sepc-value-id-input').each(function () {
  570. spec_value_ids += $(this).val() + ',';
  571. });
  572. add_spec_value.parent().find('.spec_value_ids').val(spec_value_ids.substring(0, spec_value_ids.lastIndexOf(',')));
  573. triggerCreateTableBySepc();
  574. });
  575. }
  576. // 显示或隐藏 规格值删除按钮
  577. $(document).on('mouseenter', '.goods-spec-value', function () {
  578. $(this).find('.goods-spec-value-del-x').show();
  579. });
  580. $(document).on('mouseleave', '.goods-spec-value', function () {
  581. $(this).find('.goods-spec-value-del-x').hide();
  582. });
  583. //删除规格值
  584. $(document).on('click', '.goods-spec-value-del-x', function () {
  585. var add_spec_value = $(this).parent().parent().find('.add-spec-value').first();
  586. $(this).parent().remove();
  587. specValueLater();
  588. triggerCreateTableBySepc();
  589. });
  590. // 监听规格明细输入,规格数据本地保存
  591. $(document).on('input', '#more-spec-lists-table input', function () {
  592. var key = $(this).attr('name') + $(this).parent().parent().attr('spec-value-temp-ids');
  593. spec_table_data[key] = $(this).val();
  594. });
  595. //批量填充
  596. $(document).on('click', '.batch-spec-content', function () {
  597. var title = $(this).text();
  598. var input_name = $(this).attr('input-name');
  599. layer.prompt({
  600. formType: 3
  601. , title: '批量填写' + title
  602. }, function (value, index, elem) {
  603. $('input[name="' + input_name + '[]"]').val(value);
  604. //保存值到本地
  605. $('#more-spec-lists-table input').each(function () {
  606. var key = $(this).attr('name') + $(this).parent().parent().attr('spec-value-temp-ids');
  607. spec_table_data[key] = $(this).val();
  608. });
  609. layer.close(index);
  610. });
  611. });
  612. //------------------------------------------规格型号 end ------------------------------------
  613. //------------------------------------------富文本编辑器 begin --------------------------------
  614. layEditor.set({
  615. uploadImage: {
  616. url: '{:url("file/lists")}?type=10'
  617. },
  618. })
  619. var ieditor = layEditor.build('content')
  620. form.verify({
  621. content: function(value) {
  622. return layEditor.sync(ieditor);
  623. }
  624. });
  625. //------------------------------------------富文本编辑器 end --------------------------------
  626. //------------------------------------------切换商品类型 begin --------------------------------
  627. // 切换商品类型
  628. function switchGoodsType(type) {
  629. if(type == '1') {
  630. // 虚拟商品
  631. $('.virtual-goods-data').show();
  632. $('.actual-goods-data').hide();
  633. // 配送方式
  634. $('.delivery_virtual').show();
  635. $('.delivery_express').hide();
  636. } else {
  637. // 实物商品
  638. $('.virtual-goods-data').hide();
  639. $('.actual-goods-data').show();
  640. // 配送方式
  641. $('.delivery_virtual').hide();
  642. $('.delivery_express').show();
  643. }
  644. }
  645. // 初始选中配送方式
  646. function initDeliveryType(type) {
  647. if(type == '1') {
  648. $('input[name="delivery_type[]"][value=1]').prop("checked", false);
  649. $('input[name="delivery_type[]"][value=2]').prop("checked", true);
  650. } else {
  651. $('input[name="delivery_type[]"][value=1]').prop("checked", true);
  652. $('input[name="delivery_type[]"][value=2]').prop("checked", false);
  653. }
  654. form.render();
  655. }
  656. // 渲染
  657. function renderDeliveryType(delivery_type, goods_type) {
  658. delivery_type = delivery_type.split(',');
  659. if (delivery_type == 'null' || delivery_type == '' || delivery_type.length <= 0) {
  660. console.log('delivery_type是空的');
  661. return initDeliveryType(goods_type);
  662. }
  663. for (var i = 0; i < delivery_type.length; i++) {
  664. console.log("input[name=delivery_type][value=" + delivery_type[i] + "]");
  665. $('input[name="delivery_type[]"][value=' + delivery_type[i] + ']').prop("checked", true);
  666. }
  667. form.render();
  668. }
  669. //------------------------------------------切换商品类型 end --------------------------------
  670. //------------------------------------ -----编辑页面 begin --------------------------------
  671. {notempty name='info'}
  672. var goods_info= {$info|raw|default=''};
  673. // 商品类型
  674. $("input[name=type][value="+goods_info['base']['type']+"]").prop("checked",true);
  675. switchGoodsType(goods_info['base']['type']);
  676. // 买家付款后 发货后 发货内容
  677. $("input[name=after_pay][value="+goods_info['base']['after_pay']+"]").prop("checked",true);
  678. $("input[name=after_delivery][value="+goods_info['base']['after_delivery']+"]").prop("checked",true);
  679. $('textarea[name="delivery_content"]').val(goods_info['base']['delivery_content']);
  680. // 配送方式
  681. renderDeliveryType(goods_info['base']['delivery_type'], goods_info['base']['type']);
  682. $('input[name="goods_id"]').val(goods_info['base']['id']);
  683. $('input[name="name"]').val(goods_info['base']['name']);
  684. $('input[name="code"]').val(goods_info['base']['code']);
  685. setSelectFirst(goods_info['base']['first_cate_id']);
  686. setSelectSecond(goods_info['base']['second_cate_id']);
  687. setSelectThird(goods_info['base']['third_cate_id']);
  688. like.setSelect(goods_info['base']['shop_cate_id'], shop_category_lists, "shop_cate_id", '分类');
  689. $('input[name="remark"]').val(goods_info['base']['remark']);
  690. like.setSelect(goods_info['base']['unit_id'], unit, "unit_id", '单位');
  691. like.setSelect(goods_info['base']['brand_id'], brands, "brand_id", '品牌');
  692. like.setSelect(goods_info['base']['supplier_id'], supplier, "supplier_id", '供应商');
  693. //渲染商品主图
  694. if(goods_info['base']['image']){
  695. var html = '' +
  696. '<div class="upload-image-div">' +
  697. '<img src="' + goods_info['base']['image'] + '" alt="img" />' +
  698. '<input type="hidden" name="image" value="' + goods_info['base']['image'] + '">' +
  699. // '<div class="del-upload-btn">x</div>' +
  700. '</div>' +
  701. '<div class="upload-image-elem" style="display:none;"><a class="add-upload-image" id="image"> + 添加图片</a></div>';
  702. $('#imageContainer').html(html);
  703. }
  704. //渲染分享海报
  705. if(goods_info['base']['poster']){
  706. var html = '' +
  707. '<div class="upload-image-div">' +
  708. '<img src="' + goods_info['base']['poster'] + '" alt="img" />' +
  709. '<input type="hidden" name="poster" value="' + goods_info['base']['poster'] + '">' +
  710. // '<div class="del-upload-btn">x</div>' +
  711. '</div>' +
  712. '<div class="upload-image-elem" style="display:none;"><a class="add-upload-image" id="image"> + 添加图片</a></div>';
  713. $('#posterContainer').html(html);
  714. }
  715. // 渲染视频
  716. if(goods_info['base']['video']){
  717. var html = '' +
  718. '<div class="upload-video-div">' +
  719. '<video src="' + goods_info['base']['video'] + '"></video>' +
  720. '<input type="hidden" name="video" value="' + goods_info['base']['video'] + '">' +
  721. // '<div class="del-upload-btn">x</div>' +
  722. '</div>' +
  723. '<div class="upload-image-elem" style="display:none;"><a class="add-upload-video" id="video"> + 添加视频</a></div>';
  724. $('#videoContainer').html(html);
  725. }
  726. //渲染商品轮播图
  727. if(goods_info['base']['goods_image']){
  728. var html = '';
  729. for(j = 0; j < goods_info['base']['goods_image'].length; j++) {
  730. html = html +
  731. '<div class="upload-image-div">' +
  732. '<img src="' + goods_info['base']['goods_image'][j]['abs_image'] + '" alt="img" />' +
  733. '<input type="hidden" name="goods_image[]" value="' + goods_info['base']['goods_image'][j]['abs_image'] + '">' +
  734. // '<div class="del-upload-btn">x</div>' +
  735. '</div>';
  736. }
  737. html = html + '<div class="upload-image-elem"><a class="add-upload-image" id="goodsimage"> + 添加图片</a></div>';
  738. $('#goodsImageContainer').html(html);
  739. }
  740. // 规格类型
  741. $("input[name=spec_type][value="+goods_info['base']['spec_type']+"]").prop('checked',"true");
  742. $('input[name="stock_warn"]').val(goods_info['base']['stock_warn']);
  743. $("input[name=is_show_stock][value="+goods_info['base']['is_show_stock']+"]").prop("checked",true); //是否显示库存
  744. $("input[name=express_type][value="+goods_info['base']['express_type']+"]").prop("checked",true);
  745. $('input[name="express_money"]').val(goods_info['base']['express_money']);
  746. like.setSelect(goods_info['base']['express_template_id'], freight, "express_template_id", '运费模板');
  747. $("input[name=is_member][value="+goods_info['base']['is_member']+"]").prop("checked",true); //会员价是否开启
  748. $('input[name="sort"]').val(goods_info['base']['sort']); //商品排序
  749. $("input[name=is_recommend][value="+goods_info['base']['is_recommend']+"]").prop("checked",true); // 是否推荐
  750. $("input[name=status][value="+goods_info['base']['status']+"]").prop("checked",true); //销售状态
  751. $("input[name=is_distribution][value="+goods_info['base']['is_distribution']+"]").prop("checked",true);
  752. $('input[name="first_ratio"]').val(goods_info['base']['first_ratio']); //一级分销
  753. $('input[name="second_ratio"]').val(goods_info['base']['second_ratio']); //二级分销
  754. $('input[name="third_ratio"]').val(goods_info['base']['third_ratio']); //三级分销
  755. form.render();
  756. switchSpecType(goods_info['base']['spec_type']);
  757. if(goods_info['base']['spec_type'] == 1){ // 单规格
  758. var html = '' +
  759. '<div class="upload-image-div">' +
  760. '<img src="' + goods_info['item'][0]['image'] + '" alt="img" />' +
  761. '<input type="hidden" name="one_spec_image" value="' + goods_info['item'][0]['image'] + '">' +
  762. '<div class="del-upload-btn">x</div>' +
  763. '</div>' +
  764. '<div class="upload-image-elem" style="display:none;"><a class="add-upload-image" id="one_spec_image"> + 添加图片</a></div>';
  765. if(goods_info['item'][0]['image']){
  766. $('#one_spec_image').parent().parent().html(html);
  767. }
  768. $('input[name="one_market_price"]').val(goods_info['item'][0]['market_price']);
  769. $('input[name="one_price"]').val(goods_info['item'][0]['price']);
  770. $('input[name="one_chengben_price"]').val(goods_info['item'][0]['chengben_price']);
  771. $('input[name="one_stock"]').val(goods_info['item'][0]['stock']);
  772. $('input[name="one_volume"]').val(goods_info['item'][0]['volume']);
  773. $('input[name="one_weight"]').val(goods_info['item'][0]['weight']);
  774. $('input[name="one_bar_code"]').val(goods_info['item'][0]['bar_code']);
  775. }
  776. if(goods_info['base']['spec_type'] == 2) { // 多规格
  777. for(var i in goods_info['spec']){
  778. addSpec(goods_info['spec'][i]['name']);
  779. var spes_values = goods_info['spec'][i]['values'];
  780. for(var j in spes_values){
  781. addSpecvalue($('.add-spec-value').eq(i),spes_values[j]['value'],spes_values[j]['id']);
  782. }
  783. }
  784. for(var i in goods_info['spec']){
  785. $('input[name="spec_id[]"]').eq(i).val(goods_info['spec'][i]['id']);
  786. }
  787. specValueLater();
  788. createTableBySepc();
  789. for(var i in goods_info['item']){
  790. $('#more-spec-lists-table tbody tr').each(function() {
  791. var spec_value_str = $(this).find('input[name="spec_value_str[]"]').first().val();
  792. if(spec_value_str == goods_info['item'][i]['spec_value_str']){
  793. spec_value_temp_ids = $(this).attr('spec-value-temp-ids');
  794. spec_table_data["spec_image[]"+spec_value_temp_ids] = goods_info['item'][i]['abs_image'];
  795. spec_table_data["price[]"+spec_value_temp_ids] = goods_info['item'][i]['price'];
  796. spec_table_data["chengben_price[]"+spec_value_temp_ids] = goods_info['item'][i]['chengben_price'];
  797. spec_table_data["market_price[]"+spec_value_temp_ids] = goods_info['item'][i]['market_price'];
  798. spec_table_data["stock[]"+spec_value_temp_ids] = goods_info['item'][i]['stock'];
  799. spec_table_data["volume[]"+spec_value_temp_ids] = goods_info['item'][i]['volume'];
  800. spec_table_data["weight[]"+spec_value_temp_ids] = goods_info['item'][i]['weight'];
  801. spec_table_data["bar_code[]"+spec_value_temp_ids] = goods_info['item'][i]['bar_code'];
  802. spec_table_data["item_id[]"+spec_value_temp_ids] = goods_info['item'][i]['id'];
  803. spec_table_data["spec_value_str[]"+spec_value_temp_ids] = goods_info['item'][i]['spec_value_str'];
  804. return false;
  805. }
  806. });
  807. }
  808. setTableValue();
  809. }
  810. layEditor.setContent(ieditor,goods_info['base']['content']);
  811. form.render();
  812. // 页面所有元素设置为只读
  813. setTimeout(function(){
  814. $("input").attr('readonly', true);
  815. $("textarea").attr('readonly', true);
  816. $(':radio').attr('disabled', true);
  817. $(':checkbox').attr('disabled', true);
  818. $(':button').attr('disabled', true);
  819. $('a').removeAttr('onclick');
  820. }, 1500);
  821. {/notempty}
  822. //-----------------------------------------编辑页面 end --------------------------------
  823. });
  824. </script>