wechat.js 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'weixin/template/wechat/index' + location.search,
  8. add_url: 'weixin/template/wechat/add',
  9. edit_url: 'weixin/template/wechat/edit',
  10. del_url: 'weixin/template/wechat/del',
  11. multi_url: 'weixin/template/wechat/multi',
  12. table: 'weixin_template',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. pk: 'id',
  20. sortName: 'id',
  21. columns: [
  22. [
  23. {checkbox: true},
  24. {field: 'id', title: __('Id')},
  25. {field: 'tempkey', title: __('Tempkey')},
  26. {field: 'name', title: __('Name')},
  27. // {field: 'content', title: __('Content')},
  28. {field: 'tempid', title: __('Tempid')},
  29. {field: 'add_time', title: __('Add_time'),sortable: true ,operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  30. {field: 'status', title: __('Status'), operate: false, formatter: Controller.api.formatter.status},
  31. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  32. ]
  33. ]
  34. });
  35. // 为表格绑定事件
  36. Table.api.bindevent(table);
  37. // 推送示例
  38. $(document).on("click", ".btn-demo", function () {
  39. var _html = "<pre class='layui-code'>" +
  40. "use addons\\weixin\\library\\WechatTemplateService;\r\n"+
  41. "$message = array(\r\n" +
  42. "\t'first' => '亲,您的订单已发货,请注意查收',\r\n" +
  43. "\t'keyword1' => '012345678',\r\n" +
  44. "\t'keyword2' => '100',\r\n" +
  45. "\t'keyword3' => date('Y-m-d H:i:s', time()),\r\n" +
  46. "\t'remark' => '点击查看订单详情'\r\n" +
  47. ");\r\n" +
  48. "$res = WechatTemplateService::sendTemplate(\r\n" +
  49. "\t'o-LXrv3whDgMsHZ3sTn5AmXRwO9Y',\r\n" +
  50. "\t'OPENTM410119152',\r\n" +
  51. "\t$message,\r\n" +
  52. "\t'http://fastadmin.westts.cn'\r\n" +
  53. ");" +
  54. "</pre>";
  55. Layer.open({
  56. type: 1
  57. ,title: '模板消息推送PHP示例' //不显示标题栏
  58. ,closeBtn: false
  59. ,area: '600px;'
  60. ,shade: 0.8
  61. ,id: 'LAY_layuipro' //设定一个id,防止重复弹出
  62. ,btn: ['确定', '取消']
  63. ,btnAlign: 'c'
  64. ,moveType: 1 //拖拽模式,0或者1
  65. ,content: _html
  66. });
  67. });
  68. },
  69. add: function () {
  70. Controller.api.bindevent();
  71. },
  72. edit: function () {
  73. Controller.api.bindevent();
  74. },
  75. api: {
  76. bindevent: function () {
  77. Form.api.bindevent($("form[role=form]"));
  78. },
  79. formatter: {//渲染的方法
  80. status: function (value, row, index) {
  81. if(row.status == "1"){
  82. return '<a class="btn-change text-success" data-url="weixin/template/wechat/multi" data-params="status=0" data-id="' + row.id + '"><i class="fa fa-toggle-on fa-2x"></i></a>';
  83. }else{
  84. return '<a class="btn-change text-success" data-url="weixin/template/wechat/multi" data-params="status=1" data-id="' + row.id + '"><i class="fa fa-toggle-on fa-flip-horizontal text-gray fa-2x"></i></a>';
  85. }
  86. }
  87. }
  88. }
  89. };
  90. return Controller;
  91. });