chooseProduct.html 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. {{define "chooseProduct.html"}}
  2. <!DOCTYPE html>
  3. <html lang="en">
  4. <head>
  5. <meta charset="UTF-8">
  6. <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
  7. <script src="https://cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.js"></script>
  8. <title>用户选择产品页面</title>
  9. </head>
  10. <body>
  11. <table border="0" id="tableId">
  12. <thead>
  13. <tr class="tableTitle">
  14. <th style="width: 10%"><input type="radio" name="item">
  15. </td></th>
  16. <th style="width: 5%">序号</th>
  17. <th style="width: 25%">产品名称</th>
  18. <th style="width: 20%">url</th>
  19. <th style="width: 10%">产品单价(元)</th>
  20. <th style="width: 10%">产品类型</th>
  21. <th style="width: 10%">最小单位</th>
  22. <th style="width: 10%">试用次数</th>
  23. </tr>
  24. </thead>
  25. <tbody class="box">
  26. </tbody>
  27. </table>
  28. <div class="productInfo" style="margin-top: 40px;margin-left: 20px">
  29. <div class="always"></div>
  30. <span>用户appid:</span><input id="appId" type="text"><br>
  31. <span>扣费模式:</span>
  32. <select id="costModel" style="width: 165px;height: 25px;margin-top: 10px">
  33. <option value="0">剩余量</option>
  34. <option value="1">账户余额</option>
  35. </select><br>
  36. <span>产品状态:</span>
  37. <select id="interfaceStatus" style="width: 165px;height: 25px;margin-top: 10px">
  38. <option value="0">开启</option>
  39. <option value="1">关闭</option>
  40. </select><br>
  41. <sapn>每日调用次数:</sapn>
  42. <input id="dayLimit" type="text"><br>
  43. <span>每次获取数据量:</span><input id="oneLimit" type="text"><br>
  44. <span>折扣:</span>
  45. <select id="discount" style="width: 165px;height: 25px;margin-top: 10px">
  46. <option value="10">无折扣</option>
  47. <option value="9">9折</option>
  48. <option value="8">8折</option>
  49. <option value="7">7折</option>
  50. <option value="6">6折</option>
  51. <option value="5">5折</option>
  52. <option value="4">4折</option>
  53. <option value="3">3折</option>
  54. <option value="2">2折</option>
  55. <option value="1">1折</option>
  56. </select>
  57. </div>
  58. <div style="margin-top: 10px;margin-left: 20px;">
  59. <button type="submit" onclick="submit()" style="width: 80px;height: 30px;">提交</button>
  60. </div>
  61. <div>
  62. <p class="result"></p>
  63. </div>
  64. </body>
  65. </html>
  66. <style>
  67. .box tr td {
  68. text-align: center;
  69. }
  70. .productInfo input {
  71. margin-right: 30px;
  72. }
  73. .productInfo span {
  74. width: 120px;
  75. }
  76. </style>
  77. <script>
  78. var appid = getParam("appId");
  79. if (appid != "") {
  80. $("#appId").val(appid);
  81. $("#dayLimit").val(1000);
  82. $("#oneLimit").val(100);
  83. }
  84. productList();
  85. function productList() {
  86. $.ajax({
  87. url: "/manage/product/list",
  88. type: "POST",
  89. dataType: "json",
  90. async: false,
  91. success: function (r) {
  92. if (r.code === 0) {
  93. // console.log(r.data)
  94. var str = ""
  95. for (var i = 0; i < r.data.length; i++) {
  96. var item = r.data[i];
  97. str += '<tr style="">';
  98. str += '<td style="width: 20px"><input id=' + item["id"] + ' value=' + item["id"] + ' type="radio" name="item"></td>';
  99. str += '<td style="width: 50px">' + (i + 1) + '</td>';
  100. str += '<td style="width: 100px">' + item.name + '</td>';
  101. str += '<td style="width: 200px">' + item.url + '</td>';
  102. str += '<td style="width: 100px">' + (item.unit_price / 100) + '</td>';
  103. if (item.product_type === 0) {
  104. str += '<td style="width: 100px">按次</td>';
  105. } else {
  106. str += '<td style="width: 100px">按条</td>';
  107. }
  108. str += '<td style="width: 100px">' + item.min_unit + '</td>';
  109. str += '<td style="width: 100px">' + item.test_num + '</td>';
  110. str += '</tr>';
  111. }
  112. $('.box').html(str);
  113. } else {
  114. $(".result").html(r.msg)
  115. }
  116. }
  117. })
  118. }
  119. function submit() {
  120. $(".result").html("");
  121. var productId = $("input[name='item']:checked").val();
  122. var costModel = $("#costModel").find("option:selected").val();
  123. var interfaceStatus = $("#interfaceStatus").find("option:selected").val();
  124. var dayLimit = $("#dayLimit").val();
  125. var oneLimit = $("#oneLimit").val();
  126. var appId = $("#appId").val();
  127. var discount = $("#discount").find("option:selected").val();
  128. var product = {}
  129. product["productId"] = productId
  130. if (productId === "" || productId === undefined) {
  131. alert("请选择购买的产品")
  132. return
  133. }
  134. if (appId === "" || appId === undefined) {
  135. alert("用户APPID不能为空");
  136. return
  137. }
  138. product["costModel"] = costModel
  139. product["interfaceStatus"] = interfaceStatus
  140. product["callTimesLimitDay"] = dayLimit
  141. product["dataNumOneTimes"] = oneLimit
  142. product["discount"] = discount
  143. var products = []
  144. products.push(product)
  145. var param = {
  146. "products": products,
  147. "appId": appId,
  148. "buyType": 1,
  149. };
  150. console.log("参数:", param);
  151. $.ajax({
  152. url: "/manage/user/userProductChoose",
  153. data: JSON.stringify(param),
  154. type: "POST",
  155. dataType: "json",
  156. async: false,
  157. success: function (r) {
  158. var a = JSON.stringify(r)
  159. if (r.code == 0) {
  160. $(".result").html(a);
  161. timeoutId = setTimeout(function () {
  162. window.location.reload();
  163. }, 2000);
  164. } else {
  165. $(".result").html(a);
  166. }
  167. }
  168. })
  169. }
  170. // 获取上个页面传来的参数
  171. function getParam(name) {
  172. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  173. var r = window.location.search.substr(1).match(reg); //获取url中"?"符后的字符串并正则匹配
  174. var context = "";
  175. if (r != null)
  176. context = r[2];
  177. reg = null;
  178. r = null;
  179. return context == null || context == "" || context == "undefined" ? "" : context;
  180. }
  181. </script>
  182. {{end}}