riku
2024-02-04 b6ce6a9739d7114ee740981cbbeabbf1e7e10f28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/**
 * 走航任务管理
 *
 */
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();
  },
};