123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- let table1_extend = {
- index_url: 'institution/department/institutionIndex/' + location.search,
- table: 'templates',
- };
- let table2_extend = {
- index_url: 'institution/department/departmentIndex/' + location.search,
- add_url: 'institution/department/add',
- edit_url: 'institution/department/edit',
- del_url: 'institution/department/del',
- table: 'templates',
- };
- let Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init();
- this.table.first();
- this.table.second();
- },
- table: {
- first: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: table1_extend
- });
- let table1 = $("#table1");
- // 初始化表格
- table1.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- pageSize: 10,
- toolbar: '#toolbar1',
- showToggle: false,
- showExport: false,
- showColumns: false,
- commonSearch: false,
- singleSelect: true, //是否启用单选
- clickToSelect: true,
- onCheck: function (rows) { // 选中事件
- // 刷新子级列表
- $('#selected_institution').data('id',rows.id);
- $('#toolbar2 .btn-refresh').trigger('click');
- },
- columns: [
- [
- {checkbox: true,},
- {field: 'name', title: __('Title')},
- {field: 'createdAt', title: __('CreatedAt')},
- ]
- ]
- });
- // 默认选中第一条
- table1.on('post-body.bs.table', function () {
- $('#table1 tr[data-index="0"] td input[data-index="0"]').trigger('click');
- });
-
- // 为表格绑定事件
- Table.api.bindevent(table1);
- },
- second: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: table2_extend
- });
- let table2 = $("#table2");
- // 初始化表格
- table2.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- toolbar: '#toolbar2',
- showToggle: false,
- showColumns: false,
- showExport: false,
- commonSearch: false,
- queryParams: function queryParams(params) {
- params.ins_id = $('#selected_institution').data('id');
- return params;
- },
- columns: [
- [
- {field: 'department_name', title: __('Department_name')},
- {field: 'is_report', title: __('Is_report'),formatter: Controller.api.formatter.is_report},
- {
- field: 'operate',
- export:false,
- title: __('Operate'),
- table: table2,
- events: Table.api.events.operate,
- formatter: Table.api.formatter.operate
- }
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table2);
- $('#toolbar2 .btn-add-2').on('click', function () {
- let ins_id = $('#selected_institution').data('id');
- let url = table2_extend.add_url;
- url = Table.api.replaceurl(url, {ids: ins_id}, table2);
- Fast.api.open(url, __('Add'), $(this).data() || {});
- });
- return table2;
- },
- },
- add: function () {
- Controller.api.bindevent();
- },
- edit: function () {
- Controller.api.bindevent();
- },
- api: {
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- },
- formatter: {
- is_report: function (value) {
- return value == '1' ? '是' : '否';
- }
- },
- },
- };
- return Controller;
- });
|