field.js 5.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. define(['jquery', 'table', 'form'], function($, Table, Form) {
  2. var Controller = {
  3. index: function() {
  4. Table.init = {
  5. table_elem: '#currentTable',
  6. table_render_id: 'currentTable',
  7. add_url: "cms.field/add?modelid=" + Config.modelid,
  8. edit_url: "cms.field/edit",
  9. delete_url: "cms.field/del",
  10. multi_url: 'cms.field/multi',
  11. };
  12. Table.render({
  13. init: Table.init,
  14. toolbar: ['refresh',
  15. {
  16. html: '<a class="layui-btn layui-btn-sm" type="button" href="' + Yzn.api.fixurl("cms.models/index") + '"><i class="iconfont icon-arrow-go-back-line"></i>&nbsp;返回模型</a>'
  17. }, 'add'
  18. ],
  19. url: 'cms.field/index?modelid=' + Config.modelid,
  20. cols: [
  21. [
  22. { field: 'listorder', width: 60, title: '排序', edit: 'text', search: false },
  23. { field: 'id', width: 70, title: 'ID' },
  24. { field: 'name', align: "left", title: '字段名称' },
  25. { field: 'title', align: "left", title: '标题' },
  26. { field: 'type', width: 120, title: '字段类型' },
  27. { field: 'ifsystem', width: 60, align: "center", title: '主表', templet: '<div>{{# if(d.ifsystem){ }} 是 {{# } }} </div>' },
  28. { field: 'create_time', width: 180, title: '创建时间', search: 'range' },
  29. { field: 'ifsearch', width: 90, align: "center", title: '搜索', templet: '#ifsearchTpl', unresize: true, selectList: { 0: '否', 1: '是' } },
  30. { field: 'ifrequire', width: 90, align: "center", title: '必填', templet: '#ifrequireTpl', unresize: true, selectList: { 0: '否', 1: '是' } },
  31. { field: 'isadd', width: 100, align: "center", title: '投稿显示', templet: '#isaddTpl', unresize: true, selectList: { 0: '隐藏', 1: '显示' } },
  32. { field: 'isorder', width: 100, align: "center", title: '是否排序', templet: '#isorderTpl', unresize: true, selectList: { 0: '否', 1: '是' } },
  33. { field: 'status', width: 100, align: "center", title: '状态', templet: '#switchTpl', unresize: true, selectList: { 0: '禁用', 1: '启用' } },
  34. {
  35. width: 90,
  36. title: '操作',
  37. templet: function(d) {
  38. if (d.iffixed) {
  39. return '<a class="layui-btn layui-btn-xs layui-btn-danger layui-btn-disabled">不可操作</a>';
  40. } else {
  41. return Table.formatter.tool.call(this, d, this);
  42. }
  43. },
  44. operat: ['edit', 'delete']
  45. }
  46. ]
  47. ],
  48. page: {}
  49. });
  50. Table.api.bindevent();
  51. },
  52. add: function() {
  53. Controller.api.bindevent();
  54. },
  55. edit: function() {
  56. Controller.api.bindevent();
  57. },
  58. api: {
  59. bindevent: function() {
  60. Form.api.bindevent($("form.layui-form"));
  61. layui.form.on('select(fieldtype)', function(data) {
  62. $('#define').val($(data.elem).find("option:selected").attr("data-define"));
  63. var ifstring = $(data.elem).find("option:selected").attr("data-ifstring");
  64. //搜索隐显
  65. if (ifstring == '1') {
  66. $('#ifsearch').show();
  67. } else {
  68. $('#ifsearch').hide();
  69. }
  70. if (data.value == 'checkbox' || data.value == 'select' || data.value == 'selects' || data.value == 'radio' || data.value == 'selectpage' || data.value == 'custom') {
  71. if (data.value == 'selectpage') {
  72. $('#options .options').html($('#options2').html());
  73. } else if (data.value == 'custom') {
  74. $('#options .options').html($('#options3').html());
  75. } else {
  76. $('#options .options').html($('#options1').html());
  77. }
  78. $('#options').show();
  79. layui.form.render();
  80. } else {
  81. $('#options').hide();
  82. }
  83. });
  84. layui.form.on('select(fasttype)', function(data) {
  85. $('#define').val($(data.elem).find("option:selected").attr("data-define"));
  86. });
  87. layui.form.on('select(pattern)', function(data) {
  88. $('#pattern').val($(data.elem).find("option:selected").attr("data-define"));
  89. });
  90. }
  91. }
  92. };
  93. return Controller;
  94. });