|
- var line_id = getPar('run_id');
- var run_date = getPar('run_date');
- var urlstr = base_api + 'orderManager/index.php';
- var listHTML = ''
- var newstr = base_api + 'index.php';
- var order_id = '';
- var old_data = [];
- var last_supplier_id='';
- var supplier_id= '';
- var line_name = '';
- window.onload = function () {
- $('#Wdate2').val(run_date);
- listHTML = $('#list').html();
- //修改订单时,先通过order_id获取run_date和line_id
- order_id = getPar('order_id');
- if (order_id != '') {
- //把日期设置为不可修改
- //$('#Wdate2').attr('disabled',true);
- $.ajax({
- url: newstr,
- data: {
- tp: 'order_groupOrder_getOrderInfo',
- order_id: order_id
- },
- type: "post",
- dataType: "json",
- async: false,
- success: function (data) {
- if (data.code == "0") {
- run_date = data.list[0]['PROD_START_STATION_DATE'];
- line_id = data.list[0]['LINE_ID'];
- line_name = data.list[0]['line_name'];
- old_data = data.list[0];
- supplier_id = data.list[0]['SUPPLIER_ID'];
- $('#hotel').val(data.list[0]['tavern_stay']);
- $('#substitute_add').val(data.list[0]['add_line_price']);
- var sel_text = data.list[0]['terrace'];
- $(".if_online").find('option[text='+sel_text+']').attr("selected",true);
- } else {
- ZZAlertInfo(data.info);
- }
- },
- error: function (e) {
- ZZLog(e);
- }
- });
- }
-
- reloadData();
- //载入时如果是修改订单,则重置订单值
- if (order_id != ''){
- initEditData();
- }
- //这里给上车站点的空间生成input加一个onblur事件
- $('.start_sta input').blur(function(){reset_sta()});
- total_collection();
-
- }
- //combo-select(bug)插件如果输入项没有对应值,则将显示值设置为厦门未知酒店
- function reset_sta(){
- if( $("#start_area").val()=='11964'){
- var name= $("#start_area").find("option[value='11964']").text();
- $('.start_sta input:eq(0)').val(name);
- }
- }
- //选择日期
- function selectDate() {
- run_date = $('#Wdate2').val();
- //新接口请求地址
- var newstr = base_api + 'index.php';
- var data = {
- tp: 'order_groupOrder_groupProductList',
- run_date: run_date,
- line_name:line_name,
- line_id:line_id
- };
- ZZLog(data);
- $.ajax({
- url: newstr,
- data: data,
- type: "post",
- dataType: "json",
- async: false,
- success: function (data) {
- if (data.code == "0") {
- console.log(data);
- if (data.product_list.length == 0) {
- // ZZAlertInfo('选择的日期没有相关的线路信息!');
- // $('#Wdate2').val(run_date);
-
- /*var newdate = getPar('run_date');
- $('#Wdate2').val(newdate);
- reloadData();*/
- ZZAlertInfo('选择的日期没有相关的线路信息!');
- //如果是修改订单,还原日期为修改前日期
- if (order_id != '') {
- $('#Wdate2').val(old_data['PROD_START_STATION_DATE']);
- run_date=old_data['PROD_START_STATION_DATE'];
- //如果是添加订单 ,还原日期为url上的run_date
- }else{
- var newdate = getPar('run_date');
- $('#Wdate2').val(newdate);
- run_date=newdate;
- }
- } else {
- //如果当前日期有组合线路
- $('#Wdate2').val(run_date);
- //这里判断一下原线路是否在新的可选线路中,如果有则选中该线路,否则新线路取第一项
- for(var item in data.product_list){
- if(data.product_list[item].line_id==line_id){
- var new_line_id=line_id;
- break;
- }
- }
- if(typeof new_line_id === 'undefined'){
- var new_line_id = data.product_list[0].line_id;
- }
- //按照新需求 修改逻辑 -白哥说的
- line_id=new_line_id;
- reloadData();
- }
-
- } else {
-
- ZZAlertInfo(data.info);
- }
- },
- error: function (e) {
- ZZLog(e);
- }
- });
-
- }
-
-
- //页面加载数据
- function reloadData() {
- var data = {
- tp: 'groupOrder_getProductBase',
- run_date: run_date,
- line_id: line_id
- };
- ZZLog(data);
-
- $.ajax({
- url: urlstr,
- data: data,
- type: "post",
- dataType: "json",
- async: false,
- success: function (data) {
- if (data.code == "0") {
- console.log(data);
- replaceData(data);
- } else {
- ZZAlertInfo(data.info);
- run_date = $('#Wdate2').val();
- }
- /*if (order_id != ''){
- initEditData();
- }*/
- total_collection();
-
- },
- error: function (e) {
- ZZLog(e);
- }
- });
- }
-
- //修改线路数据展示
- function replace1Data(data) {
- //修改线路列表
- var value=$('#channel_list').val();
- for(var item in data.channel_list){
- if(data.channel_list[item].supplier_id==$('#channel_list').val()){
- var new_supplier_id=data.channel_list[item].supplier_id;
- break;
- }
- }
- if(typeof new_supplier_id === 'undefined'){
- ZZConfirm('此线路无当前渠道信息,是否确认修改?', function (ok) {
- //修改线路列表
- changeLine();
- $('#line_code').html(data.line_name);
- var startHTML = '';
- var start_station = data.start_station;
- for (var i = 0; i < start_station.length; i++) {
- var tempHTML1 = '<option seq_id="[seq_id]" start_time="[start_time]" value="0">请选择</option>';
- tempHTML1 = tempHTML1.replace('请选择', start_station[i].res_name);
- tempHTML1 = tempHTML1.replace('0', start_station[i].res_id);
- tempHTML1 = tempHTML1.replace('[seq_id]', start_station[i].seq_id);
- tempHTML1 = tempHTML1.replace('[start_time]', start_station[i].start_time);
- startHTML += tempHTML1;
- }
- $('#start_area').html(startHTML);
- //如果始发站点 有 名为‘厦门未知酒店’的站点,则默认选中
- $('#start_area').comboSelect();
- $("#start_area").find("option[value='11964']").attr("selected", true);
- var new_supplier_id = data.channel_list[0].supplier_id;
- supplier_id=new_supplier_id;
- var channelHTML = '';
- var channel_list = data.channel_list;
- for (var j = 0; j < channel_list.length; j++) {
- var tempHTML = '<option saleman="[saleman]" value="0">请选择</option>';
- tempHTML = tempHTML.replace('请选择', channel_list[j].supplier_name);
- tempHTML = tempHTML.replace('0', channel_list[j].supplier_id);
- tempHTML = tempHTML.replace('[saleman]', channel_list[j].sales_man);
- $('#salesman').html(channel_list[0].sales_man);
- channelHTML += tempHTML;
- }
- $('#channel_list').html(channelHTML);
- $('.select_line').comboSelect();
- value = $('#channel_list').val();
- last_supplier_id = value;
- }, function (cancel) {
- value = last_supplier_id;
- }, function (close) {
- })
- }
- changeChannelSelected(value);
-
- }
- //首次加载数据
- function replaceData(data) {
- //修改线路列表
- changeLine();
-
- $('#line_code').html(data.line_name);
- var startHTML = '';
- var start_station = data.start_station;
- for (var i = 0; i < start_station.length; i++) {
- var tempHTML1 = '<option seq_id="[seq_id]" start_time="[start_time]" value="0">请选择</option>';
- tempHTML1 = tempHTML1.replace('请选择', start_station[i].res_name);
- tempHTML1 = tempHTML1.replace('0', start_station[i].res_id);
- tempHTML1 = tempHTML1.replace('[seq_id]', start_station[i].seq_id);
- tempHTML1 = tempHTML1.replace('[start_time]', start_station[i].start_time);
- startHTML += tempHTML1;
- }
- $('#start_area').html(startHTML);
- //如果始发站点 有 名为‘厦门未知酒店’的站点,则默认选中
- $('#start_area').comboSelect();
- $("#start_area").find("option[value='11964']").attr("selected", true);
-
- var channelHTML = '';
- var channel_list = data.channel_list;
- for (var j = 0; j < channel_list.length; j++) {
- var tempHTML = '<option saleman="[saleman]" value="0">请选择</option>';
- tempHTML = tempHTML.replace('请选择', channel_list[j].supplier_name);
- tempHTML = tempHTML.replace('0', channel_list[j].supplier_id);
- tempHTML = tempHTML.replace('[saleman]', channel_list[j].sales_man);
- $('#salesman').html(channel_list[0].sales_man);
- channelHTML += tempHTML;
- }
- $('#channel_list').html(channelHTML);
- $('.select_line').comboSelect();
- if(supplier_id) {
- var value = supplier_id;
- } else {
- var value = $('#channel_list').val();
- }
- $("#channel_list").val(value).comboSelect();
- changeChannelSelected(value);
-
-
- }
-
- //修改线路
- function changeLine() {
- //新接口请求地址
- var newstr = base_api + 'index.php';
- var data = {
- tp: 'order_groupOrder_groupProductList',
- run_date: run_date,
- line_id:line_id,
- line_name:line_name
- };
- ZZLog(data);
- $.ajax({
- url: newstr,
- data: data,
- type: "post",
- dataType: "json",
- async: false,
- success: function (data) {
- if (data.code == "0") {
- console.log(data);
- //替换线路的相关信息
- replaceLineInfo(data);
- } else {
- ZZAlertInfo(data.info);
- }
- },
- error: function (e) {
- ZZLog(e);
- }
- });
- }
-
- //替换线路的相关信息
- function replaceLineInfo(data) {
- var productHTML = '';
- var product_list = data.product_list;
-
-
- for (var i = 0; i < product_list.length; i++) {
- var tempHTML1 = '<option value="0">请选择</option>';
- tempHTML1 = tempHTML1.replace('请选择', product_list[i].line_name);
- tempHTML1 = tempHTML1.replace('0', product_list[i].line_id);
- productHTML += tempHTML1;
- }
- $('#line_info').html(productHTML);
- $('.select_line').comboSelect();
-
- // $("#line_info option[value='"+line_id+"']").attr("select","selected");
- $("#line_info").find("option[value='" + line_id + "']").attr("selected", true);
- }
-
- //切换渠道
- function changeChannelSelected(value) {
- var saleman = $("#channel_list").find("option:selected").attr('saleman');
-
- console.log(saleman);
- $('#salesman').val(saleman);
-
- var data = {
- tp: 'groupOrder_getTicketType',
- line_id: line_id,
- channel_id: value
- };
- ZZLog(data);
- $.ajax({
- url: urlstr,
- data: data,
- type: "post",
- dataType: "json",
- async: false,
- success: function (data) {
- if (data.code == "0") {
- console.log(data);
- showTicketInfo(data);
- } else {
- ZZAlertInfo(data.info);
- }
- },
- error: function (e) {
- ZZLog(e);
- }
- });
- }
-
- //展示票种信息
- function showTicketInfo(data) {
- var list = data.list;
- var newHTML = '';
- var sin_price_arr=new Array();
- var count_arr=new Array();
- for (var i = 0; i < list.length; i++) {
- var tempHTML = listHTML;
- sin_price_arr[i]=$('.sin_price').eq(i).val();
- count_arr[i]=$('.count').eq(i).val();
- tempHTML = tempHTML.replace('[座位等级]', list[i].seat_type_name);
- tempHTML = tempHTML.replace('[人群]', list[i].human_type_name);
- tempHTML = tempHTML.replace('[价格]', list[i].price);
- tempHTML = tempHTML.replace('[ticket_id]', list[i].ticket_id);
- // 数量
- var stock = 1000;
- var maxCount = stock > 55 ? 55 : stock;
- maxCount = maxCount > 0 ? maxCount : 0;
- var newHTML1 = '';
- for (var j = 0; j <= maxCount; j++) {
- var str = '<option value="[0]">[-]</option> ';
- str = str.replace('[0]', j);
- str = str.replace('[-]', j);
- newHTML1 += str;
- }
- tempHTML = tempHTML.replace('<option value="[0]">[-]</option>', newHTML1);
- tempHTML = tempHTML.replace('[总额]', '0');
- newHTML += tempHTML;
- }
- $('#list').html(newHTML);
- $('#list').show();
- for(var i =0;i<sin_price_arr.length;i++){
- $('.sin_price').eq(i).val(sin_price_arr[i]);
- $('.count').eq(i).val(count_arr[i]);
- if($('.sin_price').eq(i).val()==''){
- $('.sin_price').eq(i).val(0);
- }
- if( $('.count').eq(i).val()==''){
- $('.count').eq(i).val(0);
- }
- }
- for(var i =0;i<sin_price_arr.length;i++){
- changeTotalPrice($('.count').eq(i));
- }
- }
-
- //切换票种数量,更改价格
- function changeTotalPrice(obj) {
- var single_price = $(obj).parent().parent().find('.price').val();
- var count= $(obj).parent().parent().find('.count').val();
- var total_price = parseInt(single_price)*count;
- $(obj).parent().parent().find('.total_price').html(total_price);
- total_collection()
- }
-
-
-
- //保存按钮
- function basicInfoSave() {
- //出发日期
- var start_date = $('#Wdate2').val();
- var start_area = $('#start_area').val();
- if (!start_date || !start_area) {
- ZZAlertInfo('出发日期填写不完整!');
- return;
- }
- //订单渠道
- var order_channel = $('#channel_list').val();
- var channel_id = $('#channel_id').val();
- if (!order_channel) {
- ZZAlertInfo('订单渠道填写不完整!');
- return;
- }
- //数量
- var count_str = '';
- var rec_str = '';
- var count_num = 0;
- $('.list_info').each(function (index, dom) {
- var ticket_id = $(this).attr('id');
- var price = $(this).children().find('.price').val();
- var sin_price = $(this).children().find('.sin_price').val();
- if(!sin_price){sin_price=0}
- var count = $(this).children().find('.count').val();
- count_num += parseInt(count);
- if (count > 0) {
- var str = '{' + ticket_id + ',' + price + ',' + count + '}';
- count_str += str;
- var str2 = ticket_id + ',' + sin_price;
- rec_str +=str2+'|';
- } else {
- return;
- }
- })
- if (count_str == '') {
- ZZAlertInfo('请完善订单信息,并选择数量!');
- return;
- }
-
- //联系人
- var link_man = $('#name').val().trim();
- var link_tel = $('#tel').val().trim();
- var remarks = $('#remarks').val();
-
- //如果联系人或者备注中有半角逗号,替换为全角
- link_man=link_man.replace(/,/g, ",");
- remarks=remarks.replace(/,/g, ",");
- if (!link_man && !link_tel) {
- ZZAlertInfo('联系人信息输入不完整!');
- return;
- }
- // if (link_tel != '' && !validate(link_tel, 'phone')) {
- // return;
- // }
- var link_info = '{' + link_man + ',' + link_tel + ',' + remarks + '}';
- //业务员
- var salesman = $('#salesman').val();
- //代收
- /*var substitute = $('#substitute').val();
- // substitute = substitute== " " ? '0' : substitute;
- if (substitute == '') {
- var substitute_all = $('#substitute_all').val();
- if (substitute_all == '') {
- substitute = '0';
- }else{
- substitute = substitute_all;
- }
- }else {
- substitute = substitute * count_num;
- }*/
- var if_sin = 0;//如果为0表示代收单价没有填写,如果非0,则表示代收总价
- var terrace = $('#if_online').text();
- var tavern_stay = $('#hotel').val();
- var add_line_price = $('#substitute_add').val();
-
- $('.sin_price').each(function () {
- var tmp = $(this).val();
- if (tmp) {
- var snum = $(this).parent().parent().find('.count').val();
- if_sin += parseInt(tmp) * parseInt(snum);
- }
- })
- //总价计算规则改变--2017-01-20 娄梦宁
- var receive_value = $('#total_collection').val();
- //得到总价(如果没写任何单价[或者代收单价累计计算值为0]),则取代收总价栏的数值,否则取代收单价计算得到代收总价)
- // if (!if_sin) {
- // receive_value = substitute_all ? parseInt(substitute_all) : 0;
- // } else {
- // receive_value = if_sin;
- // }
- //alert(receive_value);
- //站点信息 order_groupOrder_groupProductList
- var seq_id = $("#start_area").find("option:selected").attr('seq_id');
- var start_time = $("#start_area").find("option:selected").attr('start_time');
- var tp = order_id != '' ? 'order_groupOrder_updateGroupOrder' : 'order_groupOrder_addOrder';
- var data = {
- tp: tp,
- line_id: line_id,
- org_id: order_channel,
- order_id: order_id,
- order_no: channel_id,
- salesman: salesman,
- start_date: start_date,
- start_station: start_area,
- prod_list: count_str,
- rec_list: rec_str, //代收单价列表
- customer_info: link_info,
- receive_value: receive_value,
- seq_id: seq_id,
- start_time: start_time,
- terrace : terrace,
- tavern_stay : tavern_stay,
- add_line_price : add_line_price
- };
- ZZLog(data);
- $.ajax({
- url: newstr,
- data: data,
- type: "post",
- dataType: "json",
- async: false,
- success: function (data) {
- if (data.code == "0") {
- ZZLog(data);
- ZZAlertInfo(data.info);
- setTimeout(function () {
- if (order_id == '')
- window.location.href = "select_product.html";
- else {
- window.location.href = "order_list.html";
- }
- }, 3000)
- } else {
- ZZAlertInfo(data.info);
- }
- },
- error: function (e) {
- ZZLog(e);
- }
- });
-
-
- }
-
-
- //切换线路
- function changeLineInfo(obj) {
- var ttt = $(obj).val();
- line_id = ttt;
- var data = {
- tp: 'groupOrder_getProductBase',
- run_date: run_date,
- line_id: line_id
- };
- ZZLog(data);
-
- $.ajax({
- url: urlstr,
- data: data,
- type: "post",
- dataType: "json",
- async: false,
- success: function (data) {
- if (data.code == "0") {
- console.log(data);
- replace1Data(data);
- } else {
- ZZAlertInfo(data.info);
- }
- },
- error: function (e) {
- ZZLog(e);
- }
- });
- }
-
- //如果是修改订单,对表单赋值
- function initEditData() {
- $("#Wdate2").val(old_data['PROD_START_STATION_DATE']);
- $("#start_area").val(old_data['PROD_START_STATION_RES_ID']).comboSelect();
- $("#channel_list").val(old_data['SUPPLIER_ID']).comboSelect();
- //没有触发 changeChannelSelected函数
- changeChannelSelected(old_data['SUPPLIER_ID']);
- var count_num = 0;
- $.each(old_data['ticket_info'], function (k, item) {
- $("#" + item['ticket_id'] + " .count").val(item['num']);
- $("#" + item['ticket_id'] + " .sin_price").val(item['sin_price']);
- var total_amount = item['num'] * $("#" + item['ticket_id'] + " .count").parent().prev('td').find('.price').val();
- $("#" + item['ticket_id'] + " .count").parent().next('.total_price').html(total_amount);
- count_num += parseInt(item['num']);
- });
- $("#channel_id").val(old_data['OUTSIDE_ORDER_NO']);
-
- $("#substitute_all").val(old_data['RECEIVE_VALUE']);
- /*if(count_num > 0)
- $("#substitute").val(parseInt(old_data['RECEIVE_VALUE']) / count_num);*/
- $("#name").val(old_data['customer_name']);
- $("#tel").val(old_data['customer_mobile']);
- $("#salesman").val(old_data['sales_man']);
- $("#remarks").val(old_data['customer_memo']);
-
- }
- //手机号验证取消,后台判断,当手机号,日期,线路一致时返回提示错误信息---娄梦宁2017-01-20
- //当手机输入框手机号码输完即时判断
- // $("#tel").bind('input propertychange', function () {
- //
- // var tel = $('#tel').val().trim();
- // if (tel.length == 11) {
- // $.ajax({
- // url: base_api + 'index.php', //请求地址
- // data: {
- // tp: "order_groupOrder_getPurchaseHistory",
- // tel: tel
- // },
- // type: "post",
- // dataType: "json",
- // success: function (data) {
- // console.log(data);
- // if (data.code == "0") {
- // $('#attention').text('提示:该电话号码今日已有下单记录!');
- // $('#attention').show();
- // return;
- // } else {
- // // $('#attention').text('提示:该电话号码今日已有下单记录!');
- // $('#attention').hide();
- // }
- //
- // }
- // });
- //
- // } else {
- // $('#attention').hide();
- // }
- // })
-
- //代收总价计算
- function total_collection(){
- var total_collection_price=0;
- var count=$('.sin_price').length;
- for(i=0;i<count;i++ ){
- if(isNaN(Number($('.sin_price').eq(i).val()))){
- total_collection_price+=0;
- }else{
- count_ticket=$('.count').eq(i).val();
- total_collection_price+=Number($('.sin_price').eq(i).val())*count_ticket;
- }
- }
- if(isNaN(Number($('#substitute_add').val()))){
- total_collection_price+=0;
- }else{
- total_collection_price+=Number($('#substitute_add').val());
- }
- $('#total_collection').val(total_collection_price);
- }
|