| /** | 
|  * 管理初始化 | 
|  */ | 
| var TAgent = { | 
|     id: "TAgentTable",    //表格id | 
|     seItem: null,        //选中的条目 | 
|     table: null, | 
|     layerIndex: -1 | 
| }; | 
|   | 
| /** | 
|  * 初始化表格的列 | 
|  */ | 
| TAgent.initColumn = function () { | 
|     return [ | 
|         {field: 'selectItem', radio: true}, | 
|             {title: '主键', field: 'id', visible: true, align: 'center', valign: 'middle'}, | 
|         {title: '添加时间', field: 'createTime', visible: true, align: 'center', valign: 'middle'}, | 
|             {title: '姓名', field: 'principal', visible: true, align: 'center', valign: 'middle'}, | 
|             {title: '联系电话', field: 'principalPhone', visible: true, align: 'center', valign: 'middle'}, | 
|             {title: '代理区域', field: 'area', visible: true, align: 'center', valign: 'middle'}, | 
|             {title: '客服电话', field: 'serviceCalls', visible: true, align: 'center', valign: 'middle'}, | 
|             {title: '订单数量', field: 'orderSum', visible: true, align: 'center', valign: 'middle'}, | 
|             {title: '有效订单', field: 'validOrder', visible: true, align: 'center', valign: 'middle'}, | 
|             {title: '已发放优惠券', field: 'issuedCoupon', visible: true, align: 'center', valign: 'middle'}, | 
|             {title: '已使用优惠券', field: 'usedCoupon', visible: true, align: 'center', valign: 'middle'}, | 
|         {title: '累计优惠券金额', field: 'couponPriceSum', visible: true, align: 'center', valign: 'middle'}, | 
|         {title: '司机充值', field: 'driverRecharge', visible: true, align: 'center', valign: 'middle'}, | 
|         {title: '司机数', field: 'driverCount', visible: true, align: 'center', valign: 'middle'}, | 
|             {title: '状态', field: 'status', visible: true, align: 'center', valign: 'middle', | 
|                 formatter: function (value, row) { | 
|                     if (row.status === 1){ | 
|                         return '<span>正常</span>' | 
|                     }else if (row.status === 2){ | 
|                         return '<span>冻结</span>' | 
|                     }else if (row.status === 3){ | 
|                         return '<span>已删除</span>' | 
|                     } | 
|                 }}, | 
|         {title: '操作', visible: true, align: 'center', valign: 'middle',width:150, | 
|             formatter: function (value, row) { | 
|                 if (row.status === 1){ | 
|                     return '<a href="#" onclick="TAgent.updateStatus('+row.id+','+row.status+')" style="color:red">停用</a>' +' ' + | 
|                         '<a href="#" onclick="TAgent.searchTAgentDetail('+row.id+')" style="color:green">详情</a>' | 
|                 }else if (row.status === 2){ | 
|                     return '<a href="#" onclick="TAgent.updateStatus('+row.id+','+row.status+')" style="color:green">解冻</a>' +' ' + | 
|                         '<a href="#" onclick="TAgent.searchTAgentDetail('+row.id+')" style="color:green">详情</a>' | 
|                 } | 
|             } | 
|         } | 
|     ]; | 
| }; | 
|   | 
| /** | 
|  * 检查是否选中 | 
|  */ | 
| TAgent.check = function () { | 
|     var selected = $('#' + this.id).bootstrapTable('getSelections'); | 
|     if(selected.length == 0){ | 
|         Feng.info("请先选中表格中的某一记录!"); | 
|         return false; | 
|     }else{ | 
|         TAgent.seItem = selected[0]; | 
|         return true; | 
|     } | 
| }; | 
|   | 
| /** | 
|  * 点击添加 | 
|  */ | 
| TAgent.openAddTAgent = function () { | 
|     var index = layer.open({ | 
|         type: 2, | 
|         title: '添加', | 
|         area: ['100%', '100%'], //宽高 | 
|         fix: false, //不固定 | 
|         maxmin: true, | 
|         content: Feng.ctxPath + '/tAgent/tAgent_add' | 
|     }); | 
|     this.layerIndex = index; | 
| }; | 
|   | 
| /** | 
|  * 提交启用冻结 | 
|  */ | 
| TAgent.updateStatus = function (id,status) { | 
|     var ajax = new $ax(Feng.ctxPath + "/tAgent/update-status?id="+id+'&status='+status, function (data) { | 
|         Feng.success("修改成功!"); | 
|         TAgent.table.refresh(); | 
|     }, function (data) { | 
|         Feng.error("修改失败!" + data.responseJSON.message + "!"); | 
|     }); | 
|     // ajax.set("id",$("#id").val()); | 
|     // ajax.set("status",$("#status").val()); | 
|     ajax.start(); | 
| }; | 
|   | 
| /** | 
|  * 打开查看详情(使用中) | 
|  */ | 
| TAgent.searchTAgentDetail = function (id) { | 
|     var index = layer.open({ | 
|         type: 2, | 
|         title: '详情', | 
|         area: ['100%', '100%'], //宽高 | 
|         fix: false, //不固定 | 
|         maxmin: true, | 
|         content: Feng.ctxPath + '/tAgent/agentDetail?agentId=' + id | 
|     }); | 
|     this.layerIndex = index; | 
| }; | 
|   | 
| /** | 
|  * 打开查看详情 | 
|  */ | 
| TAgent.openTAgentDetail = function () { | 
|     if (this.check()) { | 
|         var index = layer.open({ | 
|             type: 2, | 
|             title: '详情', | 
|             area: ['800px', '420px'], //宽高 | 
|             fix: false, //不固定 | 
|             maxmin: true, | 
|             content: Feng.ctxPath + '/tAgent/tAgent_update/' + TAgent.seItem.id | 
|         }); | 
|         this.layerIndex = index; | 
|     } | 
| }; | 
|   | 
| /** | 
|  * 打开区域选择页面 | 
|  */ | 
| TAgent.area = function () { | 
|   | 
|     var area = $('#area').val(); | 
|     var areaId = $('#areaId').val(); | 
|   | 
|     var index = layer.open({ | 
|         type: 2, | 
|         title: '区域选择', | 
|         area: ['800px', '270px'], //宽高 | 
|         fix: false, //不固定 | 
|         maxmin: true, | 
|         content: Feng.ctxPath + '/tAgent/areaDetail?area='+area+"&areaId="+areaId | 
|     }); | 
|     this.layerIndex = index; | 
| } | 
|   | 
| /** | 
|  * 查询市区 | 
|  */ | 
| TAgent.areaProvince = function () { | 
|   | 
|     //监听第一个下拉菜单的变动操作 | 
|     $("#province").change(function(){ | 
|         //当第一级下拉列表没选择值时,将二级下拉列表和三级同时设置为空 | 
|         if(this.value==""){ | 
|             $("#city").empty();//二级联动设为空设为空 | 
|             $("#city").append('<option value="">请选择</option>'); | 
|         } | 
|         if(this.value!=""){//第一级下拉菜单选择了值 | 
|             $("#city").empty();//先行置空,防止上次选择留下的元素影响效果 | 
|             $("#city").append('<option value="">请选择</option>')//设置初始选项 | 
|             var province = document.getElementById('province'); | 
|             var index= province.selectedIndex ; | 
|             var id = province.options[index].id; | 
|             var ajax = new $ax(Feng.ctxPath + "/tAgent/areaCity?parentId="+id, function (data) { | 
|                 for(var i=0,n=data.length;i<n;i++){//遍历 | 
|                     $("#city").append('<option value="'+data[i].id+'">'+data[i].name+'</option>');//创造元素 | 
|                 } | 
|             }, function (data) { | 
|                 Feng.error("查询失败!" + data.responseJSON.message + "!"); | 
|             }); | 
|             ajax.start(); | 
|         } | 
|     }); | 
|   | 
|     /*var province = document.getElementById('province'); | 
|     var index= province.selectedIndex ; | 
|     var id = province.options[index].id; | 
|     var ajax = new $ax(Feng.ctxPath + "/tAgent/areaCity?parentId="+id, function (data) { | 
|         var opts=document.getElementById('city').options; | 
|         opts.length=0;// 这一句是清空原有列表项 | 
|         for(var i=0,n=data.length;i<n;i++){ | 
|             var data1=data[i]; | 
|             var opt=new Option(data1.name,data1.id,true,true); | 
|             opts.add(opt); | 
|         } | 
|     }, function (data) { | 
|         Feng.error("查询失败!" + data.responseJSON.message + "!"); | 
|     }); | 
|     ajax.start();*/ | 
| } | 
| /** | 
|  * 选择省市 | 
|  */ | 
| TAgent.submitArea = function () { | 
|     var province = document.getElementById('province'); | 
|     var provinceIndex= province.selectedIndex ; | 
|     var provinceName = province.options[provinceIndex].value; | 
|     var provinceId = province.options[provinceIndex].id; | 
|   | 
|     if(provinceName == null || provinceName == ''){ | 
|         Feng.error("请选择省份!") | 
|         return; | 
|     } | 
|   | 
|     var city = document.getElementById('city'); | 
|     var cityIndex= city.selectedIndex ; | 
|     var cityId = city.options[cityIndex].value; | 
|     var cityName = city.options[cityIndex].innerText; | 
|   | 
|     if(cityName == null || cityName == '' || cityName =='请选择'){ | 
|         Feng.error("请选择市区!") | 
|         return; | 
|     } | 
|   | 
|     parent.$("#area").val(provinceName+'/'+cityName) | 
|     parent.$("#areaId").val(provinceId+'/'+cityId) | 
|     TAgentInfoDlg.close(); | 
| } | 
|   | 
|   | 
| /** | 
|  * 删除 | 
|  */ | 
| TAgent.delete = function () { | 
|     if (this.check()) { | 
|         var ajax = new $ax(Feng.ctxPath + "/tAgent/delete", function (data) { | 
|             Feng.success("删除成功!"); | 
|             TAgent.table.refresh(); | 
|         }, function (data) { | 
|             Feng.error("删除失败!" + data.responseJSON.message + "!"); | 
|         }); | 
|         ajax.set("tAgentId",this.seItem.id); | 
|         ajax.start(); | 
|     } | 
| }; | 
|   | 
| /** | 
|  * 代理商信息导出 | 
|  */ | 
| TAgent.export=function(){ | 
|     var principal=$("#principal").val(); | 
|     var principalPhone = $("#principalPhone").val(); | 
|     var createTime = $("#createTime").val(); | 
|     var status = $("#status").val(); | 
|     window.location.href=Feng.ctxPath + "/tAgent/export?principal="+principal | 
|         +"&principalPhone="+principalPhone | 
|         +"&createTime="+createTime | 
|         +"&status="+status | 
|     ; | 
| } | 
|   | 
| /** | 
|  * 查询列表 | 
|  */ | 
| TAgent.search = function () { | 
|     var queryData = {}; | 
|     queryData['principal'] = $("#principal").val(); | 
|     queryData['principalPhone'] = $("#principalPhone").val(); | 
|     queryData['createTime'] = $("#createTime").val(); | 
|     queryData['status'] = $("#status").val(); | 
|     TAgent.table.refresh({query: queryData}); | 
| }; | 
|   | 
| /** | 
|  * 重置 | 
|  */ | 
| TAgent.resetSearch = function (){ | 
|     $("#principal").val(''); | 
|     $("#principalPhone").val(''); | 
|     $("#createTime").val(''); | 
|     $("#status").val(''); | 
|     TAgent.search(); | 
| } | 
|   | 
| $(function () { | 
|     var defaultColunms = TAgent.initColumn(); | 
|     var table = new BSTable(TAgent.id, "/tAgent/list", defaultColunms); | 
|     table.setPaginationType("client"); | 
|     TAgent.table = table.init(); | 
| }); |