297 lines
14 KiB
JavaScript
297 lines
14 KiB
JavaScript
define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'],
|
|
function ($, undefined, Backend, Table, Form) {
|
|
$.jstree.core.prototype.get_all_checked = function (full) {
|
|
var obj = this.get_selected(), i, j;
|
|
for (i = 0, j = obj.length; i < j; i++) {
|
|
obj = obj.concat(this.get_node(obj[i]).parents);
|
|
}
|
|
obj = $.grep(obj, function (v, i, a) {
|
|
return v != '#';
|
|
});
|
|
obj = obj.filter(function (itm, i, a) {
|
|
return i == a.indexOf(itm);
|
|
});
|
|
return full ? $.map(obj, $.proxy(function (i) {
|
|
return this.get_node(i);
|
|
}, this)) : obj;
|
|
};
|
|
var Controller = {
|
|
index: function () {
|
|
// 初始化表格参数配置
|
|
Table.api.init({
|
|
extend: {
|
|
index_url: 'workers/worker/index' + location.search,
|
|
add_url: 'workers/worker/add',
|
|
edit_url: 'workers/worker/edit',
|
|
del_url: 'workers/worker/del',
|
|
multi_url: 'workers/worker/multi',
|
|
import_url: 'workers/worker/import',
|
|
table: 'worker',
|
|
}
|
|
});
|
|
|
|
var table = $("#table");
|
|
|
|
// 初始化表格
|
|
table.bootstrapTable({
|
|
url: $.fn.bootstrapTable.defaults.extend.index_url,
|
|
pk: 'id',
|
|
sortName: 'id',
|
|
fixedColumns: true,
|
|
fixedRightNumber: 1,
|
|
columns: [
|
|
[
|
|
{checkbox: true},
|
|
{field: 'id', title: __('Id')},
|
|
{field: 'admin.username', title: '创建人'},
|
|
{field: 'name', title: __('Name'), operate: 'LIKE'},
|
|
{
|
|
field: 'type', title: '师傅归属', searchList: {"1": '自营', "2": '非自营', '3': '新师傅'},
|
|
formatter: Table.api.formatter.status,
|
|
},
|
|
{field: 'tel', title: __('Tel'), operate: 'LIKE'},
|
|
{
|
|
field: 'status',
|
|
title: __('Status'),
|
|
searchList: {"1": __('Status 1'), "0": __('Status 0')},
|
|
formatter: Table.api.formatter.status
|
|
},
|
|
//{field: 'area_id', title: __('Area_id')},
|
|
//{field: 'lng', title: __('Lng'), operate:'BETWEEN'},
|
|
//{field: 'lat', title: __('Lat'), operate:'BETWEEN'},
|
|
{field: 'area.short_merge_name', title: __('Area.short_merge_name'), searchable: false},
|
|
{field: 'rate', title: '分成'},
|
|
{field: 'rate_remark', title: '分成备注'},
|
|
{field: 'remark', title: '备注'},
|
|
{field: 'deposit_amount', title: __('Deposit_amount'), operate: 'BETWEEN'},
|
|
{field: 'star', title: __('Star'), operate: 'BETWEEN'},
|
|
{
|
|
field: 'images',
|
|
title: __('Images'),
|
|
operate: false,
|
|
events: Table.api.events.image,
|
|
formatter: Table.api.formatter.images
|
|
},
|
|
{
|
|
field: 'create_time',
|
|
title: __('Create_time'),
|
|
operate: 'RANGE',
|
|
addclass: 'datetimerange',
|
|
autocomplete: false
|
|
},
|
|
{
|
|
field: 'update_time',
|
|
title: __('Update_time'),
|
|
operate: 'RANGE',
|
|
addclass: 'datetimerange',
|
|
autocomplete: false
|
|
},
|
|
{
|
|
field: 'operate', title: __('Operate'),
|
|
buttons: [
|
|
{
|
|
name: 'edit',
|
|
text: "修改",
|
|
icon: 'fa fa-pencil',
|
|
title: __('Edit'),
|
|
extend: 'data-toggle="tooltip" data-container="body"',
|
|
classname: 'btn btn-xs btn-info btn-editone',
|
|
},
|
|
{
|
|
name: 'del',
|
|
text: "删除",
|
|
icon: 'fa fa-trash',
|
|
title: __('Delete'),
|
|
extend: 'data-toggle="tooltip"',
|
|
classname: 'btn btn-xs btn-danger btn-delone',
|
|
},
|
|
],
|
|
table: table, events: Table.api.events.operate,
|
|
formatter: Table.api.formatter.operate
|
|
}
|
|
]
|
|
]
|
|
});
|
|
$("#c-city-search").on("cp:updated", function () {
|
|
var citypicker = $(this).data("citypicker");
|
|
var code = citypicker.getCode("district") || citypicker.getCode("city") || citypicker.getCode("province");
|
|
// table.bootstrapTable('refresh',{query: {area_code: code}});
|
|
$('#area_id').val(code);
|
|
});
|
|
$("#search_btn").on("click", function () {
|
|
table.bootstrapTable('refresh', {
|
|
url: $.fn.bootstrapTable.defaults.extend.index_url + '&' + getQueryData(),
|
|
});
|
|
});
|
|
|
|
function getQueryData() {
|
|
return $('#select-form').serialize();
|
|
}
|
|
|
|
|
|
$("#reset_btn").on("click", function () {
|
|
$("#c-city-search").citypicker('reset');
|
|
$("#area_id").val('');
|
|
$("#citem").val('').selectpicker('refresh');
|
|
$("#keyword").val('');
|
|
table.bootstrapTable('refresh', {
|
|
url: $.fn.bootstrapTable.defaults.extend.index_url + '?' + getQueryData(),
|
|
});
|
|
});
|
|
Form.events.citypicker($("#select-form"));
|
|
|
|
// 批量修改状态事件
|
|
$(document).on("click", ".btn-change-status-off", function () {
|
|
var ids = Table.api.selectedids(table);
|
|
if (ids.length === 0) {
|
|
Toastr.error("请选择至少一条记录");
|
|
return;
|
|
}
|
|
layer.confirm('是否全部冻结', function () {
|
|
Fast.api.ajax({
|
|
url: 'workers/worker/status',
|
|
type: "POST",
|
|
contentType: 'application/json',
|
|
data: JSON.stringify({
|
|
ids,
|
|
status: 0
|
|
}),
|
|
success:function (){
|
|
layer.closeAll();
|
|
Toastr.info('操作成功');
|
|
table.bootstrapTable("refresh");
|
|
}
|
|
});
|
|
});
|
|
}); // 批量修改状态事件
|
|
$(document).on("click", ".btn-change-status-on", function () {
|
|
var ids = Table.api.selectedids(table);
|
|
if (ids.length === 0) {
|
|
Toastr.error("请选择至少一条记录");
|
|
return;
|
|
}
|
|
layer.confirm('是否全部激活', function () {
|
|
$.ajax({
|
|
url: 'workers/worker/status',
|
|
type: "POST",
|
|
contentType: 'application/json',
|
|
data: JSON.stringify({
|
|
ids,
|
|
status: 1
|
|
}),
|
|
success:function (){
|
|
layer.closeAll();
|
|
Toastr.info('操作成功');
|
|
table.bootstrapTable("refresh");
|
|
}
|
|
});
|
|
});
|
|
});
|
|
$(document).on("click", ".btn-change-type", function () {
|
|
var ids = Table.api.selectedids(table);
|
|
if (ids.length === 0) {
|
|
Toastr.error("请选择至少一条记录");
|
|
return;
|
|
}
|
|
layer.confirm('批量修改类型', function () {
|
|
$.ajax({
|
|
url: 'workers/worker/status',
|
|
type: "POST",
|
|
contentType: 'application/json',
|
|
data: JSON.stringify({
|
|
ids,
|
|
status: 1
|
|
}),
|
|
success:function (){
|
|
layer.closeAll();
|
|
Toastr.info('操作成功');
|
|
table.bootstrapTable("refresh");
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
|
|
// 为表格绑定事件
|
|
Table.api.bindevent(table);
|
|
Form.events.citypicker($("form"));
|
|
},
|
|
add: function () {
|
|
$("#c-city").on("cp:updated", function () {
|
|
var citypicker = $(this).data("citypicker");
|
|
var code = citypicker.getCode("district") || citypicker.getCode("city") || citypicker.getCode("province");
|
|
$("#area_id").val(code);
|
|
});
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
const type = urlParams.get('type');
|
|
if (type) {
|
|
const select = document.getElementById('worker_type');
|
|
if (select) {
|
|
select.value = type;
|
|
}
|
|
}
|
|
Controller.api.bindevent();
|
|
},
|
|
edit: function () {
|
|
$("#c-city").on("cp:updated", function () {
|
|
var citypicker = $(this).data("citypicker");
|
|
var code = citypicker.getCode("district") || citypicker.getCode("city") || citypicker.getCode("province");
|
|
$("#area_id").val(code);
|
|
});
|
|
Controller.api.bindevent();
|
|
},
|
|
api: {
|
|
bindevent: function () {
|
|
Form.api.bindevent($("form[role=form]"), null, null, function () {
|
|
if ($("#treeview").length > 0) {
|
|
var r = $("#treeview").jstree("get_all_checked");
|
|
$("input[name='row[rules]']").val(r.join(','));
|
|
}
|
|
return true;
|
|
});
|
|
//渲染权限节点树
|
|
//销毁已有的节点树
|
|
$("#treeview").jstree("destroy");
|
|
Controller.api.rendertree(nodeData);
|
|
//全选和展开
|
|
$(document).on("click", "#checkall", function () {
|
|
$("#treeview").jstree($(this).prop("checked") ? "check_all" : "uncheck_all");
|
|
});
|
|
$(document).on("click", "#expandall", function () {
|
|
$("#treeview").jstree($(this).prop("checked") ? "open_all" : "close_all");
|
|
});
|
|
$("select[name='row[pid]']").trigger("change");
|
|
},
|
|
rendertree: function (content) {
|
|
$("#treeview")
|
|
.on('redraw.jstree', function (e) {
|
|
$(".layer-footer").attr("domrefresh", Math.random());
|
|
})
|
|
.jstree({
|
|
"themes": {"stripes": true},
|
|
"checkbox": {
|
|
"keep_selected_style": false,
|
|
},
|
|
"types": {
|
|
"root": {
|
|
"icon": "fa fa-folder-open",
|
|
},
|
|
"menu": {
|
|
"icon": "fa fa-folder-open",
|
|
},
|
|
"file": {
|
|
"icon": "fa fa-file-o",
|
|
}
|
|
},
|
|
"plugins": ["checkbox", "types"],
|
|
"core": {
|
|
'check_callback': true,
|
|
"data": content
|
|
}
|
|
});
|
|
}
|
|
}
|
|
};
|
|
return Controller;
|
|
});
|