autoreply.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefined, Backend, Form, Table) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'wechat/autoreply/index',
  8. add_url: 'wechat/autoreply/add',
  9. del_url: 'wechat/autoreply/del',
  10. edit_url: 'wechat/autoreply/edit',
  11. multi_url: 'wechat/autoreply/multi',
  12. }
  13. });
  14. var table = $("#table");
  15. // 初始化表格
  16. table.bootstrapTable({
  17. url: $.fn.bootstrapTable.defaults.extend.index_url,
  18. sortName: 'id',
  19. columns: [
  20. [
  21. {field: 'state', checkbox: true, },
  22. {field: 'id', title: __('Id')},
  23. // {field: 'title', title: __('Title')},
  24. {field: 'text', title: '触发关键字'},
  25. {
  26. field: 'books',
  27. title: '书籍',
  28. halign: 'center',
  29. align: 'left',
  30. formatter: function (value, row, index) {
  31. if (row.book_names) {
  32. return row.book_names.join('<br>')
  33. }
  34. }
  35. },
  36. {field: 'uv', title: '阅读人数'},
  37. {field: 'subscribe', title: '关注人数'},
  38. {field: 'money', title: '充值金额'},
  39. // {field: 'eventkey', title: __('Event key')},
  40. // {field: 'remark', title: __('Remark')},
  41. {field: 'createtime', title: __('Create time'), formatter: Table.api.formatter.datetime},
  42. // {field: 'updatetime', title: __('Update time'), formatter: Table.api.formatter.datetime},
  43. {field: 'status', title: __('Status'), formatter: Table.api.formatter.status},
  44. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function(value, row, index){
  45. if (row.title == 'subscribe') {
  46. return '请到被关注回复中修改';
  47. } else if (row.title == '签到') {
  48. return '请到签到自动回复中修改';
  49. } else {
  50. return '<a href="/admin/wechat/autoreply/edit/ids/' + row.id + '" class="btn btn-xs btn-success btn-editone" title="" data-table-id="table" data-field-index="9" data-row-index="1" data-button-index="1"><i class="fa fa-pencil"></i></a> <a href="javascript:;" class="btn btn-xs btn-danger btn-delone" title="" data-table-id="table" data-field-index="9" data-row-index="1" data-button-index="2"><i class="fa fa-trash"></i></a>';
  51. }
  52. }
  53. },
  54. {
  55. field: 'tongji',
  56. title: __("统计"),
  57. operate: false,
  58. formatter: function (value, row, index) {
  59. return '<a style="text-align:center" href="/admin/orders/index?mark=1022&push_id=' + row.id + '" class="btn btn-xs btn-success btn-editone tongji">订单详情</a>';
  60. }
  61. },
  62. ]
  63. ]
  64. });
  65. $(document).on('click', '.tongji', function () {
  66. Fast.api.open($(this).attr('href'), '订单详情', {});
  67. return false;
  68. });
  69. // 为表格绑定事件
  70. Table.api.bindevent(table);
  71. },
  72. add: function () {
  73. require(['vue', 'component', 'ELEMENT'], function (Vue, component, ELEMENT) {
  74. Vue.use(ELEMENT);
  75. Vue.use(component);
  76. Form.api.bindevent($("#edit-form"));
  77. var Main = {
  78. el: '#reply-form',
  79. data: function () {
  80. return {
  81. news: [],
  82. text: [],
  83. resource_type: 2,
  84. text_tip_input: {
  85. text_tip:'@$user_nickname,欢迎关注「$gzh_name」,点击下方继续阅读',
  86. text_split:'',
  87. },
  88. keywords: '',
  89. kandian:Config.kandian,
  90. save: function (res) {
  91. if (res.code === 0) {
  92. Toastr.error(res.msg)
  93. }else{
  94. Fast.api.close();
  95. parent.$('.fa.fa-refresh').trigger('click')
  96. }
  97. }
  98. }
  99. }
  100. };
  101. $('.loading').hide();
  102. new Vue(Main)
  103. });
  104. },
  105. edit: function () {
  106. require(['vue', 'component', 'ELEMENT'], function (Vue, component, ELEMENT) {
  107. Vue.use(ELEMENT);
  108. Vue.use(component);
  109. Form.api.bindevent($("#edit-form"));
  110. var Main = {
  111. el: '#reply-form',
  112. data: function () {
  113. return {
  114. news: Config.row.news_content,
  115. text: Config.row.text_content,
  116. resource_type: Config.row.type == 'text' ? 2 : 3,
  117. text_tip_input: Config.row.text_tip_word,
  118. keywords: Config.row.text,
  119. kandian:Config.kandian,
  120. id:Config.row.id,
  121. save: function (res) {
  122. if (res.code === 0) {
  123. Toastr.error(res.msg)
  124. }else{
  125. Fast.api.close();
  126. parent.$('.fa.fa-refresh').trigger('click')
  127. }
  128. }
  129. }
  130. }
  131. };
  132. $('.loading').hide();
  133. new Vue(Main)
  134. });
  135. },
  136. signreply: function () {
  137. require(['vue', 'component', 'ELEMENT'], function (Vue, component, ELEMENT) {
  138. Vue.use(component);
  139. Vue.use(ELEMENT);
  140. var Main = {
  141. el: '#sign',
  142. data() {
  143. return {
  144. type: Config.type,
  145. text: eval(Config.text),
  146. text_split: Config.text_split
  147. }
  148. }
  149. };
  150. new Vue(Main)
  151. });
  152. },
  153. api: {
  154. bindevent: function () {
  155. Form.api.bindevent($("form[role=form]"));
  156. var refreshkey = function (data) {
  157. $("input[name='row[eventkey]']").val(data.eventkey).trigger("change");
  158. Layer.closeAll();
  159. var keytitle = data.title;
  160. var cont = $(".clickbox .create-click:first");
  161. $(".keytitle", cont).remove();
  162. if (keytitle) {
  163. cont.append('<div class="keytitle">' + __('Event key') + ':' + keytitle + '</div>');
  164. }
  165. };
  166. $(document).on('click', "#select-resources", function () {
  167. var va = $("input[name='row[text]']").val();
  168. var key = $("input[name='row[eventkey]']").val();
  169. var filter = op = ''
  170. if (va != 'subscribe') {
  171. filter = encodeURIComponent('{"is_subscribe":"0"}');
  172. op = encodeURIComponent('{"is_subscribe":"="}');
  173. }
  174. parent.Backend.api.open($(this).attr("data") + "?key=" + key + "&filter1=" + filter + "&op1=" + op, __('Select'), {callback: refreshkey});
  175. return false;
  176. });
  177. $(document).on('click', "#add-resources", function () {
  178. var va = $("input[name='row[text]']").val();
  179. var filter = op = ''
  180. if (va != 'subscribe') {
  181. filter = encodeURIComponent('{"is_subscribe":"0"}');
  182. op = encodeURIComponent('{"is_subscribe":"="}');
  183. }
  184. parent.Backend.api.open($(this).attr("data") + "?key=" + "&filter1=" + filter + "&op1=" + op, __('Add'), {callback: refreshkey});
  185. return false;
  186. });
  187. }
  188. }
  189. };
  190. return Controller;
  191. });