trainactive.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'], function ($, undefined, Backend, Table, Form) {
  2. //读取选中的条目
  3. $.jstree.core.prototype.get_all_checked = function (full) {
  4. var obj = this.get_selected(), i, j;
  5. for (i = 0, j = obj.length; i < j; i++) {
  6. obj = obj.concat(this.get_node(obj[i]).parents);
  7. }
  8. obj = $.grep(obj, function (v, i, a) {
  9. return v != '#';
  10. });
  11. obj = obj.filter(function (itm, i, a) {
  12. return i == a.indexOf(itm);
  13. });
  14. return full ? $.map(obj, $.proxy(function (i) {
  15. return this.get_node(i);
  16. }, this)) : obj;
  17. };
  18. var Controller = {
  19. index: function () {
  20. // 初始化表格参数配置
  21. Table.api.init({
  22. extend: {
  23. index_url: 'trainactive/index' + location.search,
  24. add_url: 'trainactive/add',
  25. edit_url: 'trainactive/edit',
  26. del_url: 'trainactive/del',
  27. multi_url: 'trainactive/multi',
  28. import_url: 'trainactive/import',
  29. table: 'train_active',
  30. }
  31. });
  32. var table = $("#table");
  33. // 初始化表格
  34. table.bootstrapTable({
  35. url: $.fn.bootstrapTable.defaults.extend.index_url,
  36. pk: 'id',
  37. sortName: 'id',
  38. fixedColumns: true,
  39. fixedRightNumber: 1,
  40. columns: [
  41. [
  42. {checkbox: true},
  43. {field: 'id', title: __('Id')},
  44. {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"0":__('Status 0')}, formatter: Table.api.formatter.status},
  45. {field: 'logo_image', title: __('Logo_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
  46. {field: 'title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  47. {field: 'number', title: __('Number'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  48. {field: 'version', title: __('Version'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  49. {field: 'bianzhiren', title: __('Bianzhiren'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  50. {field: 'pizhunren', title: __('Pizhunren'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  51. {field: 'shenheren', title: __('Shenheren'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  52. {field: 'kongzhiren', title: __('Kongzhiren'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  53. {field: 'department', title: __('Department'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  54. {field: 'wenjianstatus', title: __('Wenjianstatus'), operate: 'LIKE', formatter: Table.api.formatter.status},
  55. {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  56. // {field: 'cate_id', title: __('Cate_id')},
  57. {field: 'cate.name', title: __('Cate.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  58. // {field: 'level_id', title: __('Level_id')},
  59. {field: 'level.name', title: __('Level.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  60. {field: 'fangshi', title: __('Fangshi'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  61. {field: 'starttime', title: __('Starttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  62. {field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  63. {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  64. {field: 'zhuchiren', title: __('Zhuchiren'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  65. {field: 'zhujiangren', title: __('Zhujiangren'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  66. // {field: 'type_id', title: __('Type_id')},
  67. {field: 'type.name', title: __('Type.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  68. {field: 'info', title: __('Info'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  69. {field: 'files', title: __('Files'), operate: false, formatter: Table.api.formatter.files},
  70. {field: 'pingjia_image', title: __('Pingjia_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
  71. {field: 'pingjia_time', title: __('Pingjia_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  72. {field: 'pingjia_uid', title: __('Pingjia_uid')},
  73. {field: 'sign_endtime', title: __('Sign_endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  74. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  75. {field: 'usercount', title: __('Usercount')},
  76. {field: 'userauth_status', title: __('Userauth_status'), searchList: {"0":__('Userauth_status 0'),"1":__('Userauth_status 1')}, formatter: Table.api.formatter.status},
  77. {field: 'operate', title: __('Operate'), table: table,
  78. buttons:[
  79. {
  80. name:'selectuser',
  81. text:'选择用户',
  82. title:'选择用户',
  83. icon:'fa fa-exclamation-circle',
  84. classname:'btn btn-xs btn-info btn-dialog btn-selectuser',
  85. url:'trainactive/selectuser/id/{ids}?dialog=1',
  86. target:'_self',
  87. },
  88. {
  89. name:'qrcode',
  90. text:'二维码',
  91. title:'二维码',
  92. icon:'fa fa-exclamation-circle',
  93. classname:'btn btn-xs btn-info btn-dialog',
  94. url:'trainactive/qrcode/id/{ids}?dialog=1',
  95. target:'_self',
  96. },
  97. {
  98. name:'showinfo',
  99. text:'打印',
  100. title:'打印',
  101. icon:'fa fa-exclamation-circle',
  102. classname:'btn btn-xs btn-info btn-addtabs',
  103. url:'trainactive/showinfo/id/{ids}',
  104. target:'_blank',
  105. },
  106. {
  107. name:'nograde',
  108. text:'未到',
  109. title:'未到',
  110. icon:'fa fa-exclamation-circle',
  111. classname:'btn btn-xs btn-info btn-dialog btn-nograde',
  112. url:'trainactive/nograde/id/{ids}',
  113. target:'_self',
  114. }
  115. ],
  116. events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  117. ]
  118. ],
  119. onLoadSuccess:function(){
  120. // 这里就是数据渲染结束后的回调函数
  121. $(".btn-selectuser").data("area", ['80%','80%']);
  122. }
  123. });
  124. // 为表格绑定事件
  125. Table.api.bindevent(table);
  126. },
  127. recyclebin: function () {
  128. // 初始化表格参数配置
  129. Table.api.init({
  130. extend: {
  131. 'dragsort_url': ''
  132. }
  133. });
  134. var table = $("#table");
  135. // 初始化表格
  136. table.bootstrapTable({
  137. url: 'trainactive/recyclebin' + location.search,
  138. pk: 'id',
  139. sortName: 'id',
  140. columns: [
  141. [
  142. {checkbox: true},
  143. {field: 'id', title: __('Id')},
  144. {field: 'title', title: __('Title'), align: 'left'},
  145. {
  146. field: 'deletetime',
  147. title: __('Deletetime'),
  148. operate: 'RANGE',
  149. addclass: 'datetimerange',
  150. formatter: Table.api.formatter.datetime
  151. },
  152. {
  153. field: 'operate',
  154. width: '140px',
  155. title: __('Operate'),
  156. table: table,
  157. events: Table.api.events.operate,
  158. buttons: [
  159. {
  160. name: 'Restore',
  161. text: __('Restore'),
  162. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  163. icon: 'fa fa-rotate-left',
  164. url: 'trainactive/restore',
  165. refresh: true
  166. },
  167. {
  168. name: 'Destroy',
  169. text: __('Destroy'),
  170. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  171. icon: 'fa fa-times',
  172. url: 'trainactive/destroy',
  173. refresh: true
  174. }
  175. ],
  176. formatter: Table.api.formatter.operate
  177. }
  178. ]
  179. ]
  180. });
  181. // 为表格绑定事件
  182. Table.api.bindevent(table);
  183. },
  184. add: function () {
  185. Controller.api.bindevent();
  186. },
  187. selectuser: function () {
  188. Controller.api.bindevent();
  189. },
  190. qrcode: function () {
  191. Controller.api.bindevent();
  192. },
  193. edit: function () {
  194. Controller.api.bindevent();
  195. },
  196. showinfo: function () {
  197. Controller.api.bindevent();
  198. },
  199. api: {
  200. /*bindevent: function () {
  201. Form.api.bindevent($("form[role=form]"));
  202. }*/
  203. bindevent: function () {
  204. Form.api.bindevent($("form[role=form]"), null, null, function () {
  205. if ($("#treeview").length > 0) {
  206. var r = $("#treeview").jstree("get_all_checked");
  207. $("input[name='row[user_rule]']").val(r.join(','));
  208. }
  209. return true;
  210. });
  211. //渲染权限节点树
  212. //销毁已有的节点树
  213. $("#treeview").jstree("destroy");
  214. Controller.api.rendertree(nodeData);
  215. //全选和展开
  216. $(document).on("click", "#checkall", function () {
  217. $("#treeview").jstree($(this).prop("checked") ? "check_all" : "uncheck_all");
  218. });
  219. $(document).on("click", "#expandall", function () {
  220. $("#treeview").jstree($(this).prop("checked") ? "open_all" : "close_all");
  221. });
  222. $("select[name='row[pid]']").trigger("change");
  223. },
  224. rendertree: function (content) {
  225. $("#treeview")
  226. .on('redraw.jstree', function (e) {
  227. $(".layer-footer").attr("domrefresh", Math.random());
  228. })
  229. .jstree({
  230. "themes": {"stripes": true},
  231. "checkbox": {
  232. "keep_selected_style": false,
  233. },
  234. "types": {
  235. "root": {
  236. "icon": "fa fa-folder-open",
  237. },
  238. "menu": {
  239. "icon": "fa fa-folder-open",
  240. },
  241. "file": {
  242. "icon": "fa fa-file-o",
  243. }
  244. },
  245. "plugins": ["checkbox", "types"],
  246. "core": {
  247. 'check_callback': true,
  248. "data": content
  249. }
  250. });
  251. }
  252. }
  253. };
  254. return Controller;
  255. });
  256. //打印切换
  257. $('#left').click(function(){
  258. $('#left_table').show();
  259. $('#right_table').hide();
  260. })
  261. $('#right').click(function(){
  262. $('#left_table').hide();
  263. $('#right_table').show();
  264. })
  265. //打印下载
  266. function jump(url){
  267. console.log(url);
  268. window.location.href = url;
  269. }
  270. //打印ctrl+P
  271. function printPage() {
  272. window.print();
  273. }