goods_edit.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. requestAdd = 'shop/goods/addGoods';
  2. requestEdit = 'shop/goods/editGoods';
  3. // 追加刷新商品sku数据
  4. appendRefreshGoodsSkuData = {
  5. weight: "", // 重量
  6. volume: "", // 体积
  7. };
  8. // 追加单规格数据
  9. function appendSingleGoodsData(data) {
  10. return {
  11. weight: data.field.weight,
  12. volume: data.field.volume
  13. };
  14. }
  15. // 追加保存数据
  16. function appendSaveData(data) {
  17. var supportTradeType = [];
  18. $('[name="support_trade_type"]:checked').each(function () {
  19. supportTradeType.push($(this).val())
  20. });
  21. return {
  22. support_trade_type: supportTradeType.toString()
  23. }
  24. }
  25. $(function () {
  26. layui.use(['element', 'laytpl', 'form'], function () {
  27. form = layui.form;
  28. element = layui.element;
  29. laytpl = layui.laytpl;
  30. form.render();
  31. element.render();
  32. form.on('checkbox(support_trade_type)', function (data) {
  33. if (data.value == 'express') {
  34. if ($(data.elem).is(':checked')) {
  35. $('.trade-type.express').show()
  36. } else {
  37. $('.trade-type.express').hide()
  38. }
  39. }
  40. });
  41. //是否免邮
  42. form.on("radio(is_free_shipping)", function (data) {
  43. if (data.value == 0) {
  44. $(".js-shipping-template").show();
  45. } else {
  46. $(".js-shipping-template").hide();
  47. }
  48. });
  49. // 运费模板刷新
  50. $('.delivery-refresh').click(function () {
  51. $.ajax({
  52. url: ns.url('shop/goods/getexpresstemplatelist'),
  53. dataType: 'JSON',
  54. type: 'POST',
  55. success: function (res) {
  56. if (res.code == 0) {
  57. var html = $("#deliveryHtml").html();
  58. laytpl(html).render({
  59. list: res.data,
  60. shipping_template: $('select[name="shipping_template"] option:selected').val()
  61. }, function (html) {
  62. $('select[name="shipping_template"]').html(html);
  63. form.render();
  64. });
  65. }
  66. }
  67. });
  68. });
  69. form.verify({
  70. //重量
  71. weight: function (value) {
  72. if (!$("input[name='spec_type']").is(":checked")) {
  73. if (value.length > 0) {
  74. if (isNaN(value) || !regExp.digit.test(value)) {
  75. element.tabChange('goods_tab', "price-stock");
  76. return '[重量(kg)]格式输入错误';
  77. }
  78. }
  79. }
  80. },
  81. //体积
  82. volume: function (value) {
  83. if (!$("input[name='spec_type']").is(":checked")) {
  84. if (value.length > 0) {
  85. if (isNaN(value) || !regExp.digit.test(value)) {
  86. element.tabChange('goods_tab', "price-stock");
  87. return '[体积(m³)]格式输入错误';
  88. }
  89. }
  90. }
  91. },
  92. //sku重量
  93. sku_weight: function (value) {
  94. if (value.length > 0) {
  95. if (isNaN(value) || !regExp.digit.test(value)) {
  96. element.tabChange('goods_tab', "price-stock");
  97. return '[重量(kg)]格式输入错误';
  98. }
  99. }
  100. },
  101. //sku体积
  102. sku_volume: function (value) {
  103. if (value.length > 0) {
  104. if (isNaN(value) || !regExp.digit.test(value)) {
  105. element.tabChange('goods_tab', "price-stock");
  106. return '[体积(m³)]格式输入错误';
  107. }
  108. }
  109. },
  110. express_type: function () {
  111. if ($('[name="support_trade_type"]').val() == undefined) return '请先配置配送方式';
  112. if (!$('[name="support_trade_type"]:checked').val()) return '请选择配送方式';
  113. },
  114. //运费模板
  115. shipping_template: function (value) {
  116. if ($('[name="support_trade_type"][value="express"]').is(':checked') && $("input[name='is_free_shipping']:checked").val() == 0) {
  117. if (value == "") {
  118. element.tabChange('goods_tab', "basic");
  119. return '请选择运费模板';
  120. }
  121. }
  122. }
  123. });
  124. });
  125. });