123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- /**
- * Created by CSL on 2017-03-23.
- */
- var region = '重庆';
- var feeRateFileID = 5;
- var datas = [];
- var spreadView;
- $(document).ready(function () {
- $("#inlineFormCustomSelect").change(function () {
- var libID = $("#inlineFormCustomSelect").val();
- loadLibFeeRates(libID);
- });
- $("#projectFeeFile").click(function () {
- loadProjectFeeRates(feeRateFileID);
- });
- });
- function loadProjectFeeRates(fileID) {
- $.ajax({
- type: "POST",
- url: '/fees/getProjectFeeRates',
- data: {"fileID": fileID},
- success: function (result) {
- if (result.data) {
- datas = result.data[0].rates;
- createSpreadView(true);
- }
- },
- error: function (result) {
- alert('内部程序错误!');
- }
- });
- }
- function loadStdFeeRateLibNames(region) {
- $('#inlineFormCustomSelect').empty();
- $.ajax({
- type: "POST",
- url: '/fees/getLibNames',
- data: {"region": region},
- success: function (result) {
- if (result.data) {
- for (var i = 0; i < result.data.length; i++) {
- $("#inlineFormCustomSelect").append("<option value=" + result.data[i].libID + '>' +
- result.data[i].libName + "</option>");
- }
- $("#inlineFormCustomSelect").get(0).selectedIndex = 0;
- }
- },
- error: function (result) {
- alert('内部程序错误!');
- }
- });
- }
- function loadLibFeeRates(libID) {
- $.ajax({
- type: "POST",
- url: '/fees/getLibFeeRates',
- data: {"libID": libID},
- success: function (result) {
- if (result.data) {
- datas = result.data[0].rates;
- createSpreadView(false);
- }
- },
- error: function (result) {
- alert('内部程序错误!');
- }
- });
- }
- function createSpreadView(canEdit) {
- // 创建前先销毁旧树表。
- //$('#divFee').empty(); // 清空不行,浏览器跟踪显示错误数狂飚:TypeError: G is null
- //$('#divFee').remove(); // 删除可以,但是太山寨。
- //$('#content').append($('<div class="grid" id="divFee"></div>'));
- // 以下找到官方的处理方法,比较面向对象
- if (spreadView) {
- spreadView.destroy();
- spreadView = null;
- }
- var columns = [
- {
- id: 'name',
- caption: '名称',
- dataField: 'name',
- width: 250,
- allowEditing: false
- },
- {
- id: 'rate',
- caption: '费率',
- dataField: 'rate',
- format: '0.000',
- width: 80,
- minWidth: 50,
- allowEditing: true
- },
- {
- id: 'memo',
- caption: '说明',
- dataField: 'memo',
- width: 200,
- minWidth: 120,
- allowEditing: false
- },
- {
- id: 'ID',
- caption: 'ID',
- dataField: 'ID',
- width: 80,
- visible: false,
- allowEditing: false
- },
- {
- id: 'ParentID',
- caption: '父结点ID',
- dataField: 'ParentID',
- width: 80,
- visible: false,
- allowEditing: false
- }
- ];
- var options = {
- allowSorting: false,
- showRowHeader: true,
- colMinWidth: 80,
- colHeaderHeight: 35,
- rowHeight: 30,
- allowEditing: canEdit,
- editMode: 'inline',
- editUnit: 'cell',
- selectionUnit: (canEdit == true) ? "cell" : "row",
- hierarchy: {
- keyField: 'ID',
- parentField: 'ParentID',
- collapsed: false,
- column: 'name'
- }
- };
- var dataSource = {
- loadRange: function(params) {
- params.success(datas);
- },
- update: function(params) {
- $.ajax({
- type: 'POST',
- url: '/fees/updateProjectFeeRate',
- data: {"fileID": feeRateFileID, "rateID": params.dataItem.ID, "rateValue": params.dataItem.rate},
- success: function(data) {
- var iCode = data.data;
- if (iCode == 1){
- params.success();
- }else{
- alert('(' + iCode + ') 修改失败!');
- spreadView.cancelEditing();
- params.failed();
- }
- },
- error: function(xhr, status) {
- alert('内部程序错误!');
- params.failed();
- }
- });
- }
- };
- spreadView = new GC.Spread.Views.DataView($('#divFee')[0],
- dataSource, columns, new GC.Spread.Views.Plugins.GridLayout(options));
- spreadView.invalidate();
- document.querySelector('#divFee').focus();
- }
|