123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- {layout name="layout1" /}
- <div class="wrapper">
- <div class="layui-card">
- <div class="layui-card-body">
- <div class="layui-collapse like-layui-collapse" lay-accordion="" style="border:1px dashed #c4c4c4">
- <div class="layui-colla-item">
- <h2 class="layui-colla-title like-layui-colla-title" style="background-color: #fff">操作提示</h2>
- <div class="layui-colla-content layui-show">
- <p>*微信公众号回复管理,可以设置自动回复用户输入内容;</p>
- <p>*关注回复用于用户关注公众号时回复;</p>
- <p>*关键词回复用于用户输入内容时回复。关键词相同时,根据排序回复,排序值越小越前;</p>
- <p>*默认回复用于用户输入内容未匹配时回复;</p>
- </div>
- </div>
- </div>
- </div>
- <div class="layui-tab layui-tab-card" lay-filter="tab-all">
- <!-- 选项卡头部-->
- <ul class="layui-tab-title">
- {foreach $type_list as $type => $name}
- <li data-type={$type} {if 'subscribe' == $type } class="layui-this" {/if} >{$name}</li>
- {/foreach}
- </ul>
-
- <div class="layui-tab-item layui-show">
- <div class="layui-card">
- <div class="layui-card-body">
- <div style="padding-bottom: 10px;">
- <button class="layui-btn layui-btn-sm layuiadmin-btn-reply {$view_theme_color}" data-type="add">新增回复</button>
- </div>
- <table id="reply-lists" lay-filter="reply-lists"></table>
- <script type="text/html" id="status">
- <input type="checkbox" lay-filter="switch-status" data-id={{d.id}} data-field='status' lay-skin="switch"
- lay-text="显示|隐藏" {{# if(d.status){ }} checked {{# } }} />
- </script>
- <script type="text/html" id="reply-operation">
- <a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="edit"><i class="layui-icon"></i>编辑</a>
- <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del" ><i class="layui-icon"></i>删除</a>
- </script>
-
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <style>
- .layui-table-cell {
- height: auto;
- }
- </style>
- <script>
- // 初始回复类型
- var type = 'subscribe';
-
- layui.config({
- version:"{$front_version}",
- base: '/static/lib/' //静态资源所在路径
- }).use(['table', 'element'], function(){
- var $ = layui.$
- ,form = layui.form
- ,table = layui.table
- ,element = layui.element;
-
- // 初始获取列表数据
- getList()
-
- // 事件处理函数
- var active = {
- add: function(){
- var add = layer.open({
- type: 2
- ,title: '新增回复 '
- ,content: '{:url("wechat.reply/add")}?type='+type
- ,area: ['90%','90%']
- ,btn: ['确定', '取消']
- ,yes: function(index, layero){
- var iframeWindow = window['layui-layer-iframe'+ index]
- ,submitID = 'add-reply-submit'
- ,submit = layero.find('iframe').contents().find('#'+ submitID);
- //监听提交
- iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
- var field = data.field;
- field['reply_type'] = type;
- like.ajax({
- url:'{:url("wechat.reply/add")}',
- data:field,
- type:"post",
- success:function(res)
- {
- if(res.code == 1)
- {
- layui.layer.msg(res.msg, {
- offset: '15px'
- , icon: 1
- , time: 1000
- });
- layer.close(index); //关闭弹层
- table.reload('reply-lists'); //数据刷新
- }
- },
- });
- });
- submit.trigger('click');
- }
- });
- }
- }
-
- // 监听文本框编辑
- table.on('edit(reply-lists)', function (obj) {
- var ids = [];
- var id = obj.data.id;
- var fields = obj.field;
- var field_value = obj.value;
- ids.push(id);
- if(isNaN(field_value)){
- var old_value=$(this).prev().text();
-
- layer.tips('请输入数字', $(this), {tips: [1, '#FF5722']});
- $(this).val(old_value);
-
- return false;
- }
-
- changeFields(ids,fields,field_value)
-
- });
-
- // 新增回复
- $('.layui-btn.layuiadmin-btn-reply').on('click', function(){
- var type = $(this).data('type');
- active[type] ? active[type].call(this) : '';
- });
-
- // 监听启用状态开关
- form.on('switch(switch-status)',function (obj) {
- var ids = [];
- var id = obj.elem.attributes['data-id'].nodeValue
- var fields = obj.elem.attributes['data-field'].nodeValue
- var field_value = 0;
- ids.push(id);
- if(this.checked){
- field_value = 1;
- }
- changeFields(ids,fields,field_value)
-
- })
-
- // 监听选项卡切换
- element.on('tab(tab-all)', function (data) {
- type = $(this).attr('data-type');
- getList();
- });
-
- // 加载列表数据
- function getList() {
- switch (type) {
- case "subscribe":
- var cols = [
- {field: 'name', title: '规则名称', align: 'center'}
- , {field: 'content_type', title: '回复类型', align: 'center'}
- , {field: 'content', title: '回复内容', align: 'center'}
- , {title:'启用状态', align: 'center', toolbar: '#status'}
- , {title: '操作', align: 'center', toolbar: '#reply-operation'}
- ];
- break;
- case "text":
- var cols = [
- {field: 'keyword', title: '关键词', align: 'center'}
- , {field: 'matching_type', title: '匹配方式', align: 'center'}
- , {field: 'content_type', title: '回复类型', align: 'center'}
- , {field: 'content', title: '回复内容', align: 'center'}
- , {title: 'status', title:'启用状态', align: 'center', toolbar: '#status'}
- , {field: 'sort', title: '排序', align: 'center',edit:'text'}
- , {title: '操作', align: 'center', toolbar: '#reply-operation'}
- ];
- break;
- case "default":
- var cols = [
- {field: 'name', title: '规则名称', align: 'center'}
- , {field: 'content_type', title: '回复类型', align: 'center'}
- , {field: 'content', title: '回复内容', align: 'center'}
- , {title: 'status', title:'启用状态', align: 'center', toolbar: '#status'}
- , {title: '操作', align: 'center', toolbar: '#reply-operation'}
- ];
- break;
- }
-
- //管理员管理
- table.render({
- elem: '#reply-lists'
- , url: '{:url("wechat.reply/lists")}?type='+type
- , cols: [
- cols
- ]
- , page: true
- , text: {none: '暂无数据!'}
- , response: {
- 'statusCode': 1
- }
- , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
- return {
- "code": res.code,
- "msg": res.msg,
- "count": res.data.count, //解析数据长度
- "data": res.data.list, //解析数据列表
- };
- }
- });
- }
-
- //监听工具条
- table.on('tool(reply-lists)', function(obj){
- if(obj.event === 'del'){
- var id = obj.data.id;
- var attr = obj.data.attr;
- var name = obj.data.name;
- layer.confirm('确认删除回复:'+'<span style="color: red">'+name+'</span>', function(index){
- like.ajax({
- url:'{:url("wechat.reply/del")}',
- data:{id:id},
- type:"post",
- success:function(res)
- {
- if(res.code == 1)
- {
- layui.layer.msg(res.msg, {
- offset: '15px'
- , icon: 1
- , time: 1000
- });
- layer.close(index); //关闭弹层
- table.reload('reply-lists'); //数据刷新
- }
- },
- });
- });
- }else if(obj.event === 'edit'){
- var id = obj.data.id;
- var edit = layer.open({
- type: 2
- ,title: '编辑回复'
- ,content: '{:url("wechat.reply/edit")}?id='+id
- ,area: ['90%','90%']
- ,btn: ['确定', '取消']
- ,yes: function(index, layero){
- var iframeWindow = window['layui-layer-iframe'+ index]
- ,submitID = 'edit-reply-submit'
- ,submit = layero.find('iframe').contents().find('#'+ submitID);
-
- //监听提交
- iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
- var field = data.field;
- field['reply_type'] = type;
- like.ajax({
- url:'{:url("wechat.reply/edit")}',
- data:field,
- type:"post",
- success:function(res)
- {
- if(res.code == 1)
- {
- layui.layer.msg(res.msg, {
- offset: '15px'
- , icon: 1
- , time: 1000
- });
- layer.close(index); //关闭弹层
- table.reload('reply-lists'); //数据刷新
- }
- },
- });
- });
- submit.trigger('click');
- }
- })
- }
- });
- });
-
- function changeFields(ids,fields,value) {
- like.ajax({
- url:'{:url("wechat.reply/changeFields")}',
- data:{id:ids,field:fields,value:value,reply_type:type},
- type:'post',
- dataType:'json',
- success:function (res) {
- if(res.code == 1) {
- layui.layer.msg(res.msg, {
- offset: '15px'
- , icon: 1
- , time: 1000
- }, function(){
- location.href = location.href;
- });
-
- } else {
- layui.layer.msg(res.msg, {
- offset: '15px'
- , icon: 2
- , time: 1000
- }, function(){
- location.href = location.href;
- });
- }
- }
- })
-
- }
- </script>
|