| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- define(['jquery', 'table', 'form', 'layui'], function($, Table, Form, layui) {
- Yzn.config.openArea = ['90%', '90%'];
- function formatType(val) {
- var map = {
- 'subscribe_auto': '订阅欢迎邮件',
- 'subscribe_manual': '后台补发邮件',
- 'marketing_broadcast': '营销群发邮件'
- };
- return map[val] || val || '-';
- }
- function getVariableMap() {
- return window.emailTemplateVariableMap || {};
- }
- function renderVariablesByType(type) {
- var map = getVariableMap();
- var textarea = $('#variables-textarea');
- if (!textarea.length) {
- return;
- }
- var lines = map[type] || [];
- textarea.val(lines.join("\\n"));
- }
- function initTypeVariableBinding() {
- var form = layui.form;
- var typeSelect = $('select[name="row[type]"]');
- if (!typeSelect.length) {
- return;
- }
- renderVariablesByType(typeSelect.val());
- form.on('select(emailtemplate-type)', function(data) {
- renderVariablesByType(data.value || '');
- });
- }
- var Controller = {
- index: function() {
- Table.init = {
- table_elem: '#currentTable',
- table_render_id: 'currentTable',
- add_url: 'emailtemplate/add',
- edit_url: 'emailtemplate/edit',
- delete_url: 'emailtemplate/del'
- };
- Table.render({
- init: Table.init,
- toolbar: ['refresh', {
- text: '添加',
- icon: 'iconfont icon-add-fill',
- class: 'layui-btn layui-btn-normal layui-btn-sm btn-dialog',
- auth: 'add',
- url: Table.init.add_url
- }, {
- text: '删除',
- icon: 'iconfont icon-delete-bin-line',
- class: 'layui-btn layui-btn-sm layui-btn-danger',
- auth: 'delete',
- extend: 'id="emailtemplateDeleteBtn" href="javascript:;"'
- }],
- url: 'emailtemplate/index',
- cols: [[
- {type: 'checkbox', width: 50},
- {field: 'id', width: 80, title: 'ID', sort: true},
- {field: 'name', minWidth: 180, title: '模板名称'},
- {field: 'code', width: 160, title: '模板标识'},
- {field: 'lang', width: 100, title: '语言'},
- {field: 'type', width: 160, title: '模板类型', templet: function(d) { return formatType(d.type); }},
- {field: 'subject', minWidth: 220, title: '邮件主题'},
- {field: 'status', width: 100, title: '状态', templet: function(d) { var map = {0: '禁用', 1: '启用'}; return map[d.status] || d.status; }},
- {field: 'listorder', width: 90, title: '排序', sort: true},
- {field: 'updatetime', width: 170, title: '更新时间', templet: Table.formatter.datetime},
- {field: 'createtime', width: 170, title: '创建时间', templet: Table.formatter.datetime},
- {field: 'operate', title: '操作', width: 160, fixed: 'right', templet: Table.formatter.tool, operat: ['edit', 'delete']}
- ]],
- page: {}
- });
- $('#searchBtn').on('click', function() {
- layui.table.reload('currentTable', {
- where: {
- lang: $('#lang').val(),
- type: $('#type').val(),
- status: $('#status').val(),
- keyword: $('#keyword').val()
- },
- page: {curr: 1}
- });
- });
- $('#resetBtn').on('click', function() {
- $('#lang,#keyword').val('');
- $('#type,#status').val('');
- layui.form.render('select');
- layui.table.reload('currentTable', {where: {}, page: {curr: 1}});
- });
- Table.api.bindevent();
- Form.api.bindevent($('form.layui-form'));
- },
- add: function() {
- Controller.api.bindevent();
- },
- edit: function() {
- Controller.api.bindevent();
- },
- api: {
- bindevent: function() {
- Form.api.bindevent($('form.layui-form'));
- initTypeVariableBinding();
- }
- }
- };
- return Controller;
- });
|