| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
-
- var xuwell = {
- //加载数据到Select控件,参数:id url data fieldKey fieldValue autoDisabled
- 'loadSelect': function (opt) {
- var id = typeof (opt.id) == 'undefined' ? null : opt.id;
- var url = typeof (opt.url) == 'undefined' ? null : opt.url;
- var data = typeof (opt.data) == 'undefined' ? null : opt.data;
- var fieldKey = typeof (opt.fieldKey) == 'undefined' ? null : opt.fieldKey;
- var fieldValue = typeof (opt.fieldValue) == 'undefined' ? null : opt.fieldValue;
- var autoDisabled = typeof (opt.autoDisabled) == 'undefined' ? true : false;
- var addTitle = typeof (opt.addTitle) == 'undefined' ? true : opt.addTitle;
- var onLoad = typeof (opt.onLoad) == 'undefined' ? null : opt.onLoad;
- var onError = typeof (opt.onError) == 'undefined' ? null : opt.onError;
- $.get(url, data, function (result) {
- var json = JSON.parse(result);
- if (json['success'] == true) {
- var temp = '<option value="$key$">$value$</option>';
- $(id).empty();
- if (addTitle) $(id).append('<option value="">请选择...</option>');
- for (var i = 0; i < json['rows'].length; i++) {
- $(id).append(temp
- .replace('$key$', json['rows'][i][fieldKey])
- .replace('$value$', json['rows'][i][fieldValue])
- );
- }
- $(id).prop('disabled', json['total'] == 0 && autoDisabled );
- $(id).get(0).selectedIndex = 0;
- if (onLoad != null) onLoad(json);
- }
- else {
- swal({
- title: '登录异常!',
- text: '请您先登录系统!',
- icon: 'error',
- button: '确定'
- }).then(function () {
- window.location = '../common/login.html';
- });
- }
- }).fail(function () {
- if (onError != null) onError();
- });
- },
- 'loadSelectPicker': function (opt) {
- var id = typeof (opt.id) == 'undefined' ? null : opt.id;
- var url = typeof (opt.url) == 'undefined' ? null : opt.url;
- var data = typeof (opt.data) == 'undefined' ? null : opt.data;
- var fieldKey = typeof (opt.fieldKey) == 'undefined' ? null : opt.fieldKey;
- var fieldValue = typeof (opt.fieldValue) == 'undefined' ? null : opt.fieldValue;
- var autoDisabled = typeof (opt.autoDisabled) == 'undefined' ? true : false;
- var addTitle = typeof (opt.addTitle) == 'undefined' ? true : opt.addTitle;
- var onLoad = typeof (opt.onLoad) == 'undefined' ? null : opt.onLoad;
- var onError = typeof (opt.onError) == 'undefined' ? null : opt.onError;
- $.get(url, data, function (result) {
- var json = JSON.parse(result);
- if (json['success'] == true) {
- var temp = '<option data-tokens="$key$">$value$</option>';
- $(id).empty();
- if (addTitle) $(id).append('<option data-tokens="" value="">请选择...</option>');
- for (var i = 0; i < json['rows'].length; i++) {
- $(id).append(temp
- .replace('$key$', json['rows'][i][fieldKey])
- .replace('$value$', json['rows'][i][fieldValue])
- );
- }
- $(id).prop('disabled', json['total'] == 0 && autoDisabled);
- $(id).get(0).selectedIndex = 0;
- $(id).selectpicker('refresh');
- if (onLoad != null) onLoad(json);
- }
- else {
- swal({
- title: '登录异常!',
- text: '请您先登录系统!',
- icon: 'error',
- button: '确定'
- }).then(function () {
- window.location = '../common/login.html';
- });
- }
- }).fail(function () {
- if (onError != null) onError();
- });
- },
- //加载bootstrapTable
- 'loadTable': function (opt) {
- var id = typeof (opt.id) == 'undefined' ? '#table' : opt.id;
- var toolbar = typeof (opt.toolbar) == 'undefined' ? '#toolbar' : opt.toolbar;
- var formSearchId = typeof (opt.formSearchId) == 'undefined' ? '#formSearch' : opt.formSearchId;
- var pageSize = typeof (opt.pageSize) == 'undefined' ? 10 : opt.pageSize;
- var pageNumber = typeof (opt.pageNumber) == 'undefined' ? 1 : opt.pageNumber;
- var sortable = typeof (opt.sortable) == 'undefined' ? false : opt.sortable;
- var url = typeof (opt.url) == 'undefined' ? '' : opt.url;
- $(id).bootstrapTable('destroy').bootstrapTable({
- toggle: "table",
- boolbar: toolbar,
- url: url,
- locale: "zh-CN",
- //showExport: true, //是否显示导出按钮
- //exportdatatype: 'all',//basic', 'all', 'selected'.
- //exportOptions: {
- // ignoreColumn: [0, 1], //忽略某一列的索引
- // fileName: '导出数据', //文件名称设置
- // worksheetName: 'sheet1', //表格工作区名称
- // tableName: '数据',
- // excelstyles: ['background-color', 'color', 'font-size', 'font-weight', 'border-top']
- //},
- //buttonsAlign: "right", //按钮位置
- //exportTypes: ['csv'], //导出文件类型
- sortable: sortable,
- sortOrder: "asc",
- pagination: true,
- pageNumber: pageNumber,
- pageSize: pageSize,
- pageList: "[10, 100, 500, 1000, 2000, 5000, ALL]",
- striped: true,
- sidePagination: 'server',
- queryParams: function (params) {
- var args = $.param({
- pageNumber: params.offset / params.limit,
- pageSize: params.limit,
- sort: params.sort,
- order: params.order
- }) + "&" + $(formSearchId).serialize();
- return args;
- },
- responseHandler: function (res) {
- return res;
- },
- onLoadSuccess: function (json) {
- //var json = JSON.parse(data);
- if (json['success'] == false) {
- swal({
- title: '登录异常!',
- text: '请您先登录系统!',
- icon: 'error',
- button: '确定'
- }).then(function () {
- window.location = '../common/login.html';
- });
- }
- }
- });
- },
- 'exportFile': function exportFile(tableId, fileName) {
- /**
- * 表格导出
- * style="mso-number-format:'@';"
- * 1) 文本:'@'
- * 2) 日期:'yyyy/mm/dd'
- * 3) 数字:'#,##0.00'
- * 4) 货币:'¥#,##0.00'
- * 5) 百分比:'#0.00%'
- */
- if (tableId == 'undefined') tableId = 'table';
- if (fileName == 'undefined') fileName = '数据导出.xls';
- //获取表格
- var exportFileContent = document.getElementById(tableId).innerHTML;
- exportFileContent = '<table border="1">' + exportFileContent + '</table>';
- exportFileContent = exportFileContent.replace('<tfoot style="display: none;"><tr></tr></tfoot>', '');
- //使用Blob
- var blob = new Blob([exportFileContent], { type: "text/plain;charset=utf-8" });
- //解决中文乱码问题
- blob = new Blob([String.fromCharCode(0xFEFF), blob], { type: blob.type });
- //设置链接
- var link = window.URL.createObjectURL(blob);
- var a = document.createElement("a");
- a.download = fileName;
- a.href = link;
- document.body.appendChild(a);
- a.click();
- document.body.removeChild(a);
- }
- }
|