/**
|
* 走航任务管理
|
*
|
*/
|
function TaskManage(options) {
|
this.easyTable = new EasyTable();
|
|
this.tableId = 'task_table';
|
this.btnNewTask = 'btn_task_create';
|
this.btnImport = 'btn_import';
|
|
this.head = ['序号', '任务编号', '开始时间', '结束时间', '管理'];
|
|
this.data = [
|
[1, 'SH-JS-20210102', '2021-01-02 00:00:00', '2021-01-02 23:59:59', '删除'],
|
[2, 'SH-JS-20210303', '2021-03-03 00:00:00', '2021-03-03 23:59:59', '删除'],
|
[3, 'SH-JS-20210326', '2021-03-26 00:00:00', '2021-03-26 23:59:59', '删除'],
|
[4, 'SH-JS-20210409', '2021-04-09 00:00:00', '2021-04-09 23:59:59', '删除'],
|
[5, 'SH-JS-20210421', '2021-04-21 00:00:00', '2021-04-21 23:59:59', '删除'],
|
[
|
6,
|
'BOAT-JS-20210313',
|
'2021-03-13 00:00:00',
|
'2021-03-13 23:59:59',
|
'删除',
|
],
|
];
|
|
if (options != undefined) {
|
this.tableId = options.tableId;
|
this.btnNewTask = options.btnNewTask;
|
this.btnImport = options.btnImport;
|
}
|
}
|
|
TaskManage.prototype = {
|
init: function () {
|
var that = this;
|
this.getTask();
|
|
DPicker.timePicker('task_starttime_text', function (startTime, endTime) {
|
$('#task_starttime_text').text(startTime);
|
$('#task_endtime_text').text(endTime);
|
});
|
DPicker.timePicker('task_endtime_text', function (startTime, endTime) {
|
$('#task_starttime_text').text(startTime);
|
$('#task_endtime_text').text(endTime);
|
});
|
|
$('#btn_task_delete').on('click', () => {
|
if (that.missionCode) {
|
HttpService.deleteMissionAndData(
|
that.missionCode,
|
function (result) {
|
refreshMission()
|
$('#btn_task_delete_close').click()
|
that.easyTable.deleteRow(that.index);
|
},
|
function (error) {
|
alert('任务删除失败');
|
}
|
);
|
}
|
});
|
},
|
getTask: function () {
|
var that = this;
|
HttpService.getMission(undefined, 1, 30, function (result) {
|
that.data = result;
|
var tableData = [];
|
for (let i = 0; i < result.length; i++) {
|
const d = result[i];
|
var sTime = moment(d.startTime).format('YYYY-MM-DD HH:mm:ss');
|
var eTime = moment(d.endTime).format('YYYY-MM-DD HH:mm:ss');
|
tableData.push([i + 1, d.missionCode, sTime, eTime, '删除']);
|
}
|
that.easyTable.createTable(
|
that.tableId,
|
that.head,
|
tableData,
|
function (item) {
|
that.deleteTask(item[1], item[0] - 1);
|
}
|
);
|
});
|
},
|
createTask: function (task) {
|
var mission = {
|
missionCode: task.taskcode,
|
deviceType: task.devicetype,
|
deviceCode: task.deviceCode,
|
startTime: new Date(task.starttime),
|
endTime: new Date(task.endtime),
|
};
|
HttpService.createMission(
|
mission,
|
function (result) {
|
var index = this.data.length + 1;
|
var d = [index, task.taskcode, task.starttime, task.endtime, '删除'];
|
this.data.push(d);
|
this.easyTable.onNewData([d], true);
|
document.getElementById('btn_task_create_close').click();
|
}.bind(this),
|
function (fail) {
|
alert(fail);
|
}
|
);
|
},
|
deleteTask: function (missionCode, index) {
|
this.missionCode = missionCode;
|
this.index = index;
|
Nav.newPage({
|
close: 'btn_task_delete_close',
|
page: 'dialog_check',
|
});
|
},
|
importData: function (code, type, file, onSuccess) {
|
var that = this;
|
console.log('文件导入--类型:' + type + '--路径:' + file);
|
|
var icon = $('#file_import_loading');
|
var start = '<i class="fa fa-file-excel-o fa-5x" aria-hidden="true"></i>';
|
var loading =
|
'<i class="fa fa-spinner fa-spin fa-5x" aria-hidden="true"></i>';
|
var success =
|
'<i class="fa fa-check-circle-o fa-5x" aria-hidden="true"></i>';
|
var fail =
|
'<i class="fa fa-exclamation-circle" aria-hidden="true" style="color:red;"></i>';
|
|
icon.empty();
|
icon.append(loading);
|
|
HttpService.importJinAnData(
|
code,
|
file,
|
function (data) {
|
icon.empty();
|
icon.append(success);
|
setTimeout(() => {
|
icon.empty();
|
icon.append(start);
|
that.getTask();
|
document.getElementById('btn_task_import_close').click();
|
onSuccess();
|
}, 1000);
|
},
|
function (error) {
|
icon.empty();
|
icon.append(fail);
|
alert(error);
|
setTimeout(() => {
|
icon.empty();
|
icon.append(start);
|
}, 1000);
|
}
|
);
|
},
|
downloadTemplate() {
|
HttpService.downloadJinAnTemplate();
|
},
|
};
|