/** * Created by luocj on 2016/12/15. */ var main_tr = $('.main_tr').prop('outerHTML'); var up_tr = $('.up_tr').prop('outerHTML'); var date_type = 1; var start_date = getDateTime(0); var end_date = getDateTime(0); var province = ''; var city = ''; var hotel_name = ''; var supplier_id = ''; var sale_org_id = ''; var provinceHTML = $('#province').html(); var cityHTML = $('#city').html(); var supp_op = $('.supp').prop('outerHTML'); var sale_op = $('.sale').prop('outerHTML'); window.onload = function () { $('#start_date').val(getDateTime(0)); $('#end_date').val(getDateTime(0)); getMainInfo(); getProvince(); dateFliter(); getSuppSaleInfo(); excel() }; function getMainInfo() { date_type = $('#date_type').val(); start_date = $('#start_date').val(); end_date = $('#end_date').val(); province = $('#province').val() == 0 ? '' : $('#province').val(); city = $('#city').val() == 0 ? '' : $('#city').val(); hotel_name = $('#hotel_name').val(); supplier_id = $('#supplier_id').val(); sale_org_id = $('#sale_org_id').val(); var param = { type: 'finance_ApiStatisticalReport', op:'getInfo', date_type: date_type, start_date: start_date, end_date: end_date, province: province, city: city, hotel_name: hotel_name, supplier_id: supplier_id, org_sale_id: sale_org_id }; ZZLog(param); $.ajax({ url: base_api, type: 'post', dateType: 'json', data: param, success: function (res_data) { var data = JSON.parse(res_data); ZZLog(data); if (data['code'] == 0) { setMainInfo(data); } else { ZZAlertInfo(data['info'], function () { return; }) } }, error: function (e) { ZZLog(e); } }) } //替换主体订单 function setMainInfo(data) { var sumHTML = ''; var allHTML = up_tr; //替换总计 var dict_sum = data['sum'] ? data['sum'] : ''; ZZLog(dict_sum['order_num']); if (dict_sum) { allHTML = allHTML.replace('[订单数]', dict_sum['order_num']); allHTML = allHTML.replace('[间夜数]', dict_sum['jianyecount']); allHTML = allHTML.replace('[间夜数月环比]', dict_sum['jianyecount_before'] ? (((dict_sum['jianyecount'] - dict_sum['jianyecount_before']) / dict_sum['jianyecount_before']).toFixed(2) + '%') : ''); allHTML = allHTML.replace('[销售额]', dict_sum['all_order_price']); allHTML = allHTML.replace('[销售额月环比]', dict_sum['all_order_price_before'] ? (((dict_sum['all_order_price'] - dict_sum['all_order_price_before']) / dict_sum['all_order_price_before']).toFixed(2) + '%') : ''); allHTML = allHTML.replace('[采购成本]', dict_sum['all_base_price']); allHTML = allHTML.replace('[渠道佣金]', dict_sum['all_total_commission']); allHTML = allHTML.replace('[毛利]', dict_sum['all_profit']); allHTML = allHTML.replace('[毛利月环比]', ((dict_sum['all_profit_before'] != undefined) && (dict_sum['all_profit_before'] != 0.00)) ? (((dict_sum['all_profit'] - dict_sum['all_profit_before']) / dict_sum['all_profit_before']).toFixed(2) + '%') : ''); allHTML = allHTML.replace('[毛利率]', dict_sum['all_order_price'] ? (((dict_sum['all_profit'] / dict_sum['all_order_price']).toFixed(2)) * 100 + '%') : ''); sumHTML += allHTML; } for (var i = 0, m = data['rowset'].length; i < m; i++) { var HTML = main_tr; var dict = data['rowset'][i]; HTML = HTML.replace('[酒店]', dict['hotel_name']); HTML = HTML.replace('[订单数]', dict['order_num']); HTML = HTML.replace('[间夜数]', dict['jianyecount']); HTML = HTML.replace('[间夜数月环比]', dict['jianyecount_before'] ? (((dict['jianyecount'] - dict['jianyecount_before']) / dict['jianyecount_before']).toFixed(2) + '%') : ''); HTML = HTML.replace('[销售额]', dict['all_order_price']); HTML = HTML.replace('[销售额月环比]', dict['all_order_price_before'] ? (((dict['all_order_price'] - dict['all_order_price_before']) / dict['all_order_price_before']).toFixed(2) + '%') : ''); HTML = HTML.replace('[采购成本]', dict['all_base_price']); HTML = HTML.replace('[渠道佣金]', dict['all_total_commission']); HTML = HTML.replace('[毛利]', dict['all_profit']); HTML = HTML.replace('[毛利月环比]', ((dict['all_profit_before'] != undefined) && (dict['all_profit_before'] != 0.00)) ? (((dict['all_profit'] - dict['all_profit_before']) / dict['all_profit_before']).toFixed(2) + '%') : ''); HTML = HTML.replace('[毛利率]', dict['all_order_price'] ? (((dict['all_profit'] / dict['all_order_price']).toFixed(2)) * 100 + '%') : ''); sumHTML += HTML; } $('#main_tbody').html(sumHTML); } //省 function getProvince() { 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 dateFliter() { //点击查询 $('#search').bind('click', function () { getMainInfo() }); //昨日日期 $('#yesterday').bind('click', function () { $("#start_date").val(getDateTime(10)); $("#end_date").val(getDateTime(10)); getMainInfo() }); //今日日期 $('#today').bind('click', function () { $("#start_date").val(getDateTime(0)); $("#end_date").val(getDateTime(0)); getMainInfo() }); //本周日期 $('#thisweek').bind('click', function () { $("#start_date").val(after(getDateTime(12))); $("#end_date").val(after(getDateTime(13))); getMainInfo() }); //本月日期 $('#thismonth').bind('click', function () { $("#start_date").val(getDateTime(14)); $("#end_date").val(getDateTime(15)); getMainInfo() }); //选择省的事件 $('#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; } } }) }); } //获取供应商与渠道商 function getSuppSaleInfo() { //供应商 $.ajax({ url: base_api, type: 'post', dataType: 'json', data: { op: 'supp', type: 'finance_ApiSuppSaleInfo' }, success: function (res_data) { ZZLog(res_data); if (res_data['code'] == 0) { var sumHTML = supp_op; for (var i = 0, m = res_data['rowset'].length; i < m; i++) { var HTML = supp_op; var dict = res_data['rowset'][i]; HTML=HTML.replace('请选择',dict['supplier_name']); HTML=HTML.replace('0',dict['id']); sumHTML+=HTML; } $('#supplier_id').html(sumHTML); $('.select_line').comboSelect(); } else { ZZAlertInfo(res_data['info']) } }, error: function (e) { ZZLog(e); } }); //渠道商 $.ajax({ url: base_api, type: 'post', dataType: 'json', data: { op: 'sale', type: 'finance_ApiSuppSaleInfo' }, success: function (res_data) { ZZLog(res_data); if (res_data['code'] == 0) { var sumHTML = sale_op; for (var i = 0, m = res_data['rowset'].length; i < m; i++) { var HTML = sale_op; var dict = res_data['rowset'][i]; HTML=HTML.replace('请选择',dict['sale_org_name']); HTML=HTML.replace('0',dict['id']); sumHTML+=HTML; } $('#sale_org_id').html(sumHTML); $('.select_line').comboSelect(); } else { ZZAlertInfo(res_data['info']) } }, error: function (e) { ZZLog(e); } }); } //导出函数 function excel() { $('#excel').on('click',function () { date_type = $('#date_type').val(); start_date = $('#start_date').val(); end_date = $('#end_date').val(); province = $('#province').val() == 0 ? '' : $('#province').val(); city = $('#city').val() == 0 ? '' : $('#city').val(); hotel_name = $('#hotel_name').val(); supplier_id = $('#supplier_id').val(); sale_org_id = $('#sale_org_id').val(); window.location.href = "/zz-jd/st-ht/HTcontrol.php?type=finance_ApiStatisticalReport&op=excel&date_type=" + date_type + "&start_date="+start_date+"&end_date="+end_date+"&province="+province+"&city="+city+"&hotel_name="+hotel_name+"&supplier_id="+supplier_id+"&org_sale_id="+sale_org_id; }) }