diary.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. // index: function () {
  4. // $(".btn-add").data("area", ["1020px", "775px"]);
  5. // // 初始化表格参数配置
  6. // Table.api.init({
  7. // extend: {
  8. // index_url: 'diary/index' + location.search,
  9. // add_url: 'diary/add',
  10. // edit_url: 'diary/edit',
  11. // del_url: 'diary/del',
  12. // multi_url: 'diary/multi',
  13. // import_url: 'diary/import',
  14. // table: 'diary',
  15. // }
  16. // });
  17. // var table = $("#table");
  18. // // 初始化表格
  19. // table.bootstrapTable({
  20. // url: $.fn.bootstrapTable.defaults.extend.index_url,
  21. // pk: 'id',
  22. // sortName: 'id',
  23. // columns: [
  24. // [
  25. // {
  26. // checkbox: true
  27. // },
  28. // {
  29. // field: 'order_number',
  30. // title: __('Id')
  31. // },
  32. // {
  33. // field: 'unit_id_text',
  34. // title: __('单位')
  35. // },
  36. // {
  37. // field: 'people_id_text',
  38. // title: __('People_id')
  39. // },
  40. // {
  41. // field: 'blog_date',
  42. // title: __('Blog_date'),
  43. // operate: 'LIKE'
  44. // },
  45. // {
  46. // field: 'orgcadre',
  47. // title: __('Orgcadre'),
  48. // operate: 'LIKE'
  49. // },
  50. // {
  51. // field: 'orgsoldier',
  52. // title: __('Orgsoldier'),
  53. // operate: 'RANGE'
  54. // },
  55. // {
  56. // field: 'orgcivilian',
  57. // title: __('Orgcivilian'),
  58. // operate: 'LIKE'
  59. // },
  60. // // {field: 'lead_text', title: __('Lead'), operate: 'LIKE'},
  61. // {
  62. // field: 'operate',
  63. // title: __('Operate'),
  64. // table: table,
  65. // events: Table.api.events.operate,
  66. // buttons: [
  67. // {
  68. // name: '查看',
  69. // text: '查看',
  70. // title: '查看',
  71. // classname: 'btn btn-xs btn-info btn-view btn-dialog ',
  72. // icon: 'fa fa-search',
  73. // url: 'diary/details',
  74. // extend: 'data-area=\'["1020px","775px"]\'',
  75. // refresh: true
  76. // }
  77. // ],
  78. // formatter: Table.api.formatter.operate
  79. // }
  80. // ]
  81. // ]
  82. // });
  83. // // 为表格绑定事件
  84. // Table.api.bindevent(table);
  85. // table.on('post-body.bs.table', function () {
  86. // $(".btn-editone").data("area", ["1020px", "1020px"]);
  87. // })
  88. // },
  89. index: function () {
  90. $(".btn-add").data("area", ["1020px", "775px"]);
  91. // 初始化表格参数配置
  92. Table.api.init();
  93. this.table.first();
  94. this.table.second();
  95. },
  96. table: {
  97. first: function () {
  98. // 表格1
  99. var table1 = $("#table1");
  100. table1.bootstrapTable({
  101. url: 'diary/unit_ysrj',
  102. toolbar: '#toolbar1',
  103. sortName: 'id',
  104. search: false,
  105. pagination: false,
  106. columns: [
  107. [
  108. {
  109. field: 'operate', title: __('单位'), table: table1, events: Table.api.events.operate, buttons: [
  110. {
  111. name: 'log',
  112. title: '',
  113. text: function(row){return row.name},
  114. classname: 'btn btn-success btn-xs btn-click btn-custom',
  115. click: function (e, data) {
  116. console.log(data)
  117. $("#myTabContent2 .form-commonsearch input[name='unit_id']").val(data.id);
  118. $("#myTabContent2 .btn-refresh").trigger("click");
  119. },
  120. visible:function(row){
  121. if(row.isok == 1)return true;
  122. return false;
  123. }
  124. },
  125. {
  126. name: 'log',
  127. title: '',
  128. text: function(row){return row.name},
  129. classname: 'btn btn-danger btn-xs btn-click btn-custom',
  130. click: function (e, data) {
  131. console.log(data)
  132. $("#myTabContent2 .form-commonsearch input[name='unit_id']").val(data.id);
  133. $("#myTabContent2 .btn-refresh").trigger("click");
  134. },
  135. visible:function(row){
  136. if(row.isok == 0)return true;
  137. return false;
  138. }
  139. }
  140. ], formatter: Table.api.formatter.operate
  141. }
  142. ]
  143. ]
  144. });
  145. // 为表格1绑定事件
  146. Table.api.bindevent(table1);
  147. },
  148. second: function () {
  149. // 表格2
  150. var table2 = $("#table2");
  151. table2.bootstrapTable({
  152. url: 'diary/index' + location.search,
  153. extend: {
  154. index_url: 'diary/index' + location.search,
  155. add_url: 'diary/add',
  156. edit_url: 'diary/edit',
  157. del_url: 'diary/del',
  158. multi_url: 'diary/multi',
  159. import_url: 'diary/import',
  160. table: 'diary',
  161. },
  162. toolbar: '#toolbar2',
  163. sortName: 'id',
  164. search: false,
  165. columns: [
  166. [
  167. {
  168. checkbox: true
  169. },
  170. {
  171. field: 'order_number',
  172. title: __('Id'),operate:false
  173. },
  174. {
  175. field: 'unit_id',
  176. title: __('单位ID'),visible:false
  177. },
  178. {
  179. field: 'unit_id_text',
  180. title: __('单位'),operate:false
  181. },
  182. {
  183. field: 'people_id_text',
  184. title: __('People_id'),operate:false
  185. },
  186. {
  187. field: 'blog_date',
  188. title: __('Blog_date'),operate:false
  189. },
  190. {
  191. field: 'orgcadre',
  192. title: __('Orgcadre'),operate:false
  193. },
  194. {
  195. field: 'orgsoldier',
  196. title: __('Orgsoldier'),operate:false
  197. },
  198. {
  199. field: 'orgcivilian',
  200. title: __('Orgcivilian')
  201. ,operate:false
  202. },
  203. // {field: 'lead_text', title: __('Lead'), operate: 'LIKE'},
  204. {
  205. field: 'operate',
  206. title: __('Operate'),
  207. table: table2,
  208. events: Table.api.events.operate,
  209. buttons: [
  210. {
  211. name: '查看',
  212. text: '查看',
  213. title: '查看',
  214. classname: 'btn btn-xs btn-info btn-view btn-dialog ',
  215. icon: 'fa fa-search',
  216. url: 'diary/details',
  217. extend: 'data-area=\'["1020px","775px"]\'',
  218. refresh: true
  219. },
  220. {
  221. name: '审批',
  222. text: '审批',
  223. title: '审批',
  224. classname: 'btn btn-xs btn-info btn-view btn-dialog ',
  225. icon: 'fa fa-search',
  226. url: 'diary/examine',
  227. extend: 'data-area=\'["1020px","775px"]\'',
  228. refresh: true,
  229. visible:function(row){
  230. if(row.examine == 0 && row.people_id1 == Config.admin.id || row.examine == 0 && row.admin_id == Config.admin.id){
  231. return true;
  232. }else{
  233. return false;
  234. }
  235. }
  236. },
  237. {
  238. name: '审批不通过',
  239. text: '审批不通过',
  240. title: '审批不通过',
  241. classname: 'btn btn-xs btn-info',
  242. icon: 'fa fa-search',
  243. refresh: true,
  244. visible:function(row){
  245. if(row.examine == 2 && row.people_id1 == Config.admin.id || row.examine == 2 && row.admin_id == Config.admin.id){
  246. return true;
  247. }else{
  248. return false;
  249. }
  250. }
  251. }
  252. ],
  253. formatter: function(value,row,index){
  254. var that = $.extend({},this);
  255. var table = $(that.table).clone(true);
  256. if(row.examine=="1"){
  257. $(table).data("operate-edit",null);
  258. that.table = table;
  259. }
  260. return Table.api.formatter.operate.call(that,value,row,index)
  261. //console.log(value);
  262. //console.log(row);
  263. //console.log(index);
  264. }
  265. // formatter: Table.api.formatter.operate
  266. }
  267. ]
  268. ]
  269. });
  270. // 为表格2绑定事件
  271. Table.api.bindevent(table2);
  272. table2.on('post-body.bs.table', function () {
  273. $(".btn-editone").data("area", ["1020px", "775px"]);
  274. })
  275. }
  276. },
  277. add: function () {
  278. Controller.api.bindevent();
  279. $(document).on("change", "#J_unitselect", function () {
  280. $.get('diary/huoq', {
  281. id: $("#J_unitselect").val()
  282. }, function (res) {
  283. $('#c-orgcadre').val(res.data.orgcadre);
  284. $('#c-orgsoldier').val(res.data.orgsoldier);
  285. $('#c-orgcivilian').val(res.data.orgcivilian);
  286. $('#c-nowcadre').val(res.data.nowcadre);
  287. $('#c-nowsoldier').val(res.data.nowsoldier);
  288. $('#c-nowcivilian').val(res.data.nowcivilian);
  289. });
  290. //选择单位获取一周工作计划当日内容
  291. Controller.api.getweekwork();
  292. });
  293. $(document).on("changed", "#c-blog_date", function () {
  294. Controller.api.getweekwork();
  295. });
  296. $('#fff').on('keyup','.J_should_arrive,.J_real_to',function(){
  297. var o = $(this).parents('tr');
  298. var a = o.find('.J_should_arrive').val();
  299. var b = o.find('.J_real_to').val();
  300. if(a && b)o.find('.J_percentage').val((b/a*100).toFixed(2)+"%");
  301. });
  302. $("#c-people_id,#c-dutylead,#c-dutyA,#c-dutyB,#c-dutyC,#c-dutyD,#c-dutyE,#c-dutyF,#c-lead,.people_id1").data("params", function (obj) {
  303. //console.log($(this).attr('id'))
  304. var unit_id = $('#J_unitselect').val();
  305. return {
  306. "custom[unit_id][0]": "in",
  307. "custom[unit_id][1]": unit_id
  308. };
  309. });
  310. //因为日期选择框不会触发change事件,导致无法刷新textarea,所以加上判断
  311. $(document).on("dp.change", "#add-form .datetimepicker", function () {
  312. $(this).parent().prev().find("input").trigger("change");
  313. });
  314. $(document).on("fa.event.appendfieldlist", "#add-form .btn-append", function (e, obj) {
  315. Form.events.selectpage(obj);
  316. Form.events.datetimepicker(obj);
  317. });
  318. $(document).on('click', '.btn-append', function () {
  319. var form = $("#add-form");
  320. require(['bootstrap-datetimepicker'], function () {
  321. var options = {
  322. format: 'LT',
  323. icons: {
  324. time: 'fa fa-clock-o',
  325. date: 'fa fa-calendar',
  326. up: 'fa fa-chevron-up',
  327. down: 'fa fa-chevron-down',
  328. previous: 'fa fa-chevron-left',
  329. next: 'fa fa-chevron-right',
  330. today: 'fa fa-history',
  331. clear: 'fa fa-trash',
  332. close: 'fa fa-remove'
  333. },
  334. showTodayButton: true,
  335. showClose: true
  336. };
  337. $('.datetimepicker3', form).parent().css('position', 'relative');
  338. $('.datetimepicker3', form).datetimepicker(options).on('dp.change', "#add-form .datetimepicker3", function (e) {
  339. $(this, document).trigger("changed");
  340. });
  341. });
  342. $(".people_id1,.people_id2,.people_id3,.people_id4,.people_id6,.people_id5").data("params", function (obj) {
  343. var unit_id = $('#J_unitselect').val();
  344. return {
  345. "custom[unit_id][0]": "in",
  346. "custom[unit_id][1]": unit_id
  347. };
  348. });
  349. });
  350. },
  351. edit: function () {
  352. Controller.api.bindevent();
  353. $(document).on("changed", "#c-blog_date", function () {
  354. Controller.api.getweekwork();
  355. });
  356. $(document).on("change", "#J_unitselect", function () {
  357. $.get('diary/huoq', {
  358. id: $("#J_unitselect").val()
  359. }, function (res) {
  360. $('#c-orgcadre').val(res.data.orgcadre);
  361. $('#c-orgsoldier').val(res.data.orgsoldier);
  362. $('#c-orgcivilian').val(res.data.orgcivilian);
  363. $('#c-nowcadre').val(res.data.nowcadre);
  364. $('#c-nowsoldier').val(res.data.nowsoldier);
  365. $('#c-nowcivilian').val(res.data.nowcivilian);
  366. //选择单位获取一周工作计划当日内容
  367. Controller.api.getweekwork();
  368. });
  369. });
  370. $("#c-people_id,#c-dutylead,#c-dutyA,#c-dutyB,#c-dutyC,#c-dutyD,#c-dutyE,#c-dutyF,#c-lead,.people_id1").data("params", function (obj) {
  371. console.log($(this).attr('id'))
  372. var unit_id = $('#J_unitselect').val();
  373. return {
  374. "custom[unit_id][0]": "in",
  375. "custom[unit_id][1]": unit_id
  376. };
  377. });
  378. //因为日期选择框不会触发change事件,导致无法刷新textarea,所以加上判断
  379. $(document).on("dp.change", "#edit-form .datetimepicker", function () {
  380. $(this).parent().prev().find("input").trigger("change");
  381. });
  382. $(document).on("fa.event.appendfieldlist", "#edit-form .btn-append", function (e, obj) {
  383. Form.events.selectpage(obj);
  384. Form.events.datetimepicker(obj);
  385. });
  386. $(document).on('click', '.btn-append', function () {
  387. var form = $("#edit-form");
  388. require(['bootstrap-datetimepicker'], function () {
  389. var options = {
  390. format: 'LT',
  391. icons: {
  392. time: 'fa fa-clock-o',
  393. date: 'fa fa-calendar',
  394. up: 'fa fa-chevron-up',
  395. down: 'fa fa-chevron-down',
  396. previous: 'fa fa-chevron-left',
  397. next: 'fa fa-chevron-right',
  398. today: 'fa fa-history',
  399. clear: 'fa fa-trash',
  400. close: 'fa fa-remove'
  401. },
  402. showTodayButton: true,
  403. showClose: true
  404. };
  405. $('.datetimepicker3', form).parent().css('position', 'relative');
  406. $('.datetimepicker3', form).datetimepicker(options).on('dp.change', "#edit-form .datetimepicker3", function (e) {
  407. $(this, document).trigger("changed");
  408. });
  409. });
  410. $(".people_id1,.people_id2,.people_id3,.people_id4,.people_id6,.people_id5").data("params", function (obj) {
  411. var unit_id = $('#J_unitselect').val();
  412. return {
  413. "custom[unit_id][0]": "in",
  414. "custom[unit_id][1]": unit_id
  415. };
  416. });
  417. });
  418. },
  419. examine: function () {
  420. Controller.api.bindevent();
  421. $('#J_ok').click(function(){
  422. var id = $('#id').val();
  423. Layer.confirm('确定要通过吗?',{shade:false},function(index){
  424. $.get('diary/auth_status',{ids:id,examine:1},function(res){
  425. parent.Layer.closeAll();
  426. parent.$("a.btn-refresh").trigger("click");
  427. parent.Layer.msg(res.msg);
  428. });
  429. });
  430. });
  431. $('#J_no').click(function(){
  432. var id = $('#id').val();
  433. Layer.prompt({
  434. title:'驳回原因'
  435. },function(val,index){
  436. if(val){
  437. $.get('diary/auth_status',{ids:id,examine:2,contents:val},function(res){
  438. parent.Layer.closeAll();
  439. parent.$("a.btn-refresh").trigger("click");
  440. parent.Layer.msg(res.msg);
  441. });
  442. }else{
  443. Layer.msg('请输入原因');
  444. }
  445. })
  446. });
  447. },
  448. api: {
  449. bindevent: function () {
  450. Form.api.bindevent($("form[role=form]"));
  451. },
  452. getweekwork: function () {
  453. var date = $('#c-blog_date').val();
  454. var J_unitselect = $('#J_unitselect').val();
  455. var data = [];
  456. $.get('weekwork_register/index2', {
  457. time: date,
  458. unit_id: J_unitselect
  459. }, function (res) {
  460. $('#weekwork').val(res.data);
  461. $("#weekwork").css({
  462. 'background': '#F00'
  463. });
  464. $("#weekwork").trigger("fa.event.refreshfieldlist");
  465. // Form.events.fieldlist($('#weekwork'));
  466. console.log(res.data)
  467. });
  468. }
  469. }
  470. };
  471. return Controller;
  472. });