You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

270 lines
11 KiB

  1. /**
  2. * Created by luocj on 2016/12/15.
  3. */
  4. var main_tr = $('.main_tr').prop('outerHTML');
  5. var up_tr = $('.up_tr').prop('outerHTML');
  6. var date_type = 1;
  7. var start_date = getDateTime(0);
  8. var end_date = getDateTime(0);
  9. var province = '';
  10. var city = '';
  11. var hotel_name = '';
  12. var supplier_id = '';
  13. var sale_org_id = '';
  14. var provinceHTML = $('#province').html();
  15. var cityHTML = $('#city').html();
  16. var supp_op = $('.supp').prop('outerHTML');
  17. var sale_op = $('.sale').prop('outerHTML');
  18. window.onload = function () {
  19. $('#start_date').val(getDateTime(0));
  20. $('#end_date').val(getDateTime(0));
  21. getMainInfo();
  22. getProvince();
  23. dateFliter();
  24. getSuppSaleInfo();
  25. excel()
  26. };
  27. function getMainInfo() {
  28. date_type = $('#date_type').val();
  29. start_date = $('#start_date').val();
  30. end_date = $('#end_date').val();
  31. province = $('#province').val() == 0 ? '' : $('#province').val();
  32. city = $('#city').val() == 0 ? '' : $('#city').val();
  33. hotel_name = $('#hotel_name').val();
  34. supplier_id = $('#supplier_id').val();
  35. sale_org_id = $('#sale_org_id').val();
  36. var param = {
  37. type: 'finance_ApiStatisticalReport',
  38. op:'getInfo',
  39. date_type: date_type,
  40. start_date: start_date,
  41. end_date: end_date,
  42. province: province,
  43. city: city,
  44. hotel_name: hotel_name,
  45. supplier_id: supplier_id,
  46. org_sale_id: sale_org_id
  47. };
  48. ZZLog(param);
  49. $.ajax({
  50. url: base_api,
  51. type: 'post',
  52. dateType: 'json',
  53. data: param,
  54. success: function (res_data) {
  55. var data = JSON.parse(res_data);
  56. ZZLog(data);
  57. if (data['code'] == 0) {
  58. setMainInfo(data);
  59. } else {
  60. ZZAlertInfo(data['info'], function () {
  61. return;
  62. })
  63. }
  64. },
  65. error: function (e) {
  66. ZZLog(e);
  67. }
  68. })
  69. }
  70. //替换主体订单
  71. function setMainInfo(data) {
  72. var sumHTML = '';
  73. var allHTML = up_tr;
  74. //替换总计
  75. var dict_sum = data['sum'] ? data['sum'] : '';
  76. ZZLog(dict_sum['order_num']);
  77. if (dict_sum) {
  78. allHTML = allHTML.replace('[订单数]', dict_sum['order_num']);
  79. allHTML = allHTML.replace('[间夜数]', dict_sum['jianyecount']);
  80. allHTML = allHTML.replace('[间夜数月环比]', dict_sum['jianyecount_before'] ? (((dict_sum['jianyecount'] - dict_sum['jianyecount_before']) / dict_sum['jianyecount_before']).toFixed(2) + '%') : '');
  81. allHTML = allHTML.replace('[销售额]', dict_sum['all_order_price']);
  82. 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) + '%') : '');
  83. allHTML = allHTML.replace('[采购成本]', dict_sum['all_base_price']);
  84. allHTML = allHTML.replace('[渠道佣金]', dict_sum['all_total_commission']);
  85. allHTML = allHTML.replace('[毛利]', dict_sum['all_profit']);
  86. 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) + '%') : '');
  87. allHTML = allHTML.replace('[毛利率]', dict_sum['all_order_price'] ? (((dict_sum['all_profit'] / dict_sum['all_order_price']).toFixed(2)) * 100 + '%') : '');
  88. sumHTML += allHTML;
  89. }
  90. for (var i = 0, m = data['rowset'].length; i < m; i++) {
  91. var HTML = main_tr;
  92. var dict = data['rowset'][i];
  93. HTML = HTML.replace('[酒店]', dict['hotel_name']);
  94. HTML = HTML.replace('[订单数]', dict['order_num']);
  95. HTML = HTML.replace('[间夜数]', dict['jianyecount']);
  96. HTML = HTML.replace('[间夜数月环比]', dict['jianyecount_before'] ? (((dict['jianyecount'] - dict['jianyecount_before']) / dict['jianyecount_before']).toFixed(2) + '%') : '');
  97. HTML = HTML.replace('[销售额]', dict['all_order_price']);
  98. HTML = HTML.replace('[销售额月环比]', dict['all_order_price_before'] ? (((dict['all_order_price'] - dict['all_order_price_before']) / dict['all_order_price_before']).toFixed(2) + '%') : '');
  99. HTML = HTML.replace('[采购成本]', dict['all_base_price']);
  100. HTML = HTML.replace('[渠道佣金]', dict['all_total_commission']);
  101. HTML = HTML.replace('[毛利]', dict['all_profit']);
  102. 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) + '%') : '');
  103. HTML = HTML.replace('[毛利率]', dict['all_order_price'] ? (((dict['all_profit'] / dict['all_order_price']).toFixed(2)) * 100 + '%') : '');
  104. sumHTML += HTML;
  105. }
  106. $('#main_tbody').html(sumHTML);
  107. }
  108. //省
  109. function getProvince() {
  110. var apiurl = base_api + "?type=hotel_AddHotelProduct&op=provinceCity &area_id=";
  111. ZZLog(apiurl);
  112. $.getJSON(apiurl, function (res_data) {
  113. ZZLog(res_data);
  114. if (res_data['code'] != "0") {
  115. ZZAlertInfo(res_data['info']);
  116. } else {
  117. //地区
  118. var area_list = res_data['area_list'];
  119. var areaHTML = '<option value="0" style="font-size:12px;">选择省</option>';
  120. for (var i = 0, m = area_list.length; i < m; i++) {
  121. var tempDict = area_list[i];
  122. var tempHTML = provinceHTML;
  123. tempHTML = tempHTML.replace('选择省', tempDict['area_name']);
  124. tempHTML = tempHTML.replace('0', tempDict['area_id']);
  125. areaHTML += tempHTML;
  126. }
  127. $('#province').html(areaHTML);
  128. $('#province')[0].selectedIndex = 0;
  129. }
  130. })
  131. }
  132. //查询 昨日今日本周本月
  133. function dateFliter() {
  134. //点击查询
  135. $('#search').bind('click', function () {
  136. getMainInfo()
  137. });
  138. //昨日日期
  139. $('#yesterday').bind('click', function () {
  140. $("#start_date").val(getDateTime(10));
  141. $("#end_date").val(getDateTime(10));
  142. getMainInfo()
  143. });
  144. //今日日期
  145. $('#today').bind('click', function () {
  146. $("#start_date").val(getDateTime(0));
  147. $("#end_date").val(getDateTime(0));
  148. getMainInfo()
  149. });
  150. //本周日期
  151. $('#thisweek').bind('click', function () {
  152. $("#start_date").val(after(getDateTime(12)));
  153. $("#end_date").val(after(getDateTime(13)));
  154. getMainInfo()
  155. });
  156. //本月日期
  157. $('#thismonth').bind('click', function () {
  158. $("#start_date").val(getDateTime(14));
  159. $("#end_date").val(getDateTime(15));
  160. getMainInfo()
  161. });
  162. //选择省的事件
  163. $('#province').bind('change', function () {
  164. var area_id = $(this).val();
  165. if (area_id == "0" || area_id == "") {
  166. $('#city').html(cityHTML);
  167. return;
  168. }
  169. var url = base_api + "?type=hotel_AddHotelProduct&op=provinceCity&area_id=" + area_id;
  170. ZZLog(url);
  171. $.getJSON(url, function (res_data) {
  172. ZZLog(res_data);
  173. if (res_data['code'] != "0") {
  174. ZZAlertInfo(res_data['info']);
  175. } else {
  176. //地区
  177. var area_list = res_data['area_list'];
  178. var areaHTML = '<option value="0" style="font-size: 12px;">选择市</option>';
  179. for (var i = 0, m = area_list.length; i < m; i++) {
  180. var tempDict = area_list[i];
  181. var tempHTML = cityHTML;
  182. tempHTML = tempHTML.replace('选择市', tempDict['area_name']);
  183. tempHTML = tempHTML.replace('0', tempDict['area_id']);
  184. areaHTML += tempHTML;
  185. }
  186. if (areaHTML) {
  187. $('#city').html(areaHTML);
  188. $('#city')[0].selectedIndex = 0;
  189. }
  190. }
  191. })
  192. });
  193. }
  194. //获取供应商与渠道商
  195. function getSuppSaleInfo() {
  196. //供应商
  197. $.ajax({
  198. url: base_api,
  199. type: 'post',
  200. dataType: 'json',
  201. data: {
  202. op: 'supp',
  203. type: 'finance_ApiSuppSaleInfo'
  204. },
  205. success: function (res_data) {
  206. ZZLog(res_data);
  207. if (res_data['code'] == 0) {
  208. var sumHTML = supp_op;
  209. for (var i = 0, m = res_data['rowset'].length; i < m; i++) {
  210. var HTML = supp_op;
  211. var dict = res_data['rowset'][i];
  212. HTML=HTML.replace('请选择',dict['supplier_name']);
  213. HTML=HTML.replace('0',dict['id']);
  214. sumHTML+=HTML;
  215. }
  216. $('#supplier_id').html(sumHTML);
  217. $('.select_line').comboSelect();
  218. } else {
  219. ZZAlertInfo(res_data['info'])
  220. }
  221. },
  222. error: function (e) {
  223. ZZLog(e);
  224. }
  225. });
  226. //渠道商
  227. $.ajax({
  228. url: base_api,
  229. type: 'post',
  230. dataType: 'json',
  231. data: {
  232. op: 'sale',
  233. type: 'finance_ApiSuppSaleInfo'
  234. },
  235. success: function (res_data) {
  236. ZZLog(res_data);
  237. if (res_data['code'] == 0) {
  238. var sumHTML = sale_op;
  239. for (var i = 0, m = res_data['rowset'].length; i < m; i++) {
  240. var HTML = sale_op;
  241. var dict = res_data['rowset'][i];
  242. HTML=HTML.replace('请选择',dict['sale_org_name']);
  243. HTML=HTML.replace('0',dict['id']);
  244. sumHTML+=HTML;
  245. }
  246. $('#sale_org_id').html(sumHTML);
  247. $('.select_line').comboSelect();
  248. } else {
  249. ZZAlertInfo(res_data['info'])
  250. }
  251. },
  252. error: function (e) {
  253. ZZLog(e);
  254. }
  255. });
  256. }
  257. //导出函数
  258. function excel() {
  259. $('#excel').on('click',function () {
  260. date_type = $('#date_type').val();
  261. start_date = $('#start_date').val();
  262. end_date = $('#end_date').val();
  263. province = $('#province').val() == 0 ? '' : $('#province').val();
  264. city = $('#city').val() == 0 ? '' : $('#city').val();
  265. hotel_name = $('#hotel_name').val();
  266. supplier_id = $('#supplier_id').val();
  267. sale_org_id = $('#sale_org_id').val();
  268. 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;
  269. })
  270. }