define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: async function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'mobile/index' + location.search,
add_url: 'mobile/add',
edit_url: 'mobile/edit',
del_url: 'mobile/del',
multi_url: 'mobile/multi',
import_url: 'mobile/import',
batch: 'mobile/batch',
table: 'mobile',
cancel_discount: 'mobile/cancelsetdiscount',
set_discount: 'mobile/setdiscount',
}
});
var table = $("#table");
let status = await $.getJSON('mobile/status')
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
search: false,
searchFormVisible: true,
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'no', title: __('手机号'), operate: "LIKE"},
{field: 'province', title: __('Province')},
{field: 'city', title: __('归属地')},
{field: 'network', title: __('运营商'), formatter: Table.api.formatter.label},
{field: 'proxy.nickname', title: __('代理商'), formatter: Table.api.formatter.label},
{field: 'brand', title: __('卡品牌'), formatter: Table.api.formatter.label},
{
field: 'rules', title: __('规律'), searchList: Object.keys(filters), formatter(a) {
return a.join('
')
}
},
{
field: 'info.describe',
title: __('套餐信息'),
operate: "like",
formatter: Table.api.formatter.content,
width: 300
},
{field: 'amount_original', title: __('Amount_original'), operate: 'BETWEEN'},
{field: 'amount_di', title: __('底价'), operate: 'BETWEEN'},
{field: 'amount_base', title: __('Amount'), operate: 'BETWEEN'},
{field: 'amount_charge', title: __('预存话费'), operate: 'BETWEEN'},
{field: 'remark', title: __('备注'), operate: 'like'},
{
field: 'top_time',
title: __('Top_time'),
operate: 'RANGE',
addclass: 'datetimerange',
autocomplete: false,
formatter(a, b, c) {
return `
`
}
},
{
field: 'rec_time',
title: __('Rec_time'),
operate: 'RANGE',
addclass: 'datetimerange',
autocomplete: false,
formatter(a, b, c) {
return `
`
}
},
//{field: 'is_hold', title: __('预占'),formatter: Table.api.formatter.toggle,searchList:{0:'否',1:'是'}},
{
field: 'buttons',
width: "120px",
title: __('操作'),
table: table,
events: Table.api.events.operate,
operate: false,
formatter: Table.api.formatter.buttons,
buttons: [
{
name: 'detail',
text: __('预占'),
title: __('预占'),
classname: 'btn btn-xs btn-info btn-dialog',
url: 'mobile/takeit',
callback: function (data) {
},
visible: function (row) {
return true;
}
},
{
name: 'detail',
text: __('记录'),
title: __('记录'),
classname: 'btn btn-xs btn-info btn-dialog',
url: 'mobile_price_log/index?a=1',
callback: function (data) {
},
visible: function (row) {
return true;
}
},
]
},
{field: 'status', title: __('状态'), formatter: Table.api.formatter.label, searchList: status},
{
field: 'update_time',
title: __('Update_time'),
operate: 'RANGE',
addclass: 'datetimerange',
autocomplete: false,
formatter: Table.api.formatter.datetime
},
{
field: 'create_time',
title: __('上架时间'),
operate: 'RANGE',
addclass: 'datetimerange',
autocomplete: false,
formatter: Table.api.formatter.datetime
},
{field: 'sort', title: __('Sort'), operate: "BETWEEN"},
{field: 'hold_chan', title: __('预占通道'), operate: "="},
{field: 'hold_user', title: __('预占用户ID'), operate: "="},
{field: 'admin_id', title: __('上传用户'), operate: "="},
/*{field: 'name', title: __('Name')},
{field: 'type', title: __('Type'),formatter: Table.api.formatter.label,searchList:no_type},
{field: 'amount_exists', title: __('Amount_exists'), operate:'BETWEEN'},
{field: 'amount_base', title: __('Amount_base'), operate:'BETWEEN'},
{field: 'summary', title: __('Summary')},
{field: 'saled', title: __('Saled'),formatter: Table.api.formatter.label,searchList:{0:'否',1:'是'}},
{field: 'is_activity', title: __('Is_activity'),formatter: Table.api.formatter.label,searchList:{0:'否',1:'是'}},
{field: 'activity_time_end', title: __('Activity_time_end'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
{field: 'sort', title: __('Sort'),operate: "BETWEEN"},*/
{
field: 'operate',
title: __('Operate'),
table: table,
events: Table.api.events.operate,
formatter: Table.api.formatter.operate,
buttons: [
{
name: 'detail',
text: __('取消预占'),
title: __('取消预占'),
classname: 'btn btn-xs btn-info btn-ajax',
url: 'mobile/cancel_hold',
callback: function (data) {
},
visible: function (row) {
return row.is_hold === 1;
}
},
{
name: 'detail',
text: __('记录'),
title: __('记录'),
classname: 'btn btn-xs btn-info btn-dialog',
url: 'mobile_price_log/index?a=1',
callback: function (data) {
},
visible: function (row) {
return true;
}
},
]
},
]
]
});
let setStatus = function (_this, field) {
let a = layer.load()
$.post('mobile/batch', {
id: _this.attr('data-id'),
status: _this.attr('data-value') ? 0 : 1,
field: field
}, function (res) {
if (res.code) {
_this.attr('data-value', res.data.status)
if (res.data.status) {
_this.find('i').removeClass('fa-flip-horizontal text-gray')
} else {
_this.find('i').addClass('fa-flip-horizontal text-gray')
}
} else {
layer.msg('操作失败')
}
layer.close(a)
})
}
$(document).on('click', '.btn-change-top', function () {
setStatus($(this), 'top_time')
})
$(document).on('click', '.btn-change-rec', function () {
setStatus($(this), 'rec_time')
})
$(document).on('click', '.btn-set-discount', function () {
let set = $(this).data('set')
let select = table.bootstrapTable('getSelections'),
a = []
if (!select.length) {
return
}
select.forEach(item => {
a.push(item.id)
})
if (!set) {
$.post($.fn.bootstrapTable.defaults.extend.cancel_discount, {ids: a}, function () {
layer.msg('操作成功')
$('.btn-refresh').trigger('click')
})
} else {
Fast.api.open($.fn.bootstrapTable.defaults.extend.set_discount + `/ids/${a.join(',')}`, '设置特价', {
close() {
$('.btn-refresh').trigger('click')
}
})
}
})
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
$('.kill-discount-radio').change(function (){
let amount=$('#c-amount_base').val(),
dis=this.value
let total=amount*dis
$('#c-amount_kill').val(total.toFixed(2))
})
$('.kill-discount').bind('input propertychange',function (){
let amount=$('#c-amount_base').val(),
dis=this.value
let total=amount*dis/10
$('#c-amount_kill').val(total.toFixed(2))
})
},
setdiscount(){
Controller.api.bindevent();
$(document).on('click','#activity_forever input',function (){
if(this.value==0){
$('input[name="row[activity_time_end]"]').attr('disabled',false)
}else{
$('input[name="row[activity_time_end]"]').attr('disabled',true)
}
})
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
},
takeit(){
Controller.api.bindevent();
$('.kill-discount-radio').change(function (){
let amount=$('#c-amount_base').val(),
dis=this.value
let total=amount*dis
$('#c-amount_kill').val(total.toFixed(2))
})
$('.kill-discount').bind('input propertychange',function (){
let amount=$('#c-amount_base').val(),
dis=this.value
let total=amount*dis/10
$('#c-amount_kill').val(total.toFixed(2))
})
}
};
return Controller;
});