var change_id = getPar('prod_id');
//采购范围html
var rangeHTML = '';
//联系信息html
var infoHTML = '';
//判断是否有采购范围信息
var range_count = 0;
//判断是否有联系信息
var contact_count = 0;
var prod_id = '';
var urlstr = base_api + 'index.php';
window.onload = function(){
rangeHTML = $('#range_info').html();
infoHTML = $('#table_info_list').html();
//省市信息
reloadProvinceInfo();
prod_id = getPar('prod_id');
var data = {
tp:'supply_supplier_getSupplierInfo',
supply_id:change_id
};
console.log(data);
$.ajax({
url:urlstr, //请求地址
data:data,
type: "post",
dataType: "json",
success: function (data) {
if(data.code == "0"){
console.log(data);
reloadData(data.list);
}else{
ZZAlertInfo(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);
//省份
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 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 = {
tp:"supply_dataInfo_getArea",
area_id:0
};
console.log(data);
$.ajax({
url:urlstr, //请求地址
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