//json/jsonHotelWaitConfirm.html
//订单备注-tr_str
var cur_order_id = 0;
var pay_end_time = '';
var ht_tr_com_one_str = ''; //订单备注tr的str
var ht_tr_mes_one_str = ''; //短信通知tr的str
//详情
var base_url = "./st-xm/Api/ht_get_order_detail.php";
//my--moyan
var my_base_url_ok = "./st-xm/Api/hotel_order_status.php";
var my_base_url_cancel="./st-xm/Api/hotel_order_cancel_changeback.php";
//页面加载的时候调用
window.onload = function() {
ht_tr_com_one_str = $('#ht_tr_com_one').prop('outerHTML');
ht_tr_com_one_str = ht_tr_com_one_str.replace('none', 'table-row');
ht_tr_mes_one_str = $('#ht_tr_mes_one').prop('outerHTML');
ht_tr_mes_one_str = ht_tr_mes_one_str.replace('none', 'table-row');
var order_id = getPar('order_id');
cur_order_id=order_id;
if (!order_id) {
alert('缺少订单号');
return;
}
//调用 函数
var url = base_url + '?method=getOrderDetail&order_id=' + order_id;
get_http_data_by_url(url);
}
// 请求方法,传入URL
function get_http_data_by_url(myURL) {
$.getJSON(myURL, function(httpData) {
if (httpData['code'] != "0") {
alert(httpData['info']);
return;
}
if (httpData['order_detail'].length <= 0) {
alert('没有符合条件的数据');
return;
}
//头部左侧
var order_detail = httpData['order_detail'][0];
var current_status = order_detail["order_status_id"];
var top_left_HTML = $('#chartLeftSpan').html();
top_left_HTML = top_left_HTML.replace('[订单号]', getPar('order_id'));
var st = order_detail['order_status_str'];
top_left_HTML = top_left_HTML.replace('[是否入住]', st);
top_left_HTML = top_left_HTML.replace('[分销商(上海驴妈妈)]', order_detail['org_name']);
top_left_HTML = top_left_HTML.replace('[酒店]', '酒店');
$('#chartLeftSpan').html(top_left_HTML);
//头部右侧
var or_st = httpData['order_status'];
var new_or_st = new Array();
if(or_st){
for (var i = 0; i < or_st.length; i++) {
var temp = or_st[i];
new_or_st[temp['order_status_id']] = temp;
}
}
if (new_or_st['145']) { //待支付
var arr_date_time = new_or_st['145']['status_date'].split(' ');
$('#one_date').html(arr_date_time[0]);
$('#one_time').html(arr_date_time[1]);
pay_end_time = order_detail['pay_end_time'];
if(!new_or_st['198']){
ShowCountDown();
timer = setInterval('ShowCountDown()', 1000);
}
//变成支付,,添加支付剩余时间
}
if (new_or_st['198']) { //待确认
var arr_date_time = new_or_st['198']['status_date'].split(' ');
$('#two_date').html(arr_date_time[0]);
$('#two_time').html(arr_date_time[1]);
$('#two_cir').css('border', '3px solid greenyellow');
$('#two_cir').css('border-radius', '15px;');
$('#pay_time').html('');
$('#downBtn1').html('确认');
$('#downBtn3').css('width','100px');
$('#downBtn3').html('退改申请');
$('#downBtn2').css('display', 'none');
$('#downBtn2').html('');
}
if (new_or_st['200']) { //待安排
var arr_date_time = new_or_st['200']['status_date'].split(' ');
$('#three_date').html(arr_date_time[0]);
$('#three_time').html(arr_date_time[1]);
$('#three_cir').css('border', '3px solid greenyellow');
$('#three_cir').css('border-radius', '15px;');
$('#downBtn1').css('width', '125px');
$('#downBtn1').html('录入确认号');
$('#downBtn2').css('display', 'none');
$('#downBtn2').html('');
$('#downBtn3').css('width', '100px');
$('#downBtn3').html('退改申请');
}
if (new_or_st['199']) { //待通知
var arr_date_time = new_or_st['199']['status_date'].split(' ');
$('#four_date').html(arr_date_time[0]);
$('#four_time').html(arr_date_time[1]);
$('#four_cir').css('border', '3px solid greenyellow');
$('#four_cir').css('border-radius', '15px;');
$('#downBtn1').css('width', '150px');
$('#downBtn1').html('人工确认通知');
$('#downBtn2').css('display', 'none');
$('#downBtn2').html('');
}
if (new_or_st['218']) { //已安排
var arr_date_time = new_or_st['218']['status_date'].split(' ');
$('#five_date').html(arr_date_time[0]);
$('#five_time').html(arr_date_time[1]);
$('#five_cir').css('border', '3px solid greenyellow');
$('#five_cir').css('border-radius', '15px;');
$('#downBtn1').css('display', 'none');
$('#downBtn1').html('');
$('#downBtn3').css('width', '100px');
$('#downBtn3').html('退改申请');
$('#downBtn2').css('display', 'none');
$('#downBtn2').html('');
}
if (new_or_st['201']) { //退改中
$('#pay_time').html('');
// $('#pay_time').css('display','none');
$('#six_cir').css('border', '3px solid darkgray');
$('#downBtn1').css('display', 'none');
$('#downBtn1').html('');
$('#downBtn2').css('display', 'none');
$('#downBtn2').html('');
$('#downBtn3').css('width', '100px');
$('#downBtn3').html('退单确认');
}
if (new_or_st['147']) { //已完成
if(!new_or_st['201']){
$('#pay_time').html('入住日期:' + order_detail['check_in_date']);
$('#downBtn3').css('width', '100px');
$('#downBtn3').html('退改申请');
$('#six_cir').css('border', '3px solid greenyellow');
$('#six_cir').css('border-radius', '15px;');
$('#downBtn2').css('display', 'none');
$('#downBtn2').html('');
}
}
if (new_or_st['238'] || current_status == 238 ) { //已退单
$('#downBtn1').css('display', 'none');
$('#downBtn1').html('');
$('#downBtn2').css('display', 'none');
$('#downBtn2').html('');
$('#downBtn3').css('display', 'none');
$('#downBtn3').html('');
}
if (new_or_st['148'] || current_status == 148 ){//已取消
$('#downBtn1').css('display','none');
$('#downBtn2').css('display','none');
$('#downBtn3').css('display','none');
$('#downBtn1').html('');
$('#downBtn2').html('');
$('#downBtn3').html('');
$('#pay_time').html('');
clearInterval(timer);
}
// 订单备注短信通知
$('#span_order_remark').html('订单备忘:' + order_detail['com_count'] + '条');
$('#span_info_noti').html('短信通知:' + order_detail['mes_count'] + '条');
// 1.预订信息
$('#hotel_room').html(order_detail['prod_name']);
var ruzhu = $('#ruzhu_date').html();
ruzhu = ruzhu.replace('[开始日期]', order_detail['start_date']);
ruzhu = ruzhu.replace('[结束日期]', order_detail['end_date']);
ruzhu = ruzhu.replace('[num]', order_detail['all_day']);
ruzhu = ruzhu.replace('[hour]', order_detail['latest_time']);
$('#ruzhu_date').html(ruzhu);
// 表格
var detail_date_arr = httpData['detail_date_arr'];
var tr_booking = $('#tr_booking_one').prop('outerHTML');
var bookingHTML = '';
for (var i = 0; i < detail_date_arr.length; i++) {
var tempDict = detail_date_arr[i];
var tempHTML = tr_booking;
tempHTML = tempHTML.replace('[入住日期]', tempDict['check_in_date']);
tempHTML = tempHTML.replace('[数量]', tempDict['count']);
tempHTML = tempHTML.replace('[采购价]', tempDict['base_price']);
tempHTML = tempHTML.replace('[结算价]', tempDict['mid_price']);
tempHTML = tempHTML.replace('[零售价]', tempDict['order_price']);
tempHTML = tempHTML.replace('[采购价金额]', tempDict['base_balance']);
tempHTML = tempHTML.replace('[结算价金额]', tempDict['mid_balance']);
tempHTML = tempHTML.replace('[销售利润]', tempDict['profits']);
bookingHTML += tempHTML;
}
//支付金额
$('#pay_money').html(order_detail['all_order_balance'] + " " + '元');
//订单退单
$('#order_return_pay_money1').html(order_detail['all_order_balance'] + " " + '元');
//
$('#order_return_pay_money2').html(order_detail['all_order_balance'] + " " + '元');
//总计
var tr_final = $('#tr_booking_final').prop('outerHTML');
tr_final = tr_final.replace('[总零售价]', order_detail['all_order_balance']);
tr_final = tr_final.replace('[采购价金额]', order_detail['all_base_balance']);
tr_final = tr_final.replace('[结算价金额]', order_detail['all_mid_balance']);
tr_final = tr_final.replace('[销售利润]', order_detail['all_profits']);
bookingHTML += tr_final
$('#booking_list').html(bookingHTML);
// 2.客人信息
$('#guest_name').html(order_detail['customer_name']);
$('#guest_phone').html(order_detail['customer_mobile']);
//显示整个页面
$('.hotelWaitConfirm').css('display', 'block');
//订单备注
get_order_comment(base_url + '?method=getOrderRemark&order_id=' + cur_order_id);
//短信通知
get_order_send_message(base_url + '?method=getOrderSendMessage&order_id=' + cur_order_id);
});
}
//请求订单备注
function get_order_comment(com_url) {
$.getJSON(com_url, function(res_data) {
var ht_comment_list = $('#ht_comment_list');
var order_remark_arr = res_data['order_remark_arr'];
if(order_remark_arr==undefined){return;}
var comHTML = '';
for (var i = 0; i < order_remark_arr.length; i++) {
var dict = order_remark_arr[i];
var HTML = ht_tr_com_one_str;
HTML = HTML.replace('[类型]', dict['comment_type_str']);
HTML = HTML.replace('[内容]', dict['comment_txt']);
HTML = HTML.replace('[添加人]', dict['user_name']);
HTML = HTML.replace('[添加时间]', dict['create_time']);
comHTML += HTML;
}
ht_comment_list.html(comHTML);
});
}
//请求订单-短信通知
function get_order_send_message(mes_url) {
$.getJSON(mes_url, function(res_data) {
var ht_send_message_list = $('#ht_send_message_list');
var order_send_message_arr = res_data['order_send_message_arr'];
if (order_send_message_arr==undefined) {return;}
var mesHTML = '';
for (var i = 0; i < order_send_message_arr.length; i++) {
var dict = order_send_message_arr[i];
var HTML = ht_tr_mes_one_str;
HTML = HTML.replace('[内容]', dict['send_mobile'] + ":" + dict['message']);
HTML = HTML.replace('[操作人]', dict['user_name']);
HTML = HTML.replace('[发送时间]', dict['send_time']);
mesHTML += HTML;
}
ht_send_message_list.html(mesHTML);
});
}
//点击右下角三个按钮
function click_OK(self_obj_id, btn_name) {
var self_obj = $(self_obj_id);
var ifStay = $('#ifStay');
switch (btn_name) {
case "确认":
// self_obj.css('display','none');
self_obj.html('');
var ok_url = my_base_url_ok + "?method=confirm&order_id=" + cur_order_id;
$.getJSON(ok_url, function(res_data) {
if (res_data['code'] != "0") {
alert(res_data['info']);
self_obj.css('display','table-row');
self_obj.html('确认');
return;
}
location.replace(location.href);
// var listURL = "hotelWaitConfirm.html?order_id=" + cur_order_id;
// // 跳转前将URL编码
// listURL = encodeURI(listURL);
// window.location.href = listURL;
});
break;
case "支付":
center_show($('.order_pay'));
$(document).ready(function() {
$('#btn_order_pay_submit').click(function() {
var pay_type = $("#select_order_pay").find("option:selected").val();
if (pay_type == undefined || pay_type == "") {
pay_type = "232";//天猫旗舰店支付
}
if ($('#pay_water_num').val().trim().length <= 0) {
alert('请输入流水号!!!');
return;
}
var wather_num = $('#pay_water_num').val();
var url = my_base_url_ok + "?method=pay&order_id=" + cur_order_id + "&pay_type=" + pay_type + "&serial_number=" + wather_num;
$.getJSON(url, function(res_data) {
console.log('支付'+url);
console.log(res_data);
if (res_data['code'] != "0") {
alert(res_data['info']);
return;
}
location.replace(location.href);
});
});
});
break;
case "修改":
var listURL = "hotelModifyOrder.html?order_id=" + cur_order_id;
// 跳转前将URL编码
listURL = encodeURI(listURL);
window.location.href = listURL;
break;
case "取消":
bootbox.dialog({
message: "是否真的要取消订单!",
title: "温馨提示:",
buttons: {
Cancel: {
label: "否",
className: "btn-default",
callback: function () {
return;
}
}
, OK: {
label: "是",
className: "btn-primary",
callback: function () {
var cancel_url=my_base_url_cancel+"?method=cancel&order_id="+cur_order_id;
$.getJSON(cancel_url,function(res_data){
console.log('取消'+cancel_url);
console.log(res_data);
if(res_data['code']!="0"){alert(res_data['info']);return;}
location.replace(location.href);
});
}
}
}
});
//正确
// var result = confirm("确定取消订单吗?")
// if (result) {
// var cancel_url=my_base_url_cancel+"?method=cancel&order_id="+cur_order_id;
// $.getJSON(cancel_url,function(res_data){
// console.log('取消'+cancel_url);
// console.log(res_data);
// if(res_data['code']!="0"){alert(res_data['info']);return;}
// location.replace(location.href);
// });
// }
// var cancel_url=my_base_url_cancel+"?method=cancel&order_id="+cur_order_id;
// $.getJSON(cancel_url,function(res_data){
// console.log('取消'+cancel_url);
// console.log(res_data);
// if(res_data['code']!="0"){alert(res_data['info']);return;}
// location.replace(location.href);
// });
break;
case "人工确认通知":
//改变自己的文本
self_obj.css('display','none');
self_obj.html('');
var people_confirm_url = my_base_url_ok + "?method=notice&order_id=" + cur_order_id;
$.getJSON(people_confirm_url, function(res_data) {
console.log('人工确认通知'+people_confirm_url);
console.log(res_data);
if(res_data['code']!="0"){
alert(res_data['info']);
self_obj.css('display','table-row');
self_obj.html('人工确认通知');
return;
}
location.replace(location.href);
});
break;
case "录入确认号":
center_show($('.hotel_OK'));
$(document).ready(function() {
$('#btn_hotel_ok_submit').click(function() {
var ok_code = $('#ht_ok_code').val();
var ok_comment = $('#ht_ok_comment').val();
if (ok_code.trim().length <= 0 || ok_comment.trim().length <= 0) {
alert('信息填写不完整!!!');
return;
}
var ok_num_url = my_base_url_ok + "?method=confirmnum&order_id=" + cur_order_id + "&comment_code=" + ok_code + "&comment_text=" + ok_comment;
$.getJSON(ok_num_url, function(res_data) {
if (res_data['code'] != "0") {
alert(res_data['info']);
return;
}
location.replace(location.href);
});
});
});
break;
case "退单确认":
center_show($('.order_return'));
var url =base_url + "?method=getOrderRefund&order_id="+cur_order_id;
$.getJSON(url, function(res_data) {
if (res_data['code'] != "0") {
alert(res_data['info']);
return;
}
console.log(res_data)
var back_info = res_data['order_refund'];
if (back_info.length > 0) {
$('#payMoney').html(back_info[0]['refund_amount'] + " " + "元");
$('#order_return_pay_money2').html(back_info[0]['org_back'] + " " + "元");
$('#order_return_pay_time').html(back_info[0]['pay_time']);
$('#order_return_pay_type1').html(back_info[0]['type_name']);
$('#order_return_pay_type2').html(back_info[0]['type_name']);
$('#order_return_comment').html(back_info[0]['reason']);
}
});
$(document).ready(function() {
$('#btn_order_return_submit').click(function() {
var comment=$('#order_return_comment').val();
if(comment.trim().length<=0){alert('请输入备注!!!');return;}
var url=my_base_url_cancel+"?method=check&comment_text="+comment+"&order_id="+cur_order_id;
$.getJSON(url,function(res_data){
if(res_data['code']!="0"){alert(res_data['info']);return;}
location.replace(location.href);
});
});
});
break;
case "退改申请":
center_show($('.back_apply'));
$(document).ready(function() {
$('#btn_back_apply_submit').click(function() {
var balance = $("input[name='refund_balance']").val();
var supplier = $("input[name='suppliers_return']").val();
var refund_reason = $("textarea[name='refund_reason']").val();
if (balance.trim().length <= 0) {
alert('请输入退款金额!!!');
return;
}
if (supplier.trim().length <= 0) {
alert('请输入供应商!!!');
return;
}
if (refund_reason.trim().length <= 0) {
alert('请输入退改原因!!!');
return;
}
//a,b,c
var url = my_base_url_cancel + "?method=apply&apply="+balance+","+supplier+","+refund_reason+"&order_id="+cur_order_id;
$.getJSON(url, function(res_data) {
if (res_data['code'] != "0") {
alert(res_data['info']);
return;
}
location.replace(location.href);
});
});
});
break;
default:
break;
}
}
//计时
var timer = null;
function ShowCountDown() {
// pay_end_time
var dt1 = getDateTime(0) + " " + getDateTime(2);
var dt2 = pay_end_time;
if(dt2==""){return;}
var date1y = dt1.substring(0,4);
var date1m = dt1.substring(5,7);
var date1d = dt1.substring(8,10);
var date1h = dt1.substring(11,13);
var date1i = dt1.substring(14,16);
var date1s = dt1.substring(17,19);
var date2y = dt2.substring(0,4);
var date2m = dt2.substring(5,7);
var date2d = dt2.substring(8,10);
var date2h = dt2.substring(11,13);
var date2i = dt2.substring(14,16);
var date2s = dt2.substring(17,19);
var date1 = new Date(date1y,date1m,date1d,date1h,date1i,date1s);
var date2 = new Date(date2y,date2m,date2d,date2h,date2i,date2s);
var date3 = date2 - date1;
//计算出相差天数
var days = Math.floor(date3 / (24 * 3600 * 1000))
//计算出小时数
var leave1 = date3 % (24 * 3600 * 1000) //计算天数后剩余的毫秒数
var hours = Math.floor(leave1 / (3600 * 1000))
//计算相差分钟数
var leave2 = leave1 % (3600 * 1000) //计算小时数后剩余的毫秒数
var minutes = Math.floor(leave2 / (60 * 1000))
//计算相差秒数
var leave3 = leave2 % (60 * 1000) //计算分钟数后剩余的毫秒数
var seconds = Math.round(leave3 / 1000);
var str = days + "日" + hours + "时" + minutes + "分" + seconds + "秒";
if (hours < 10) {
str = str.replace('日', '日0');
// str = days + "日0" + hours + "时" + minutes + "分" + seconds + "秒";
}
if (minutes < 10) {
str = str.replace('时', '时0')
// str = days + "日" + hours + "时0" + minutes + "分" + seconds + "秒";
}
if (seconds < 10) {
str = str.replace('分', '分0');
// str = days + "日" + hours + "时" + minutes + "分0" + seconds + "秒";
}
if(date2==date1){
location.replace(location.href);
}else if(date2