You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
3.7 KiB
122 lines
3.7 KiB
5 years ago
|
$(document).on('turbolinks:load', function() {
|
||
|
if ($('body.admins-user-schools-statistics-index-page').length > 0) {
|
||
|
var $form = $('.user-schools-statistic-list-form');
|
||
|
|
||
|
// ************** 学校选择 *************
|
||
|
var matcherFunc = function(params, data){
|
||
|
if ($.trim(params.term) === '') {
|
||
|
return data;
|
||
|
}
|
||
|
if (typeof data.text === 'undefined') {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
if (data.name && data.name.indexOf(params.term) > -1) {
|
||
|
var modifiedData = $.extend({}, data, true);
|
||
|
return modifiedData;
|
||
|
}
|
||
|
|
||
|
// Return `null` if the term should not be displayed
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
// ************* 省份选择 *****************
|
||
|
var matcherProvinceFunc = function(params, data){
|
||
|
if ($.trim(params.term) === '') {
|
||
|
return data;
|
||
|
}
|
||
|
if (typeof data.text === 'undefined') {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
if (data.province && data.province.indexOf(params.term) > -1) {
|
||
|
var modifiedData = $.extend({}, data, true);
|
||
|
return modifiedData;
|
||
|
}
|
||
|
// Return `null` if the term should not be displayed
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
var defineSchoolSelect = function (schools) {
|
||
|
$form.find('.school-select').select2({
|
||
|
theme: 'bootstrap4',
|
||
|
placeholder: '选择学校/单位',
|
||
|
minimumInputLength: 1,
|
||
|
data: schools,
|
||
|
templateResult: function (item) {
|
||
|
if(!item.id || item.id === '') return item.text;
|
||
|
return item.name;
|
||
|
},
|
||
|
templateSelection: function(item){
|
||
|
if (item.id) {
|
||
|
$form.find('#school_id').val(item.id);
|
||
|
}
|
||
|
return item.name || item.text;
|
||
|
},
|
||
|
matcher: matcherFunc
|
||
|
});
|
||
|
};
|
||
|
|
||
|
var defineProvinceSelect = function (province) {
|
||
|
$form.find('.province-select').select2({
|
||
|
theme: 'bootstrap4',
|
||
|
placeholder: '选择省份',
|
||
|
minimumInputLength: 1,
|
||
|
data: province,
|
||
|
templateResult: function (item) {
|
||
|
if(!item.province || item.province === '') return item.text;
|
||
|
return item.province;
|
||
|
},
|
||
|
templateSelection: function(item){
|
||
|
if (item.province) {
|
||
|
$form.find('#province').val(item.province);
|
||
|
}
|
||
|
return item.province || item.text;
|
||
|
},
|
||
|
matcher: matcherProvinceFunc
|
||
|
});
|
||
|
};
|
||
|
|
||
|
|
||
|
// 初始化学校选择器
|
||
|
$.ajax({
|
||
|
url: '/api/schools/for_option.json',
|
||
|
dataType: 'json',
|
||
|
type: 'GET',
|
||
|
success: function(data) {
|
||
|
defineSchoolSelect(data.schools);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// 初始化身份选择器
|
||
|
$.ajax({
|
||
|
url: '/api/schools/for_province_option.json',
|
||
|
dataType: 'json',
|
||
|
type: 'GET',
|
||
|
success: function (data) {
|
||
|
console.log(data.province);
|
||
|
defineProvinceSelect(data.province);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// 清空
|
||
|
$form.on('click', '.clear-btn', function(){
|
||
|
$form.find('select[name="date"]').val('');
|
||
|
$form.find('.school-select').val('').trigger('change');
|
||
|
$form.find('.province-select').val('').trigger('change');
|
||
|
$form.find('input[type="submit"]').trigger('click');
|
||
|
})
|
||
|
|
||
|
|
||
|
// 导出
|
||
|
$('.export-action').on('click', function(){
|
||
|
var form = $(".user-schools-statistic-list-form .search-form")
|
||
|
var exportLink = $(this);
|
||
|
var date = form.find("select[name='date']").val();
|
||
|
var schoolId = form.find('input[name="school_id"]').val();
|
||
|
|
||
|
var url = exportLink.data("url").split('?')[0] + "?date=" + date + "&school_id=" + schoolId;
|
||
|
window.open(url);
|
||
|
});
|
||
|
}
|
||
|
});
|