| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- {extend name="base"/}
- {block name="resources"}
- <style>
- .layui-layout-admin.admin-style-2 .layui-body .layui-tab + .body-content{padding-top: 65px !important;}
- .promote-flex {display:flex;margin-top:15px;padding:0 10px 0;}
- .promote-img {background-color:#f8f8f8;display:flex;justify-content:center;align-items:center;width:160px;height:160px;}
- .promote-img img {width:140px;height:140px;}
- .label-width {width:100px;}
- .block-left {margin-left:100px !important;display:flex;}
- .promote-download {margin-left:20px;}
- .path-wrap {margin-left:20px;}
- .path-wrap .copy {width:1px;height:0px;border:0px;}
- .path-wrap span {display:block;margin-bottom:10px;}
- .path-wrap p input {height:30px;line-height:30px;border:1px solid #e6e6e5;width:260px;padding:0px 5px;border-radius:5px;margin-right:10px;}
- </style>
- {/block}
- {block name="main"}
- <!-- 筛选面板 -->
- <!-- <div class="screen layui-collapse">
- <div class="layui-colla-item">
- <form class="layui-colla-content layui-form layui-show">
- <div class="layui-form-item">
- <div class="layui-inline">
- <label class="layui-form-label">接收范围:</label>
- <div class="layui-input-inline">
- <select name="receiving_type">
- <option value="">全部</option>
- <option value="mobile">手机端</option>
- </select>
- </div>
- </div>
- <button class="layui-btn" lay-submit lay-filter="search">筛选</button>
- <button type="reset" class="layui-btn layui-btn-primary">重置</button>
- </div>
- </form>
- </div>
- </div> -->
- <!-- 搜索框 -->
- <div class="single-filter-box">
- <button class="layui-btn" onclick="add()">添加公告</button>
- <div class="layui-form">
- <div class="layui-input-inline">
- <input type="text" name="search_text" placeholder="请输入公告名称" autocomplete="off" class="layui-input">
- <button type="button" class="layui-btn layui-btn-primary" lay-filter="search" lay-submit>
- <i class="layui-icon"></i>
- </button>
- </div>
- </div>
- </div>
- <!-- 列表 -->
- <table id="notice_list" lay-filter="notice_list"></table>
- <!-- 操作 -->
- <script type="text/html" id="operation">
- <div class="table-btn">
- <a class="layui-btn" lay-event="promote">推广</a>
- <a class="layui-btn" lay-event="basic">查看</a>
- <a class="layui-btn" lay-event="edit">编辑</a>
- {{# if(!d.is_top){ }}
- <a class="layui-btn" lay-event="setTop">置顶</a>
- {{# } }}
- <a class="layui-btn" lay-event="del">删除</a>
- </div>
- </script>
- <!-- 编辑排序 -->
- <script type="text/html" id="editSort">
- <input name="sort" type="number" onchange="editSort({{d.id}}, this)" value="{{d.sort}}" class="layui-input edit-sort len-short">
- </script>
- <!-- 推广 -->
- <script type="text/html" id="promote">
- <div class="promote-flex">
- <div class="promote-img">
- <img src="{{ ns.img(d.h5.path) }}" alt="推广二维码">
- </div>
- <div class="layui-form">
- <div class="layui-form-item">
- <label class="layui-form-label label-width">选择端口:</label>
- <div class="layui-input-block block-left">
- <input type="radio" name="promote_type" value="h5" title="H5" checked lay-filter="promote_type" >
- <input type="radio" name="promote_type" value="weapp" title="小程序" lay-filter="promote_type">
- {if $pc_is_exit == 1}
- <input type="radio" name="promote_type" value="pc" title="PC" lay-filter="promote_type">
- {/if}
- </div>
- </div>
- <div class="path-wrap">
- <span>推广链接</span>
- <p class="tips text-color">
- <input type="text" value="{{d.h5.url}}" readonly />
- <a class="layui-btn" href="javascript:ns.copy('article_url_{{ d.id }}');">复制</a>
- </p>
- <input type="text" id="article_url_{{ d.id }}" value="{{d.h5.url}}" readonly class="copy"/>
- </div>
- <div class="promote-download">
- <a class="text-color" href="{{ ns.img(d.h5.path) }}" download>下载二维码</a>
- </div>
- </div>
- </div>
- </script>
- {/block}
- {block name="script"}
- <script type="text/javascript">
- var form,laytpl,table,repeat_flag = false; //防重复标识
- layui.use(['form','laytpl'], function() {
- form = layui.form;
- laytpl = layui.laytpl;
- form.render();
- table = new Table({
- elem: '#notice_list',
- url: ns.url("shop/notice/index"),
- cols: [
- [{
- width: '35%',
- title: '公告标题',
- unresize: 'false',
- templet: function(data) {
- var html = data.is_top ? '<span class="required">[ 置顶 ] </span>' : '';
- html += data.title;
- return html;
- }
- },
- // {
- // field:'receiving_name',
- // width: '20%',
- // title: '接收范围',
- // unresize: 'false',
- // },
- {
- width: '25%',
- title: '创建时间',
- unresize: 'false',
- templet: function(data) {
- return ns.time_to_date(data.create_time);
- }
- }, {
- field: 'sort',
- unresize:'false',
- title: '排序',
- sort : true,
- width: '20%',
- templet: '#editSort'
- }, {
- title: '操作',
- unresize: 'false',
- templet: '#operation',
- align : 'right'
- }
- ]]
- });
- table.tool(function(obj) {
- var data = obj.data;
- var event = obj.event;
- switch (obj.event) {
- case 'promote': // 推广
- promote(data);
- break;
- case 'edit': //编辑
- location.href = ns.url("shop/notice/editNotice?id=" + data.id);
- break;
- case 'delete': //删除
- deleteNotice(data.id);
- break;
- case 'setTop': // 置顶
- modifySiteNoticeTop(data.id);
- break;
- case 'basic':
- location.href = ns.url("shop/notice/detail?id=" + data.id);
- break;
- }
- });
- /**
- * 搜索功能
- */
- form.on('submit(search)', function(data) {
- table.reload({
- page: {
- curr: 1
- },
- where: data.field
- });
- });
- function deleteNotice(id) {
- if (repeat_flag) return;
- repeat_flag = true;
- layer.confirm('确定要删除该公告吗?', function() {
- $.ajax({
- type: "post",
- async: false,
- url: ns.url("shop/notice/deleteNotice"),
- data: {
- 'id': id
- },
- dataType: "JSON",
- success: function(res) {
- layer.msg(res.message);
- repeat_flag = false;
- if (res.code == 0) {
- table.reload();
- }
- }
- });
- }, function() {
- repeat_flag = false;
- layer.close();
- }
- );
- }
- table.on("sort",function (obj) {
- table.reload({
- page: {
- curr: 1
- },
- where: {
- order:obj.field,
- sort:obj.type
- }
- });
- });
- function modifySiteNoticeTop(id) {
- if (repeat_flag) return;
- repeat_flag = true;
-
- $.ajax({
- type: "POST",
- dataType: "JSON",
- async: false,
- url: ns.url("shop/notice/modifyNoticeTop"),
- data: {id},
- success: function(res) {
- layer.msg(res.message);
- repeat_flag = false;
- if (res.code == 0) {
- table.reload();
- }
- }
- });
- }
- });
-
- function add() {
- location.href = ns.url("shop/notice/addNotice");
- }
- // 监听单元格编辑
- function editSort(id, event){
- var data = $(event).val();
- if (data == '') {
- $(event).val(0);
- data = 0;
- }
- if(!new RegExp("^-?[0-9]\\d*$").test(data)){
- layer.msg("排序号只能是整数");
- return ;
- }
- if(data<0){
- layer.msg("排序号必须大于0");
- return ;
- }
- $.ajax({
- type: 'POST',
- url: ns.url("shop/notice/modifySort"),
- data: {
- sort: data,
- id: id
- },
- dataType: 'JSON',
- success: function(res) {
- layer.msg(res.message);
- if(res.code==0){
- table.reload();
- }
- }
- });
- }
- function promote(data) {
- $.ajax({
- type: "POST",
- url: ns.url("shop/notice/promote"),
- data: {
- notice_id: data.id
- },
- dataType: 'JSON',
- success: function (res) {
- if(res.code==0){
- res.data.id = data.id;
- laytpl($("#promote").html()).render(res.data, function (html) {
- layer.open({
- type: 1,
- area: ['600px', '280px'],
- offset: '155px',
- title: ['推广'],
- content: html,
- success: function(){
- // 推广渠道监听
- form.on('radio(promote_type)', function(radio){
- if(radio.value == 'h5') {
- var content = "";
- content += '<img src="'+ res.data.h5.path +'"/>';
- $('.promote-img').html(content);
- $('.path-wrap p input').val(res.data.h5.url);
- $('.path-wrap .copy').val(res.data.h5.url);
- $('.promote-download a').attr('href',res.data.h5.path).show();
- $(".path-wrap").show();
- }else if(radio.value == 'weapp') {
- if(res.data.weapp.path == ""){
- var content = "";
- content += '<span>小程序配置错误</span>';
- $('.promote-img').html(content);
- $('.promote-download a').attr('href','').hide();
- }else{
- $('.promote-img img').attr('src',res.data.weapp.path);
- $('.promote-download a').attr('href',res.data.weapp.path).show();
- }
- $(".path-wrap").hide();
- }else if(radio.value == 'pc') {
- var content = "";
- content += '<img src="'+ res.data.pc.path +'"/>';
- $('.promote-img').html(content);
- $('.path-wrap p input').val(res.data.pc.url);
- $('.path-wrap .copy').val(res.data.pc.url);
- $('.promote-download a').attr('href',res.data.pc.path).show();
- $(".path-wrap").show();
- }
- });
- }
- });
- form.render();
- });
- }else{
- layer.msg('加载失败,请重试');
- }
- }
- });
- }
- </script>
- {/block}
|