123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'comment', 'selectpage'], function ($, undefined, Backend, Table, Form, Comment, Selectpage) {
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- var status = GetQueryString('status');
- Table.api.init({
- extend: {
- index_url: 'protector/index' + '/status/' + status,
- add_url: 'protector/add',
- edit_url: 'protector/edit',
- del_url: 'protector/del',
- multi_url: 'protector/multi',
- table: 'protector',
- }
- });
- 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: __('Unit_name')},
- {field: 'contacts', title: __('Contacts')},
- {field: 'con_position', title: __('Con_position'),searchable: false},
- {field: 'unit_type', title: __('Unit_type'),searchable: false},
- {field: 'number', title: __('Number'),searchable: false},
- {field: 'depart_id', title: '操作人部门',searchList: $.getJSON('auth/group/departList'),formatter:function (value, row) {
- return row.usr_depart;
- }},
- {field: 'usr_nickname', title: '操作人'},
- {field: 'usr_depart', title: '操作人部门'},
- {field: 'pro_date', title: __('Pro_date'), operate:'RANGE', addclass:'datetimerange',searchable: false},
- {field: 'ex_date', title: __('Ex_date'),searchable: false, operate:'RANGE', addclass:'datetimerange'},
- {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();
- },
- 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({name: 'giveup', text: '放弃', classname: 'btn btn-xs btn-danger btn-giveup'});
- buttons.push({name: 'sign', text: '签单', classname: 'btn btn-xs btn-success btn-sign'});
- break;
- case 1:
- buttons.push({name: 'again', text: '再次保护', classname: 'btn btn-xs btn-success btn-again'});
- break;
- case 4:
- buttons.push({name: 'again', text:'再次保护', classname: 'btn btn-xs btn-success btn-again'});
- break;
- }
- buttons.push({name: 'follow', text:'跟进', classname: 'btn btn-xs btn-info btn-follow'});
- 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: 'protector/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-sign': function(e, value, row) {
- Layer.confirm('您确定签单吗?',function (index) {
- var id = row.id;
- $.ajax({
- url: 'protector/sign',
- 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-again': function(e, value, row) {
- Layer.confirm('您确定再次保护吗?',function (index) {
- var id = row.id;
- $.ajax({
- url: 'protector/again',
- 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) {
- var id = row.id;
- $.ajax({
- url: 'protector/showFollow',
- type: 'post',
- data: { id:id },
- dataType: 'json',
- success: function success(res) {
- Layer.open({
- area: ['600px','100%'],
- content:res.data,
- yes: function(index){
- addFollow(row.id,row.unit_name);
- layer.close(index); //如果设定了yes回调,需进行手工关闭
- }
- })
- }
- });
- }
- }
- }
- }
- };
- var addFollow;
- // 添加跟进记录
- addFollow = function (id,unit_name) {
- var time = $('#follow_time').val();
- var main = $('#main_text').val();
- $.ajax({
- url: 'protector/addFollow',
- type: 'post',
- data: { follow_time:time, main:main, id:id, unit_name:unit_name },
- dataType: 'json',
- success: function success(res) {
- if(res.code ==1){
- Toastr.success(res.msg);
- }
- }
- });
- }
- return Controller;
- });
|