No Description

index.js 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. var list = [];//商品列表
  2. var port,way,jsonPath,img,title,coupon,brokerage,ticketPrice,volume;
  3. function searchEvent () {
  4. //搜索事件
  5. port = $("#port").val().trim()//接口地址
  6. way = $("#way").val().trim()//接口请求方式
  7. jsonPath = $("#jsonPath").val().trim()//数据json路径
  8. img = $("#img").val().trim()//图片参数
  9. title = $("#title").val().trim()//标题参数,
  10. coupon = $("#coupon").val().trim()//优惠券参数,
  11. brokerage = $("#brokerage").val().trim()//佣金比例参数
  12. ticketPrice = $("#ticketPrice").val().trim();//请输入券后价格
  13. volume = $("#volume").val().trim();//请输入销量
  14. if(!port || port == ""){
  15. showMsg('请输入接口名称');
  16. return;
  17. }
  18. if(!way || way == ""){
  19. showMsg('请输入接口请求方式');
  20. return;
  21. }
  22. if(!jsonPath || jsonPath == ""){
  23. showMsg('请输入数据json路径');
  24. return;
  25. }
  26. if(!img || img == ""){
  27. showMsg('请输入图片参数');
  28. return;
  29. }
  30. if(!title || title == ""){
  31. showMsg('请输入标题参数');
  32. return;
  33. }
  34. portEvent(way,port)
  35. }
  36. function portEvent(type,url) {
  37. $.ajax({
  38. type:type,
  39. url:url,
  40. dataType:'json',
  41. success: function (res) {
  42. var data = res;
  43. console.log(res)
  44. list = eval("data." + jsonPath);
  45. var listHtml = '',quan = '',brokerageHtml = '',ticketPriceHtml = '',volumeHtml = '';
  46. list.forEach(function (item,index) {
  47. if(volume){
  48. volumeHtml = `<span class="volume">销量: ${item[volume]}</span>`
  49. }
  50. if(coupon){
  51. quan = `<div class="goods_coupon" ><span>券</span><span>${item[coupon]}元</span></div>`
  52. }
  53. if(brokerage){
  54. brokerageHtml = `<span class="old_price">佣金比例:${item[brokerage]}</span>`
  55. }
  56. if(ticketPrice){
  57. ticketPriceHtml = `<span class="new_price">券后 ¥${item[ticketPrice]}</span>`
  58. }
  59. listHtml += `<div class="goodsItem">
  60. <div class="goods_item">
  61. <img src="${item[img]}" alt="" class="goods_img">
  62. <div class="goods_name">
  63. ${item[title]}
  64. </div>
  65. <div class="quan">
  66. ${quan}
  67. ${volumeHtml}
  68. </div>
  69. <div class="goods_price">
  70. ${ticketPriceHtml}
  71. ${brokerageHtml}
  72. </div>
  73. </div>
  74. </div>`;
  75. $(".commodityList").html(listHtml)
  76. })
  77. },
  78. fail: function (err) {
  79. showMsg('请求失败');
  80. }
  81. });
  82. }
  83. function showMsg(msg) {
  84. var msgBox = document.getElementsByClassName('alert-info')[0];
  85. msgBox.children[0].innerText = msg;
  86. msgBox.style.display="block";
  87. setTimeout(function() {
  88. msgBox.style.display="none";
  89. }, 1500);
  90. }