You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
4.5 KiB
113 lines
4.5 KiB
define(["jquery", "easy-admin", "tableSelect"], function ($, ea) {
|
|
|
|
let tableSelect = layui.tableSelect;
|
|
|
|
let init = {
|
|
table_elem: '#currentTable',
|
|
table_render_id: 'currentTableRenderId',
|
|
index_url: 'liveroom.task/index',
|
|
add_url: 'liveroom.task/add',
|
|
edit_url: 'liveroom.task/edit',
|
|
delete_url: 'liveroom.task/delete',
|
|
user_list_url: 'user.api/getUserPageList',
|
|
live_room_list_url: 'user.api/getLiveRoomPageList',
|
|
};
|
|
|
|
let TaskController = {
|
|
|
|
index: function () {
|
|
let status_json = $("#status_json").val();
|
|
let status_select = JSON.parse(status_json);
|
|
|
|
ea.table.render({
|
|
init: init,
|
|
toolbar: [
|
|
'refresh',
|
|
'add',
|
|
'delete'
|
|
],
|
|
cols: [[
|
|
{type: "checkbox"},
|
|
{field: 'id', width: 80, title: '编号'},
|
|
{field: 'uuid', minWidth: 80, title: '任务编号'},
|
|
{field: 'title', minWidth: 80, title: '任务名称'},
|
|
{field: 'live_room_id', width: 100, title: '直播间ID'},
|
|
{field: 'integral', width: 80, title: '积分'},
|
|
{field: 'deduction_ratio', width: 110, title: '扣减比例', templet: function (d) {
|
|
return d.deduction_ratio + '%';
|
|
}},
|
|
{field: 'duration', width: 80, title: '时长', templet: function (d) {
|
|
return d.duration + 'h';
|
|
}},
|
|
{field: 'add_uid', width: 110, title: '创建用户'},
|
|
{field: 'assign_uid', width: 110, title: '指派用户'},
|
|
{field: 'status', title: '状态', width: 100, search: 'select', selectList: status_select, templet: function (d) {
|
|
let html_arr = ['disabled', 'primary', '', 'normal', 'warm', 'danger'];
|
|
return '<button type="button" class="layui-btn layui-btn-'+html_arr[d.status]+' layui-btn-xs">' + d.status_str + '</button>';
|
|
}},
|
|
{field: 'create_time', minWidth: 80, title: '创建时间', search: 'range'},
|
|
{
|
|
width: 250,
|
|
title: '操作',
|
|
templet: ea.table.tool,
|
|
operat: [
|
|
'edit',
|
|
'delete'
|
|
]
|
|
}
|
|
]],
|
|
});
|
|
|
|
ea.listen();
|
|
},
|
|
add: function () {
|
|
getSelect();
|
|
ea.listen();
|
|
},
|
|
edit: function () {
|
|
getSelect();
|
|
ea.listen();
|
|
}
|
|
};
|
|
|
|
function getSelect() {
|
|
getLiveRoomSelect();
|
|
getUserSelect();
|
|
getUserSelect('assign_uname', 'assign_uid');
|
|
}
|
|
|
|
function getLiveRoomSelect() {
|
|
let cos = [{ type: 'radio' }, { field: 'id', title: 'ID' }, { field: 'room_id', title: '直播间编号' }]
|
|
getTableSelect('room_id', 'live_room_id', init.live_room_list_url, cos, 'id', 'room_id');
|
|
}
|
|
|
|
function getUserSelect(elemKey = 'add_uname', valueKey = 'add_uid') {
|
|
let cos = [{ type: 'radio' }, { field: 'uid', title: 'ID' }, { field: 'nick_name', title: '用户名' }]
|
|
getTableSelect(elemKey, valueKey, init.user_list_url, cos, 'uid', 'nick_name');
|
|
}
|
|
|
|
function getTableSelect(elemKey, valueKey, url, cols = [], checkedKey = 'id', dataKey = 'id') {
|
|
tableSelect.render({
|
|
elem: '#' + elemKey, //定义输入框input对象
|
|
checkedKey: checkedKey, //表格的唯一建值,非常重要,影响到选中状态 必填
|
|
searchKey: 'keyword', //搜索输入框的name值 默认keyword
|
|
searchPlaceholder: '关键词搜索', //搜索输入框的提示文字 默认关键词搜索
|
|
table: { //定义表格参数,与LAYUI的TABLE模块一致,只是无需再定义表格elem
|
|
url: ea.url(url),
|
|
cols: [cols]
|
|
},
|
|
done: function (elem, data) {
|
|
let elemArr = []
|
|
let valueArr = []
|
|
layui.each(data.data, function (index, item) {
|
|
valueArr.push(item[checkedKey])
|
|
elemArr.push(item[dataKey])
|
|
})
|
|
$("#"+valueKey).val(valueArr.join(','))
|
|
$("#"+elemKey).val(elemArr.join(','))
|
|
}
|
|
})
|
|
}
|
|
|
|
return TaskController;
|
|
});
|
|
|