/**
* Created by luocj on 2016/9/24.
*/
var tr_order_str = $('#tr_order').prop('outerHTML');//获取tr中所有的字符串
var order_status = $("#search_status").val();
var start_date = '';
var end_date = '';
var province = '0';
var city = '0';
var hotel_name = $("#hotel_name").val();
var org_id = '';
var more_search = '';
var date_type = '';
var yesterday = '';
var today = '';
var thisweekstartdate = '';
var thisweekenddate = '';
var thismonthstartdate = '';
var thismonthenddate = '';
var user_id = 1;
var current = '1';
var page_size = '30';
var memodiv = $('.memo1').prop('outerHTML');
var firstLoad = true;
window.onload = function () {
start_date = "";
end_date = "";
getHotelList();
/*
provinceHTML = $('#province').html();
cityHTML = $('#city').html();
var apiurl = base_api + "?type=hotel_AddHotelProduct&op=provinceCity&area_id=";
ZZLog(apiurl);
$.getJSON(apiurl, function (res_data) {
ZZLog(res_data);
if (res_data['code'] != "0") {
ZZAlertInfo(res_data['info']);
} else {
//地区
var area_list = res_data['area_list'];
var areaHTML = '';
for (var i = 0, m = area_list.length; i < m; i++) {
var tempDict = area_list[i];
var tempHTML = provinceHTML;
tempHTML = tempHTML.replace('选择省', tempDict['area_name']);
tempHTML = tempHTML.replace('0', tempDict['area_id']);
areaHTML += tempHTML;
}
$('#province').html(areaHTML);
$('#province')[0].selectedIndex = 0;
}
})
*/
};
//获取订单列表
function getHotelList() {
order_status = $("#search_status").val();
if( order_status == 313 ) {
$("#send_button").show();
$("#confirm_button").hide();
$("#send_button2").show();
$("#confirm_button2").hide();
} else {
$("#send_button").hide();
$("#confirm_button").show();
$("#send_button2").hide();
$("#confirm_button2").show();
}
province = '0';
city = '0';
hotel_name = $("#hotel_name").val();
var com_url = base_api + "?type=order_HotelOrderList&op=sendconfirm_list&province=" + province + "&city=" + city + "&hotel_name=" + hotel_name + "&order_status=" + order_status + "¤t=" + current + "&page_size=" + page_size;
ZZLog(com_url);
if(!firstLoad)
loading();
firstLoad = false;
$.getJSON(com_url, function (data) {
closeLoading();
ZZLog(data);
setDataBody(data);
if (data['total_count'] < 0) {
$('.pageDiv').hide();
} else {
$(".pageDiv").createPage({
pageCount: data['total_page'],//总页数
current: current,//当前页
turndown: 'true',//是否显示跳转框,显示为true,不现实为false,一定记得加上引号...
backFn: function (p) {
current = p;
havePageData();
}
});
$('.pageDiv').show();
}
}).error(function (msg) {
closeLoading();
});
}
//替换订单主体
function setDataBody(data) {
var order_list = data['order_list'];
var comHTML = '';
for (var i = 0; i < order_list.length; i++) {
var dict = order_list[i];
var HTML = tr_order_str;
var order_id = dict['order_id'];
var order_status_name = dict['order_status_name'];
var org_name = dict['org_name'];
var status_txt = '';
//var order_info = filterRepeatStr(dict['order_description']);
HTML = HTML.replace('[订单编号]', dict['order_id'] === null ? '-' : dict['order_id']);
HTML = HTML.replace('[order_id_c]', dict['order_id'] === null ? '-' : dict['order_id']);
HTML = HTML.replace('[order_id]', dict['order_id'] === null ? '-' : dict['order_id']);
HTML = HTML.replace('[order_status]', dict['order_status_name'] === null ? '-' : dict['order_status_name']);
HTML = HTML.replace('[org_name]', dict['org_name'] === null ? '-' : dict['org_name']);
HTML = HTML.replace('[org_id]', dict['org_id'] === null ? '-' : dict['org_id']);
HTML = HTML.replace('[room_type]', dict['room_type'] === null ? '-' : dict['room_type']);
HTML = HTML.replace('[hotel_id]', dict['hotel_id'] === null ? '-' : dict['hotel_id']);
HTML = HTML.replace('[预订时间]', dict['create_time'] === null ? '-' : dict['create_time']);
HTML = HTML.replace('[供应商]', dict['prod_supply_org_name'] === null ? '-' : dict['prod_supply_org_name']);
HTML = HTML.replace('[预订产品]', dict['hotel_name'] + ' ' + dict['zifangxing'] + '
' + dict['order_description'] + '');
HTML = HTML.replace('[客人信息]', dict['customer_name'] + '
' + dict['customer_mobile']);
HTML = HTML.replace('[订单渠道]', dict['org_name'] === null ? '-' : dict['org_name'] + '
');
HTML = HTML.replace('[订单金额]', '¥' + dict['order_price']);
HTML = HTML.replace('[支付方式]', dict['order_pay_type'] === null ? '-' : dict['order_pay_type']);
//取消状态的订单要显示
if ((dict['order_status'] == 148 || dict['order_status'] == 383) && dict['cancel_reason']) {
status_txt = '' + dict['order_status_name'] + '';
} else {
status_txt = dict['order_status_name'];
}
HTML = HTML.replace('[状态]', status_txt);
var order_id = dict['order_id'];
var order_status = dict['order_status'];
var hotel_id = dict['hotel_id'];
var parent_room_type = dict['parent_room_type'];
var room_type = dict['room_type'];
var org_name = dict['org_name'];
var org_id = dict['org_id'];
/*
var modify = ' 修改 ';
var cancel = ' 取消 ';
var confirm = ' 确认 ';
var send = ' 发送确认单 ';
var sp_deal = ' 异常订单处理 ';
if (dict['order_status'] == 145) {
var cstr145 = modify + cancel;
HTML = HTML.replace('[操作]', cstr145);
} else if (dict['order_status'] == 313) {
var cstr313 = modify + cancel + send;
HTML = HTML.replace('[操作]', cstr313)
} else if (dict['order_status'] == 198) {
var cstr198 = confirm + sp_deal;
HTML = HTML.replace('[操作]', cstr198)
} else if (dict['order_status'] == 314) {
HTML = HTML.replace('[操作]', sp_deal)
} else if (dict['order_status'] == 382) { //已安排的订单 异常操作处理了,
cancel = ' 取消 ';
var cstr313 = modify + cancel + send;
HTML = HTML.replace('[操作]', cstr313)
} else if (dict['order_status'] == 383) {
HTML = HTML.replace('[操作]', '-')
HTML = HTML.replace('[font-color]', 'color: gray');
}
*/
// else if (dict['order_status'] == 314 && dict['order_pay_type'] == '现金支付') {
// HTML = HTML.replace('[操作]', sp_deal)
// } else if (dict['order_status'] == 314 && dict['order_pay_type'] == '微信支付') {
// var cstr314wx = modify;
// HTML = HTML.replace('[操作]', cstr314wx)
// }
/*
else if (dict['order_status'] == 147) {
var cstr147 = modify + cancel;
HTML = HTML.replace('[操作]', cstr147)
} else if (dict['order_status'] == 148 || dict['order_status'] == 383) {
HTML = HTML.replace('[操作]', '—');
HTML = HTML.replace('[font-color]', 'color: #cccccc');
}
*/
//公共备注
if (dict['memo_flag'] != '') {
HTML = HTML.replace('[公共备注]', '有')
} else {
HTML = HTML.replace('[公共备注]', '无')
}
comHTML += HTML;
}
$('#order_list').html(comHTML);
$('#order_list').show();
}
function havePageData() {
order_status = $("#search_status").val();
if( order_status == 313 ) {
$("#send_button").show();
$("#confirm_button").hide();
$("#send_button2").show();
$("#confirm_button2").hide();
} else {
$("#send_button").hide();
$("#confirm_button").show();
$("#send_button2").hide();
$("#confirm_button2").show();
}
province = '0';
city = '0';
hotel_name = $("#hotel_name").val();
var com_url = base_api + "?type=order_HotelOrderList&op=sendconfirm_list&province=" + province + "&city=" + city + "&hotel_name=" + hotel_name + "&order_status=" + order_status + "¤t=" + current + "&page_size=" + page_size;
ZZLog(com_url);
$.getJSON(com_url, function (data) {
ZZLog(data);
if (data['code'] != "0") {
ZZAlertInfo(data['info']);
} else {
setDataBody(data);
}
})
}
// 复选框事件
function select_checked(index) {
//index=0最上面的全选 index=1表示的是下面所有的
var cur_check = $('.ace')[0];
var checkList = $('.ace');
var checkCount = checkList.length - 1;
var true_count = 0;
for (var i = 1; i < checkList.length; i++) {
if (index == '0') {
checkList[i].checked = cur_check.checked;
} else {
if (checkList[i].checked == false) {
cur_check.checked = false
} else {
true_count = true_count + 1;
}
}
}
//判断下面是否选中完
if (checkCount == true_count) {
cur_check.checked = true;
}
}
$(document).ready(function () {
//点击查询
$('#search').bind('click', function () {
getHotelList();
});
//昨日日期
$('#yesterday').bind('click', function () {
$("#start_date").val(getDateTime(10));
$("#end_date").val(getDateTime(10));
getHotelList();
});
//今日日期
$('#today').bind('click', function () {
$("#start_date").val(getDateTime(0));
$("#end_date").val(getDateTime(0));
getHotelList();
});
//本周日期
$('#thisweek').bind('click', function () {
$("#start_date").val(after(getDateTime(12)));
$("#end_date").val(after(getDateTime(13)));
getHotelList();
});
//本月日期
$('#thismonth').bind('click', function () {
$("#start_date").val(getDateTime(14));
$("#end_date").val(getDateTime(15));
getHotelList();
});
//选择省的事件
$('#province').bind('change', function () {
var area_id = $(this).val();
if (area_id == "0" || area_id == "") {
$('#city').html(cityHTML);
return;
}
var url = base_api + "?type=hotel_AddHotelProduct&op=provinceCity&area_id=" + area_id;
ZZLog(url);
$.getJSON(url, function (res_data) {
ZZLog(res_data);
if (res_data['code'] != "0") {
ZZAlertInfo(res_data['info']);
} else {
//地区
var area_list = res_data['area_list'];
var areaHTML = '';
for (var i = 0, m = area_list.length; i < m; i++) {
var tempDict = area_list[i];
var tempHTML = cityHTML;
tempHTML = tempHTML.replace('选择市', tempDict['area_name']);
tempHTML = tempHTML.replace('0', tempDict['area_id']);
areaHTML += tempHTML;
}
if (areaHTML) {
$('#city').html(areaHTML);
$('#city')[0].selectedIndex = 0;
}
}
})
});
}
);
//订单状态筛选
var tempobj = null;
function submit(param, obj) {
if (tempobj) {
$(tempobj).css("cssText", "font-size: 12px;width: 50px; padding: 3px;display: inline-block;margin-left: 5px;");
}
if (obj) {
$(obj).css("cssText", "font-size: 12px;width: 50px; padding: 3px;display: inline-block;margin-left: 5px;background:dimgrey!important");
}
tempobj = obj;
var url = getSelectInfo(param);
getHotelList();
}
function getSelectInfo(status) {
order_status = status;
getHotelList();
}
//end 订单状态筛选
//批量确认
function get_seleted_order_list() {
var checkList = $('.ace');
var checkCount = checkList.length - 1;
var true_count = 0;
var order_list = "";
for (var i = 1; i < checkList.length; i++) {
if (checkList[i].checked == true ) {
if( true_count == 0 ) {
order_list = checkList[i].value;
} else {
order_list = order_list + "," + checkList[i].value;
}
true_count ++;
}
}
if( true_count <= 0 ) {
return false;
} else {
return order_list;
}
}
function make_sure_all() {
order_list = get_seleted_order_list();
if( order_list == false ) {
ZZAlertInfo('请选择要确认的订单');return;
}
var make_sure_num = ZZInput("请输入确认号", function (make_sure_num) {
var make_sure_order_id = order_list;
if (make_sure_num) { //点击的是确定
make_sure_order_update(make_sure_order_id, make_sure_num);
} else if (make_sure_num == "") { //没有输入内窝 点击了取消
ZZAlertInfo('请正确输入确认单号');
} else { //点击了取消
}
});
function make_sure_order_update(make_sure_order_id, make_sure_num) {
var url = base_api;
var param = {
type: "order_HotelOrderList",
op: "make_sure_all",
make_sure_order_id: make_sure_order_id,
make_sure_num: make_sure_num
}
loading();
$.ajax({
url: url,
type: "post",
dataType: "json",
data: param,
success: function (res_data) {
ZZLog(res_data);
ZZAlertInfo(res_data['info']);
getHotelList();
closeLoading();
},
error: function (res_data) {
closeLoading();
}
})
}
}
//发单
function billing_all() {
order_list = get_seleted_order_list();
if( order_list == false ) {
ZZAlertInfo('请选择要发单的订单');return;
}
ZZConfirm("确定发送确认单吗?", function () {
var url = base_api;
var param = {
type: "order_HotelOrderList",
op: "billing_all",
user_id: user_id,
order_id: order_list
};
loading();
$.ajax({
url: url,
type: "post",
dataType: "json",
data: param,
success: function (res_data) {
ZZLog(res_data);
ZZAlertInfo(res_data['info'])
getHotelList();
closeLoading();
},
error: function (res_data) {
closeLoading();
}
})
});
}
//删掉重复显示的房型
function filterRepeatStr(str) {
var array = str.split("|");
var data = '
';
var dict = array[0];//得到第一条数据
var str2 = dict.split(",");
var str3 = str2[0];//得到重复房型
for (var i = 0; i < array.length; i++) {
var dict1 = array[i];
if (i == 0) {
data += dict1;
} else {
dict1 = dict1.replace(str3 + ",", "|");
data += dict1;
}
}
return data;
}
//点击备注
function remarks(memo) {
$('#beizhu').show();
$('#mask').show();
var row_arr = memo.split('|');
var sumHTML = '';
if (row_arr) {
for (var i = 0; i < row_arr.length; i++) {
var dict = row_arr[i];
var HTML = memodiv;
var temp = dict.split(',');
var main = temp[2];
var time = temp[1];
var user = temp[0];
HTML = HTML.replace('[备注main]', main);
HTML = HTML.replace('[备注time]', time);
HTML = HTML.replace('[备注user]', user);
sumHTML += HTML
}
$('#beizhumain').html(sumHTML);
$('.memo1:odd').css('background', 'lightgray');
}
}
// 点击蒙板
function showMB(order_id, order_status, order_status_name) {
$('#exception_handling').show();
$('#mask').show();
//提交异常状态处理状态
var order_id = order_id;
var order_status = order_status;
var order_status_name = order_status_name;
$('#make_sure').unbind('click');
$('#make_sure').on('click', function () {
var text_reason = $('#text_reason').val();
var url = base_api;
var param = {
type: 'order_HotelOrderList',
op: 'handle_order',
user_id: 1,
order_id: order_id,
text_reason: text_reason,
order_status: order_status,
order_status_name: order_status_name
}
$.ajax({
url: url,
type: "post",
dataType: "json",
data: param,
success: function (res_data) {
ZZLog(res_data);
if (res_data['code'] != "0") {
ZZAlertInfo(res_data['info']);
} else {
ZZLog('code=0');
hideMB();
getHotelList();
}
}, error: function (error) {
ZZLog(error);
}
})
})
}
function hideMB() {
$('#exception_handling').hide();
$('#mask').hide();
$("#text_reason").val('');
$("#beizhu").hide();
}