|
- //date:2017-04-12
- let cache_res_data = {};
-
- let order_id = '';
- let mao_location = '';
- let temp_all_html = '';
-
- let save_info = '保存';
- let save_update_info = '保存并生成修改单';
-
- let temp_docking_type = '';
- let temp_order_status = '';
- $(document).ready(function() {
- order_id = getPar('order_id');
- mao_location = getPar('location');
- if(mao_location.indexOf('#') != -1) {
- let index = mao_location.indexOf('#');
- mao_location = mao_location.substring(0, index);
- }
- if('' == order_id) {
- ZZAlertInfo('缺少订单号!');
- return;
- }
- loading();
- httpLoadInfo()
- })
-
- //加载基本信息
- function httpLoadInfo() {
-
- let data = {
- "type": "order_HotelOrderDetailLevel",
- "order_id": order_id
- }
- $.ajax({
- type: "post",
- url: base_api,
- async: true,
- data: data,
- dataType: "json",
- success: (res_data) => {
- ZZLog(res_data);
- if(res_data['code'] != "0") {
- ZZAlertInfo(res_data['info']);
- } else {
- cache_res_data[order_id] = res_data;
- loadHtml(res_data);
- loadUpLog(res_data);
- httpLoadLog();
- closeLoading();
-
- //锚点定位
- // location.href = "#"+mao_location;
-
- if(mao_location != "") window.location.hash = '#' + mao_location;
-
- }
- },
- error: () => {
- ZZAlertInfo(infoApiError);
- }
- });
- }
- //根据初始数据刷新页面
- function loadHtml(res_data) {
- // order_info
- //:如果是直连订单 不能更改销售价
-
- let order_info = res_data['order_info'];
- let order_id = order_info['order_id'];
- let order_status_name = order_info['order_status_name']
- let org_id = order_info['org_id'];
- let org_name = order_info['org_name'];
- let org_num = order_info['org_num'];
- $('#top-order-id').html('订单编号:' + order_id);
- $('#top-order-status').html(order_status_name);
- $('#top-order-channel').html('订单渠道:' + org_name);
- $('#top-order-channel-order-id').html(org_num);
- let docking_type = order_info['docking_type'];
- temp_docking_type = docking_type;
- let docking_type_desc = order_info['docking_type_desc'];
- if('557' == docking_type) {
- // $('#ludan').html(docking_type_desc);
- $('#ludan').html('录');
- $('#ludan').removeClass('hide_f')
- }
- if('556' == docking_type) {
- // $('#zhilian').html(docking_type_desc);
- $('#zhilian').html('直');
- $('#zhilian').removeClass('hide_f')
- }
- let cha = order_info['seconds'];
- if(cha >= 0) { //后30分钟内
- timeJian();
-
- function timeJian() {
- cha--;
- if(cha < 0) cha = 0;
- let m = parseInt(cha / 60);
- let s = cha % 60;
- if(0 == m && s == 0) {
- $('#top-order-status-main').children().eq(2).html(`${order_status_name} <span style="color:red;">(超时)</span>`);
- return;
- }
- m = m < 10 ? `0${m}` : m;
- s = s < 10 ? `0${s}` : s;
- $('#top-order-status-main').children().eq(1).html('|');
- $('#top-order-status-main').children().eq(2).html(`${order_status_name} <span style="color:red;">(${m}:${s})</span>`);
- setTimeout(timeJian, 1000);
- }
- }
-
- //订单状态
- let order_status = res_data['order_status'];
- if(order_status.hasOwnProperty('198')) $('.198').addClass('active'); //待安排
- if(order_status.hasOwnProperty('314')) $('.314').addClass('active'); //已安排
- if(order_status.hasOwnProperty('147')) $('.147').addClass('active'); //已入住
- if('147' == order_info['order_status']) $('.147').addClass('active'); //已入住
- temp_order_status = order_info['order_status'];
-
- //三个单 下载 0:确认单 1:修改单 2:取消单
- if('0' == order_info['order_level']) {
- $('#top-btn-ok-d').removeClass('hide_f')
- $('#top-btn-update-d').addClass('hide_f')
- $('#top-btn-cancele-d').addClass('hide_f')
- };
- if('1' == order_info['order_level']) {
- $('#top-btn-update-d').removeClass('hide_f')
- $('#top-btn-ok-d').addClass('hide_f')
- $('#top-btn-cancele-d').addClass('hide_f')
- };
- if('2' == order_info['order_level']) {
- $('#top-btn-cancel-d').removeClass('hide_f')
- $('#top-btn-ok-d').addClass('hide_f')
- $('#top-btn-update-d').addClass('hide_f')
- };
-
- //1.入住需求
- let hotel_id = order_info['hotel_id'];
- let hotel_name = order_info['hotel_name'];
- let room_type = order_info['room_type'];
- let base_room_type = order_info['base_room_type'];
- let room_name = order_info['room_name'];
-
- $('#rz-hotel-name').attr('data-hotel-id', hotel_id);
- $('#rz-hotel-name').html(hotel_name);
- $('#rz-hotel-room').attr('data-room-type', room_type);
- $('#rz-hotel-room').attr('data-base-room-type', base_room_type);
- $('#rz-hotel-room').html(room_name);
-
- //1.1渠道订单号
- $('#order_channel_order_id_txt').html(org_num);
- $('#order_channel_order_id').val(org_num);
-
- $('#order_channel_txt').html(org_name);
- let org_list = res_data['org_list'];
- let channel_html = '';
- org_list.forEach((v, i) => {
- channel_html += `<option value="${v.org_id}">${v.org_name}</option>`;
- })
- $('#order_channel').html(channel_html);
- $('#order_channel').val(org_id);
-
- //1.2入住日期
- let start_date = order_info['start_date'];
- let end_date = order_info['end_date'];
- $('#start_date').children().eq(0).val(start_date);
- $('#end_date').children().eq(0).val(end_date);
- let s_s = start_date.replace(/\-/g, '');
- let e_s = end_date.replace(/\-/g, '');
- let days = e_s - s_s - 0;
- $('#datediff').html(`共${days}晚`);
- $('#start_date_txt').html(start_date);
- $('#end_date_txt').html(end_date);
- //1.3表格
- let one_day = order_info['one_day'];
-
- let one_html = '';
- let all_commission = order_info['all_commission'];
- let all_price = order_info['all_price'];
- let all_profit = order_info['all_profit'];
- let all_html = `<tr style="font-weight:bold">
- <td>小计</td>
- <td></td>
- <td></td>
- <td></td>
- <td class="all_price" data-value="${all_price}">${all_price}元</td>
- <td class="all_commission" data-value="${all_price}">${all_commission}元</td>
- <td class="all_profit" data-value="${all_price}">${all_profit}元</td>
- </tr>`;
- temp_all_html = all_html;
- one_day.forEach((v, i) => {
- let cstr1 = '';
- for(let j = 1; j <= 20; j++) {
- cstr1 += `<option value="${j}">${j}</option>`;
- }
- one_html += `<tr class="tr_line" height="45">
- <td>${v.start_date}</td>
- <td>
- <span class="update1_s">${v.count}</span>
- <select class="form-control hide_f update1_h room_count" style="width: 40px;padding:0px">
- ${cstr1}
- </select>
- </td>
- <td>
- <span class="update2_s">${v.order_price}</span>
- <input data-price="${v.order_price}" type="text" class="form-control hide_f update2_h sale_single_price" style="width: 80px;" value="${v.order_price}"/>
- </td>
- <td>
- <span class="update3_s">${v.base_price}</span>
- <input data-price="${v.base_price}" type="text" class="form-control hide_f update3_h cai_base_price" style="width: 80px;" value="${v.base_price}"/>
- </td>
- <td class="tr_all_price">${toDecimal2(v.order_price*v.count)}</td>
- <td class="tr_all_commission" data-commission="${toDecimal2(v.commission)}">${toDecimal2(v.commission)}</td>
- <td class="tr_profit_value">${toDecimal2(v.profit_value)}</td>
- </tr>`;
- });
- one_html += all_html;
- $('#rz-table').html(one_html);
-
- $('.room_count').on('change', function() {
- $parent = $(this).closest('.tr_line');
- changeCount($parent);
- })
- $('.sale_single_price').on('input', function() {
- $parent = $(this).closest('.tr_line');
- tr_change($parent);
- })
-
- $('.cai_base_price').on('input', function() {
- $parent = $(this).closest('.tr_line');
- tr_change($parent);
- })
-
- $('.sale_single_price').on('blur', function() {
- let val = $(this).val();
- val = val.trim() == "" ? "0" : val.trim();
- $(this).val(val);
- })
- $('.cai_base_price').on('blur', function() {
- let val = $(this).val();
- val = val.trim() == "" ? "0" : val.trim();
- $(this).val(val);
- })
- //1.5三个按钮
- //如果是直连 则不能够修改销售价 556:直连 557:录单
- if('556' == docking_type) {
- $('#btn-rz-update-xsj').hide();
- $('#btn-rz-update-xsj').remove();
- $('#btn-rz-update-xsj').css('opacity', '0');
- //1.5.1
- let status_arr1 = ['313'];
- let status_arr2 = ["198", "382"];
- let status_arr3 = ['313', '198', '382'];
-
- if($.inArray(temp_order_status, status_arr3) == -1) {
- $('#btn-rz-update-xq').hide();
- $('#btn-rz-update-xq').remove();
- $('#btn-rz-update-xq').css('opacity', '0');
- $('#btn-rz-update-cgj').hide();
- $('#btn-rz-update-cgj').remove();
- $('#btn-rz-update-cgj').css('opacity', '0');
- $('#btn-rz-update-cancel').hide();
- $('#btn-rz-update-cancel').remove();
- $('#btn-rz-update-cancel').css('opacity', '0');
- //客人信息
- $('#btn-customer-update').closest('.myBody').children().eq(2).css('opacity', '0');
- $('#btn-customer-update').closest('.myBody').children().eq(2).hide();
- //订单备注
- $('.order-remark').css('opacity', '0');
- $('.order-remark').hide();
- $('.btn-comment').attr("disabled", "disabled");
- $('.btn-comment').hide();
- }
- }
- if("557" == docking_type) {
- //1.5.2
- let status_arr1 = ['313'];
- let status_arr2 = ["198", "382"];
- let status_arr3 = ['313', '198', '382'];
-
- if($.inArray(temp_order_status, status_arr3) == -1) {
- //三个按钮
- $('#btn-rz-update-xq').hide();
- $('#btn-rz-update-xq').remove();
- $('#btn-rz-update-xq').css('opacity', '0');
- $('#btn-rz-update-xsj').hide();
- $('#btn-rz-update-xsj').remove();
- $('#btn-rz-update-xsj').css('opacity', '0');
- $('#btn-rz-update-cgj').hide();
- $('#btn-rz-update-cgj').remove();
- $('#btn-rz-update-cgj').css('opacity', '0');
- $('#btn-rz-update-cancel').hide();
- $('#btn-rz-update-cancel').remove();
- $('#btn-rz-update-cancel').css('opacity', '0');
- //客人信息
- $('#btn-customer-update').closest('.myBody').children().eq(2).css('opacity', '0');
- $('#btn-customer-update').closest('.myBody').children().eq(2).hide();
- //订单备注
- $('.order-remark').css('opacity', '0');
- $('.order-remark').hide();
- $('.btn-comment').attr("disabled", "disabled");
- $('.btn-comment').hide();
- }
- }
-
- //2.0客人信息
- let customer_name = order_info['customer_name'];
- let customer_mobile = order_info['customer_mobile'];
- $('#customer_name_txt').html(customer_name);
- $('#customer_name').val(customer_name);
-
- $('#customer_phone_txt').html(customer_mobile ? customer_mobile : "-");
- $('#customer_phone').val(customer_mobile);
-
- //3.0订单备注
- let order_comment = res_data['order_comment'];
- let comment_html = '';
- order_comment.forEach((v, i) => {
- comment_html += ` <tr>
- <td data-type="${v.comment_type}">${v.comment_type_desc}</td>
- <td>${v.comment_txt}</td>
- <td>${v.user_true_name?v.user_true_name:"-"}</td>
- <td>${v.create_time}</td>
- <td>
- <button type="button" data-comment-id="${v.comment_id}" class="btn btn-link btn-comment" style="padding-left: 0;">删除</button>
- </td>
- </tr>`;
- })
- $('#remark-table').html(comment_html);
-
- //删除备注
- $('.btn-comment').on('click', function() {
- let $this = $(this);
- ZZConfirm("您真的要删除该条备注吗?", function() {
- let comment_id = $this.attr('data-comment-id');
- let data = {
- type: "order_ModifyHTOrderLevel",
- op: "commentDel",
- order_id,
- comment_id
- }
- $.ajax({
- type: "post",
- url: base_api,
- async: true,
- data: data,
- dataType: "json",
- success: (res_data) => {
- ZZLog(res_data);
- if(res_data['code'] != "0") {
- ZZAlertInfo(res_data['info']);
- } else {
- httpLoadInfo();
- }
- },
- error: () => {
- ZZAlertInfo(infoApiError);
- }
- });
- })
-
- })
-
- }
-
- function changeCount($parent) {
- // 房间数量
- var room_count = $parent.find('.room_count');
- // 结算单价
- var room_price = $parent.find('.sale_single_price');
- // 佣金规则
- var dict = getJsonHtml($parent.attr('data-json'));
- var dict_maiduan = getJsonHtml($parent.attr('data-json-maiduan'));
- var dict_baoliu = getJsonHtml($parent.attr('data-json-baoliu'));
- var dict_xianxun = getJsonHtml($parent.attr('data-json-xianxun'));
- var commision_price = 0;
- if(dict['commision_flag'] == '1') { //有佣金规则
- if(dict['back_commision_method'] == '309') { //308 按销售金额309 按结算金额
- commision_price = dict['back_value']
- } else if(dict['back_commision_method'] == '308') {
- commision_price = room_count * room_price * parseFloat(dict['back_percent']) / 100;
- }
- } else { //无佣金规则
- commision_price = 0;
- }
- //end 佣金规则
- //结算总价
- var jiesuan_price = room_count * room_price;
- //end 结算总价
- //库存类型与成本
- var maiduan_count = dict_maiduan['remaining_count'] == undefined ? 0 : dict_maiduan['remaining_count'];
- var baoliu_count = dict_baoliu['remaining_count'] == undefined ? 0 : dict_baoliu['remaining_count'];
- var xianxun_count = dict_xianxun['remaining_count'] == undefined ? 0 : dict_xianxun['remaining_count'];
- var maiduan_price = dict_maiduan['cost_price'] == undefined ? 0 : dict_maiduan['cost_price'];
- var baoliu_price = dict_baoliu['cost_price'] == undefined ? 0 : dict_baoliu['cost_price'];
- var xianxun_price = dict_xianxun['cost_price'] == undefined ? 0 : dict_xianxun['cost_price'];
- //end 库存类型与成本
- //销售利润
- var profit = 0;
- if(parseInt(room_count) <= parseInt(maiduan_count)) { //所选房间数小于等于买断数
- profit = jiesuan_price - commision_price - maiduan_price * room_count
- } else if(parseInt(room_count) > parseInt(maiduan_count) && parseInt(room_count) <= (parseInt(maiduan_count) + parseInt(baoliu_count))) { //所选房间数大于买断数,小于等于保留数+买断数
- profit = jiesuan_price - commision_price - maiduan_price * maiduan_count - baoliu_price * (room_count - maiduan_count)
- } else if(parseInt(room_count) > (parseInt(maiduan_count) + parseInt(baoliu_count)) && parseInt(room_count) <= (parseInt(maiduan_count) + parseInt(baoliu_count) + parseInt(xianxun_count))) {
- profit = jiesuan_price - commision_price - maiduan_price * maiduan_count - baoliu_price * baoliu_count - xianxun_price * (room_count - maiduan_count - baoliu_count)
- }
- //end 销售利润
- //佣金显示
- var commision_price1 = parseFloat(commision_price).toFixed(2);
- if(dict['commision_flag'] == 1) {
- $parent.find('.tr_all_commission').text(commision_price1);
- } else {
- $parent.find('.tr_all_commission').text('-');
- }
- //结算总价显示
- var jiesuan_price1 = parseFloat(jiesuan_price).toFixed(2);
- if(jiesuan_price1) {
- $parent.find('.tr_all_price').text(jiesuan_price1);
- }
- //销售利润显示
- var profit1 = parseFloat(profit).toFixed(2);
- if(profit1) {
- $parent.find('.tr_profit_value').text(profit1);
- }
- total_price_jisuan();
- }
-
- function tr_change($parent) {
- let room_count = $parent.find('.room_count').val();
- let sale_single_price = $parent.find('.sale_single_price').val();
- let cai_base_price = $parent.find('.cai_base_price').val();
- let commission = $parent.find('.tr_all_commission').attr('data-commission');
-
- let tr_all_1 = sale_single_price * room_count;
- tr_all_1 = tr_all_1.toFixed(2);
- let tr_all_2 = commission * room_count;
- tr_all_2 = tr_all_2.toFixed(2);
- let tr_all_3 = tr_all_1 - cai_base_price * room_count;
- tr_all_3 = tr_all_3.toFixed(2);
- if(isNaN(tr_all_1)) tr_all_1 = 0;
- if(isNaN(tr_all_2)) tr_all_2 = 0;
- if(isNaN(tr_all_3)) tr_all_3 = 0;
- // if(0==tr_all_1) tr_all_1 = '-';
- // if(0==tr_all_2) tr_all_2 = '-';
- // if(0==tr_all_3) tr_all_3 = '-';
-
- $parent.find('.tr_all_price').text(tr_all_1);
- $parent.find('.tr_all_commission').text(tr_all_2);
- $parent.find('.tr_profit_value').text(tr_all_3);
- total_price_jisuan();
- }
-
- function total_price_jisuan() {
- let all_1 = 0,
- all_2 = 0,
- all_3 = 0;
- $('.tr_all_price').each(function(index, dom) {
- let tr_all_1 = $(this).text();
- all_1 += tr_all_1 - 0;
- })
- $('.tr_all_commission').each(function(index, dom) {
- let tr_all_2 = $(this).text();
- all_2 += tr_all_2 - 0;
- })
- $('.tr_profit_value').each(function(index, dom) {
- let tr_all_3 = $(this).text();
- all_3 += tr_all_3 - 0;
- })
- if(isNaN(all_1)) all_1 = 0;
- if(isNaN(all_2)) all_2 = 0;
- if(isNaN(all_3)) all_3 = 0;
-
- $('.all_price').text(all_1.toFixed(2) + '元');
- $('.all_price').attr('data-value', all_1.toFixed(2));
-
- $('.all_commission').text(all_2.toFixed(2) + '元');
- $('.all_commission').attr('data-value', all_2.toFixed(2));
-
- $('.all_profit').text(all_3.toFixed(2) + '元');
- $('.all_profit').attr('data-value', all_2.toFixed(2));
- }
-
- function loadUpLog(res_data) {
- let log_update_user = res_data['log_update_user'];
- let log_html = ' <option value="0">全部</option>';
- log_update_user.forEach((v, i) => {
- log_html += `<option value="${v.id}">${v.true_name}</option>`;
- })
- $('#update-user').html(log_html);
- $('#update-user').comboSelect();
- }
- $('#log-search').on('click', function() {
- httpLoadLog();
- })
- //请求操作日志
- function httpLoadLog() {
- let log_user = $('#update-user').val();
- let log_start_date = $('#log-start-date').val();
- let log_end_date = $('#log-end-date').val();
- let data = {
- order_id,
- type: "log_LogLogInformation",
- name: "getHotelDetail",
- operator: log_user,
- startDate: log_start_date,
- endDate: log_end_date
- }
- ZZLog(JSON.stringify(data));
- $.ajax({
- type: "post",
- url: base_api,
- async: true,
- data: data,
- dataType: 'json',
- success: (res_data) => {
- ZZLog(res_data);
- if(res_data['code'] != "0") {
- ZZAlertInfo(res_data['info']);
- } else {
- let log_list = res_data['result'];
- let log_html = '';
- let _room_name = '';
- log_list = log_list.reverse();
- log_list.forEach((v, i) => {
- log_html += `<tr height="40px">
- <td>${v.true_name}</td>
- <td>${v.create_time}</td>
- <td>${v.log_desc.replace(/\;/g,'<br/>')}</td>
- </tr>`;
- })
- $('#log-table').html(log_html);
- }
- },
- error: () => {
- ZZAlertInfo(infoApiError);
- }
- });
- }
- //确认单
- $('#top-btn-ok-d').on('click', function() {
- window.location.href = base_api + "?type=order_HotelOrderDetailLevel&op=export&order_id=" + order_id;
- })
- //修改单
- $('#top-btn-update-d').on('click', function() {
- window.location.href = base_api + "?type=order_HotelOrderDetailLevel&op=export&order_id=" + order_id;
- })
- //取消单
- $('#top-btn-cancel-d').on('click', function() {
- window.location.href = base_api + "?type=order_HotelOrderDetailLevel&op=export&order_id=" + order_id;
- })
- //入住时间
- $('#start_date').on('changeDate', function(e) {
- changeStartEndDate();
- })
- //离店时间
- $('#end_date').on('changeDate', function(e) {
- changeStartEndDate();
- })
-
- function changeStartEndDate() {
- let start_date = $('#start_date').children().eq(0).val();
- let end_date = $('#end_date').children().eq(0).val();
-
- let s_s = start_date.replace(/\-/g, '');
- let e_s = end_date.replace(/\-/g, '');
- let days = e_s - s_s - 0;
- $('#datediff').html(`共${days}晚`);
-
- let hotel_id = $('#rz-hotel-name').attr('data-hotel-id');
- let room_type = $('#rz-hotel-room').attr('data-room-type');
- let base_room_type = $('#rz-hotel-room').attr('data-base-room-type');
- let org_id = $('#order_channel').val();
-
- let data = {
- "type": "order_ModifyHTOrderLevel",
- "op": "stockGetList",
- start_date,
- end_date,
- hotel_id,
- room_type,
- org_id,
- "parent_room_type": base_room_type
- }
- ZZLog(JSON.stringify(data));
- $.ajax({
- type: "post",
- url: base_api,
- async: true,
- data: data,
- dataType: "json",
- success: (res_data) => {
- ZZLog(res_data);
- if(res_data['code'] != "0") {
- ZZAlertInfo(res_data['info']);
- } else {
- loadStockHtml(res_data);
- }
- },
- error: () => {
- ZZAlertInfo(infoApiError);
- }
- });
- }
- //加载库存相差
- function loadStockHtml(res_data) {
- let price_info_list = res_data['price_info_list'];
- let stock_list = res_data['stock_list'];
-
- let sumHTML = '';
- price_info_list.forEach((v, i) => {
- let HTML = `<tr class="tr_line" height="45" data-json=[data-json] data-json-maiduan=[data-json-maiduan] data-json-baoliu=[data-json-baoliu] data-json-xianxun=[data-json-xianxun]>
- <td>[入住日期]</td>
- <td>
- <span class="update1_h hide_f room_count_txt">[间数1]</span>
- <select class="form-control update1_s room_count" style="width: 40px;padding:0px">
- [间数2]
- </select>
- </td>
- <td>
- <span class="update2_s sale_single_price_txt">[销售单价]</span>
- <input data-price="[销售单价]" type="text" class="form-control hide_f update2_h sale_single_price" style="width: 80px;" value="[销售单价]">
- </td>
- <td>
- <span class="update3_s cai_base_price_txt">[采购成本价]</span>
- <input data-price="[采购成本价]" type="text" class="form-control hide_f update3_h cai_base_price" style="width: 80px;" value="[采购成本价]">
- </td>
- <td class="tr_all_price">[销售总价]</td>
- <td class="tr_all_commission" data-commission=[渠道佣金]>[渠道佣金]</td>
- <td class="tr_profit_value">[利润]</td>
- </tr>`;
- HTML = HTML.replace('[入住日期]', v['run_date']);
- //得到替换数量,逻辑:先判断超售oversell_flag,1为可以超售,如果可以超售则取data['order_list'][1]中的该天所有库存,超了不能下单。
- let count = 0;
- if(1 == v['oversell_flag'] && -1 != v['remaining_count']) {
- stock_list.forEach((v2, i2) => {
- if(v['run_date'] == v2['run_date']) {
- count += parseInt(v2['remaining_count']);
- if("228" == v2['stock_type']) { //买断
- HTML = HTML.replace('[data-json-maiduan]', JSON.stringify(v2));
- } else if("229" == v2['stock_type']) { //现询
- HTML = HTML.replace('[data-json-xianxun]', JSON.stringify(v2));
- } else if("230" == v2["stock_type"]) { //保留
- HTML = HTML.replace('[data-json-baoliu]', JSON.stringify(v2));
- } else {
- ZZAlertInfo('没有该库存类型');
- }
- }
-
- })
- } else {
-
- stock_list.forEach((v2, i2) => {
- if(v['run_date'] == v2['run_date']) {
- if("228" == v2['stock_type']) { //买断
- count += parseInt(v2['remaining_count']);
- HTML = HTML.replace('[data-json-maiduan]', JSON.stringify(v2));
- } else if("229" == v2['stock_type']) { //现询
- HTML = HTML.replace('[data-json-xianxun]', JSON.stringify(v2));
- } else if("230" == v2["stock_type"]) { //保留
- count += parseInt(v2['remaining_count']);
- HTML = HTML.replace('[data-json-baoliu]', JSON.stringify(v2));
- } else {
- ZZAlertInfo('没有该库存类型');
- }
- }
- })
- count = parseInt(v['remaining_count'] == -1 ? 0 : v['remaining_count']);
- }
- let optionHTML = '';
- for(let m = 0; m <= count; m++) {
- if(m > 20) break;
- let temp = `<option value="${m}">${m}</option>`;
- optionHTML += temp;
- }
- HTML = HTML.replace('[间数2]', optionHTML);
- HTML = HTML.replace(/\[销售单价]/g, v['price']);
-
- HTML = HTML.replace(/\[采购成本价]/g, v['price']);
-
- //佣金规则
- let ling = 0;
- let ling1 = ling.toFixed(2);
- if(0 == v['commission_flag']) { //为0不返佣 为1返佣
- HTML = HTML.replace(/\[渠道佣金]/g, '-');
- } else {
- HTML = HTML.replace(/\[渠道佣金]/g, ling1);
- }
-
- HTML = HTML.replace('[销售总价]', ling1);
- HTML = HTML.replace('[利润]', ling1);
-
- //将非超卖库存存入data-json
- HTML = HTML.replace('[data-json]', JSON.stringify(v));
- sumHTML += HTML;
- })
- sumHTML += temp_all_html;
- $('#rz-table').html(sumHTML);
- $('.room_count').on('change', function() {
- $parent = $(this).closest('.tr_line');
- tr_change($parent);
- })
- let hotel_child_order_detail = {};
- if(cache_res_data.hasOwnProperty(order_id)) {
- hotel_child_order_detail = cache_res_data[order_id]['hotel_child_order_detail'];
- $('#rz-table .tr_line').each(function(index, dom) {
- for(let n = 0; n < hotel_child_order_detail.length; n++) {
- if(hotel_child_order_detail[n]['run_date'] == $(dom).find('td:first').text()) {
- let dict = hotel_child_order_detail[n];
- $(dom).find('.room_count').val(dict['total']); //间数
- $(dom).find('.sale_single_price_txt').text(dict['order_price']); //销售单价
- $(dom).find('.sale_single_price').attr('data-price', dict['order_price']);
- $(dom).find('.sale_single_price').attr('value', dict['order_price']);
-
- $(dom).find('.cai_base_price_txt').text(dict['base_price']); //采购成本价
- $(dom).find('.cai_base_price').attr('data-price', dict['base_price']);
- $(dom).find('.cai_base_price').attr('value', dict['base_price']);
-
- $(dom).find('.tr_all_price').html(dict['all_price']); //销售总价
- $(dom).find('.tr_profit_value').text(dict['benefit']); //利润
-
- //根据不同类型,选择不同库存
- let json_type = '';
- if("228" == dict['stock_type']) json_type = "data-json-maiduan";
- if("229" == dict['stock_type']) json_type = "data-json-xianxun";
- if("230" == dict['stock_type']) json_type = "data-json-baoliu";
-
- let tr_json_data = $(dom).attr(json_type);
- if(tr_json_data != '' && tr_json_data.indexOf('[data-json') == -1) {
- let tmp_data = JSON.parse(tr_json_data);
- tmp_data['remaining_count'] = parseInt(tmp_data['remaining_count']) + parseInt(dict['total']);
- var json_str = JSON.stringify(tmp_data);
- $(dom).attr(json_type, json_str);
- }
- let count = parseInt($(dom).find('.room_count option:last').html());
- let new_count = count + parseInt(dict['total']);
- for(var i = count + 1; i <= new_count && i < 20; i++) {
- $(dom).find('.room_count option:last').after('<option value="' + i + '">' + i + '</option>');
- }
- $(dom).find('.room_count').val(dict['total']).change();
- }
- }
- })
- }
- //刷新总计
- total_price_jisuan();
- }
-
- $('#btn-rz-update-xq').on('click', function() {
- //1:修改入住需求 2:保存并生成修改单 3:保存
- let btn_status = $(this).attr('data-btn-status') ? $(this).attr('data-btn-status') : "1";
- if('1' == btn_status) {
- ZZLog('修改入住需求');
- $('#btn-rz-cancel').attr('data-main-status', '1');
- $('#btn-rz-cancel').removeClass('hide_f');
- $('#btn-rz-update-xsj').addClass('hide_f');
- $('#btn-rz-update-cgj').addClass('hide_f');
- //切换编辑状态
- $('.update1_h').removeClass('hide_f');
- $('.update1_s').addClass('hide_f');
- changeStartEndDate();
- click_three_btn($(this));
- }
- if('2' == btn_status || "3" == btn_status) {
- ZZLog('保存入住需求');
- commit($(this));
-
- }
-
- })
-
- function commit($this) {
- //提交的参数
- let hotel_id = '';
- let room_type = '';
- if(cache_res_data.hasOwnProperty(order_id)) {
- hotel_id = cache_res_data[order_id]['order_info']['hotel_id'];
- room_type = cache_res_data[order_id]['order_info']['room_type'];
- }
- if('' == hotel_id || '' == room_type) {
- ZZAlertInfo('缺少参数,逻辑出错');
- return;
- }
- //获取联系人,联系方式,备注
- var contacts = $('#customer_name').val().replace(/\,/g, ' ').trim();
- var phone = $('#customer_phone').val();
- var more = '',
- total = 0;
- //拒单标识0为不能拒单,1为可以拒单
- var if_cancel = 0;
-
- let cus_list = `{${contacts},${phone},${more}}`;
- //最晚到店时间
- let checkin_time = "23:59";
- let org_num = $('#order_channel_order_id').val();
- let org_id = $('#order_channel').val();
- //房型列表
- let room_list = '';
- let room_count = 0;
- let dan_yongj = 0;
- let all_yongj = $('.all_commission').attr('data-value');
- let all_profit = $('.all_profit').attr('data-value');
- let temp_arr = [];
- $('.tr_line').each(function(index, dom) {
- let start_date = $(this).children().eq(0).text();
- let all_count = $(this).find('.room_count').val();
- room_count += parseInt(all_count) - 0;
- if(all_count == 0) {
- temp_arr.push('1');
- // ZZAlertInfo('请选择库存');
- // return;
- }
- let dan_jiesuan = $(this).find('.sale_single_price').val();
- dan_yongj = 0;
- if("-" == $(this).find('.tr_all_commission').text()) dan_yongj = 0;
- if("-" != $(this).find('.tr_all_commission').text()) dan_yongj = parseFloat($(this).find('.tr_all_commission').text()) / parseInt(all_count);
- //获得买断,保留,现询的价格与库存
- let dict_maiduan = getJsonHtml($(this).attr('data-json-maiduan'));
- let dict_baoliu = getJsonHtml($(this).attr('data-json-baoliu'));
- let dict_xianxun = getJsonHtml($(this).attr('data-json-xianxun'));
-
- //库存类型与成本
- var maiduan_count = dict_maiduan == 0 ? 0 : dict_maiduan['remaining_count'];
- var baoliu_count = dict_baoliu == 0 ? 0 : dict_baoliu['remaining_count'];
- var xianxun_count = dict_xianxun == 0 ? 0 : dict_xianxun['remaining_count'];
- var maiduan_price = dict_maiduan == 0 ? 0 : dict_maiduan['cost_price'];
- var baoliu_price = dict_baoliu == 0 ? 0 : dict_baoliu['cost_price'];
- var xianxun_price = dict_xianxun == 0 ? 0 : dict_xianxun['cost_price'];
- if(maiduan_price == 0 && baoliu_price == 0 && xianxun_price == 0) {
- temp_arr.push('2');
- // ZZAlertInfo('存在成本价为零,请至对应房型列表确认');
- // return;
- }
- //判断库存
- var maiduan_field = '';
- var baoliu_field = '';
- var xianxun_field = '';
- var sum_field = '';
- if(parseInt(all_count) <= parseInt(maiduan_count)) { //小于等于买断库存228
- sum_field = '228' + ',' + all_count + ',' + maiduan_price
- } else if(parseInt(all_count) > parseInt(maiduan_count) && parseInt(all_count) <= (parseInt(maiduan_count) + parseInt(baoliu_count))) {
- maiduan_field = '228' + ',' + maiduan_count + ',' + maiduan_price;
- baoliu_field = '230' + ',' + (all_count - maiduan_count) + ',' + baoliu_price;
- sum_field = maiduan_field + '|' + baoliu_field
- } else if(parseInt(all_count) > (parseInt(maiduan_count) + parseInt(baoliu_count)) && parseInt(all_count) <= (parseInt(maiduan_count) + parseInt(baoliu_count) + parseInt(xianxun_count))) {
- if_cancel = 1;
- maiduan_field = '228' + ',' + maiduan_count + ',' + maiduan_price;
- baoliu_field = '230' + ',' + baoliu_count + ',' + baoliu_price;
- xianxun_field = '229' + ',' + (all_count - baoliu_count - maiduan_count) + ',' + xianxun_price;
- sum_field = maiduan_field + '|' + baoliu_field + '|' + xianxun_field
- } else {
- // alert('出错了,不可能!!');
- temp_arr.push('3');
- // return;
- }
-
- room_list += '{\'\'' + start_date + '\'\',' + all_count + ',' + dan_jiesuan + ',' + dan_yongj + '}';
- total += all_count;
-
- })
- if($.inArray('1', temp_arr) >= 0) {
- ZZAlertInfo('请选择库存');
- return;
- } else if($.inArray('2', temp_arr) >= 0) {
- ZZAlertInfo('存在成本价为零,请至对应房型列表确认');
- return;
- } else if($.inArray('3', temp_arr) >= 0) {
- ZZAlertInfo('出错了,不可能!!');
- return;
- } else {}
- let start_date = $('#start_date').children().eq(0).val();
- let end_date = $('#end_date').children().eq(0).val();
- let data = {
- // type: "order_ModifyHTOrder",
- // op: "modify_order",
- type: "order_ModifyHTOrderLevel",
- op: "orderUpdateCheckIn",
- hotel_id: hotel_id,
- room_type: room_type,
- org_id: org_id,
- org_num: org_num,
- room_list: room_list,
- room_count: room_count,
- cus_list: cus_list,
- contact: contacts,
- mobile: phone,
- start_date: start_date,
- end_date: end_date,
- // memo: more,
- // total: total,//这两个参数 php没有接收
- checkin_time: checkin_time,
- if_cancel: if_cancel,
- order_id: order_id,
- total_commission: all_yongj,
- benefit: all_profit
- }
- ZZLog(JSON.stringify(data));
- $.ajax({
- type: "post",
- url: base_api,
- async: true,
- data: data,
- dataType: "json",
- success: (res_data) => {
- ZZLog(res_data);
- if(res_data['code'] != "0") {
- ZZAlertInfo(res_data['info']);
- } else {
- //在这里写保存的操作
- $('#btn-rz-cancel').addClass('hide_f');
- $('#btn-rz-update-xsj').removeClass('hide_f');
- $('#btn-rz-update-cgj').removeClass('hide_f');
- //浏览状态
- $('.update1_h').addClass('hide_f');
- $('.update1_s').removeClass('hide_f');
- $(this).attr('data-btn-status', '1');
- $(this).html('修改入住需求');
- httpLoadInfo();
- }
- },
- error: () => {
- ZZAlertInfo(infoApiError);
- }
- });
- }
- //修改销售价
- $('#btn-rz-update-xsj').on('click', function() {
- //1:修改销售价 2:保存销售价
-
- let btn_status = $(this).attr('data-btn-status') ? $(this).attr('data-btn-status') : "1";
- if('1' == btn_status) {
- ZZLog('修改销售价');
- $('#btn-rz-cancel').attr('data-main-status', '2');
- $('#btn-rz-cancel').removeClass('hide_f');
- $('#btn-rz-update-xq').addClass('hide_f');
- $('#btn-rz-update-cgj').addClass('hide_f');
- $(this).attr('data-btn-status', '2');
- $(this).html(save_info);
- //切换编辑状态
- $('.update2_h').removeClass('hide_f');
- $('.update2_s').addClass('hide_f');
-
- }
- if('2' == btn_status) {
- ZZLog('保存销售价');
- //在这里写保存的操作
- $('#btn-rz-cancel').addClass('hide_f');
- $('#btn-rz-update-xq').removeClass('hide_f');
- $('#btn-rz-update-cgj').removeClass('hide_f');
- $(this).attr('data-btn-status', '1');
- $(this).html('修改销售价');
- //浏览状态
- $('.update2_h').addClass('hide_f');
- $('.update2_s').removeClass('hide_f');
-
- let room_list = [];
- $('.tr_line').each(function(index, dom) {
- let run_date = $(this).children().eq(0).text();
- let old = $(this).find('.sale_single_price').attr('data-price');
- let sale_single_price = $(this).find('.sale_single_price').val();
- if(old != sale_single_price) {
- let obj = {
- run_date,
- "order_price": sale_single_price
- };
- room_list.push(obj);
- }
- })
-
- let data = {
- type: "order_ModifyHTOrderLevel",
- op: "orderUpdateXSJ",
- order_id,
- room_list: JSON.stringify(room_list)
- }
- $.ajax({
- type: "post",
- url: base_api,
- async: true,
- data: data,
- dataType: "json",
- success: (res_data) => {
- ZZLog(res_data);
- if(res_data['code'] != "0") {
- ZZAlertInfo(res_data['info']);
- } else {
- httpLoadInfo();
- }
- },
- error: () => {
- ZZAlertInfo(infoApiError);
- }
- });
- }
- })
- //修改采购价
- $('#btn-rz-update-cgj').on('click', function() {
-
- //1:修改采购价 2:保存并生成修改单 3:保存采购价
- let btn_status = $(this).attr('data-btn-status') ? $(this).attr('data-btn-status') : "1";
- if('1' == btn_status) {
- ZZLog('修改采购价');
- $('#btn-rz-cancel').attr('data-main-status', '3');
- $('#btn-rz-cancel').removeClass('hide_f');
- $('#btn-rz-update-xq').addClass('hide_f');
- $('#btn-rz-update-xsj').addClass('hide_f');
- //切换编辑状态
- $('.update3_h').removeClass('hide_f');
- $('.update3_s').addClass('hide_f');
-
- click_three_btn($(this));
- }
- if('2' == btn_status || "3" == btn_status) {
- ZZLog('保存采购价');
- //在这里写保存的操作
- $('#btn-rz-cancel').addClass('hide_f');
- $('#btn-rz-update-xq').removeClass('hide_f');
- $('#btn-rz-update-xsj').removeClass('hide_f');
- $(this).attr('data-btn-status', '1');
- $(this).html('修改采购价');
- //浏览状态
- $('.update3_h').addClass('hide_f');
- $('.update3_s').removeClass('hide_f');
-
- let cus_list = [];
- $('.tr_line').each(function(index, dom) {
- let run_date = $(this).children().eq(0).text();
- let old = $(this).find('.cai_base_price').attr('data-price');
- let base_price = $(this).find('.cai_base_price').val();
- if(old != base_price) {
- let obj = {
- run_date,
- "base_price": base_price
- };
- cus_list.push(obj);
- }
- })
-
- let data = {
- type: "order_ModifyHTOrderLevel",
- op: "orderUpdateCGJ",
- order_id,
- cus_list: JSON.stringify(cus_list)
- }
- $.ajax({
- type: "post",
- url: base_api,
- async: true,
- data: data,
- dataType: "json",
- success: (res_data) => {
- ZZLog(res_data);
- if(res_data['code'] != "0") {
- ZZAlertInfo(res_data['info']);
- } else {
- httpLoadInfo();
- }
- },
- error: () => {
- ZZAlertInfo(infoApiError);
- }
- });
-
- }
- })
-
- //入住需求取消
- $('#btn-rz-cancel').on('click', function() {
- //data-main-status 1:修改入住需求 2:修改销售价 3:修改采购价
- var btn_main_status = $(this).attr('data-main-status') ? $(this).attr('data-main-status') : "1";
-
- if('1' == btn_main_status) {
- //修改入住需求
- ZZLog('入住需求取消-修改入住需求');
- $('#btn-rz-update-xq').html('修改入住需求');
- $('#btn-rz-update-xq').attr('data-btn-status', '1');
- }
- if('2' == btn_main_status) {
- //修改销售价
- ZZLog('入住需求取消-修改销售价');
- $('#btn-rz-update-xsj').html('修改销售价');
- $('#btn-rz-update-xsj').attr('data-btn-status', '1');
- }
- if('3' == btn_main_status) {
- //修改采购价
- ZZLog('入住需求取消-修改采购价');
- $('#btn-rz-update-cgj').html('修改采购价');
- $('#btn-rz-update-cgj').attr('data-btn-status', '1');
- }
-
- $(this).addClass('hide_f');
- $('#btn-rz-update-xq').removeClass('hide_f');
- $('#btn-rz-update-xsj').removeClass('hide_f');
- $('#btn-rz-update-cgj').removeClass('hide_f');
-
- $('.update1_s').removeClass('hide_f');
- $('.update1_h').addClass('hide_f');
- $('.update2_s').removeClass('hide_f');
- $('.update2_h').addClass('hide_f');
- $('.update3_s').removeClass('hide_f');
- $('.update3_h').addClass('hide_f');
-
- if(cache_res_data.hasOwnProperty(order_id)) {
- loadHtml(cache_res_data[order_id]);
- }
-
- })
- //客人修改
- $('#btn-customer-update').on('click', function() {
- //1:客人信息修改 2:保存并生成修改单 3:保存
- ZZLog('客人信息修改');
- let btn_status = $(this).attr('data-btn-status') ? $(this).attr('data-btn-status') : "1";
- if('1' == btn_status) {
- $('#btn-customer-cancel').removeClass('hide_f');
- click_customer_update1($(this));
- $('.update4_h').removeClass('hide_f');
- $('.update4_s').addClass('hide_f');
- }
- if('2' == btn_status || '3' == btn_status) {
- customer_cancel_css();
-
- let customer_name = $('#customer_name').val().trim();
- let customer_mobile = $('#customer_phone').val().trim();
-
- let old_customer_name = $('#customer_name_txt').text();
- let old_customer_mobile = $('#customer_phone_txt').text();
-
- if(old_customer_name == customer_name && old_customer_mobile == customer_mobile) {
- return;
- }
-
- let data = {
- type: "order_ModifyHTOrderLevel",
- op: "customerUpdate",
- order_id,
- customer_name,
- customer_mobile
- }
- $.ajax({
- type: "post",
- url: base_api,
- async: true,
- data: data,
- dataType: 'json',
- success: (res_data) => {
- ZZLog(res_data);
- if(res_data['code'] != "0") {
- ZZAlertInfo(res_data['info']);
- } else {
- httpLoadInfo();
- httpLoadLog(); //重新加载log
- }
- },
- error: () => {
- ZZAlertInfo(infoApiError);
- }
- });
-
- }
-
- })
-
- function click_customer_update1($this) {
- let btn_status = '';
- let btn_info = '';
- let status_arr1 = ["313"];
- let status_arr2 = ["198", "382"];
-
- if($.inArray(temp_order_status, status_arr1) >= 0) {
- btn_status = '3';
- btn_info = save_info;
- }
- if($.inArray(temp_order_status, status_arr2) >= 0) {
- btn_status = '2';
- btn_info = save_update_info;
- }
- // //1.录单
- // if("557" == temp_docking_type) {
- // }
- // //2.直连
- // if("556" == temp_docking_type) {
- // }
-
- $this.attr('data-btn-status', btn_status);
- $this.html(btn_info);
- }
- //客人取消
- $('#btn-customer-cancel').on('click', function() {
- ZZLog('客人信息取消');
- customer_cancel_css();
- })
- $('.comment-type').on('click', function() {
- $('.comment-type0').removeClass('comment_selected');
- $('.comment-type1').removeClass('comment_selected');
- $(this).addClass('comment_selected');
- if($(this).hasClass('comment-type0')) {
- //内部备注
- $(this).removeClass('btn-default');
- $(this).addClass('btn-primary');
- $('#btn-order-remark-save-update-d').html('保存');
- $('.comment-type1').removeClass('btn-primary');
- $('.comment-type1').addClass('btn-default');
- }
- if($(this).hasClass('comment-type1')) {
- //公共备注
- $(this).removeClass('btn-default');
- $(this).addClass('btn-primary');
-
- let btn_info = '';
- let status_arr1 = ['313'];
- let status_arr2 = ["198", "382"];
- if($.inArray(temp_order_status, status_arr1) >= 0) btn_info = save_info;
- if($.inArray(temp_order_status, status_arr2) >= 0) btn_info = save_update_info;
- $('#btn-order-remark-save-update-d').html(btn_info);
- // $('#btn-order-remark-save-update-d').html('保存并生成修改单');
- $('.comment-type0').removeClass('btn-primary');
- $('.comment-type0').addClass('btn-default');
- }
-
- })
-
- //备注保存并生成修改单
- $('#btn-order-remark-save-update-d').on('click', function() {
- ZZLog('备注保存并生成修改单');
-
- let comment_type = $('.comment_selected').attr('data-value');
- let comment_txt = $('#comment-txt').val();
-
- let data = {
- type: "order_ModifyHTOrderLevel",
- op: "commentAdd",
- order_id,
- comment_type,
- comment_txt
- }
- $.ajax({
- type: "post",
- url: base_api,
- async: true,
- data: data,
- dataType: "json",
- success: (res_data) => {
- ZZLog(res_data);
- if(res_data['code'] != "0") {
- ZZAlertInfo(res_data['info']);
- } else {
- $('#comment-txt').val('');
- $('#comment-type').val('0');
- httpLoadInfo();
- }
- },
- error: () => {
- ZZAlertInfo(infoApiError);
- }
- });
-
- })
-
- //客人取消
- function customer_cancel_css() {
- $('#btn-customer-cancel').addClass('hide_f');
- $('#btn-customer-update').attr('data-btn-status', '1');
- $('#btn-customer-update').html('修改');
- $('.update4_h').addClass('hide_f');
- $('.update4_s').removeClass('hide_f');
- }
-
- //时间戳转换函数
- function getLocalTime(nS) {
- return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/, ' ');
- }
- //取出html存入的json
- function getJsonHtml(data) {
- if(data && data.indexOf('[') == -1) {
- var data_info = JSON.parse(data);
- return data_info;
- } else {
- return 0
- }
- }
- //制保留2位小数,如:2,会在2后面补上00.即2.00
- function toDecimal2(x) {
- var f = parseFloat(x);
- if(isNaN(f)) {
- return false;
- }
- var f = Math.round(x * 100) / 100;
- var s = f.toString();
- var rs = s.indexOf('.');
- if(rs < 0) {
- rs = s.length;
- s += '.';
- }
- while(s.length <= rs + 2) {
- s += '0';
- }
- return s;
- }
-
- function click_three_btn($this) {
-
- let btn_status = '';
- let btn_info = '';
- let status_arr1 = ['313'];
- let status_arr2 = ["198", "382"];
- if($.inArray(temp_order_status, status_arr1) >= 0) {
- btn_status = '3';
- btn_info = save_info;
- }
- if($.inArray(temp_order_status, status_arr2) >= 0) {
- btn_status = '2';
- btn_info = save_update_info;
- }
- $this.attr('data-btn-status', btn_status);
- $this.html(btn_info);
-
- }
|