trainactive.js 15 KB

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