Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

738 řádky
32 KiB

  1. /*
  2. * 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园(http://www.learun.cn)
  3. * Copyright (c) 2013-2018 北京泉江科技有限公司
  4. * 创建人:陈彬彬
  5. * 日 期:2018.04.28
  6. * 描 述:表格字段编辑
  7. */
  8. var keyValue = request('keyValue');
  9. var gridSetting = top[keyValue];
  10. var bootstrap = function ($, learun) {
  11. "use strict";
  12. var currentRow = null;
  13. var setFlag = false;
  14. function initData(data) {
  15. var colDatas = [];
  16. var map = {};
  17. $.each(gridSetting.fields, function (_index, _item) {
  18. map[_item.field] = _item;
  19. });
  20. $.each(data, function (_index, _item) {
  21. var point = {
  22. isHide: 0,
  23. field: _item.f_column,
  24. name: _item.f_remark,
  25. width: 80,
  26. align: 'left',
  27. type: 'input'
  28. };
  29. if (map[_item.field]) {
  30. point = map[_item.field];
  31. }
  32. colDatas.push(point);
  33. });
  34. gridSetting.fields = colDatas;
  35. }
  36. function setRowOp() {
  37. console.log(currentRow);
  38. setFlag = true;
  39. var res = [];
  40. var parentId = currentRow.parentId;
  41. $('.field').show();
  42. $.each(gridSetting.fields, function (_index, _item) {
  43. if (_item.field === '' && _item.name !== '' && _item.id !== currentRow.id) {
  44. res.push({ 'id': _item.id, 'text': _item.name });
  45. }
  46. if (currentRow.id === _item.parentId) {
  47. $('.field').hide();
  48. }
  49. });
  50. $('#parentId').lrselectRefresh({
  51. data: res
  52. });
  53. //$('#colop').lrSetFormData(currentRow);
  54. $('#name').val(currentRow.name);
  55. $('#parentId').lrselectSet(parentId);
  56. $('#field').lrselectSet(currentRow.field);
  57. $('#align').lrselectSet(currentRow.align);
  58. $('#width').val(currentRow.width);
  59. $('#type').lrselectSet(currentRow.type);
  60. switch (currentRow.type) {
  61. case 'label':
  62. case 'input':
  63. case 'guid':
  64. break;
  65. case 'radio':
  66. case 'checkbox':
  67. case 'select':
  68. $('#dataSource').lrselectSet(currentRow.dataSource);
  69. $('#dfvalue').lrselectSet(currentRow.dfvalue);
  70. if (currentRow.dataSource === '0') {
  71. $('#dataItemId').lrselectSet(currentRow.itemCode);
  72. }
  73. else {
  74. $('#dataSourceId').lrselectSet(currentRow.dataSourceId);
  75. $('#showField').lrselectSet(currentRow.showField);
  76. $('#saveField').lrselectSet(currentRow.saveField);
  77. }
  78. break;
  79. case 'layer':
  80. $('#layerW').val(currentRow.layerW || '');
  81. $('#layerH').val(currentRow.layerH || '');
  82. break;
  83. case 'datetime':
  84. $('#datetime').lrselectSet(currentRow.datetime);
  85. break;
  86. }
  87. setFlag = false;
  88. }
  89. // 设置弹层显示数据
  90. function setLayerGridData(data) {
  91. currentRow.layerData = data || [
  92. { label: '项目名', name: 'F_ItemName', value: '', width: '100', align: 'left', hide: 0 },
  93. { label: '项目值', name: 'F_ItemValue', value: '', width: '100', align: 'left', hide: 0 }
  94. ];
  95. $('#layerGrid').jfGridSet('refreshdata', currentRow.layerData);
  96. }
  97. var page = {
  98. init: function () {
  99. page.bind();
  100. },
  101. bind: function () {
  102. $('#colopWrap').lrscroll();
  103. // 显示名称
  104. $('#name').on("input propertychange", function (e) {
  105. var value = $(this).val();
  106. currentRow['name'] = value;
  107. $('#edit_grid').jfGridSet('updateRow');
  108. });
  109. // 字段绑定
  110. $('#field').lrselect({
  111. value: 'f_column',
  112. text: 'f_column',
  113. title: 'f_remark',
  114. allowSearch: true,
  115. select: function (item) {
  116. if (item) {
  117. currentRow.field = item.f_column;
  118. if (currentRow.name === '') {
  119. currentRow.name = item.f_remark;
  120. $('#name').val(currentRow.name);
  121. }
  122. $('.lastcol').show();
  123. }
  124. else {
  125. if (currentRow) {
  126. currentRow.field = '';
  127. }
  128. $('.lastcol').hide();
  129. }
  130. $('#edit_grid').jfGridSet('updateRow');
  131. }
  132. });
  133. // 对齐方式
  134. $('#align').lrselect({
  135. placeholder: false,
  136. data: [
  137. { 'id': 'left', 'text': '靠左' },
  138. { 'id': 'center', 'text': '居中' },
  139. { 'id': 'right', 'text': '靠右' }
  140. ],
  141. select: function (item) {
  142. currentRow.align = item.id;
  143. $('#edit_grid').jfGridSet('updateRow');
  144. }
  145. });
  146. // 字段宽度
  147. $('#width').on("input propertychange", function (e) {
  148. var value = $(this).val();
  149. currentRow['width'] = value;
  150. });
  151. // 字段类型
  152. $('#type').lrselect({
  153. placeholder: false,
  154. data: [
  155. { 'id': 'label', 'text': '文本' },
  156. { 'id': 'input', 'text': '输入框' },
  157. { 'id': 'select', 'text': '下拉框' },
  158. { 'id': 'radio', 'text': '单选框' },
  159. { 'id': 'checkbox', 'text': '多选框' },
  160. { 'id': 'layer', 'text': '弹层选择框' },
  161. { 'id': 'datetime', 'text': '日期' },
  162. { 'id': 'guid', 'text': 'GUID' }
  163. ],
  164. select: function (item) {
  165. currentRow.type = item.id;
  166. $('#layerop').hide();
  167. $('#layerop').parent().removeClass('layerop');
  168. $('.layer').hide();
  169. switch (item.id) {
  170. case 'label':
  171. case 'input':
  172. case 'guid':
  173. $('.datasource').hide();
  174. $('.datasource1').hide();
  175. $('.datetime').hide();
  176. break;
  177. case 'radio':
  178. case 'checkbox':
  179. case 'select':
  180. $('.datetime').hide();
  181. $('.datasource').show();
  182. $('#dataSource').lrselectSet(currentRow.dataSource);
  183. if (currentRow.dataSource === '0') {
  184. $('#dataItemId').lrselectSet(currentRow.itemCode || currentRow.dataItemCode);
  185. }
  186. else {
  187. $('#dataSourceId').lrselectSet(currentRow.dataSourceId);
  188. $('#showField').lrselectSet(currentRow.showField);
  189. $('#saveField').lrselectSet(currentRow.saveField);
  190. }
  191. break;
  192. case 'layer':
  193. $('.datetime').hide();
  194. $('.datasource1').hide();
  195. $('.datasource').show();
  196. $('.dfvalue').hide();
  197. $('#dataSource').lrselectSet(currentRow.dataSource);
  198. if (currentRow.dataSource === '0') {
  199. $('#dataItemId').lrselectSet(currentRow.itemCode || currentRow.dataItemCode);
  200. }
  201. else {
  202. $('#dataSourceId').lrselectSet(currentRow.dataSourceId);
  203. }
  204. $('.layer').show();
  205. $('#layerop').show();
  206. $('#layerop').parent().addClass('layerop');
  207. break;
  208. case 'datetime':
  209. $('.datetime').show();
  210. $('.datasource').hide();
  211. $('.datasource1').hide();
  212. break;
  213. }
  214. $('#edit_grid').jfGridSet('updateRow');
  215. }
  216. });
  217. // 上级列头
  218. $('#parentId').lrselect({
  219. select: function (item) {
  220. if (!item) {
  221. currentRow.parentId = '';
  222. }
  223. else {
  224. if (currentRow.parentId !== item.id) {
  225. currentRow.parentId = item.id;
  226. }
  227. }
  228. if (!setFlag) {
  229. $('#edit_grid').jfGridSet('refreshdata', gridSetting.fields);
  230. }
  231. }
  232. });
  233. // 数据来源
  234. $('#dfvalue').lrselect({
  235. allowSearch: true,
  236. select: function (item) {
  237. if (item) {
  238. if (currentRow.dataSource === '0') {
  239. currentRow.dfvalue = item.id;
  240. }
  241. else {
  242. currentRow.dfvalue = item[currentRow.saveField];
  243. }
  244. }
  245. else {
  246. currentRow.dfvalue = '';
  247. }
  248. }
  249. });
  250. // 数据字典选项
  251. $('#dataItemId').lrselect({
  252. allowSearch: true,
  253. url: top.$.rootUrl + '/LR_SystemModule/DataItem/GetClassifyTree',
  254. type: 'tree',
  255. value: 'value',
  256. select: function (item) {
  257. if (item) {
  258. if (currentRow.dataSourceId !== item.id) {
  259. currentRow.dfvalue = '';
  260. currentRow.itemCode = item.value;
  261. }
  262. if (currentRow.type === 'radio' || currentRow.type === 'checkbox' || currentRow.type === 'select') {
  263. learun.clientdata.getAllAsync('dataItem', {
  264. code: item.value,
  265. callback: function (dataes) {
  266. var list = [];
  267. $.each(dataes, function (_index, _item) {
  268. if (_item.parentId === "0") {
  269. list.push({ id: _item.value, text: _item.text, title: _item.text, k: _index });
  270. }
  271. });
  272. var _value = currentRow.dfvalue;
  273. $('#dfvalue').lrselectRefresh({
  274. value: "id",
  275. text: "text",
  276. title: "title",
  277. data: list,
  278. url: ''
  279. });
  280. if (_value !== '' && _value !== undefined && _value !== null) {
  281. $('#dfvalue').lrselectSet(_value);
  282. }
  283. }
  284. });
  285. }
  286. }
  287. else {
  288. currentRow.itemCode = '';
  289. currentRow.dataItemCode && (currentRow.dataItemCode = '');
  290. if (currentRow.type === 'radio' || currentRow.type === 'checkbox' || currentRow.type === 'select') {
  291. currentRow.dfvalue = '';
  292. $('#dfvalue').lrselectRefresh({ url: '', data: [] });
  293. }
  294. }
  295. }
  296. });
  297. // 数据源
  298. $('#showField').lrselect({
  299. title: 'text',
  300. text: 'text',
  301. value: 'value',
  302. allowSearch: true,
  303. select: function (item) {
  304. if (item) {
  305. currentRow.showField = item.value;
  306. if (currentRow.saveField !== '') {
  307. learun.clientdata.getAllAsync('sourceData', {
  308. code: currentRow.dataSourceId,
  309. callback: function (dataes) {
  310. var _value = currentRow.dfvalue;
  311. $('#dfvalue').lrselectRefresh({
  312. value: currentRow.saveField,
  313. text: currentRow.showField,
  314. title: currentRow.showField,
  315. url: '',
  316. data: dataes
  317. });
  318. if (_value !== '' && _value !== undefined && _value !== null) {
  319. $('#dfvalue').lrselectSet(_value);
  320. }
  321. }
  322. });
  323. }
  324. }
  325. }
  326. });
  327. $('#saveField').lrselect({
  328. title: 'text',
  329. text: 'text',
  330. value: 'value',
  331. allowSearch: true,
  332. select: function (item) {
  333. if (item) {
  334. currentRow.saveField = item.value;
  335. if (currentRow.showField !== '') {
  336. learun.clientdata.getAllAsync('sourceData', {
  337. code: currentRow.dataSourceId,
  338. callback: function (dataes) {
  339. var _value = currentRow.dfvalue;
  340. $('#dfvalue').lrselectRefresh({
  341. value: currentRow.saveField,
  342. text: currentRow.showField,
  343. title: currentRow.showField,
  344. url: '',
  345. data: dataes
  346. });
  347. if (_value !== '' && _value !== undefined && _value !== null) {
  348. $('#dfvalue').lrselectSet(_value);
  349. }
  350. }
  351. });
  352. }
  353. }
  354. }
  355. });
  356. $('#dataSourceId').lrselect({
  357. allowSearch: true,
  358. url: top.$.rootUrl + '/LR_SystemModule/DataSource/GetList',
  359. value: 'F_Code',
  360. text: 'F_Name',
  361. title: 'F_Name',
  362. select: function (item) {
  363. var flag = true;
  364. if (item) {
  365. if (currentRow.dataSourceId !== item.F_Code) {
  366. currentRow.showField = '';
  367. currentRow.saveField = '';
  368. currentRow.dfvalue = '';
  369. flag = false;
  370. }
  371. currentRow.dataSourceId = item.F_Code;
  372. if (currentRow.type === 'radio' || currentRow.type === 'checkbox' || currentRow.type === 'select') {
  373. var _value = currentRow.dfvalue;
  374. $('#dfvalue').lrselectRefresh({ url: '', data: [] });
  375. currentRow.dfvalue = _value;
  376. //获取字段数据
  377. learun.httpAsync('GET', top.$.rootUrl + '/LR_SystemModule/DataSource/GetDataColName', { code: item.F_Code }, function (data) {
  378. var fieldData = [];
  379. for (var i = 0, l = data.length; i < l; i++) {
  380. var id = data[i];
  381. var selectpoint = { value: id, text: id };
  382. fieldData.push(selectpoint);
  383. }
  384. $('#showField').lrselectRefresh({
  385. data: fieldData,
  386. placeholder: false
  387. });
  388. $('#showField').lrselectSet(currentRow.showField || fieldData[0].value);
  389. $('#saveField').lrselectRefresh({
  390. data: fieldData,
  391. placeholder: false
  392. });
  393. $('#saveField').lrselectSet(currentRow.saveField || fieldData[0].value);
  394. });
  395. }
  396. else if (currentRow.type === 'layer') {
  397. if (!flag || currentRow.layerData.length === 0) {
  398. learun.httpAsync('GET', top.$.rootUrl + '/LR_SystemModule/DataSource/GetDataColName', { code: item.F_Code }, function (data) {
  399. var fieldData = [];
  400. $.each(data, function (_index, _item) {
  401. var selectpoint = { label: '', name: _item, value: '', width: '100', align: 'left', hide: 0 };
  402. fieldData.push(selectpoint);
  403. });
  404. setLayerGridData(fieldData);
  405. });
  406. }
  407. else {
  408. setLayerGridData(currentRow.layerData);
  409. }
  410. }
  411. }
  412. else {
  413. currentRow.dataSourceId = '';
  414. if (currentRow.type === 'radio' || currentRow.type === 'checkbox' || currentRow.type === 'select') {
  415. currentRow.showField = '';
  416. currentRow.saveField = '';
  417. currentRow.dfvalue = '';
  418. $('#showField').lrselectRefresh({
  419. data: [],
  420. placeholder: '请选择'
  421. });
  422. $('#saveField').lrselectRefresh({
  423. data: [],
  424. placeholder: '请选择'
  425. });
  426. $('#dfvalue').lrselectRefresh({ url: '', data: [] });
  427. } else if (currentRow.type === 'layer') {
  428. setLayerGridData([]);
  429. }
  430. }
  431. }
  432. });
  433. $('#dataSource').lrselect({
  434. data: [{ id: '0', text: '数据字典' }, { id: '1', text: '数据源' }],
  435. value: 'id',
  436. text: 'text',
  437. placeholder: false,
  438. select: function (item) {
  439. if (currentRow) {
  440. if (currentRow.dataSource === '0' && item.id === '1') {
  441. currentRow.layerData = [];
  442. }
  443. else if (currentRow.dataSource === '1' && item.id === '0') {
  444. currentRow.layerData = [
  445. { label: '项目名', name: 'F_ItemName', value: '', width: '100', align: 'left', hide: 0 },
  446. { label: '项目值', name: 'F_ItemValue', value: '', width: '100', align: 'left', hide: 0 }
  447. ];
  448. }
  449. currentRow.dataSource = item.id;
  450. }
  451. if (item.id === '0') {
  452. $('#dataSourceId').hide();
  453. $('#dataItemId').show();
  454. $('.datasource1').hide();
  455. if (currentRow.type === 'layer') {
  456. setLayerGridData(currentRow.layerData);
  457. }
  458. }
  459. else {
  460. $('#dataItemId').hide();
  461. $('#dataSourceId').show();
  462. if (currentRow.type === 'radio' || currentRow.type === 'checkbox' || currentRow.type === 'select') {
  463. $('.datasource1').show();
  464. }
  465. else {
  466. $('.datasource1').hide();
  467. }
  468. if (currentRow.type === 'layer') {
  469. setLayerGridData(currentRow.layerData || []);
  470. }
  471. }
  472. }
  473. });
  474. // 弹层数据设置
  475. $('#layerGrid').jfGrid({
  476. headData: [
  477. {
  478. label: "字段名", name: "label", width: 150, align: "left",
  479. edit: {
  480. type: 'input'
  481. }
  482. },
  483. { label: "字段ID", name: "name", width: 150, align: "left" },
  484. {
  485. label: "绑定字段", name: "value", width: 150, align: "left",
  486. edit: {
  487. type: 'select',
  488. init: function (row, $self) {// 选中单元格后执行
  489. $self.lrselectRefresh({
  490. data: gridSetting.fieldMap[gridSetting.dbId + gridSetting.tableName]
  491. });
  492. },
  493. op: {
  494. value: 'f_column',
  495. text: 'f_column',
  496. title: 'f_remark',
  497. allowSearch: true
  498. }
  499. }
  500. },
  501. {
  502. label: "宽度", name: "width", width: 70, align: "center",
  503. edit: {
  504. type: 'input'
  505. }
  506. },
  507. {
  508. label: "对齐", name: "align", width: 70, align: "center",
  509. edit: {
  510. type: 'select',
  511. op: {
  512. placeholder: false,
  513. data: [
  514. { 'id': 'left', 'text': '靠左' },
  515. { 'id': 'center', 'text': '居中' },
  516. { 'id': 'right', 'text': '靠右' }
  517. ]
  518. }
  519. }
  520. },
  521. {
  522. label: "隐藏", name: "hide", width: 50, align: "center",
  523. formatter: function (value, row, op, $cell) {
  524. $cell.on('click', function () {
  525. var v = $cell.find('span').text();
  526. if (v === '是') {
  527. row.hide = 0;
  528. $cell.html('<span class=\"label label-success \" style=\"cursor: pointer;\">否</span>');
  529. }
  530. else {
  531. row.hide = 1;
  532. $cell.html('<span class=\"label label-default \" style=\"cursor: pointer;\">是</span>');
  533. }
  534. return false;
  535. });
  536. if (value === 1) {
  537. return '<span class=\"label label-default \" style=\"cursor: pointer;\">是</span>';
  538. } else if (value === 0) {
  539. return '<span class=\"label label-success \" style=\"cursor: pointer;\">否</span>';
  540. }
  541. }
  542. },// 1 隐藏 0 显示
  543. {
  544. label: "", name: "btn1", width: 50, align: "center",
  545. formatter: function (value, row, op, $cell) {
  546. $cell.on('click', function () {
  547. var rowindex = parseInt($cell.attr('rowindex'));
  548. var res = $('#layerGrid').jfGridSet('moveUp', rowindex);
  549. return false;
  550. });
  551. return '<span class=\"label label-info\" style=\"cursor: pointer;\">上移</span>';
  552. }
  553. },
  554. {
  555. label: "", name: "btn2", width: 50, align: "center",
  556. formatter: function (value, row, op, $cell) {
  557. $cell.on('click', function () {
  558. var rowindex = parseInt($cell.attr('rowindex'));
  559. var res = $('#layerGrid').jfGridSet('moveDown', rowindex);
  560. return false;
  561. });
  562. return '<span class=\"label label-warning\" style=\"cursor: pointer;\">下移</span>';
  563. }
  564. }
  565. ],
  566. isShowNum: false
  567. });
  568. // 弹层宽
  569. $('#layerW').on("input propertychange", function (e) {
  570. var value = $(this).val();
  571. currentRow['layerW'] = value;
  572. });
  573. // 弹层高
  574. $('#layerH').on("input propertychange", function (e) {
  575. var value = $(this).val();
  576. currentRow['layerH'] = value;
  577. });
  578. // 日期格式
  579. $('#datetime').lrselect({
  580. placeholder: false,
  581. data: [
  582. { 'id': 'date', 'text': '仅日期' },
  583. { 'id': 'datetime', 'text': '日期和时间' }
  584. ],
  585. select: function (item) {
  586. if (currentRow) {
  587. if (item) {
  588. currentRow.datetime = item.id;
  589. }
  590. else {
  591. currentRow.datetime = 'date';
  592. }
  593. }
  594. }
  595. }).lrselectSet('date');
  596. $('#edit_grid').jfGrid({
  597. headData: [
  598. {
  599. label: "显示名称", name: "name", width: 200, align: "left"
  600. },
  601. {
  602. label: "绑定字段", name: "field", width: 200, align: "left"
  603. },
  604. {
  605. label: "类型", name: "type", width: 100, align: "center",
  606. formatter: function (value, row, op, $cell) {
  607. switch (value) {
  608. case 'label':
  609. return '文本';
  610. case 'input': // 输入框 文本,数字,密码
  611. return '输入框';
  612. case 'select': // 下拉框选择
  613. return '下拉框';
  614. case 'radio': // 单选
  615. return '单选框';
  616. case 'checkbox': // 多选
  617. return '多选框';
  618. case 'datetime': // 时间
  619. return '日期';
  620. case 'layer': // 弹层
  621. return '弹层选择框';
  622. case 'guid':
  623. return 'GUID';
  624. }
  625. }
  626. },
  627. {
  628. label: "", name: "btn1", width: 50, align: "center",
  629. formatter: function (value, row, op, $cell) {
  630. $cell.on('click', function () {
  631. var rowindex = parseInt($cell.attr('rowindex'));
  632. var res = $('#edit_grid').jfGridSet('moveUp', rowindex);
  633. return false;
  634. });
  635. return '<span class=\"label label-info\" style=\"cursor: pointer;\">上移</span>';
  636. }
  637. },
  638. {
  639. label: "", name: "btn2", width: 50, align: "center",
  640. formatter: function (value, row, op, $cell) {
  641. $cell.on('click', function () {
  642. var rowindex = parseInt($cell.attr('rowindex'));
  643. var res = $('#edit_grid').jfGridSet('moveDown', rowindex);
  644. return false;
  645. });
  646. return '<span class=\"label label-warning\" style=\"cursor: pointer;\">下移</span>';
  647. }
  648. },
  649. {
  650. label: "", name: "", width: 5, align: "center"
  651. }
  652. ],
  653. isEdit: true,
  654. isShowNum: false,
  655. mainId: 'id',
  656. isTree: true,
  657. onSelectRow: function (rowdata) {
  658. $('#colopWrap').show();
  659. $('#colopWrap').parent().addClass('editopen');
  660. currentRow = rowdata;
  661. setRowOp();
  662. },
  663. onAddRow: function (row, rows) {
  664. row.id = learun.newGuid();
  665. row.name = '';
  666. row.type = 'label';
  667. row.width = 100;
  668. row.align = 'left';
  669. row.parentId = '';
  670. row.field = '';
  671. row.dataSource = '0';
  672. },
  673. onMinusRow: function (row, rows) {
  674. }
  675. });
  676. $('#edit_grid').jfGridSet('refreshdata', gridSetting.fields);
  677. if (!gridSetting.fieldMap[gridSetting.dbId + gridSetting.tableName]) {
  678. learun.httpAsync('GET', top.$.rootUrl + '/LR_SystemModule/DatabaseTable/GetFieldList', { databaseLinkId: gridSetting.dbId, tableName: gridSetting.tableName }, function (data) {
  679. gridSetting.fieldMap[gridSetting.dbId + gridSetting.tableName] = data;
  680. $('#field').lrselectRefresh({
  681. data: data
  682. });
  683. });
  684. }
  685. else {
  686. $('#field').lrselectRefresh({
  687. data: gridSetting.fieldMap[gridSetting.dbId + gridSetting.tableName]
  688. });
  689. }
  690. }
  691. };
  692. page.init();
  693. };