baseData.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. define(['jquery', 'base', 'config'], function($, base, config) {
  2. var con = {
  3. init: function() {
  4. base.listType('#bd-type', config.baseUrl + config.baseData.listAllType, 0);
  5. this.getAllType();
  6. this.addType();
  7. this.searchType('.bd-search', '#bd-dg');
  8. this.updateType();
  9. },
  10. //获取页面数据
  11. getAllType: function() {
  12. var self = this;
  13. $('#bd-dg').datagrid({
  14. url: config.baseUrl + config.baseData.listPage,
  15. method: 'post',
  16. toolbar: '#bd-toolbar',
  17. rownumbers: false,
  18. pagination: true,
  19. fitColumns:true,
  20. singleSelect: true,
  21. title: '基础参数管理',
  22. fit: true,
  23. columns: [[
  24. {field:'typeId', title:'编码', width:'20%'},
  25. {field:'name', title:'名称', width:'20%'},
  26. {field:'typeName', title:'类型', width:'20%'},
  27. {field:'remarks', title:'备注', width:'20%'},
  28. {
  29. field:'id',
  30. title:'操作',
  31. width:'20%',
  32. align: 'center',
  33. formatter: function(value, row, index) {
  34. return '<a class="t-update bd-update" data-id=' + value + '>修改</a>&nbsp;|&nbsp;<a class="t-del bd-del" data-id=' + value + '>删除</a>';
  35. }
  36. }
  37. ]],
  38. loadFilter: function(e) {
  39. return {
  40. page: e.data.pageNo,
  41. total: e.data.count,
  42. rows: e.data.list
  43. };
  44. },
  45. onLoadSuccess: function() {
  46. self.updateType();
  47. // self.delType();
  48. base.delInfo('.bd-del', config.baseData.delete, '#bd-dg');
  49. }
  50. });
  51. },
  52. //添加字典
  53. addType: function() {
  54. var self = this;
  55. //渲染window窗口
  56. base.renderwindow('.bd-add-win', {
  57. width: 400,
  58. height: 260,
  59. title: '添加类型'
  60. });
  61. //绑定点击新增事件
  62. $('.bd-add-bt').on('click', function() {
  63. //打开window窗口
  64. $('.bd-add-win').window('open');
  65. //设置名称默认值
  66. $('.bd-w-name').textbox('setValue', '');
  67. $('.bd-w-type').combobox('select', '');
  68. //设置备注默认值
  69. $('.bd-w-backup').textbox('setValue', '');
  70. //调用获取所有类型函数
  71. base.listType('.bd-w-type', config.baseUrl + config.baseData.listAllType, 0);
  72. self.doAddType('.bd-win-y', '.bd-add-win', config.baseData.insert, 0);
  73. });
  74. },
  75. /**
  76. * 执行添加类型的函数
  77. * @param {string} selector 确认按钮的类
  78. * @param {string} wSelector window窗口的类
  79. * @param {string} url 请求地址
  80. * @param {模式} mode 0为插入,1为更新
  81. * @return {null}
  82. */
  83. doAddType: function(selector, wSelector, url, mode) {
  84. //解绑之前的点击事件
  85. $(selector).off('click');
  86. //绑定点击确定按钮事件
  87. $(selector).on('click', function(e) {
  88. //阻止默认事件
  89. e.preventDefault();
  90. var data = {
  91. name: $('input[name=name]').val(),
  92. typeId: $('input[name=bd-type]').val(),
  93. remarks: $('input[name=bd-backup]').val()
  94. };
  95. //如果是更新操作的话,获取绑定在确认按钮上的id值
  96. if(mode === 1) {
  97. data.id = $(this).data('id');
  98. }
  99. //发送添加ajax请求
  100. base.ajaxFunc('post', url, data, function(e) {
  101. //请求成功后的提示
  102. base.requestTip(e, wSelector, '#bd-dg', 0);
  103. });
  104. });
  105. },
  106. /**
  107. * 查询
  108. * @param {string} selector 绑定搜索
  109. * @param {string} dSelector 需要重新载入数据的表格
  110. * @return {null} 无
  111. */
  112. searchType: function(selector, dSelector) {
  113. $(selector).on('click', function(e) {
  114. e.preventDefault();
  115. $(dSelector).datagrid('load', {
  116. name: $('input[name=bd-s-name]').val(),
  117. typeId: $('input[name=bd-s-type]').val()
  118. });
  119. });
  120. },
  121. updateType: function() {
  122. var self = this,
  123. id = -1;
  124. $('.bd-update').on('click', function(e) {
  125. e.preventDefault();
  126. //渲染window窗口
  127. base.renderwindow('.bd-add-win', {
  128. width: 400,
  129. height: 260,
  130. title: '更新类型'
  131. });
  132. $('.bd-add-win').window('open');
  133. var id = $(this).data('id');
  134. //将id的值绑定到确认按钮上
  135. $('.bd-win-y').data('id', id);
  136. base.ajaxFunc('post', config.baseData.listPage, {id:id}, function(e) {
  137. //设置名称默认值
  138. $('.bd-w-name').textbox('setValue', e.data.list[0].name);
  139. //设置备注默认值
  140. $('.bd-w-backup').textbox('setValue', e.data.list[0].remarks);
  141. //获取所有type类型
  142. base.listType('.bd-w-type', config.baseUrl + config.baseData.listAllType, 0);
  143. //选中返回的类型
  144. $('.bd-w-type').combobox('select', e.data.list[0].typeId);
  145. });
  146. self.doAddType('.bd-win-y', '.bd-add-win', config.baseData.update, 1);
  147. });
  148. }
  149. };
  150. con.init();
  151. });