define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
Date.prototype.Format = function (fmt) { // author: meizz
var o = {
"M+": this.getMonth() + 1, // 月份
"d+": this.getDate(), // 日
"h+": this.getHours(), // 小时
"m+": this.getMinutes(), // 分
"s+": this.getSeconds(), // 秒
"q+": Math.floor((this.getMonth() + 3) / 3), // 季度
"S": this.getMilliseconds() // 毫秒
};
if (/(y+)/.test(fmt))
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
//选择平台的js
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'platform/index',
add_url: 'platform/add',
edit_url: 'platform/edit',
// del_url: 'platform/del',
multi_url: 'platform/multi',
table: 'platform',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'name', title: __('Name')},
{field: 'authhost', title: __('Authhost')},
{field: 'status', title: __('Status'), visible:false, searchList: {"0":__('Status 0'),"1":__('Status 1')}},
{field: 'status_text', title: __('Status'), operate:false, operate:false},
{field: 'isdefault', title: __('Isdefault'), visible:false, searchList: {"0":__('Isdefault 0'),"1":__('Isdefault 1')}},
{field: 'isdefault_text', title: __('Isdefault'), operate:false, operate:false},
{field: 'appid', title: __('Appid')},
{field: 'secret', title: __('Secret'), operate:false},
{field: 'token', title: __('Token'), operate:false},
{field: 'aes_key', title: __('Aes_key'), operate:false},
{field: 'platfile', title: __('Platfile'), operate:false},
{field: 'p_desc', title: __('描述'), operate:false},
{field: 'proxy_config', title: __('代理IP'), visible:true, operate: 'LIKE %...%'},
{field: 'job_proxy_config', title: __('Job推送代理IP'), visible:true, operate: 'LIKE %...%'},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime, operate:false},
{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime, operate:false},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.isdefault();
Controller.api.bindevent();
},
edit: function () {
Controller.api.isdefault();
Controller.api.bindevent();
},
// switchmenuhost:function(){
// //选择业务域名&菜单业务域名
// var op_list = [
// {host_key:"c-menuophost_id",pay_key:"c-menuwxpay_id"},
// {host_key:"c-new_menuophost_id",pay_key:"c-new_menuwxpay_id"}
// ];
// $.each(op_list,function(index,data){
// $('#'+data.host_key).change(function () {
// var ophost_id = $(this).val();
// var platform_id =$("#"+data.host_key+" option[value='"+ophost_id+"']").data('platform_id');
// if(ophost_id && ophost_id != undefined && platform_id && platform_id != undefined){
// Controller.api.addOphostPayList(platform_id,ophost_id,data.pay_key);
// }else{
// Controller.api.delWxpayList(data.pay_key);
// }
// });
// });
// Form.api.bindevent($("form[role=form]"),
// function (data,result) {
// Controller.api.showResultWindow(data);
// return false;
// },
// function (data,result) {
// layer.alert(result.msg);
// return false;
// }
// );
// },
// switchophost:function(){
// //选择业务域名&菜单业务域名
// var op_list = [
// {host_key:"c-ophost_id",pay_key:"c-wxpay_id"},
// {host_key:"c-new_ophost_id",pay_key:"c-new_wxpay_id"},
// ];
// $.each(op_list,function(index,data){
// $('#'+data.host_key).change(function () {
// var ophost_id = $(this).val();
// var platform_id =$("#"+data.host_key+" option[value='"+ophost_id+"']").data('platform_id');
// if(ophost_id && ophost_id != undefined && platform_id && platform_id != undefined){
// Controller.api.addOphostPayList(platform_id,ophost_id,data.pay_key);
// }else{
// Controller.api.delWxpayList(data.pay_key);
// }
// });
// });
// Form.api.bindevent($("form[role=form]"),
// function (data,result) {
// Controller.api.showResultWindow(data);
// return false;
// },
// function (data,result) {
// layer.alert(result.msg);
// return false;
// }
// );
// },
switchplatform:function(){
$("form[role=form]").validator({
valid: function(form) {
var is_post = true;
$('#c-create_by-id').isValid(function(v){
if (!v) {is_post = false;}
});
$('#c-nickname').isValid(function(v){
if (!v) {is_post = false;}
});
if(is_post){
var post_data = $(form).serializeArray();
var search_data = $('#search-form').serializeArray();
$.post(location.href,post_data.concat(search_data),function(result){
if(result.code){
Controller.api.showResultWindow(result.data);
}else{
layer.alert(result.msg);
}
})
}
}
});
},
api: {
//添加支付域名列表
addOphostPayList:function(platform_id,ophost_id,wxpayName){
$.get("auth/channel/ajaxgetwxpaylistbyplatformid?platform_id=" + platform_id+'&ophost_id='+ophost_id, function (data) {
if (data.code) {
Controller.api.delWxpayList(wxpayName);
var pay_list = data.data;
for (var key in pay_list) {
$('#'+wxpayName).append("
");
}
}else{
Toastr.error(data.msg);
}
});
},
showResultWindow:function(data){
var html = "
符合条件的总数为:"+data.total+"个
"; html += "没有授权的总数为:"+data.unauthorized+"个
"; html += "平台不符的总数为:"+data.platform+"个
"; html += "切换成功的总数为:"+data.success+"个
"; html += "切换失败的总数为:"+data.fail+"个
"; if(data.export == true){ layer.confirm(html, { btn: ['导出切换渠道','不导出切换渠道'] //按钮 }, function(){ window.location.href = "/admin/platform/export" layer.close(layer.index) }, function(){ }); }else{ layer.alert(html); } }, delWxpayList:function(wxpayName){ $("#"+wxpayName+" option").remove(); $("#"+wxpayName).append("