inspectors.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. /**
  2. * inspectors.js
  3. * 巡检人管理界面
  4. * emial: yaoqiang@chinausky.com
  5. * create: 2018-12-08
  6. */
  7. Ext.Loader.setConfig({
  8. enabled: true
  9. });
  10. Ext.Loader.setPath('Ext.ux', '../../res/extjs/examples/ux');
  11. Ext.require([
  12. 'Ext.grid.*',
  13. 'Ext.data.*',
  14. 'Ext.ux.RowExpander',
  15. 'Ext.selection.CheckboxModel'
  16. ]);
  17. var sm = Ext.create('Ext.selection.CheckboxModel');
  18. Ext.define('Inspectors', {
  19. extend: 'Ext.data.Model',
  20. fields: [
  21. { name: 'id', type: 'string' },
  22. { name: 'name', type: 'string' },
  23. { name: 'phone', type: 'string' },
  24. { name: 'Job_duties', type: 'string' },
  25. { name: 'company_code', type: 'string' },
  26. ]
  27. });
  28. Ext.onReady(function () {
  29. var baseUrl = document.getElementById('basePath').value;
  30. var theme = document.getElementById('theme').value;
  31. var chkIcon = '<img src="' + baseUrl + 'res/img/common/check.gif"/>'
  32. var unchkIcon = '<img src="' + baseUrl + 'res/img/common/uncheck.gif"/>'
  33. var countPerPage = 20;
  34. var maxHeight = 10000;
  35. var chkBoolean = function (flag) {
  36. if (flag)
  37. return chkIcon;
  38. return unchkIcon;
  39. }
  40. var clear_append_form = function () {
  41. Ext.getCmp('fa_name').setValue("");
  42. Ext.getCmp('fa_phone').setValue("");
  43. Ext.getCmp('fa_Job_duties').setValue("");
  44. Ext.getCmp('fa_company_code').setValue("");
  45. Ext.getCmp('InspectorsListPanel').getStore().reload();
  46. }
  47. var myStore = Ext.create('Ext.data.Store', {
  48. model: 'Inspectors',
  49. pageSize: countPerPage,
  50. proxy: {
  51. type: 'ajax',
  52. url: baseUrl + 'iot/inspectors/getList',
  53. reader: {
  54. type: 'json',
  55. root: 'RESULT',
  56. totalProperty: 'totalCount'
  57. }
  58. },
  59. remoteSort: true
  60. });
  61. function public_phone(e) {
  62. if (!(/^1(?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d)\d{8}$/.test(e))) {
  63. Ext.Msg.alert('提示', '不是完整的11位手机号或者正确的手机号前七位!', function (btn, txt) {
  64. Ext.getCmp('fa_phone').setValue('');
  65. Ext.getCmp('ff_phone').setValue('');
  66. });
  67. return false;
  68. }
  69. }
  70. var AppendForm = Ext.create('Ext.form.Panel', {
  71. id: 'InspectorsAppendForm',
  72. labelWidth: 55,
  73. url: baseUrl + 'iot/inspectors/append',
  74. defaultType: 'textfield',
  75. bodyPadding: 15,
  76. items: [{
  77. fieldLabel: '姓名',
  78. id: 'fa_name',
  79. name: 'name',
  80. maxLength: 20,
  81. maxLengthText: '长度不得超出{0}',
  82. anchor: '75%',
  83. listeners: {
  84. change: function (o, e) {
  85. if (e.length > 20) {
  86. Ext.getCmp('fa_Inspectors_name').setValue(e.substring(0, 20));
  87. return;
  88. }
  89. }
  90. }
  91. }, {
  92. fieldLabel: '手机号',
  93. id: 'fa_phone',
  94. name: 'phone',
  95. maxLength: 250,
  96. maxLengthText: '长度不得超出{0}',
  97. anchor: '95%',
  98. listeners: {
  99. change: function (o, e) {
  100. if (e.length == 11) {
  101. public_phone(e);
  102. } else {
  103. Ext.getCmp('fa_phone').setValue(e.substring(0, 11));
  104. e.length == 11 ? public_phone(e) : ''
  105. }
  106. }
  107. }
  108. }, {
  109. fieldLabel: '职务',
  110. id: 'fa_Job_duties',
  111. name: 'Job_duties',
  112. maxLength: 30,
  113. maxLengthText: '长度不得超出{0}',
  114. anchor: '95%'
  115. }, {
  116. fieldLabel: '单位编号',
  117. id: 'fa_company_code',
  118. name: 'company_code',
  119. maxLength: 30,
  120. maxLengthText: '长度不得超出{0}',
  121. anchor: '95%'
  122. }, {
  123. id: 'fa_queryJson',
  124. name: 'queryJson',
  125. hidden: true
  126. }],
  127. buttons: [{
  128. text: '提交',
  129. iconCls: 'ok_btn',
  130. handler: function () {
  131. var form = this.up('form').getForm();
  132. if (form.isValid()) {
  133. var query = new Object();
  134. query.name = Ext.getCmp('fa_name').getValue();
  135. query.phone = Ext.getCmp('fa_phone').getValue();
  136. query.Job_duties = Ext.getCmp('fa_Job_duties').getValue();
  137. query.company_code = Ext.getCmp('fa_company_code').getValue();
  138. var jsonstr = Ext.JSON.encode(query);
  139. Ext.getCmp('fa_queryJson').setValue(jsonstr);
  140. form.submit({
  141. method: 'post',
  142. success: function (form, action) {
  143. Ext.Msg.alert('操作成功', '已保存', function (btn, txt) {
  144. clear_append_form();
  145. });
  146. },
  147. failure: function (form, action) {
  148. Ext.Msg.alert('操作失败', action.Msg, function (btn, txt) {
  149. clear_append_form();
  150. });
  151. }
  152. });
  153. }
  154. }
  155. }, {
  156. text: '关闭',
  157. iconCls: 'cancel_btn',
  158. handler: function () {
  159. this.up('window').hide();
  160. }
  161. }]
  162. });
  163. var appendwin = function () {
  164. Ext.create('Ext.window.Window', {
  165. title: '新增',
  166. height: 350,
  167. width: 400,
  168. layout: 'fit',
  169. items: AppendForm,
  170. closeAction: 'hide'
  171. }).show();
  172. }
  173. //筛选
  174. var clear_filter_form = function () {
  175. Ext.getCmp('ff_name').setValue("");
  176. Ext.getCmp('ff_phone').setValue("");
  177. Ext.getCmp('ff_Job_duties').setValue("");
  178. Ext.getCmp('ff_company_code').setValue("");
  179. }
  180. var FilterWin = Ext.create('Ext.form.Panel', {
  181. id: 'InspectorsFilterForm',
  182. labelWidth: 55,
  183. defaultType: 'textfield',
  184. bodyPadding: 15,
  185. items: [{
  186. fieldLabel: '姓名',
  187. id: 'ff_name',
  188. name: 'name',
  189. maxLength: 20,
  190. maxLengthText: '长度不得超出{0}',
  191. value: document.getElementById('name').value,
  192. anchor: '75%',
  193. listeners: {
  194. change: function (o, e) {
  195. if (e.length > 10) {
  196. Ext.Msg.alert('提示', '姓名长度不可超过10个字!', function (btn, txt) {
  197. Ext.getCmp('ff_name').setValue('');
  198. });
  199. return false;
  200. }
  201. }
  202. }
  203. }, {
  204. fieldLabel: '手机号',
  205. id: 'ff_phone',
  206. name: 'phone',
  207. maxLength: 250,
  208. maxLengthText: '长度不得超出{0}',
  209. value: document.getElementById('phone').value,
  210. editable: false,
  211. listeners: {
  212. change: function (o, e) {
  213. if (e.length == 11) {
  214. public_phone(e);
  215. } else {
  216. Ext.getCmp('ff_phone').setValue(e.substring(0, 11));
  217. e.length == 11 ? public_phone(e) : ''
  218. }
  219. }
  220. }
  221. }, {
  222. fieldLabel: '职务',
  223. id: 'ff_Job_duties',
  224. name: 'Job_duties',
  225. maxLength: 250,
  226. maxLengthText: '长度不得超出{0}',
  227. value: document.getElementById('Job_duties').value,
  228. anchor: '95%'
  229. }, {
  230. fieldLabel: '单位编号',
  231. id: 'ff_company_code',
  232. name: 'company_code',
  233. maxLength: 250,
  234. maxLengthText: '长度不得超出{0}',
  235. value: document.getElementById('company_code').value,
  236. anchor: '95%'
  237. }, {
  238. id: 'ff_queryJson',
  239. name: 'queryJson',
  240. hidden: true
  241. }],
  242. buttons: [{
  243. text: '提交',
  244. iconCls: 'ok_btn',
  245. handler: function () {
  246. var form = this.up('form').getForm();
  247. if (form.isValid()) {
  248. var query = new Object();
  249. if (Ext.getCmp('ff_name').getValue().length > 0)
  250. query.name = Ext.getCmp('ff_name').getValue();
  251. if (Ext.getCmp('ff_phone').getValue().length > 0)
  252. query.phone = Ext.getCmp('ff_phone').getValue();
  253. if (Ext.getCmp('ff_Job_duties').getValue().length > 0)
  254. query.Job_duties = Ext.getCmp('ff_Job_duties').getValue();
  255. if (Ext.getCmp('ff_company_code').getValue().length > 0)
  256. query.company_code = Ext.getCmp('ff_company_code').getValue();
  257. var jsonstr = Ext.JSON.encode(query);
  258. myStore.getProxy().extraParams = {
  259. queryJson: jsonstr
  260. };
  261. Ext.getCmp('InspectorsListPageToolbar').moveFirst();
  262. Ext.getCmp('name').setValue(query.name);
  263. Ext.getCmp('phone').setValue(query.phone);
  264. Ext.getCmp('Job_duties').setValue(query.Job_duties);
  265. Ext.getCmp('company_code').setValue(query.company_code);
  266. // myStore.reload();
  267. clear_filter_form();
  268. this.up('window').hide();
  269. }
  270. }
  271. }, {
  272. text: '关闭',
  273. iconCls: 'cancel_btn',
  274. handler: function () {
  275. this.up('window').hide();
  276. }
  277. }]
  278. });
  279. var filterwin = function () {
  280. Ext.create('Ext.window.Window', {
  281. title: '筛选',
  282. height: 300,
  283. width: 350,
  284. layout: 'fit',
  285. items: FilterWin,
  286. closeAction: 'hide'
  287. }).show();
  288. }
  289. var clear_modify_form = function () {
  290. Ext.getCmp('fm_id').setValue("");
  291. Ext.getCmp('fm_name').setValue("");
  292. Ext.getCmp('fm_phone').setValue("");
  293. Ext.getCmp('fm_Job_duties').setValue("");
  294. Ext.getCmp('fm_company_code').setValue("");
  295. Ext.getCmp('InspectorsListPanel').getStore().reload();
  296. }
  297. var ModifyForm = Ext.create('Ext.form.Panel', {
  298. id: 'InspectorsEditForm',
  299. labelWidth: 55,
  300. url: baseUrl + 'iot/inspectors/update',
  301. defaultType: 'textfield',
  302. bodyPadding: 15,
  303. items: [{
  304. fieldLabel: '姓名',
  305. id: 'fm_name',
  306. name: 'name',
  307. maxLength: 20,
  308. maxLengthText: '长度不得超出{0}',
  309. anchor: '75%'
  310. }, {
  311. fieldLabel: '手机号',
  312. id: 'fm_phone',
  313. name: 'phone',
  314. maxLength: 250,
  315. maxLengthText: '长度不得超出{0}',
  316. anchor: '95%'
  317. }, {
  318. fieldLabel: '职务',
  319. id: 'fm_Job_duties',
  320. name: 'Job_duties',
  321. maxLength: 250,
  322. maxLengthText: '长度不得超出{0}',
  323. anchor: '95%'
  324. }, {
  325. fieldLabel: '单位编号',
  326. id: 'fm_company_code',
  327. name: 'company_code',
  328. maxLength: 250,
  329. maxLengthText: '长度不得超出{0}',
  330. anchor: '95%'
  331. }, {
  332. id: 'fm_id',
  333. name: 'id',
  334. hidden: true
  335. }, {
  336. id: 'fm_queryJson',
  337. name: 'queryJson',
  338. hidden: true
  339. }],
  340. buttons: [{
  341. text: '修改',
  342. iconCls: 'ok_btn',
  343. handler: function () {
  344. var form = this.up('form').getForm();
  345. if (form.isValid()) {
  346. var query = new Object();
  347. query.id = Ext.getCmp('fm_id').getValue();
  348. query.name = Ext.getCmp('fm_name').getValue();
  349. query.phone = Ext.getCmp('fm_phone').getValue();
  350. query.Job_duties = Ext.getCmp('fm_Job_duties').getValue();
  351. query.company_code = Ext.getCmp('fm_company_code').getValue();
  352. var jsonstr = Ext.JSON.encode(query);
  353. Ext.getCmp('fm_queryJson').setValue(jsonstr);
  354. form.submit({
  355. method: 'post',
  356. success: function (form, action) {
  357. Ext.Msg.alert('操作成功', '已修改', function (btn, txt) {
  358. clear_modify_form();
  359. });
  360. },
  361. failure: function (form, action) {
  362. Ext.Msg.alert('操作失败', action.Msg, function (btn, txt) {
  363. clear_modify_form();
  364. });
  365. }
  366. });
  367. this.up('window').hide();
  368. }
  369. }
  370. }, {
  371. text: '关闭',
  372. iconCls: 'cancel_btn',
  373. handler: function () {
  374. this.up('window').hide();
  375. }
  376. }]
  377. });
  378. var modifywin = function () {
  379. Ext.create('Ext.window.Window', {
  380. title: '修改',
  381. height: 350,
  382. width: 400,
  383. layout: 'fit',
  384. items: ModifyForm,
  385. closeAction: 'hide'
  386. }).show();
  387. }
  388. var chk_sm = function () {
  389. if (sm.getCount() == 1) {
  390. modifywin();
  391. var selected = sm.getSelection();
  392. Ext.getCmp('fm_id').setValue(selected[0].raw.id);
  393. Ext.getCmp('fm_name').setValue(selected[0].raw.name);
  394. Ext.getCmp('fm_phone').setValue(selected[0].raw.phone);
  395. Ext.getCmp('fm_Job_duties').setValue(selected[0].raw.Job_duties);
  396. Ext.getCmp('fm_company_code').setValue(selected[0].raw.company_code);
  397. } else {
  398. Ext.Msg.alert('请先选择', '请先选择一条记录,再点击修改');
  399. }
  400. }
  401. //
  402. // var deletewin = function() {
  403. // window.alert("无此功能");
  404. //
  405. // }
  406. Ext.create('Ext.grid.Panel', {
  407. title: '巡检人管理',
  408. id: 'InspectorsListPanel',
  409. store: myStore,
  410. selModel: sm,
  411. columns: [
  412. //{ header: 'ID', dataIndex: 'UQ_POINT_ID',hidden:true, menuDisabled:true },
  413. { header: 'ID', dataIndex: 'id', width: 40, menuDisabled: true },
  414. { header: '姓名', dataIndex: 'name', width: 120, align: 'center', menuDisabled: true },
  415. { header: '手机号', dataIndex: 'phone', width: 160, align: 'center', menuDisabled: true },
  416. { header: '职务', dataIndex: 'Job_duties', width: 120, align: 'center', menuDisabled: true },
  417. { header: '单位编号', dataIndex: 'company_code', width: 120, align: 'center', menuDisabled: true },
  418. // { header: '记录版本', dataIndex: 'I_VERSION', width:120, align:'center', menuDisabled:true },
  419. // {
  420. // xtype : 'actioncolumn',
  421. // width:20,
  422. // sortable:false,
  423. //
  424. //
  425. // //这里
  426. // align:'center',
  427. // menuDisabled:true,
  428. // items:[{
  429. // icon: '../../res/img/common/forum.gif',
  430. // tooltip: '版本记录',
  431. // handler: function(grid, rowIndex, colIndex) {
  432. // var rec = grid.getStore().getAt(rowIndex);
  433. // window.location = 'version.jsp?theme='+theme+'&pointId='+rec.get('UQ_POINT_ID');
  434. // }
  435. // }]
  436. // }
  437. ],
  438. columnLines: true,
  439. tbar: [
  440. {
  441. xtype: 'button',
  442. iconCls: 'filter_btn',
  443. text: '筛选',
  444. listeners: {
  445. click: filterwin
  446. }
  447. }, '-',
  448. { xtype: 'tbfill' }, '-',
  449. {
  450. xtype: 'button',
  451. iconCls: 'append_btn',
  452. text: '新增',
  453. listeners: {
  454. click: appendwin
  455. }
  456. },
  457. {
  458. xtype: 'button',
  459. iconCls: 'modify_btn',
  460. text: '修改',
  461. listeners: {
  462. click: chk_sm
  463. }
  464. },
  465. // {
  466. // xtype: 'button',
  467. // iconCls:'delete_btn',
  468. // text: '注销',
  469. // listeners: {
  470. // click: deletewin
  471. // }
  472. // }
  473. // ,{
  474. // xtype: 'button',
  475. // iconCls:'delete_btn',
  476. // text: '导出',
  477. // listeners: {
  478. // click: export_sj
  479. // }
  480. // }
  481. ],
  482. height: maxHeight,
  483. width: '100%',
  484. bbar: new Ext.PagingToolbar({
  485. store: myStore,
  486. id: 'InspectorsListPageToolbar',
  487. displayInfo: true,
  488. pageSize: countPerPage,
  489. prependButtons: true,
  490. displayMsg: '显示第 {0}条到 {1}条记录,总共 {2}条',
  491. emptyMsg: "没有记录",
  492. firstText: '第一页',
  493. prevText: '前一页',
  494. nextText: '后一页',
  495. lastText: '最后一页',
  496. refreshText: '刷新',
  497. // doRefresh:function(start){
  498. // alert(start);
  499. // relushDataFunction(start); // 调用函数刷新数据
  500. // this.cursor = start; // 更新页签
  501. // }
  502. }),
  503. frame: true,
  504. border: false,
  505. iconCls: 'icon-grid',
  506. renderTo: Ext.getBody()
  507. });
  508. myStore.reload();
  509. maxHeight = document.documentElement.clientHeight;
  510. Ext.getCmp('InspectorsListPanel').setHeight(maxHeight);
  511. });