| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'stock/customer/index',
- add_url: 'stock/customer/add',
- edit_url: 'stock/customer/edit',
- del_url: 'stock/customer/del',
- multi_url: 'stock/customer/multi',
- table: 'stock_customer',
- }
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'weigh',
- escape: false,
- columns: [
- [
- { checkbox: true },
- { field: 'id', title: __('Id'),width:50 },
- { field: 'encode', title: __('Encode'),align:'left' },
- { field: 'name', title: __('Name'),width:150,align:'left' },
- {
- field: 'id',
- title: '<a href="javascript:;" class="btn btn-success btn-xs btn-toggle"><i class="fa fa-chevron-up"></i></a>',
- operate: false,
- formatter: Controller.api.formatter.subnode
- },
- { field: 'shortname', title: __('Shortname') },
- { field: 'innerphone', title: __('Innerphone') },
- { field: 'weigh', title: __('Weigh') },
- { field: 'enabledmark', title: __('Enabledmark'), visible: false, searchList: { "1": __('Enabledmark 1'), "0": __('Enabledmark 0') } },
- { field: 'enabledmark_text', title: __('Enabledmark'), operate: false },
- { field: 'remark', title: __('Remark') },
- { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate }
- ]
- ],
- pagination: false,
- search: false,
- commonSearch: false,
- });
- //当内容渲染完成后
- table.on('post-body.bs.table', function (e, settings, json, xhr) {
- //默认隐藏所有子节点
- // $("a.btn[data-id][data-pid][data-pid!=0]").closest("tr").hide();
- // $(".btn-node-sub.disabled").closest("tr").hide();
- //显示隐藏子节点
- $(".btn-node-sub").off("click").on("click", function (e) {
- var status = $(this).data("shown") ? true : false;
- $("a.btn[data-pid='" + $(this).data("id") + "']").each(function () {
- $(this).closest("tr").toggle(!status);
- });
- $(this).data("shown", !status);
- return false;
- });
- $(".btn-change[data-id],.btn-delone,.btn-dragsort").data("success", function (data, ret) {
- Fast.api.refreshmenu();
- });
- });
- //批量删除后的回调
- $(".toolbar > .btn-del,.toolbar .btn-more~ul>li>a").data("success", function (e) {
- Fast.api.refreshmenu();
- });
- //展开隐藏一级
- $(document.body).on("click", ".btn-toggle", function (e) {
- $("a.btn[data-id][data-pid][data-pid!=0].disabled").closest("tr").hide();
- var that = this;
- var show = $("i", that).hasClass("fa-chevron-down");
- $("i", that).toggleClass("fa-chevron-down", !show);
- $("i", that).toggleClass("fa-chevron-up", show);
- $("a.btn[data-id][data-pid][data-pid!=0]").not('.disabled').closest("tr").toggle(show);
- $(".btn-node-sub[data-pid=0]").data("shown", show);
- });
- //展开隐藏全部
- $(document.body).on("click", ".btn-toggle-all", function (e) {
- var that = this;
- var show = $("i", that).hasClass("fa-plus");
- $("i", that).toggleClass("fa-plus", !show);
- $("i", that).toggleClass("fa-minus", show);
- $(".btn-node-sub.disabled").closest("tr").toggle(show);
- $(".btn-node-sub").data("shown", show);
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- add: function () {
- Controller.api.bindevent();
- },
- edit: function () {
- Controller.api.bindevent();
- },
- api: {
- formatter: {
- subnode: function (value, row, index) {
- return '<a href="javascript:;" data-toggle="tooltip" title="' + __('Toggle sub menu') + '" data-id="' + row.id + '" data-pid="' + row.pid + '" class="btn btn-xs '
- + (row.haschild == 1 || row.ismenu == 1 ? 'btn-success' : 'btn-default disabled') + ' btn-node-sub"><i class="fa fa-sitemap"></i></a>';
- }
- },
- bindevent: function () {
- //ajax请求根据父级客户产生客户代码
- function madeEncode() {
- $.ajax({
- url: 'stock/customer/madeencode',
- type: 'POST', //GET
- async: true, //或false,是否异步
- timeout: 5000, //超时时间
- dataType: 'json', //返回的数据格式:json/xml/html/script/jsonp/text
- data: { id: $('#c-pid option:selected').val() },
- success: function (data) {
- $('#c-encode').val(data);
- }
- });
- }
- $('#c-pid').change(madeEncode);
-
- Form.api.bindevent($("form[role=form]"));
- }
- }
- };
- return Controller;
- });
|