<!--{include file="<!--{$oetplpath}-->block_head.tpl"}-->

<!--{if $a == "run"}-->
<div class="layui-fluid oe_fluid">

  <div class="oe_breadcrumb_box clearfix">
    <div class="layui-breadcrumb fl" lay-filter="breadcrumb" style="visibility: visible;">
      <a href="javascript:;">获客推广</a><span lay-separator="">/</span>
      <a href="javascript:;">营销管理</a><span lay-separator="">/</span>
      <a><cite>短信模板</cite></a>
    </div>
  </div>
  <!--//Top End -->

  <div class="oe_table_wrap layui-form">
  
    <table class="layui-table">
      <thead>
        <tr>
          <th width="7%">ID</th>
          <th width="10%">类型</th>
          <th>模板</th>
          <th width="15%" style="display:none;">短链接</th>
          <th width="10%">操作</th>
        </tr> 
      </thead>
      <!--{if empty($smstpl)}-->
      <tr>
        <td colspan="5" class="text_center">没有符合条件的信息</td>
      </tr>
      <!--{else}-->
      <!--{foreach $smstpl as $volist}-->
      <tr>
        <td class="text_center"><!--{$volist.tplid}--></td>
        <td class="text_center"><!--{$volist.type}--></td>
        <td>
          <!--{$volist.content}-->
          <!--{if !empty($volist.longurl)}-->
          <br />链接：<!--{$volist.longurl}-->
          <!--{/if}-->
        </td>
        <td class="text_center" style="display:none;">
          <!--{if !empty($volist.shorturl)}-->
          <!--{$volist.shorturl}-->
          <!--{else}-->
          --
          <!--{/if}-->
        </td>
        <td class="text_center">
          <!--{if $volist.issystem == '0'}-->
          <a href="<!--{$oefile}-->&c=<!--{$c}-->&a=edit&id=<!--{$volist.tplid}-->&<!--{$comeurl}-->" class="layui-btn layui-btn-xs layui-btn-normal">编辑</a>
          <!--{/if}-->

          <!--{if !empty($volist.longurl) && false}-->
          <a href="javascript:;" f="but_create_shorturl" data-id="<!--{$volist.tplid}-->">生成短链接</a>
          <!--{/if}-->
        </td>
      </tr>
      <!--{/foreach}-->
      <!--{/if}-->
    </table>
    
    <div class="oe_page_box"><!--{$showpage}--></div>
    
    
  </div>
</div>

<script type="text/javascript">
$(function(){

    //生成短链接
    $(document).on("click", "[f='but_create_shorturl']", function(){
        $id = $(this).attr("data-id");
        $.ajax({
            type: "POST",
            url: "<!--{$oefile}-->&c=<!--{$c}-->",
            cache: false,
            data: {
                a:"shorturl", id:$id, r:get_rndnum(8)
            },
            dataType: "json",
            success: function($data) {
                $json = eval($data);
                $response = $json.response;
                $result = $json.result;
                if ($response == '1') {
                    layer.msg("生成成功："+$result);
                    setTimeout(function(){
                        window.location.reload();
                    }, 700);
                }
                else {
                    if ($result.length > 0) {
                        layer.msg($result);
                    }
                    else {
                        layer.msg("生成失败，请检查RP开放平台设置是否正确");
                    }
                }
            },
            error: function() {
                layer.msg("系统繁忙，请稍后再试");
            }
        });
    });
});
</script>
<!--{/if}-->

<!--{if $a == "edit"}-->
<div class="layui-fluid oe_fluid">

  <div class="oe_breadcrumb_box clearfix">
    <div class="layui-breadcrumb fl" lay-filter="breadcrumb" style="visibility: visible;">
      <a href="javascript:;">获客管理</a><span lay-separator="">/</span>
      <a href="javascript:;">营销管理</a><span lay-separator="">/</span>
      <a><cite>短信模板</cite></a>
    </div>
    <div class="oe_tool_bar ft">
      <button class="layui-btn layui-btn-sm layui-btn-radius" id="but_submit_post2" lay-submit lay-filter="editform">
        编辑保存
        <span class="oe_btn_loading layui-anim layui-icon layui-anim-rotate layui-anim-loop" style="display:none;">&#xe63d;</span>
      </button>
      <span class="layui-btn layui-btn-sm layui-btn-primary layui-btn-radius"><a href="<!--{$oefile}-->&c=<!--{$c}-->&<!--{$comeurl}-->">返回列表</a></span>
    </div>
  </div>
  
  <form class="layui-form" id="myform" action="<!--{$oefile}-->&c=<!--{$c}-->&<!--{$comeurl}-->" method="post">
  <input type="hidden" name="a" id="a" value="saveedit" />
	<input type="hidden" name="id" id="id" value="<!--{$id}-->" />
  <div class="layui-card">
    <div class="layui-card-header">编辑模板</div>
    <div class="layui-card-body">
      <table class="oe_tbl_form layui-form">
        <tr>
          <th width="15%">模板类型：</th>
          <td width="85%">
            <!--{$smstpl.type}-->
          </td>
        </tr>
        <tr>
          <th><font color="red">*</font>模板内容：</th>
          <td>
            <textarea name="content" id="content" class="layui-textarea" style="width:50%;height:90px;"><!--{$smstpl.content}--></textarea>
            <span class="text_tip_inline">
              一条短信内容尽量不要超过70个字。
            （全局标签可用：{sitename}-网站名称，{siteurl}-网站URL）
            </span>
          </td>
        </tr>
      </table>
    </div>
  </div>
  </form>
  
  <div class="oe_tbl_form_btn">
    <button class="layui-btn" id="but_submit_post" lay-submit lay-filter="editform">
      编辑保存
      <span class="oe_btn_loading layui-anim layui-icon layui-anim-rotate layui-anim-loop" style="display:none;">&#xe63d;</span>
    </button>
  </div>
  
</div>
<script type="text/javascript">
$(function(){

    layui.use('form', function(){
        $form = layui.form;
        //保存...
        $form.on('submit(editform)', function(data){
            $obj_id = data.elem.getAttribute("id");
            if (!$("#"+$obj_id).hasClass("forbid_submit")) {
            
                if ($("#content").val().length  == 0) {
                    layer.msg("请填写模板内容");
                    return false;
                }
                
                $("#"+$obj_id).addClass("forbid_submit");
                if ($("#"+$obj_id).find("span").length > 0) {
                    $("#"+$obj_id).find("span").show();
                }
                $("#myform").submit();
            }
        });   
    });
    
});
</script>
<!--{/if}-->
</body>
</html>