123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], function ($, undefined, Backend, Table, Form, SelectPage) {
- let Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'auth/admin/index',
- add_url: 'auth/admin/add',
- edit_url: 'auth/admin/edit',
- del_url: 'auth/admin/del',
- multi_url: 'auth/admin/multi',
- }
- });
- let table = $("#table");
- //在表格内容渲染完成后回调的事件
- table.on('post-body.bs.table', function (e, json) {
- $("tbody tr[data-index]", this).each(function () {
- if (parseInt($("td:eq(1)", this).text()) == Config.admin.id) {
- $("input[type=checkbox]", this).prop("disabled", true);
- }
- });
- });
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- showToggle: false,
- showColumns: false,
- queryParams: function (params) {
- //如果希望追加搜索条件,可使用
- let filter = params.filter ? JSON.parse(params.filter) : {};
- let op = params.op ? JSON.parse(params.op) : {};
- if(filter.institution_id){
- params.institution_id = filter.institution_id;
- delete filter.institution_id;
- }
- if(op.institution_id){
- delete op.institution_id;
- }
- params.filter = JSON.stringify(filter);
- params.op = JSON.stringify(op);
- return params;
- },
- columns: [
- [
- // {field: 'state', checkbox: true, },
- // {field: 'id', title: 'ID'},
- {field: 'username', title: __('Username')},
- {field: 'nickname', title: __('Nickname')},
- {field: 'phone', title: __('Phone')},
- {field: 'institution_id', title: __('医院'),visible: false},
- {
- field: 'groups_text',
- title: __('Group'),
- operate:false,
- width: '20%',
- formatter: Table.api.formatter.label
- },
- // {
- // field: 'institution_text',
- // title: __('Institution_count'),
- // width: '10%',
- // searchable: true,
- // formatter: function (val) {
- // if(val){
- // return '<strong>'+ val.split(',').length +'</strong>';
- // } else {
- // return 0;
- // }
- // }
- // },
- {field: 'email', title: __('Email')},
- {
- field: 'status',
- title: __("Status"),
- formatter: Table.api.formatter.status,
- searchList: {1: '正常', 2: '禁用'},
- custom: {1: 'success', 2: 'danger'},
- },
- {field: 'logintime', title: __('Login time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
- {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function (value, row, index) {
- if(row.id == Config.admin.id){
- return '';
- }
- return Table.api.formatter.operate.call(this, value, row, index);
- }}
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- initInstitutionSearchList('institution_text');
- $.ajax({
- url: 'institution/institution/institutionSelectList',
- type: 'post',
- dataType: 'json',
- success: function success(res) {
- let data = res.rows;
- $('#institution_id').selectPage({
- data : data,
- orderBy: 'index'
- });
- }
- });
- },
- add: function () {
- initInstitutionSearchList('c-institution');
- Form.api.bindevent($("form[role=form]"));
- },
- edit: function () {
- initInstitutionSearchList('c-institution');
- Form.api.bindevent($("form[role=form]"));
- }
- };
- let initInstitutionSearchList = function (id) {
- $.ajax({
- url: 'institution/institution/institutionSelectList',
- type: 'post',
- dataType: 'json',
- success: function success(res) {
- let data = res.rows;
- $('#'+id).selectPage({
- data : data,
- orderBy: 'index',
- multiple: true
- });
- }
- });
- };
- return Controller;
- });
|