123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage', 'bootstrap-datetimepicker'], function ($, undefined, Backend, Table, Form, Selectpage, Datetimepicker) {
- 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',
- sign_url: 'protector/sign',
- follow_url: 'protector/follow',
- del_url: 'protector/del',
- sign_url: 'protector/sign',
- 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: '公司名称'},
- {field: 'unit_type', title:'单位性质',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: 'pro_date', title: __('Pro_date'), operate:'RANGE', addclass:'datetimerange'},
- {field: 'ex_date', title: __('Ex_date'),searchable: false, visible: status == 'contract' ? false : true, operate:'RANGE', addclass:'datetimerange'},
- {field: 'again_date', title: '签单到期时间',searchable: false, visible: status == 'contract' ? true : 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,
- });
- }
- });
- Controller.api.bindevent();
- },
- edit: 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();
- },
- follow: function () {
- Controller.api.bindevent();
- },
- sign: 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({name:'sign',text: '签单', classname: 'btn btn-xs btn-success btn-sign'});
- 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-success btn-again'});
- 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-success btn-again'});
- 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: '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) {
- e.stopPropagation();
- e.preventDefault();
- var options = $(this).closest('table').bootstrapTable('getOptions');
- var open = Fast.api.open(options.extend.sign_url + (options.extend.sign_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + row[options.pk], __('Sign'), {
- title: '签单',
- maxmin: false
- });
- },
- // 再次保护
- '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) {
- 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 = '<table class="table table-striped table-bordered table-hover">';
- html += '<tr><td>公司名称</td><td>'+ row.unit_name +'</td></tr>';
- html += '<tr><td>联系人</td><td>'+ row.contacts +'</td></tr>';
- html += '<tr><td>联系方式</td><td>'+ row.phone +'</td></tr>';
- html += '<tr><td>固定电话</td><td>'+ row.fixed_phone +'</td></tr>';
- html += '<tr><td>地址</td><td>'+ row.address +'</td></tr>';
- html += '<tr><td>联系人职位</td><td>'+ row.con_position +'</td></tr>';
- html += '<tr><td>单位性质</td><td>'+ row.unit_type +'</td></tr>';
- html += '<tr><td>人数</td><td>'+ row.number +'</td></tr>';
- html += '<tr><td>单价</td><td>'+ row.price +'</td></tr>';
- html += '<tr><td>备注</td><td>'+ row.remark +'</td></tr>';
- html += '<tr><td>总价</td><td>'+ row.total +'</td></tr>';
- html += '<tr><td>操作人</td><td>'+ row.usr_nickname +'</td></tr>';
- html += '<tr><td>操作人部门</td><td>'+ row.usr_depart +'</td></tr>';
- html += '</table>';
- 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);
- }
- );
- }
- }
- }
- }
- };
- // 添加跟进记录
- 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);
- }
- }
- });
- };
- // 检测保护单位名称
- $('.btn-TestingName').click(function () {
- var unit_name = $('#c-unit_name').val();
- if(unit_name != null){
- $.ajax({
- url: 'protector/TestingName',
- type: 'post',
- data: {unit_name:unit_name},
- dataType: 'json',
- success: function success(res) {
- if(res.code == 1){
- Toastr.success(res.msg);
- } else {
- Toastr.error(res.msg);
- }
- }
- });
- }
- });
- // 全系统搜索
- $('.btn-all-search').click(function () {
- var val = $('.input-all-search').val();
- $.ajax({
- url: 'protector/allSearch',
- type: 'post',
- data: { val:val },
- dataType: 'json',
- success: function success(res) {
- Layer.open({
- content:res,
- area:['800px'],
- title:val
- })
- }
- });
- });
- return Controller;
- });
- var addFollow;
|