goods-add.js 957 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. $(document).ready(function() {
  2. initSelectData()
  3. })
  4. function initSelectData() {
  5. //加载商品类型
  6. var res=getData('/goods/type');
  7. $.each(res.data, function(index, item) {
  8. $('#goods-type-select').append(new Option(item.type, item.id)); // 下拉菜单里添加元素
  9. });
  10. layui.form.render("select");
  11. }
  12. /**
  13. * @param {JSON} data
  14. */
  15. function addGoods(data) {
  16. $.ajax({
  17. url: getRootUrl() + '/goods/add',
  18. type: 'POST',
  19. headers: {
  20. token: getToken()
  21. },
  22. contentType: 'application/json',
  23. dataType: 'json',
  24. data: data,
  25. success(e) {
  26. lay.msg(e.message)
  27. var goodsId = e.data;
  28. },
  29. error(e) {
  30. lar.msg('添加失败')
  31. }
  32. })
  33. }
  34. function renderCarousel(id){
  35. //渲染轮播图
  36. layui.use('carousel', function() {
  37. var carousel = layui.carousel;
  38. //建造实例
  39. carousel.render({
  40. elem: id,
  41. width: '150px', //设置容器宽度
  42. height: '150px',
  43. arrow: 'hover' ,//始终显示箭头
  44. indicator:'none'
  45. });
  46. });
  47. }