define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], function ($, undefined, Backend, Table, Form, Selectpage) { var Controller = { index: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'intention/index', add_url: 'intention/add', edit_url: 'intention/edit', del_url: 'intention/del', follow_url: 'intention/follow', multi_url: 'intention/multi', table: 'intention', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'id', showToggle: false, showColumns: false, showExport: false, columns: [ [ {field: 'unit_name', title: '公司名称'}, {field: 'unit_type', title: __('Unit_type'), searchable: false}, {field: 'usr_nickname', title: '操作人'}, {field: 'depart_id', title: '操作人部门',searchable: false,searchList: $.getJSON('auth/group/departList'),formatter:function (value, row) { return row.usr_depart; }}, {field: 'created_at', title: '创建时间', operate:'RANGE', addclass:'datetimerange', searchable: false}, {field: 'operate', title: __('Operate'),searchable: false, table: table, events: Controller.api.events.operate, formatter: Controller.api.formatter.operate } ] ] }); // 为表格绑定事件 Table.api.bindevent(table); }, add: function () { $.ajax({ url: 'intention/unitTypeList', type: 'post', dataType: 'json', success: function success(res) { var data = res.rows; $('#c-unit_type').selectPage({ data : data, }); console.log(data); } }); Controller.api.bindevent(); }, edit: function () { Controller.api.bindevent(); }, follow: function () { Controller.api.bindevent(); }, api: { bindevent: function () { Form.api.bindevent($("form[role=form]")); }, formatter:{ operate: function (value, row, index) { var table = this.table; // 操作配置 var options = table ? table.bootstrapTable('getOptions') : {}; // 默认按钮组 var buttons = $.extend([], this.buttons || []); switch (row.status){ case 0: //保护中 buttons.push({text: '放弃', classname: 'btn btn-xs btn-danger btn-giveup'}); buttons.push({text:'跟进', classname: 'btn btn-xs btn-info btn-follow'}); buttons.push({text:'修改', classname: 'btn btn-xs btn-primary btn-editone'}); buttons.push({text:'详情', classname: 'btn btn-xs btn-warning btn-detail'}); buttons.push({ name: 'del', icon: 'fa fa-trash', title: __('Del'), extend: 'data-toggle="tooltip"', classname: 'btn btn-xs btn-danger btn-delone' }); break; case 1: buttons.push({text:'详情', classname: 'btn btn-xs btn-warning btn-detail'}); break; case 2: buttons.push({text:'修改', classname: 'btn btn-xs btn-primary btn-editone'}); buttons.push({text:'详情', classname: 'btn btn-xs btn-warning btn-detail'}); break; case 4: buttons.push({text:'详情', classname: 'btn btn-xs btn-warning btn-detail'}); break; } return Table.api.buttonlink(this, buttons, value, row, index, 'operate'); }, }, events:{ operate: { // 放弃 'click .btn-giveup': function(e, value, row) { Layer.confirm('您确定放弃吗?',function (index) { var id = row.id; $.ajax({ url: 'intention/giveup', type: 'post', data: { id:id }, dataType: 'json', success: function success(res) { Layer.close(index); if(res.code == 1){ Toastr.success(res.msg); $('.btn-refresh').click(); } else { Toastr.error(res.msg); } } }); }); }, // 跟进 'click .btn-follow': function (e, value, row) { e.stopPropagation(); e.preventDefault(); var options = $(this).closest('table').bootstrapTable('getOptions'); var open = Fast.api.open(options.extend.follow_url + (options.extend.follow_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + row[options.pk], __('Follow'), { title: '跟进', maxmin: false }); }, // 修改 'click .btn-editone': function clickBtnEditone(e, value, row, index) { e.stopPropagation(); e.preventDefault(); var options = $(this).closest('table').bootstrapTable('getOptions'); var open = Fast.api.open(options.extend.edit_url + (options.extend.edit_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + row[options.pk], __('Edit'), { title: '修改', maxmin: false }); }, 'click .btn-detail': function clickBtnEditone(e, value, row, index) { var html = ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += '
公司名称'+ row.unit_name +'
联系人'+ row.contacts +'
手机'+ row.phone +'
固定电话'+ row.fixed_phone +'
地址'+ row.address +'
联系人职位'+ row.con_position +'
单位性质'+ row.unit_type +'
人数'+ row.number +'
单价'+ row.price +'
备注'+ row.remark +'
操作人'+ row.usr_nickname +'
操作人部门'+ row.usr_depart +'
'; Layer.open({ content : html, area : ['500px'], }) }, 'click .btn-delone': function (e, value, row, index) { e.stopPropagation(); e.preventDefault(); var that = this; var top = $(that).offset().top - $(window).scrollTop(); var 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) { var table = $(that).closest('table'); var options = table.bootstrapTable('getOptions'); Table.api.multi("del", row[options.pk], table, that); Layer.close(index); } ); } } } } }; // 全系统搜索 $('.btn-all-search').click(function () { var val = $('.input-all-search').val(); $.ajax({ url: 'intention/allSearch', type: 'post', data: { val:val }, dataType: 'json', success: function success(res) { Layer.open({ content:res, area:['800px'], title:val }) } }); }); return Controller; });