attribute.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. window.onload = function (ev) {
  2. init();
  3. }
  4. init = function () {
  5. getAttributeInfo();
  6. }
  7. getAttributeInfo = function () {
  8. var parameter = urlEncode(["SelectAllProductAttribute"]);
  9. $.ajax({
  10. type: "post",
  11. url: "/taiwan/php/index.php",
  12. data: {mode: parameter},
  13. dataType: "json",
  14. success: function (data) {
  15. if (data[0].length == 0 || data == -1) {
  16. var th = '<th colspan="9" scope="col" class="text-c f-20" style="padding: 50px 0;">暂无数据</th>';
  17. $("#warp").html(th);
  18. return;
  19. }
  20. printAttributeInfo(data);
  21. console.log(data);
  22. }
  23. });
  24. }
  25. printAttributeInfo = function (data) {
  26. var warp = $("#warp"),
  27. tr,
  28. href,
  29. title = "'查看商品信息'";
  30. warp.html("");
  31. for (var i = 0; i < data.length; i++) {
  32. href = "'product-add.html?pid=" + data[i].ProductId + "'";
  33. tr = $('<tr class="text-c">' +
  34. '<td>' + data[i].ProductInfoClassId + '</td>' +
  35. '<td>' + data[i].ProductInfoClassName + '</td>' +
  36. '<td>' + data[i].InfoClassIdAddTime + '</td>' +
  37. '<td>' +
  38. '<a class="btn btn-primary radius td-button" onclick=deleteAttribute("' + data[i].ProductInfoClassId + '")>删除</>' +
  39. '<a class="btn btn-primary radius td-button" onclick=showUpdateAttribute("' + data[i].ProductInfoClassName + '","' + data[i].ProductInfoClassId + '")>修改</>' +
  40. '</td></tr>'
  41. )
  42. ;
  43. warp.append(tr);
  44. }
  45. $("#loading").css({"display": "none"});
  46. $("#warp").css({"display": "table-row-group"});
  47. }
  48. showAddWarp = function () {
  49. $("#modal-demo").modal("show");
  50. }
  51. setAttribute = function (jugde, text, aid) {
  52. var _el = $("#addAttribute");
  53. if (jugde) {
  54. $(_el).bind("click", function () {
  55. addAttribute();
  56. });
  57. }
  58. else {
  59. $(_el).bind("click", function () {
  60. updateAttribute(text, aid);
  61. });
  62. }
  63. }
  64. addAttribute = function () {
  65. var name = $("#AttributeName").val();
  66. if (name == "" || name.trim() == "") {
  67. $.Huimodalalert('请输入属性名!', 2000);
  68. }
  69. else {
  70. var parameter = urlEncode(["InsertAttribute", name]);
  71. $.ajax({
  72. type: "post",
  73. url: "/taiwan/php/index.php",
  74. data: {mode: parameter},
  75. dataType: "json",
  76. success: function (data) {
  77. $("#AttributeName")[0].value = "";
  78. getAttributeInfo();
  79. }
  80. });
  81. $("#warp").css({"display": "none"});
  82. $("#modal-demo").modal("hide");
  83. $("#loading").css({"display": "block"});
  84. }
  85. }
  86. deleteAttribute = function (aid) {
  87. layer.confirm('是否删除属性?', {
  88. btn: ['确定', '取消'] //按钮
  89. }, function (e, a) {
  90. var parameter = urlEncode(["DeleteAttribute", aid]);
  91. $.ajax({
  92. type: "post",
  93. url: "/taiwan/php/index.php",
  94. data: {mode: parameter},
  95. dataType: "json",
  96. success: function (data) {
  97. if (data[0].mode == 1) {
  98. getAttributeInfo();
  99. $.Huimodalalert('删除成功', 2000);
  100. console.log(data);
  101. }
  102. }
  103. });
  104. $(a).prev().remove();
  105. $(a).remove();
  106. $("#warp").css({"display": "none"});
  107. $("#loading").css({"display": "block"});
  108. });
  109. }
  110. showUpdateAttribute = function (text, aid) {
  111. showAddWarp();
  112. $("#AttributeName").val(text);
  113. setAttribute(false, text, aid);
  114. }
  115. updateAttribute = function (text, aid) {
  116. var name = $("#AttributeName").val();
  117. if (name == "" || name.trim() == "") {
  118. $.Huimodalalert('请输入属性名!', 2000);
  119. }
  120. else {
  121. var parameter = urlEncode(["UpdateAttributeName", aid, name]);
  122. $.ajax({
  123. type: "post",
  124. url: "/taiwan/php/index.php",
  125. data: {mode: parameter},
  126. dataType: "json",
  127. success: function (data) {
  128. $("#AttributeName")[0].value = "";
  129. getAttributeInfo();
  130. }
  131. });
  132. $("#warp").css({"display": "none"});
  133. $("#modal-demo").modal("hide");
  134. $("#loading").css({"display": "block"});
  135. }
  136. }
  137. urlEncode = function (arr) {
  138. var i; //循环初始化
  139. for (i = 0; i < arr.length; i++) {
  140. arr[i] = encodeURIComponent(encodeURIComponent(arr[i]));
  141. }
  142. return arr.join();
  143. }