<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
	<meta http-equiv="pragma" content="no-cache"/> 
	<meta http-equiv="cache-control" content="no-cache,must-revalidate"/>
	<meta http-equiv="expires" content="0"/>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link href="{{yzypt}}/static/favicon.ico" type="image/x-icon" rel="shortcut icon">
    {% include '/common/layui_css.html' %}
	<style>
        body {
            background-color: #ffffff;
        }
	</style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
			<ul class="layui-tab-title">
				<li class="layui-this">基本信息</li>
				<li>平台参数</li>
				<li>数据处理</li>
			</ul>
			<div class="layui-tab-content">
				<div class="layui-tab-item layui-show" style="line-height:40px;">					
                    <form class="layui-form layuimini-form" action="">
                        <input name="id" value="{{info.id}}" type="hidden"/>
                        <div class="layui-form-item">
                            <label class="layui-form-label required">接口名称:</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" placeholder="请填写" class="layui-input" lay-verify="required" value="{{info.name}}" />
                            </div>
                        </div>

                        <div class="layui-form-item" pane="">
                            <label class="layui-form-label">是否启用</label>
                            <div class="layui-input-block">
                                <input type="checkbox" {% if info.state == 1 %}checked=""{% endif%} value="1" name="state" lay-skin="switch" lay-filter="switchTest" lay-text="启用|禁用">
                            </div>
                        </div>
                        
                        <div class="layui-form-item">
                            <label class="layui-form-label">所在平台:</label>
                            <div class="layui-input-inline">
                                <select name="type" lay-verify="required">
                                    <option value=""></option>
                                    {% for pt in ptxx_list %}
                                    <option value="{{pt.id}}" {% if pt.id == info.type %}selected{% endif %}>{{pt.name}}</option>
                                    {% endfor %}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label required">排序:</label>
                            <div class="layui-input-inline">
                                <input type="text" name="rank" placeholder="" class="layui-input" lay-verify="required" value="{{info.rank}}" />
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="saveBtn">保存</button>
                            </div>
                        </div>
                    </form>
                </div>

                <div class="layui-tab-item">
                    <form class="layui-form layuimini-form" action="">
                        <input name="id" value="{{ztn_data_info.id}}" type="hidden"/>
                        <input name="type" value="{{info.type}}" type="hidden"/>
                        <div class="layui-form-item">
                            <label class="layui-form-label required">app_id:</label>
                            <div class="layui-input-block">
                                <input type="text" name="app_id" placeholder="" class="layui-input" lay-verify="required" value="{{ztn_data_info.app_id}}" />
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label required">app_secret</label>
                            <div class="layui-input-block">
                                <input type="text" name="app_secret" placeholder="" class="layui-input" lay-verify="required" value="{{ztn_data_info.app_secret}}" />
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label required">passid:</label>
                            <div class="layui-input-block">
                                <input type="text" name="passid" placeholder="" class="layui-input" lay-verify="required" value="{{ztn_data_info.passid}}" />
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label required">passtoken:</label>
                            <div class="layui-input-block">
                                <input type="text" name="passtoken" placeholder="" class="layui-input" lay-verify="required" value="{{ztn_data_info.passtoken}}" />
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label required">service_id:</label>
                            <div class="layui-input-block">
                                <input type="text" name="service_id" placeholder="" class="layui-input" lay-verify="required" value="{{ztn_data_info.service_id}}" />
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="saveBtn2">保存</button>
                            </div>
                        </div>
                    </form>
                </div>

                <div class="layui-tab-item">
                    <form class="layui-form layuimini-form" action="">
                        <input id="id" name="id" value="{{info.id}}" type="hidden"/>
                        <div style="margin-bottom: 20px;">
                            <div class="x-ce-xace-container" id="jscript-editor" style="height: 540px;width:100%;"></div>
                        </div>
                        <div style="text-align: center;">
                            <div class="layui-input-block" style="margin-left:0;">
                                <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="saveBtn3">保存</button>
                                <button class="layui-btn" id="testBtn">测试</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% include '/common/layui_js.html' %}
<script>
	var post_url = "{{post_url}}";
	var id = "{{info.id}}";
    var editor;

    layui.use(['form', 'layer', 'element', 'xAce'], function () {
        var $ = layui.jquery,
            form = layui.form,
            xAce = layui.xAce,
            layer = layui.layer;
        
        $.get("api_jscript.json?id="+id+"&rnd="+new Date(), function(data, status) {
            xAce.render({
                id: "jscript-editor",
                theme: 'eclipse',
                lang: "javascript",
                initValue: data,
                readOnly: false
            }).then(res => {
                editor = res;
            });
        });
        
		layui.$('#testBtn').on('click', function() {
            var id = $('#id').val();
            var params = editor.getValue();
            var data = JSON.stringify({"id": id, "params": params});
            var loading = layer.load(1, {time: 300*1000});
            $.post("test.html", data, function(r) {
                layer.close(loading);
                if(r.ret == 0) {
                    layer.alert(r.msg, {icon:1});				
				}
				else {
					layer.alert(r.msg, { icon: 2 });
				}
            });
            return false;
        });

		layui.$('#exitBtn').on('click', function() {
			var iframeIndex = parent.layer.getFrameIndex(window.name);
		    parent.layer.close(iframeIndex);
			return false;
		});

        form.on('submit(saveBtn)', function (data) {
			var data = JSON.stringify(data.field);
            $.post("edit.html?page=1", data, function(r) {
				if(r.ret == 0) {
                    layer.msg(r.msg, {icon:1});					
				}
				else {
					layer.alert(r.msg, { icon: 2 });
				}
			});
            return false;
        });

        form.on('submit(saveBtn2)', function (data) {
			var data = JSON.stringify(data.field);
            $.post("edit.html?page=2", data, function(r) {
				if(r.ret == 0) {
                    layer.msg(r.msg, {icon:1});					
				}
				else {
					layer.alert(r.msg, { icon: 2 });
				}
			});
            return false;
        });

        form.on('submit(saveBtn3)', function (data) {
            var data = data.field;
            data['params'] = editor.getValue();
			var data = JSON.stringify(data);
            $.post("edit.html?page=3", data, function(r) {
				if(r.ret == 0) {
                    layer.msg(r.msg, {icon:1});					
				}
				else {
					layer.alert(r.msg, { icon: 2 });
				}
			});
            return false;
        });
    });
</script>

</body>
</html>