|
- /**
- * Created by admin on 2017/1/10.
- */
-
- var send_type = '', res_id = '', org_id = '', list;
- $(document).ready(function () {
- //司机和车辆可以拖动
- $('#bus_driver_list').on('dragstart', 'tr', handleDragStart);
- $('#bus_driver_list').on('dragenter', 'tr', handleDragEnter);
- $('#bus_driver_list').on('dragend', 'tr', handleDragEnd);
-
- //拖动的行可以在列表扔下
- $('#order_list-ajax').on('drop', 'tr', handleDragSend);
- $('#order_list-ajax').on('dragover', 'tr', handleDragOver);
- $('#order_list-ajax').on('dragleave', 'tr', handleDragLeave);
-
- $('#order_list-ajax').on('pjax:success', function () {
- // $('.date-picker').datepicker({
- // format: "yyyy-mm-dd",
- // language: "zh-CN",
- // autoclose: true
- // });
-
- tabelInit();
- });
- $("#order_list-ajax").on('click', "tbody tr", function () {
- chooseDate($(this).find('td:nth-child(4)').text());
- });
- tabelInit();
- $('#order_list-ajax').on('pjax:complete', function(){selectItems()});
- })
-
- function tabelInit() {
- $('.grid-view table tbody tr').click(function (event) {
- if (event.target.type !== 'checkbox') {
- var flag = false;
- if ($(this).hasClass('info')) {
- flag = true;
- }
- $('.grid-view table tr').removeClass('info');
- if (!flag) {
- $(this).addClass('info')
- }
- }
- });
- }
-
- function handleDragStart(e) {
- this.style.opacity = '0.4'; // this / e.target is the source node.
- send_type = $(e.currentTarget).attr('send_type');
- res_id = $(e.currentTarget).find('.res_id').val();
- org_id = $(e.currentTarget).find('.org_id').val();
- }
-
- function handleDragOver(e) {
- if (e.preventDefault) {
- e.preventDefault(); // Necessary. Allows us to drop.
- }
-
- e.currentTarget.style.border = "2px dashed red";
-
- // e.dataTransfer.dropEffect = 'move'; // See the section on the DataTransfer object.
-
- return false;
- }
-
- function handleDragEnter(e) {
- // this / e.target is the current hover target.
- this.classList.add('over');
- }
-
- function handleDragLeave(e) {
- e.currentTarget.style.border = "inherit";
- this.classList.remove('over'); // this / e.target is previous target element.
- }
- function handleDragEnd(e) {
- // this/e.target is the source node.
-
- this.style.opacity = '1';
- // [].forEach.call(cols, function (col) {
- // col.classList.remove('over');
- // });
- }
-
- // 调度确认弹框
- function handleDragSend(e) {
- if (res_id == '') {
- z.showTip('info', '没有获取到车ID,请联系研发解决');
- }
- $.ajax({
- type: 'POST',
- url: '/motorcade/bus/send-outside?res_id=' + res_id,
- data: {
- _csrf: yii.getCsrfToken()
- },
- success: function (data) {
- var res = JSON.parse(data);
- if (res['code'] == 1) { //外部车辆提示
- parent.bootbox.dialog({
- title: '车辆调度',
- className:'modal_over',
- message: '<h4>外部车辆,请输入外部用车车价</h4>\n<p><input type="text" class="form-control " id="outside_value" placeholder="车价" /> </p>',
- buttons: {
- cancel: {
- label: "取消",
- className: 'btn-default',
- },
- sure: {
- label: "确定",
- className: 'btn btn-primary',
- callback: function () {
- if (parent.$("#outside_value").val() == '') {
- z.showTip('info', '请输入外部用车车价');
- handleDragSend(e);
- } else {
- sendBus(e, parent.$("#outside_value").val());
- }
- }
- }
- }
- })
- }else if(res['code'] == 3) //维保时间 + 外部车辆 提示
- {
- parent.bootbox.dialog({
- title: '车辆调度',
- className:'modal_over',
- message: '<h4>该车辆已到维保时间,是否确认调度</h4>',
- buttons: {
- cancel: {
- label: "取消",
- className: 'btn-default',
- },
- sure: {
- label: "确定",
- className: 'btn btn-primary',
- callback: function () { // 回调 确认调度后确认外部车辆是否派车提示
- parent.bootbox.dialog({
- title: '车辆调度',
- className:'modal_over',
- message: '<h4>外部车辆,请输入外部用车车价</h4>\n<p><input type="text" class="form-control " id="outside_value" placeholder="车价" /> </p>',
- buttons: {
- cancel: {
- label: "取消",
- className: 'btn-default',
- },
- sure: {
- label: "确定",
- className: 'btn btn-primary',
- callback: function () {
- if (parent.$("#outside_value").val() == '') {
- z.showTip('info', '请输入外部用车车价');
- handleDragSend(e);
- } else {
- sendBus(e, parent.$("#outside_value").val());
- }
- }
- }
- }
- })
- }
- }
- }
- });
- }else if(res['code'] == 2) // 维保时间提示
- {
- parent.bootbox.dialog({
- title: '车辆调度',
- className:'modal_over',
- message: '<h4>该车辆已到维保时间,是否确认调度</h4>',
- buttons: {
- cancel: {
- label: "取消",
- className: 'btn-default',
- },
- sure: {
- label: "确定",
- className: 'btn btn-primary',
- callback: function () {
- sendBus(e, parent.$("#outside_value").val());
- }
- }
- }
- });
- } else { // 没有提示直接调派
- sendBus(e);
- }
- }
- });
-
- e.currentTarget.style.border = "inherit";
- }
-
- //调派车辆
- function sendBus(e, outside_value) {
- var id = $(e.currentTarget).find('input[type="checkbox"]').val();
- $.ajax({
- type: 'POST',
- url: '/motorcade/bus/send?type=' + send_type + '&id=' + id + '&res_id=' + res_id,
- dataType: 'json',
- data: {
- _csrf: yii.getCsrfToken(),
- outside_value: outside_value
- },
- success: function (data) {
- if (data.code == 0) {
- //更新列表中的数据
- $.pjax.reload({container: "#order_list-ajax", timeout: false});
- Command: parent.toastr["success"]("调派成功");
- } else {
- if (Array.isArray(data.data)) {
- $.each(data.data, function (key, item) {
- var firstKey = Object.keys(item)[0];
- Command: parent.toastr["warning"](item[firstKey]);
- })
- } else {
- var firstKey = Object.keys(data.data)[0];
- Command: parent.toastr["warning"](data.data[firstKey]);
-
- }
- }
- },
- error: function (data) {
- }
- });
- }
-
- //确认调度
- function sendSure(id) {
-
- var dialog = parent.bootbox.dialog({
- title: '确认调度',
- message: '<p>确定要将出车任务进行调度确认吗?</p>',
- className:'modal_over',
- buttons: {
- cancel: {
- label: "取消",
- className: 'btn-default',
- },
- sure: {
- label: "确定",
- className: 'btn btn-primary',
- callback: function () {
- $.ajax({
- type: 'POST',
- url: '/motorcade/bus/sure?id=' + id + '&attribute=send_status',
- dataType: 'json',
- data: {
- _csrf: yii.getCsrfToken()
- },
- success: function (data) {
- if (data.code == 0) {
- //更新列表中的数据
- $.pjax.reload({container: "#order_list-ajax", timeout: false});
- Command: parent.toastr["success"]("确认调度成功");
- } else {
- if (Array.isArray(data.data)) {
- $.each(data.data, function (key, item) {
- var firstKey = Object.keys(item)[0];
- Command: parent.toastr["warning"](item[firstKey]);
- })
- } else {
- var firstKey = Object.keys(data.data)[0];
- Command: parent.toastr["warning"](data.data[firstKey]);
-
- }
- }
- },
- error: function (data) {
- }
- });
- }
- }
- }
- })
- }
-
- //驳回调度
- function sendReject(id) {
- var dialog = parent.bootbox.dialog({
- title: '调度驳回',
- message: '<h4>请输入驳回原因</h4>\n<p><input type="text" class="form-control " id="reject_msg" placeholder="请输入驳回原因" /> </p>',
- className:'modal_over',
- buttons: {
- cancel: {
- label: "取消",
- className: 'btn-default',
- },
- sure: {
- label: "确定",
- className: 'btn btn-primary',
- callback: function () {
- //必须输入驳回原因
- if (parent.$("#reject_msg").val() == '') {
- parent.bootbox.alert("请输入驳回原因", function () {
- sendReject(id);
- });
- } else {
- $.ajax({
- type: 'POST',
- url: '/motorcade/bus/reject?id=' + id + '&msg=' + parent.$("#reject_msg").val() + '&attribute=send_status',
- dataType: 'json',
- data: {
- _csrf: yii.getCsrfToken()
- },
- success: function (data) {
- if (data.code == 0) {
- Command: parent.toastr["success"]("驳回成功");
- } else {
- if (Array.isArray(data.data)) {
- $.each(data.data, function (key, item) {
- var firstKey = Object.keys(item)[0];
- Command: parent.toastr["warning"](item[firstKey]);
- })
- } else {
- var firstKey = Object.keys(data.data)[0];
- Command: parent.toastr["warning"](data.data[firstKey]);
-
- }
- }
- //更新列表中的数据
- $.pjax.reload({container: "#order_list-ajax", timeout: false});
- },
- error: function (data) {
- }
- });
- }
- }
- }
- }
- })
- }
-
- //重置调度状态
- function sendReset(id) {
- var dialog = parent.bootbox.dialog({
- title: '重置调度',
- message: '<p>确定要对已经调度的出车任务进行调度重置吗?</p>',
- className:'modal_over',
- buttons: {
- cancel: {
- label: "取消",
- className: 'btn-default',
- },
- sure: {
- label: "确定",
- className: 'btn btn-primary',
- callback: function () {
- $.ajax({
- type: 'POST',
- url: '/motorcade/bus/reset?id=' + id,
- dataType: 'json',
- data: {
- _csrf: yii.getCsrfToken()
- },
- success: function (data) {
- if (data.code == 0) {
- //更新列表中的数据
- $.pjax.reload({container: "#order_list-ajax", timeout: false});
- Command: parent.toastr["success"]("调度重置成功,请重新安排车辆和司机");
- } else {
- if (Array.isArray(data.data)) {
- $.each(data.data, function (key, item) {
- var firstKey = Object.keys(item)[0];
- Command: parent.toastr["warning"](item[firstKey]);
- })
- } else {
- var firstKey = Object.keys(data.data)[0];
- Command: parent.toastr["warning"](data.data[firstKey]);
-
- }
- }
- },
- error: function (data) {
- }
- });
- }
- }
- }
- })
- }
- /**
- * 根据输入的关键字检索车辆信息
- */
- function selectBus() {
- searchDriverBus();
- }
-
- /**
- * 根据输入的关键字检索司机信息
- */
- function selectDriver() {
- searchDriverBus();
- }
-
- //搜索车辆、司机
- function searchDriverBus() {
- var key_driver = $("#key_driver").val();
- var key_bus = $("#key_bus").val();
- var key = $("#select_company").val();
- var key1 = $("#select_company1").val();
- var li = $("#driver_bus_ul li.active");
- var date = $("#searchDate").val();
-
- var params = {
- key_driver: key_driver,
- key_bus: key_bus,
- key: key,
- key1: key1,
- active: $(li).attr('data-active'),
- date: date
- }
- $.pjax.reload({container: "#bus_driver_list", data: params, timeout: false, replace: false});
- }
-
- //根据调度状态进行搜索
- function searchStatus(status) {
- $("#search-send_status").val(status);
- loading();
- $("#search-form").submit();
- }
-
- //点击checkbox,根据选中日期,获取司机和车辆当日使用次数
- function chooseDate(date) {
- $("#searchDate").val(date.substr(0, 10));
- searchDriverBus();
- }
-
- //批量操作,确认 驳回 重置
- function batch(type) {
- var url = '/motorcade/bus/batch';
- var keys = $("#order-list-grid-view").yiiGridView("getSelectedRows").length;
- if (keys > 0) {
- list = [];
- $.each($("#order-list-grid-view tbody input:checked"), function (k, e) {
- list.push($(e).attr('bus_order_id'));
- });
-
- $.ajax({
- type: 'POST',
- url: url,
- dataType: 'json',
- data: {
- _csrf: yii.getCsrfToken(),
- list: list,
- type: type
- },
- success: function (msg) {
- // msg = JSON.parse(msg)
- // if (msg.status == 0) {
- // } else if (msg.status == 1) {
- //
- // } else {
- //
- // }
- if (msg.status == 1) {
- z.showTip('error', msg.fail);
- }
- z.showTip(msg.type, msg.msg);
- if (msg.status != 2){
- $.pjax.reload({container: "#order_list-ajax", timeout: false});
- }
-
-
- },
- error: function (msg) {
-
- }
- });
- } else {
- z.showTip('info', '请选择出车任务')
- }
- }
-
- //选择已经选择的行
- function selectItems() {
- $.each(list, function (k, e) {
- $("#order-list-grid-view").find('input:checkbox[bus_order_id="' + e + '"]').prop('checked', true);
- })
- list = [];
- }
|