emailtemplate.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. define(['jquery', 'table', 'form', 'layui'], function($, Table, Form, layui) {
  2. Yzn.config.openArea = ['90%', '90%'];
  3. function formatType(val) {
  4. var map = {
  5. 'subscribe_auto': '订阅欢迎邮件',
  6. 'subscribe_manual': '后台补发邮件',
  7. 'marketing_broadcast': '营销群发邮件'
  8. };
  9. return map[val] || val || '-';
  10. }
  11. function getVariableMap() {
  12. return window.emailTemplateVariableMap || {};
  13. }
  14. function renderVariablesByType(type) {
  15. var map = getVariableMap();
  16. var textarea = $('#variables-textarea');
  17. if (!textarea.length) {
  18. return;
  19. }
  20. var lines = map[type] || [];
  21. textarea.val(lines.join("\\n"));
  22. }
  23. function initTypeVariableBinding() {
  24. var form = layui.form;
  25. var typeSelect = $('select[name="row[type]"]');
  26. if (!typeSelect.length) {
  27. return;
  28. }
  29. renderVariablesByType(typeSelect.val());
  30. form.on('select(emailtemplate-type)', function(data) {
  31. renderVariablesByType(data.value || '');
  32. });
  33. }
  34. var Controller = {
  35. index: function() {
  36. Table.init = {
  37. table_elem: '#currentTable',
  38. table_render_id: 'currentTable',
  39. add_url: 'emailtemplate/add',
  40. edit_url: 'emailtemplate/edit',
  41. delete_url: 'emailtemplate/del'
  42. };
  43. Table.render({
  44. init: Table.init,
  45. toolbar: ['refresh', {
  46. text: '添加',
  47. icon: 'iconfont icon-add-fill',
  48. class: 'layui-btn layui-btn-normal layui-btn-sm btn-dialog',
  49. auth: 'add',
  50. url: Table.init.add_url
  51. }, {
  52. text: '删除',
  53. icon: 'iconfont icon-delete-bin-line',
  54. class: 'layui-btn layui-btn-sm layui-btn-danger',
  55. auth: 'delete',
  56. extend: 'id="emailtemplateDeleteBtn" href="javascript:;"'
  57. }],
  58. url: 'emailtemplate/index',
  59. cols: [[
  60. {type: 'checkbox', width: 50},
  61. {field: 'id', width: 80, title: 'ID', sort: true},
  62. {field: 'name', minWidth: 180, title: '模板名称'},
  63. {field: 'code', width: 160, title: '模板标识'},
  64. {field: 'lang', width: 100, title: '语言'},
  65. {field: 'type', width: 160, title: '模板类型', templet: function(d) { return formatType(d.type); }},
  66. {field: 'subject', minWidth: 220, title: '邮件主题'},
  67. {field: 'status', width: 100, title: '状态', templet: function(d) { var map = {0: '禁用', 1: '启用'}; return map[d.status] || d.status; }},
  68. {field: 'listorder', width: 90, title: '排序', sort: true},
  69. {field: 'updatetime', width: 170, title: '更新时间', templet: Table.formatter.datetime},
  70. {field: 'createtime', width: 170, title: '创建时间', templet: Table.formatter.datetime},
  71. {field: 'operate', title: '操作', width: 160, fixed: 'right', templet: Table.formatter.tool, operat: ['edit', 'delete']}
  72. ]],
  73. page: {}
  74. });
  75. $('#searchBtn').on('click', function() {
  76. layui.table.reload('currentTable', {
  77. where: {
  78. lang: $('#lang').val(),
  79. type: $('#type').val(),
  80. status: $('#status').val(),
  81. keyword: $('#keyword').val()
  82. },
  83. page: {curr: 1}
  84. });
  85. });
  86. $('#resetBtn').on('click', function() {
  87. $('#lang,#keyword').val('');
  88. $('#type,#status').val('');
  89. layui.form.render('select');
  90. layui.table.reload('currentTable', {where: {}, page: {curr: 1}});
  91. });
  92. Table.api.bindevent();
  93. Form.api.bindevent($('form.layui-form'));
  94. },
  95. add: function() {
  96. Controller.api.bindevent();
  97. },
  98. edit: function() {
  99. Controller.api.bindevent();
  100. },
  101. api: {
  102. bindevent: function() {
  103. Form.api.bindevent($('form.layui-form'));
  104. initTypeVariableBinding();
  105. }
  106. }
  107. };
  108. return Controller;
  109. });