123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- let table1_extend = {
- index_url: 'template/privatetmp/parentIndex/' + location.search,
- table: 'templates',
- };
- let table2_extend = {
- index_url: 'template/privatetmp/childIndex/' + location.search,
- 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) { // 选中事件
- // 刷新子级列表
- $('#child_name').text(rows.title);
- $('#selected_parent').data('pid',rows.id);
- $('#toolbar2 .btn-refresh').trigger('click');
- },
- columns: [
- [
- {checkbox: true,},
- {field: 'title', title: __('Title')},
- {field: 'exam_class_id', title: __('Exam_class_id')},
- {
- field: 'operate',
- title: __('Operate'),
- table: table1,
- events: Controller.api.events.table1_operate,
- formatter: Table.api.formatter.operate
- }
- ]
- ]
- });
- // 默认选中第一条
- table1.on('post-body.bs.table', function () {
- $('#table1 tr[data-index="0"] td input[data-index="0"]').trigger('click');
- });
-
- // 为表格绑定事件
- Table.api.bindevent(table1);
- // 自定义添加按钮事件
- $('#toolbar1 .btn-add-1').on('click', function () {
- let ids = Table.api.selectedids(table1);
- let url = table1_extend.add_url;
- if (url.indexOf("{ids}") !== -1) {
- url = Table.api.replaceurl(url, {ids: ids.length > 0 ? ids.join(",") : 0}, table1);
- }
- Fast.api.open(url, __('Add'), $(this).data() || {});
- });
- },
- second: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: table2_extend
- });
- let table2 = $("#table2");
- // 初始化表格
- table2.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- toolbar: '#toolbar2',
- sortName: 'createdAt',
- showToggle: false,
- showColumns: false,
- queryParams: function queryParams(params) {
- params.pid = $('#selected_parent').data('pid');
- return params;
- },
- columns: [
- [
- {field: 'title', title: __('Title'), align: "left"},
- {field: 'exam_class_id', title: __('Exam_class_id'),searchable:false},
- {field: 'description', title: __('Description'), searchable:false, formatter:Table.api.formatter.content, width: '200'},
- {field: 'impression', title: __('Impression'), searchable:false, formatter:Table.api.formatter.content, width: '200'},
- {field: 'createdAt', title: __('Createdat'), operate: 'RANGE', addclass: 'datetimerange'},
- {
- field: 'operate',
- 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 pid = $('#selected_parent').data('pid');
- let url = table2_extend.add_url;
- url = Table.api.replaceurl(url, {ids: pid}, table2);
- Fast.api.open(url, __('Add'), $(this).data() || {});
- });
- return table2;
- },
- },
- api: {
- formatter: {
- name: function (value) {
- return "<strong>" + value + "</strong>";
- }
- },
- events: {
- table1_operate: {
- 'click .btn-editone': function (e, value, row, index) {
- e.stopPropagation();
- e.preventDefault();
- let table = $(this).closest('table');
- let options = table.bootstrapTable('getOptions');
- let ids = row[options.pk];
- row = $.extend({}, row ? row : {}, {ids: ids});
- let url = table1_extend.edit_url;
- Fast.api.open(Table.api.replaceurl(url, row, table), __('Edit'), $(this).data() || {});
- },
- 'click .btn-delone': function (e, value, row, index) {
- e.stopPropagation();
- e.preventDefault();
- let that = this;
- $(that).data('url',table1_extend.del_url);
- let top = $(that).offset().top - $(window).scrollTop();
- let left = $(that).offset().left - $(window).scrollLeft() - 260;
- if (top + 154 > $(window).height()) {
- top = top - 154;
- }
- if ($(window).width() < 480) {
- top = left = undefined;
- }
- Layer.confirm(
- __('Are you sure you want to delete this item?'),
- {icon: 3, title: __('Warning'), offset: [top, left], shadeClose: true},
- function (index) {
- let table = $(that).closest('table');
- let options = table.bootstrapTable('getOptions');
- Table.api.multi("del", row[options.pk], table, that);
- Layer.close(index);
- }
- );
- }
- }
- }
- },
- };
- return Controller;
- });
|