| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- {extend name="base"/}
- {block name="resources"}
- <style>
- .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="single-filter-box top">
- <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="article_list" lay-filter="article_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="edit">编辑</a>
- <a class="layui-btn" lay-event="delete">删除</a>
- </div>
- </script>
- <script type="text/html" id="sort">
- <input name="sort" type="number" onchange="editSort({{d.article_id}},this)" value="{{d.sort}}" placeholder="请输入排序" 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>
- var form,laytpl,table, repeat_flag = false;//防重复标识;
- layui.use(['form','laytpl'], function() {
- form = layui.form;
- laytpl = layui.laytpl;
- form.render();
- table = new Table({
- elem: '#article_list',
- url: ns.url("shop/article/lists"),
- cols: [
- [ {
- field: 'article_title',
- title: '文章标题',
- width: '30%',
- unresize: 'false'
- }, {
- field: 'category_name',
- title: '文章分类',
- width: '20%',
- unresize: 'false'
- },{
- field: 'sort',
- title: '排序',
- width: '15%',
- sort : true,
- unresize: 'false',
- templet: '#sort'
- }, {
- field: 'create_time',
- title: '创建时间',
- width: '20%',
- unresize: 'false',
- templet: function (data) {
- return ns.time_to_date(data.create_time);
- }
- }, {
- title: '操作',
- toolbar: '#operation',
- unresize: 'false',
- align : 'right'
- }]
- ],
- });
-
- /**
- * 搜索功能
- */
- form.on('submit(search)', function(data) {
- table.reload({
- page: {
- curr: 1
- },
- where: data.field
- });
- });
- table.on("sort",function (obj) {
- table.reload({
- page: {
- curr: 1
- },
- where: {
- order:obj.field,
- sort:obj.type
- }
- });
- });
-
- /**
- * 监听工具栏操作
- */
- table.tool(function(obj) {
- var data = obj.data;
- switch (obj.event) {
- case 'promote': // 推广
- promote(data);
- break;
- case 'edit': //编辑
- location.href = ns.url("shop/article/edit?article_id=" + data.article_id);
- break;
- case 'delete': //删除
- deleteArticle(data.article_id);
- break;
- }
- });
- });
- /**
- * 删除
- */
- function deleteArticle(article_id) {
- if (repeat_flag) return false;
- repeat_flag = true;
- layer.confirm('确定要删除该文章内容吗?', function () {
- $.ajax({
- url: ns.url("shop/article/delete"),
- data: {article_id},
- dataType: 'JSON',
- type: 'POST',
- success: function (res) {
- layer.msg(res.message);
- repeat_flag = false;
- if (res.code == 0) {
- layer.close(layer.index - 1);
- table.reload();
- }
- }
- });
- },
- function () {
- repeat_flag = false;
- layer.close();
- });
- }
- // 监听单元格编辑
- function editSort(article_id, event) {
- var data = $(event).val();
- if (!new RegExp("^-?[1-9]\\d*$").test(data)) {
- layer.msg("排序号只能是整数");
- return;
- }
- if(data < 0){
- layer.msg("排序号必须大于0");
- return ;
- }
- $.ajax({
- type: 'POST',
- url: ns.url("shop/article/modifySort"),
- data: {
- sort: data,
- article_id: article_id
- },
- dataType: 'JSON',
- success: function(res) {
- layer.msg(res.message);
- if (res.code == 0) {
- location.reload();
- }
- }
- });
- }
- function promote(data) {
- $.ajax({
- type: "POST",
- url: ns.url("shop/article/promote"),
- data: {
- article_id: data.article_id
- },
- dataType: 'JSON',
- success: function (res) {
- if(res.code==0){
- res.data.id = data.article_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('加载失败,请重试');
- }
- }
- });
- }
- function add() {
- location.href = ns.url("shop/article/add");
- }
- </script>
- {/block}
|