<!--{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 class="oe_tool_bar ft" style="display:none;">
      <button class="layui-btn layui-btn-sm search" id="but_submit_search" lay-submit lay-filter="searchform2">
        <i class="layui-icon layui-icon-search"></i>
        搜索
        <span class="oe_btn_loading layui-anim layui-icon layui-anim-rotate layui-anim-loop" style="display:none;">&#xe63d;</span>
      </button>
    </div>
  </div>
  <!--//top end -->
  <div class="oe_searchbar layui-form">
    <div class="more_search_open"></div>
    <div class="layui-form-item">
      温馨提示：
      需要开启微信公众号，并在公众号后台：用户管理->用户标签 新建、管理标签。<br />
      一个公众号，最多可以创建100个用户标签。通过扫码标签二维码，用户关注公众号，可自动保存所在用户标签组
      <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-normal" f="get_wxtags">获取/更新微信用户标签</a>
      <img src="<!--{$urlpath}-->tpl/static/images/loading.gif" id="loading_img" style="display:none;" />
      <span id="tips_msg"></span>
    </div>
  </div>
  <!--//search End -->
  <script type="text/javascript">
	$(function(){
      //获取用户标签
      $(document).on("click", "[f='get_wxtags']", function(){
          $("#tips_msg").html("");
          $("#loading_img").show();
          $.ajax({
              type: "POST",
              url: "<!--{$oefile}-->&c=wxpush&a=getwxtag",
              cache: false,
              data: {r:get_rndnum(8)},
              dataType: "json",
              success: function($data) {
                  $json = eval($data);
                  $response = $json.response;
                  $result = $json.result;
                  if ($response == 1){
                      $("#tips_msg").html("<font color='green'>获取成功</font>");
                      setTimeout(function(){
                          window.location.reload();
                      }, 500);
                  }
                  else {
                      if ($result.length > 0) {
                          $("#tips_msg").html("<font color='red'>"+$result+"</font>");
                      }
                      else {
                          $("#tips_msg").html("<font color='red'>公众号故障或公众号未创建用户标签</font>");
                      }
                  }
                  $("#loading_img").hide();
              },
              error: function() {

              }
          });
      });
	});
	</script>


  <div class="oe_table_wrap layui-form">

    <table class="layui-table">
      <thead>
        <tr>
          <th width="10%">序号</th>
          <th width="10%">ID</th>
          <th width="20%">标签名称</th>
          <th width="10%">用户数量</th>
          <th>推广二维码</th>
          <th width="20%">操作</th>
        </tr> 
      </thead>
      
      <!--{if empty($list)}-->
      <tr>
        <td class="text_center" colspan="5">还没有微信用户标签，请点击按钮“获取微信用户标签”</td>
      </tr>
      <!--{else}-->
      <!--{foreach $list as $volist}-->
      <tr>
        <td class="text_center"><!--{$volist.i}--></td>
        <td class="text_center"><!--{$volist.id}--></td>
        <td><!--{$volist.name}--></td>
        <td class="text_center"><!--{$volist.count}--></td>
        <td class="text_center" id="img_<!--{$volist.id}-->">
          <!--{if !empty($volist.qrimageurl)}-->
          <img src="<!--{$volist.qrimageurl}-->" width="100px" height="100px" f="viewimg" />
          <!--{else}-->
          --
          <!--{/if}-->
        </td>
        <td class="text_center">
          <a class="layui-btn layui-btn-xs" href="javascript:;" f="but_create_qrimg" data-id="<!--{$volist.id}-->">生成二维码</a> 
          <img src="<!--{$urlpath}-->tpl/static/images/loading.gif" id="loading_img_<!--{$volist.id}-->" style="display:none;" />
        </td>
      </tr>

      <!--{/foreach}-->
      <!--{/if}-->
    </table>
    
    <div class="oe_page_box">合计：<!--{$total}--></div>
    
  </div>
</div>

<script type="text/javascript">
$(function(){
    //生成二维码
    $(document).on("click", "[f='but_create_qrimg']", function(){
        $id = $(this).attr("data-id");
        $("#loading_img_"+$id+"").show();

        $.ajax({
            type: "POST",
            url: "<!--{$oefile}-->&c=wxpush&a=getargqr",
            cache: false,
            data: {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("操作成功");
                    $("#img_"+$id+"").html("<img src='"+$result+"' width='100px' height='100px' />");
                }
                else {
                  if ($result.length > 0) {
                      layer.msg($result);
                  }
                  else {
                      layer.msg("生成失败，请检查");
                  }
                }
                $("#loading_img_"+$id+"").hide();
            },
            error: function() {

            }
        });
    });
});
</script>
<!--{/if}-->
</body>
</html>