123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- {{define "chooseProduct.html"}}
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
- <script src="https://cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.js"></script>
- <title>用户选择产品页面</title>
- </head>
- <body>
- <table border="0" id="tableId">
- <thead>
- <tr class="tableTitle">
- <th style="width: 10%"><input type="radio" name="item">
- </td></th>
- <th style="width: 5%">序号</th>
- <th style="width: 25%">产品名称</th>
- <th style="width: 20%">url</th>
- <th style="width: 10%">产品单价(元)</th>
- <th style="width: 10%">产品类型</th>
- <th style="width: 10%">最小单位</th>
- <th style="width: 10%">试用次数</th>
- </tr>
- </thead>
- <tbody class="box">
- </tbody>
- </table>
- <div class="productInfo" style="margin-top: 40px;margin-left: 20px">
- <div class="always"></div>
- <span>用户appid:</span><input id="appId" type="text"><br>
- <span>扣费模式:</span>
- <select id="costModel" style="width: 165px;height: 25px;margin-top: 10px">
- <option value="0">剩余量</option>
- <option value="1">账户余额</option>
- </select><br>
- <span>产品状态:</span>
- <select id="interfaceStatus" style="width: 165px;height: 25px;margin-top: 10px">
- <option value="0">开启</option>
- <option value="1">关闭</option>
- </select><br>
- <sapn>每日调用次数:</sapn>
- <input id="dayLimit" type="text"><br>
- <span>每次获取数据量:</span><input id="oneLimit" type="text"><br>
- <span>折扣:</span>
- <select id="discount" style="width: 165px;height: 25px;margin-top: 10px">
- <option value="10">无折扣</option>
- <option value="9">9折</option>
- <option value="8">8折</option>
- <option value="7">7折</option>
- <option value="6">6折</option>
- <option value="5">5折</option>
- <option value="4">4折</option>
- <option value="3">3折</option>
- <option value="2">2折</option>
- <option value="1">1折</option>
- </select>
- </div>
- <div style="margin-top: 10px;margin-left: 20px;">
- <button type="submit" onclick="submit()" style="width: 80px;height: 30px;">提交</button>
- </div>
- <div>
- <p class="result"></p>
- </div>
- </body>
- </html>
- <style>
- .box tr td {
- text-align: center;
- }
- .productInfo input {
- margin-right: 30px;
- }
- .productInfo span {
- width: 120px;
- }
- </style>
- <script>
- var appid = getParam("appId");
- if (appid != "") {
- $("#appId").val(appid);
- $("#dayLimit").val(1000);
- $("#oneLimit").val(100);
- }
- productList();
- function productList() {
- $.ajax({
- url: "/manage/product/list",
- type: "POST",
- dataType: "json",
- async: false,
- success: function (r) {
- if (r.code === 0) {
- // console.log(r.data)
- var str = ""
- for (var i = 0; i < r.data.length; i++) {
- var item = r.data[i];
- str += '<tr style="">';
- str += '<td style="width: 20px"><input id=' + item["id"] + ' value=' + item["id"] + ' type="radio" name="item"></td>';
- str += '<td style="width: 50px">' + (i + 1) + '</td>';
- str += '<td style="width: 100px">' + item.name + '</td>';
- str += '<td style="width: 200px">' + item.url + '</td>';
- str += '<td style="width: 100px">' + (item.unit_price / 100) + '</td>';
- if (item.product_type === 0) {
- str += '<td style="width: 100px">按次</td>';
- } else {
- str += '<td style="width: 100px">按条</td>';
- }
- str += '<td style="width: 100px">' + item.min_unit + '</td>';
- str += '<td style="width: 100px">' + item.test_num + '</td>';
- str += '</tr>';
- }
- $('.box').html(str);
- } else {
- $(".result").html(r.msg)
- }
- }
- })
- }
- function submit() {
- $(".result").html("");
- var productId = $("input[name='item']:checked").val();
- var costModel = $("#costModel").find("option:selected").val();
- var interfaceStatus = $("#interfaceStatus").find("option:selected").val();
- var dayLimit = $("#dayLimit").val();
- var oneLimit = $("#oneLimit").val();
- var appId = $("#appId").val();
- var discount = $("#discount").find("option:selected").val();
- var product = {}
- product["productId"] = productId
- if (productId === "" || productId === undefined) {
- alert("请选择购买的产品")
- return
- }
- if (appId === "" || appId === undefined) {
- alert("用户APPID不能为空");
- return
- }
- product["costModel"] = costModel
- product["interfaceStatus"] = interfaceStatus
- product["callTimesLimitDay"] = dayLimit
- product["dataNumOneTimes"] = oneLimit
- product["discount"] = discount
- var products = []
- products.push(product)
- var param = {
- "products": products,
- "appId": appId,
- "buyType": 1,
- };
- console.log("参数:", param);
- $.ajax({
- url: "/manage/user/userProductChoose",
- data: JSON.stringify(param),
- type: "POST",
- dataType: "json",
- async: false,
- success: function (r) {
- var a = JSON.stringify(r)
- if (r.code == 0) {
- $(".result").html(a);
- timeoutId = setTimeout(function () {
- window.location.reload();
- }, 2000);
- } else {
- $(".result").html(a);
- }
- }
- })
- }
- // 获取上个页面传来的参数
- function getParam(name) {
- var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
- var r = window.location.search.substr(1).match(reg); //获取url中"?"符后的字符串并正则匹配
- var context = "";
- if (r != null)
- context = r[2];
- reg = null;
- r = null;
- return context == null || context == "" || context == "undefined" ? "" : context;
- }
- </script>
- {{end}}
|