選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

480 行
17 KiB

  1. /**
  2. * Created by admin on 2017/1/10.
  3. */
  4. var send_type = '', res_id = '', org_id = '', list;
  5. $(document).ready(function () {
  6. //司机和车辆可以拖动
  7. $('#bus_driver_list').on('dragstart', 'tr', handleDragStart);
  8. $('#bus_driver_list').on('dragenter', 'tr', handleDragEnter);
  9. $('#bus_driver_list').on('dragend', 'tr', handleDragEnd);
  10. //拖动的行可以在列表扔下
  11. $('#order_list-ajax').on('drop', 'tr', handleDragSend);
  12. $('#order_list-ajax').on('dragover', 'tr', handleDragOver);
  13. $('#order_list-ajax').on('dragleave', 'tr', handleDragLeave);
  14. $('#order_list-ajax').on('pjax:success', function () {
  15. // $('.date-picker').datepicker({
  16. // format: "yyyy-mm-dd",
  17. // language: "zh-CN",
  18. // autoclose: true
  19. // });
  20. tabelInit();
  21. });
  22. $("#order_list-ajax").on('click', "tbody tr", function () {
  23. chooseDate($(this).find('td:nth-child(4)').text());
  24. });
  25. tabelInit();
  26. $('#order_list-ajax').on('pjax:complete', function(){selectItems()});
  27. })
  28. function tabelInit() {
  29. $('.grid-view table tbody tr').click(function (event) {
  30. if (event.target.type !== 'checkbox') {
  31. var flag = false;
  32. if ($(this).hasClass('info')) {
  33. flag = true;
  34. }
  35. $('.grid-view table tr').removeClass('info');
  36. if (!flag) {
  37. $(this).addClass('info')
  38. }
  39. }
  40. });
  41. }
  42. function handleDragStart(e) {
  43. this.style.opacity = '0.4'; // this / e.target is the source node.
  44. send_type = $(e.currentTarget).attr('send_type');
  45. res_id = $(e.currentTarget).find('.res_id').val();
  46. org_id = $(e.currentTarget).find('.org_id').val();
  47. }
  48. function handleDragOver(e) {
  49. if (e.preventDefault) {
  50. e.preventDefault(); // Necessary. Allows us to drop.
  51. }
  52. e.currentTarget.style.border = "2px dashed red";
  53. // e.dataTransfer.dropEffect = 'move'; // See the section on the DataTransfer object.
  54. return false;
  55. }
  56. function handleDragEnter(e) {
  57. // this / e.target is the current hover target.
  58. this.classList.add('over');
  59. }
  60. function handleDragLeave(e) {
  61. e.currentTarget.style.border = "inherit";
  62. this.classList.remove('over'); // this / e.target is previous target element.
  63. }
  64. function handleDragEnd(e) {
  65. // this/e.target is the source node.
  66. this.style.opacity = '1';
  67. // [].forEach.call(cols, function (col) {
  68. // col.classList.remove('over');
  69. // });
  70. }
  71. // 调度确认弹框
  72. function handleDragSend(e) {
  73. if (res_id == '') {
  74. z.showTip('info', '没有获取到车ID,请联系研发解决');
  75. }
  76. $.ajax({
  77. type: 'POST',
  78. url: '/motorcade/bus/send-outside?res_id=' + res_id,
  79. data: {
  80. _csrf: yii.getCsrfToken()
  81. },
  82. success: function (data) {
  83. var res = JSON.parse(data);
  84. if (res['code'] == 1) { //外部车辆提示
  85. parent.bootbox.dialog({
  86. title: '车辆调度',
  87. className:'modal_over',
  88. message: '<h4>外部车辆,请输入外部用车车价</h4>\n<p><input type="text" class="form-control " id="outside_value" placeholder="车价" /> </p>',
  89. buttons: {
  90. cancel: {
  91. label: "取消",
  92. className: 'btn-default',
  93. },
  94. sure: {
  95. label: "确定",
  96. className: 'btn btn-primary',
  97. callback: function () {
  98. if (parent.$("#outside_value").val() == '') {
  99. z.showTip('info', '请输入外部用车车价');
  100. handleDragSend(e);
  101. } else {
  102. sendBus(e, parent.$("#outside_value").val());
  103. }
  104. }
  105. }
  106. }
  107. })
  108. }else if(res['code'] == 3) //维保时间 + 外部车辆 提示
  109. {
  110. parent.bootbox.dialog({
  111. title: '车辆调度',
  112. className:'modal_over',
  113. message: '<h4>该车辆已到维保时间,是否确认调度</h4>',
  114. buttons: {
  115. cancel: {
  116. label: "取消",
  117. className: 'btn-default',
  118. },
  119. sure: {
  120. label: "确定",
  121. className: 'btn btn-primary',
  122. callback: function () { // 回调 确认调度后确认外部车辆是否派车提示
  123. parent.bootbox.dialog({
  124. title: '车辆调度',
  125. className:'modal_over',
  126. message: '<h4>外部车辆,请输入外部用车车价</h4>\n<p><input type="text" class="form-control " id="outside_value" placeholder="车价" /> </p>',
  127. buttons: {
  128. cancel: {
  129. label: "取消",
  130. className: 'btn-default',
  131. },
  132. sure: {
  133. label: "确定",
  134. className: 'btn btn-primary',
  135. callback: function () {
  136. if (parent.$("#outside_value").val() == '') {
  137. z.showTip('info', '请输入外部用车车价');
  138. handleDragSend(e);
  139. } else {
  140. sendBus(e, parent.$("#outside_value").val());
  141. }
  142. }
  143. }
  144. }
  145. })
  146. }
  147. }
  148. }
  149. });
  150. }else if(res['code'] == 2) // 维保时间提示
  151. {
  152. parent.bootbox.dialog({
  153. title: '车辆调度',
  154. className:'modal_over',
  155. message: '<h4>该车辆已到维保时间,是否确认调度</h4>',
  156. buttons: {
  157. cancel: {
  158. label: "取消",
  159. className: 'btn-default',
  160. },
  161. sure: {
  162. label: "确定",
  163. className: 'btn btn-primary',
  164. callback: function () {
  165. sendBus(e, parent.$("#outside_value").val());
  166. }
  167. }
  168. }
  169. });
  170. } else { // 没有提示直接调派
  171. sendBus(e);
  172. }
  173. }
  174. });
  175. e.currentTarget.style.border = "inherit";
  176. }
  177. //调派车辆
  178. function sendBus(e, outside_value) {
  179. var id = $(e.currentTarget).find('input[type="checkbox"]').val();
  180. $.ajax({
  181. type: 'POST',
  182. url: '/motorcade/bus/send?type=' + send_type + '&id=' + id + '&res_id=' + res_id,
  183. dataType: 'json',
  184. data: {
  185. _csrf: yii.getCsrfToken(),
  186. outside_value: outside_value
  187. },
  188. success: function (data) {
  189. if (data.code == 0) {
  190. //更新列表中的数据
  191. $.pjax.reload({container: "#order_list-ajax", timeout: false});
  192. Command: parent.toastr["success"]("调派成功");
  193. } else {
  194. if (Array.isArray(data.data)) {
  195. $.each(data.data, function (key, item) {
  196. var firstKey = Object.keys(item)[0];
  197. Command: parent.toastr["warning"](item[firstKey]);
  198. })
  199. } else {
  200. var firstKey = Object.keys(data.data)[0];
  201. Command: parent.toastr["warning"](data.data[firstKey]);
  202. }
  203. }
  204. },
  205. error: function (data) {
  206. }
  207. });
  208. }
  209. //确认调度
  210. function sendSure(id) {
  211. var dialog = parent.bootbox.dialog({
  212. title: '确认调度',
  213. message: '<p>确定要将出车任务进行调度确认吗?</p>',
  214. className:'modal_over',
  215. buttons: {
  216. cancel: {
  217. label: "取消",
  218. className: 'btn-default',
  219. },
  220. sure: {
  221. label: "确定",
  222. className: 'btn btn-primary',
  223. callback: function () {
  224. $.ajax({
  225. type: 'POST',
  226. url: '/motorcade/bus/sure?id=' + id + '&attribute=send_status',
  227. dataType: 'json',
  228. data: {
  229. _csrf: yii.getCsrfToken()
  230. },
  231. success: function (data) {
  232. if (data.code == 0) {
  233. //更新列表中的数据
  234. $.pjax.reload({container: "#order_list-ajax", timeout: false});
  235. Command: parent.toastr["success"]("确认调度成功");
  236. } else {
  237. if (Array.isArray(data.data)) {
  238. $.each(data.data, function (key, item) {
  239. var firstKey = Object.keys(item)[0];
  240. Command: parent.toastr["warning"](item[firstKey]);
  241. })
  242. } else {
  243. var firstKey = Object.keys(data.data)[0];
  244. Command: parent.toastr["warning"](data.data[firstKey]);
  245. }
  246. }
  247. },
  248. error: function (data) {
  249. }
  250. });
  251. }
  252. }
  253. }
  254. })
  255. }
  256. //驳回调度
  257. function sendReject(id) {
  258. var dialog = parent.bootbox.dialog({
  259. title: '调度驳回',
  260. message: '<h4>请输入驳回原因</h4>\n<p><input type="text" class="form-control " id="reject_msg" placeholder="请输入驳回原因" /> </p>',
  261. className:'modal_over',
  262. buttons: {
  263. cancel: {
  264. label: "取消",
  265. className: 'btn-default',
  266. },
  267. sure: {
  268. label: "确定",
  269. className: 'btn btn-primary',
  270. callback: function () {
  271. //必须输入驳回原因
  272. if (parent.$("#reject_msg").val() == '') {
  273. parent.bootbox.alert("请输入驳回原因", function () {
  274. sendReject(id);
  275. });
  276. } else {
  277. $.ajax({
  278. type: 'POST',
  279. url: '/motorcade/bus/reject?id=' + id + '&msg=' + parent.$("#reject_msg").val() + '&attribute=send_status',
  280. dataType: 'json',
  281. data: {
  282. _csrf: yii.getCsrfToken()
  283. },
  284. success: function (data) {
  285. if (data.code == 0) {
  286. Command: parent.toastr["success"]("驳回成功");
  287. } else {
  288. if (Array.isArray(data.data)) {
  289. $.each(data.data, function (key, item) {
  290. var firstKey = Object.keys(item)[0];
  291. Command: parent.toastr["warning"](item[firstKey]);
  292. })
  293. } else {
  294. var firstKey = Object.keys(data.data)[0];
  295. Command: parent.toastr["warning"](data.data[firstKey]);
  296. }
  297. }
  298. //更新列表中的数据
  299. $.pjax.reload({container: "#order_list-ajax", timeout: false});
  300. },
  301. error: function (data) {
  302. }
  303. });
  304. }
  305. }
  306. }
  307. }
  308. })
  309. }
  310. //重置调度状态
  311. function sendReset(id) {
  312. var dialog = parent.bootbox.dialog({
  313. title: '重置调度',
  314. message: '<p>确定要对已经调度的出车任务进行调度重置吗?</p>',
  315. className:'modal_over',
  316. buttons: {
  317. cancel: {
  318. label: "取消",
  319. className: 'btn-default',
  320. },
  321. sure: {
  322. label: "确定",
  323. className: 'btn btn-primary',
  324. callback: function () {
  325. $.ajax({
  326. type: 'POST',
  327. url: '/motorcade/bus/reset?id=' + id,
  328. dataType: 'json',
  329. data: {
  330. _csrf: yii.getCsrfToken()
  331. },
  332. success: function (data) {
  333. if (data.code == 0) {
  334. //更新列表中的数据
  335. $.pjax.reload({container: "#order_list-ajax", timeout: false});
  336. Command: parent.toastr["success"]("调度重置成功,请重新安排车辆和司机");
  337. } else {
  338. if (Array.isArray(data.data)) {
  339. $.each(data.data, function (key, item) {
  340. var firstKey = Object.keys(item)[0];
  341. Command: parent.toastr["warning"](item[firstKey]);
  342. })
  343. } else {
  344. var firstKey = Object.keys(data.data)[0];
  345. Command: parent.toastr["warning"](data.data[firstKey]);
  346. }
  347. }
  348. },
  349. error: function (data) {
  350. }
  351. });
  352. }
  353. }
  354. }
  355. })
  356. }
  357. /**
  358. * 根据输入的关键字检索车辆信息
  359. */
  360. function selectBus() {
  361. searchDriverBus();
  362. }
  363. /**
  364. * 根据输入的关键字检索司机信息
  365. */
  366. function selectDriver() {
  367. searchDriverBus();
  368. }
  369. //搜索车辆、司机
  370. function searchDriverBus() {
  371. var key_driver = $("#key_driver").val();
  372. var key_bus = $("#key_bus").val();
  373. var key = $("#select_company").val();
  374. var key1 = $("#select_company1").val();
  375. var li = $("#driver_bus_ul li.active");
  376. var date = $("#searchDate").val();
  377. var params = {
  378. key_driver: key_driver,
  379. key_bus: key_bus,
  380. key: key,
  381. key1: key1,
  382. active: $(li).attr('data-active'),
  383. date: date
  384. }
  385. $.pjax.reload({container: "#bus_driver_list", data: params, timeout: false, replace: false});
  386. }
  387. //根据调度状态进行搜索
  388. function searchStatus(status) {
  389. $("#search-send_status").val(status);
  390. loading();
  391. $("#search-form").submit();
  392. }
  393. //点击checkbox,根据选中日期,获取司机和车辆当日使用次数
  394. function chooseDate(date) {
  395. $("#searchDate").val(date.substr(0, 10));
  396. searchDriverBus();
  397. }
  398. //批量操作,确认 驳回 重置
  399. function batch(type) {
  400. var url = '/motorcade/bus/batch';
  401. var keys = $("#order-list-grid-view").yiiGridView("getSelectedRows").length;
  402. if (keys > 0) {
  403. list = [];
  404. $.each($("#order-list-grid-view tbody input:checked"), function (k, e) {
  405. list.push($(e).attr('bus_order_id'));
  406. });
  407. $.ajax({
  408. type: 'POST',
  409. url: url,
  410. dataType: 'json',
  411. data: {
  412. _csrf: yii.getCsrfToken(),
  413. list: list,
  414. type: type
  415. },
  416. success: function (msg) {
  417. // msg = JSON.parse(msg)
  418. // if (msg.status == 0) {
  419. // } else if (msg.status == 1) {
  420. //
  421. // } else {
  422. //
  423. // }
  424. if (msg.status == 1) {
  425. z.showTip('error', msg.fail);
  426. }
  427. z.showTip(msg.type, msg.msg);
  428. if (msg.status != 2){
  429. $.pjax.reload({container: "#order_list-ajax", timeout: false});
  430. }
  431. },
  432. error: function (msg) {
  433. }
  434. });
  435. } else {
  436. z.showTip('info', '请选择出车任务')
  437. }
  438. }
  439. //选择已经选择的行
  440. function selectItems() {
  441. $.each(list, function (k, e) {
  442. $("#order-list-grid-view").find('input:checkbox[bus_order_id="' + e + '"]').prop('checked', true);
  443. })
  444. list = [];
  445. }