var change_id = getPar('prod_id'); //采购范围html var rangeHTML = ''; //联系信息html var infoHTML = ''; //判断是否有采购范围信息 var range_count = 0; //判断是否有联系信息 var contact_count = 0; var prod_id = ''; window.onload = function () { //加载采购人信息 loadPurchaser(); rangeHTML = $('#range_info').html(); infoHTML = $('#table_info_list').html(); //省市信息 reloadProvinceInfo(); prod_id = getPar('prod_id'); var data = { type: 'supply_detail_get', supply_id: change_id }; console.log(data); $.ajax({ url: base_path + 'control.php', //请求地址 data: data, type: "post", dataType: "json", success: function (data) { if (data.code == "0") { console.log(data); reloadData(data.list); } else { alert(data.info); } } }); } //加载数据 function reloadData(data) { $('#name_str').val(data.supplier_name); $('#all_name').val(data.company_name); $('input[name="sale_style"][value="' + data.sett_type + '"]').attr('checked', true); $('input[name="sale_time"][value="' + data.sett_frequency + '"]').attr('checked', true); $('#bank').val(data.account_bank); $('#account_name').val(data.account_num); $('#bank_id').val(data.account_name); $('#deduct_type').val(data.deduct_type); $('#alert_balance').val(data.alert_balance); //省份 reloadCityInfo(data.province_id); $('#province').val(data.province_id); $('#cantonal').val(data.city_id); // //采购范围 // var html = ''; // for (var i = 0 ; i < data.purchase.length; i ++) { // var tempHTML = rangeHTML; // html += tempHTML; // } // $('#range_info').html(html); // for (var i = 0 ; i < data.purchase.length; i ++) { // $('.select_status').each(function(index,dom){ // $(this).attr('value',data.purchase.product_type); // }) // } //采购范围 var newhtml = $('#range_info').html(); $('#range_info').children().remove(); for (var i = 0; i < data.purchase.length; i++) { $("#range_info").prepend(newhtml); $("#range_info").children().eq(0).attr('id', 'tt' + data.purchase[i].id); $('#tt' + data.purchase[i].id).find('.select_status').val(data.purchase[i].product_type); $('#tt' + data.purchase[i].id).find('.people').val(data.purchase[i].purchaser_name); $('#tt' + data.purchase[i].id).find('.people').removeAttr('readonly'); } //联系信息 var newHTML1 = $('#table_info_list').html(); $('#table_info_list').children().remove(); for (var i = 0; i < data.link_info.length; i++) { $("#table_info_list").prepend(newHTML1); $("#table_info_list").children().eq(0).attr('id', data.link_info[i].id); $('#' + data.link_info[i].id).find('.contact').val(data.link_info[i].link_name); $('#' + data.link_info[i].id).find('.name').val(data.link_info[i].contact_name); $('#' + data.link_info[i].id).find('.tel').val(data.link_info[i].contact_mobile); $('#' + data.link_info[i].id).find('.tel_short').val(data.link_info[i].contact_telphone); $('#' + data.link_info[i].id).find('.fax').val(data.link_info[i].fax); $('#' + data.link_info[i].id).find('.mail').val(data.link_info[i].email); $('#' + data.link_info[i].id).find('.remarks').val(data.link_info[i].remark); $('#' + data.link_info[i].id).find('input,textarea').attr('readonly', 'readonly'); $('#' + data.link_info[i].id).find('input,textarea').addClass('input_no'); $('#' + data.link_info[i].id).find('.save').hide(); $('#' + data.link_info[i].id).find('.change').show(); } } //加载采购负责人 function loadPurchaser() { var data = { type: "data_purchaser" } $.ajax({ url: base_path + 'control.php', //请求地址 type: "post", //请求方式 data: data, async: false, dataType: "json", success: function (data) { if (data.code == 0) { var HTML = ''; var proList = data.list; for (var i = 0; i < proList.length; i++) { var dict = proList[i]; var tempHTML = ''; tempHTML = tempHTML.replace('请选择', dict['true_name']); tempHTML = tempHTML.replace('0', dict['id']); HTML += tempHTML; } $(".people").html(HTML); } else { alert(data.info); } } }); } //添加采购范围 function addRange() { var newhtml = rangeHTML; $("#range_info").prepend(newhtml); } //删除对应的采购范围 function delThisInfo(obj) { $(obj).parent().remove(); var value = $(obj).parent().children().eq(0).val(); var value1 = $(this).children().eq(1).children().eq(0).val(); if (value != -1 && value1 != '') { range_count = range_count - 1; } } //得到url上的参数 function getPar(par) { var local_url = document.location.href; local_url = decodeURI(local_url); var get = local_url.indexOf(par + "="); if (get == -1) { return false; } var get_par = local_url.slice(par.length + get + 1); var nextPar = get_par.indexOf("&"); if (nextPar != -1) { get_par = get_par.slice(0, nextPar); } return get_par; } //加载省的信息 function reloadProvinceInfo() { var data = { type: "data_area", area_id: 0 }; console.log(data); $.ajax({ url: base_path + 'control.php', //请求地址 type: "post", //请求方式 data: data, async: false, dataType: "json", success: function (data) { if (data.code == 0) { console.log(data); var HTML = ""; var proList = data.list; for (var i = 0; i < proList.length; i++) { var dict = proList[i]; var tempHTML = ''; tempHTML = tempHTML.replace('请选择省', proList[i]['area_name']); tempHTML = tempHTML.replace('0', proList[i]['id']); HTML += tempHTML; } $('#province').html(HTML); } else { alert(data.info); } } }); } //加载市的信息 function reloadCityInfo(proid) { var data = { type: "data_area", area_id: proid }; console.log(data); $.ajax({ url: base_path + 'control.php', //请求地址 type: "post", //请求方式 data: data, async: false, dataType: "json", success: function (data) { if (data.code == 0) { var HTML = ""; var proList = data.list; for (var i = 0; i < proList.length; i++) { var dict = proList[i]; var tempHTML = ''; tempHTML = tempHTML.replace('请选择市', proList[i]['area_name']); tempHTML = tempHTML.replace('0', proList[i]['id']); HTML += tempHTML; } $('#cantonal').html(HTML); } else { alert(data.info); } } }); } //选择省份 function selectOneProvince(selected) { $("#province").find("option:selected").text(); reloadCityInfo(selected.value); } //添加采购范围 function addRange() { var newhtml = rangeHTML; $("#range_info").prepend(newhtml); } //删除对应的采购范围 function delThisInfo(obj) { $(obj).parent().remove(); var value = $(obj).parent().children().eq(0).val(); var value1 = $(this).children().eq(1).children().eq(0).val(); if (value != -1 && value1 != '') { range_count = range_count - 1; } } //添加联系信息 function addInfo() { var newhtml = infoHTML; $("#table_info_list").prepend(newhtml); } //联系信息的删除 function delBtnDidClicked(obj) { var link_id = $(obj).closest('.tabbable_info').attr('id'); if (link_id == "-1") { $(obj).closest('.tabbable_info').remove(); var contact = $(obj).closest('.tabbable_info').find('.contact').val(); var name = $(obj).closest('.tabbable_info').find('.name').val(); if (contact != '' && name != '') { contact_count = contact_count - 1; } } else { $.ajax({ url: base_path + 'control.php', //请求地址 data: { type: "data_link", operate: "delete", link_id: link_id }, type: "post", dataType: "json", success: function (data) { console.log(data); if (data.code == "0") { $(obj).closest('.tabbable_info').remove(); var contact = $(obj).closest('.tabbable_info').find('.contact').val(); var name = $(obj).closest('.tabbable_info').find('.name').val(); if (contact != '' && name != '') { contact_count = contact_count - 1; } } else { alert(data.info); } } }); } } //联系信息的取消 function cancelBtnDidClicked(obj) { var link_id = $(obj).closest('.tabbable_info').attr('id'); if (link_id == '-1') { $(obj).closest('.tabbable_info').remove(); var contact = $(obj).closest('.tabbable_info').find('.contact').val(); var name = $(obj).closest('.tabbable_info').find('.name').val(); if (contact != '' && name != '') { contact_count = contact_count - 1; } } else { $.ajax({ url: base_path + 'control.php', //请求地址 data: { type: "data_link", operate: "select", link_id: link_id }, type: "post", dataType: "json", success: function (data) { console.log(data); if (data.code == "0") { $(obj).closest('.tabbable_info').find('.contact').val(data.list.link_name); $(obj).closest('.tabbable_info').find('.name').val(data.list.contact_name); $(obj).closest('.tabbable_info').find('.tel').val(data.list.contact_mobile); $(obj).closest('.tabbable_info').find('.tel_short').val(data.list.contact_telphone); $(obj).closest('.tabbable_info').find('.fax').val(data.list.fax); $(obj).closest('.tabbable_info').find('.mail').val(data.list.email); $(obj).closest('.tabbable_info').find('.remarks').val(data.list.remark); $(obj).parent().parent().parent().find('input,textarea').attr('readonly', 'readonly'); $(obj).parent().parent().parent().find('input,textarea').addClass('input_no'); $(obj).closest('.tabbable_info').find('.save').hide(); $(obj).closest('.tabbable_info').find('.change').show(); } else { alert(data.info); } } }); } // // $(obj).closest('.tabbable_info').remove(); // var contact = $(obj).closest('.tabbable_info').find('.contact').val(); // var name = $(obj).closest('.tabbable_info').find('.name').val(); // if (contact != '' && name != '') { // contact_count = contact_count -1; // } } //联系信息的小保存 function saveBtnDidClicked(obj) { var link_id = $(obj).closest('.tabbable_info').attr('id'); var contact = $(obj).closest('.tabbable_info').find('.contact').val(); var name = $(obj).closest('.tabbable_info').find('.name').val(); if (contact == '' || name == '') { alert('联系信息不完整!') return; } else { var contact = $(obj).closest('.tabbable_info').find('.contact').val(); var name = $(obj).closest('.tabbable_info').find('.name').val(); var tel = $(obj).closest('.tabbable_info').find('.tel').val(); var tel_short = $(obj).closest('.tabbable_info').find('.tel_short').val(); var fax = $(obj).closest('.tabbable_info').find('.fax').val(); var mail = $(obj).closest('.tabbable_info').find('.mail').val(); var remarks = $(obj).closest('.tabbable_info').find('.remarks').val(); var data = ''; if (link_id == -1) { data = { type: "data_link", operate: "insert", link_name: contact, contact_name: name, contact_mobile: tel, contact_telphone: tel_short, fax: fax, email: mail, remark: remarks }; } else { data = { type: "data_link", operate: "update", link_id: link_id, link_name: contact, contact_name: name, contact_mobile: tel, contact_telphone: tel_short, fax: fax, email: mail, remark: remarks }; } console.log(data); $.ajax({ url: base_path + 'control.php', //请求地址 data: data, type: "post", dataType: "json", success: function (data) { console.log(data); if (data.code == "0") { $(obj).closest('.tabbable_info').attr('id', data.list.link_id); $(obj).parent().parent().parent().find('input,textarea').attr('readonly', 'readonly'); $(obj).parent().parent().parent().find('input,textarea').addClass('input_no'); $(obj).closest('.tabbable_info').find('.save').hide(); $(obj).closest('.tabbable_info').find('.change').show(); } else { alert(data.info); } } }); } } //联系信息的修改 function changeBtnDidClicked(obj) { // var link_id = $(obj).closest('.tabbable_info').attr('id'); // var contact = $(obj).closest('.tabbable_info').find('.contact').val(); // var name = $(obj).closest('.tabbable_info').find('.name').val(); // var tel = $(obj).closest('.tabbable_info').find('.tel').val(); // var tel_short = $(obj).closest('.tabbable_info').find('.tel_short').val(); // var fax = $(obj).closest('.tabbable_info').find('.fax').val(); // var mail = $(obj).closest('.tabbable_info').find('.mail').val(); // var remarks = $(obj).closest('.tabbable_info').find('.remarks').val(); // $.ajax({ // url:base_path+'control.php', //请求地址 // data:{ // type:"data_link", // operate:"update", // link_id:link_id, // link_name:contact, // contact_name:name, // contact_mobile:tel, // contact_telphone:tel_short, // fax:fax, // email:mail, // remark:remarks // }, // type: "post", // dataType: "json", // success: function (data) { // console.log(data); // if(data.code == "0"){ $(obj).closest('.tabbable_info').find('input,textarea').removeAttr('readonly'); $(obj).closest('.tabbable_info').find('input,textarea').removeClass('input_no'); $(obj).closest('.tabbable_info').find('.change').hide(); $(obj).closest('.tabbable_info').find('.save').show(); // }else{ // alert(data.info); // } // } // }); // } //总保存按钮 function saveInfo() { var deduct_type = $("#deduct_type").val(); var alert_balance = $("#alert_balance").val(); var name_str = $('#name_str').val(); var all_name = $('#all_name').val(); var sale_style = $('input[name="sale_style"]:checked').val(); var sale_time = $('input[name="sale_time"]:checked').val(); var bank = $('#bank').val(); var account_name = $('#account_name').val(); var bank_id = $('#bank_id').val(); var city_id = $('#cantonal').val(); if (name_str == '') { alert('名称不能为空!'); return; } if (all_name == '') { alert('公司全称不能为空!'); return; } if (deduct_type == -1) { alert('请选择扣款口径!'); return; } if (alert_balance == '') { alert('请输入预警金额!'); return; } //采购范围的参数 range_count = 0; var range_str = ''; $('.range_every').each(function (index, dom) { var value = $(this).children().eq(0).val(); var value1 = $(this).children().eq(1).children().eq(0).val(); var value2 = $(this).attr('id'); value2 = value2.substring(2); if (value != -1 && value1 != '') { range_str += '{' + value2 + ',' + value + ',' + value1 + '}'; range_count++; } }) if (range_count == 0) { alert('采购信息输入不完整!'); return; } console.log('采购范围参数'); console.log(range_str); //联系信息的参数 var submit_link_id_arr = []; $('.tabbable_info').each(function (index, dom) { var link_id = $(this).closest('.tabbable_info').attr('id'); submit_link_id_arr.push(link_id); }) if ($.inArray("-1", submit_link_id_arr) != "-1") { alert("联系信息未保存"); return; } ; // contact_count = 0; // var contact_str = '{'; // $('.tabbable_info').each(function(index,dom){ // var link_id = $(this).closest('.tabbable_info').attr('id'); // if (link_id != -1) { // contact_str += link_id + ',' // alert(contact_str); // } // }) // contact_str = contact_str.substring(0,contact_str.length-1); // contact_str = contact_str +'}'; // console.log('联系信息参数'); // console.log(contact_str); var data = { type: 'supply_detail_update', supplier_name: name_str, area_id: city_id, company_name: all_name, purchase: range_str, sett_type: sale_style, sett_frequency: sale_time, account_bank: bank, account_num: account_name, account_name: bank_id, link_info: submit_link_id_arr.toString(), supply_id: prod_id, deduct_type: deduct_type, alert_balance: alert_balance } console.log('这里是data') console.log(data); $.ajax({ url: base_path + 'control.php', //请求地址 data: data, type: "post", dataType: "json", success: function (data) { if (data.code == "0") { alert(data.info); window.location.href = './supplier_list.html'; } else { alert(data.info); } } }); } //失去焦点 $("#name_str").blur(function () { var value = $('#name_str').val(); var prod_id = getPar('prod_id'); $.ajax({ url: base_path + 'control.php', //请求地址 data: { type: "data_check", supplier_name: value, supplier_type: '187', supplier_id: prod_id }, type: "post", dataType: "json", success: function (data) { console.log(data); if (data.code == "0") { $('#attention').text('名称可用'); } else { $('#attention').text('名称已存在'); } } }); })