|
-
- var prod_id = '';
- var listHTML = '';
- var stopListHTML = '';
-
- //停用启用的html
- var html_stop = '';
- var html_start = '';
-
- window.onload = function(){
- prod_id = getPar('prod_id');
- listHTML = $('#list_info').html();
- stopListHTML = $('#list_info_no').html();
-
- html_stop = $('#html_stop').html();
- html_start = $('#html_start').html();
- var data = {
- type:'data_user',
- supplier_id:prod_id,
- operate:'list'
- }
- 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);
- reloadData(data);
- }else{
- console.log(data.info);
- }
- }
- });
- }
-
- //填充数据
- function reloadData(data){
- var list = data.list;
- var newHTML='';
- for(var i=0;i<list.length;i++){
- var tempHTML = '';
- if (list[i].status == '停用') {
- tempHTML = listHTML;
- } else{
- tempHTML = stopListHTML;
- }
- tempHTML=tempHTML.replace('[姓名]',list[i].true_name);
- tempHTML=tempHTML.replace('[id]',list[i].id);
- newHTML+=tempHTML;
- }
- $('#list_info').html(newHTML);
- }
-
-
- //添加账号
- function addAccount(){
- window.location.href = './add_account.html?prod_id='+prod_id;
- }
-
- //修改
- function changeDidClicked(obj){
- var user_id = $(obj).closest('.acoont_info').attr('id');
- window.location.href = './change_account.html?user_id='+user_id+'&prod_id='+prod_id;
- }
-
- //停用
- function stopDidClicked(obj){
- var user_id = $(obj).closest('.acoont_info').attr('id');
- var data = {
- type:'data_user',
- user_id:user_id,
- operate:'stop'
- }
- console.log('停用参数');
- 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);
- $(obj).parent().html(html_start);
- }else{
- console.log(data.info);
- }
- }
- });
- // $(obj).closest('.acoont_info').find('.btns').removeClass('btn-primary');
- // $(obj).closest('.acoont_info').find('.btns').addClass('btn_stop');
- // $(obj).closest('.acoont_info').find('.stop_info_btn').addClass('ui_hide');
- // $(obj).closest('.acoont_info').find('.start_info_btn').removeClass('ui_hide');
- // $(obj).closest('.acoont_info').find('.change_info_btn').removeAttr('onclick');
- // $(obj).closest('.acoont_info').find('.del_info_btn').removeAttr('onclick');
- }
-
- //启用
- function startDidClicked(obj){
- var user_id = $(obj).closest('.acoont_info').attr('id');
- var data = {
- type:'data_user',
- user_id:user_id,
- operate:'start'
- }
- console.log('启用参数');
- 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);
- $(obj).parent().html(html_stop);
- }else{
- console.log(data.info);
- }
- }
- });
- // $(obj).closest('.acoont_info').find('.btns').addClass('btn-primary');
- // $(obj).closest('.acoont_info').find('.btns').removeClass('btn_stop');
- // $(obj).closest('.acoont_info').find('.stop_info_btn').removeClass('ui_hide');
- // $(obj).closest('.acoont_info').find('.start_info_btn').addClass('ui_hide');
- // $(obj).closest('.acoont_info').find('.change_info_btn').attr('onclick','changeDidClicked(this);');
- // $(obj).closest('.acoont_info').find('.del_info_btn').attr('onclick','delDidClicked(this);');
- }
-
- //删除
- function delDidClicked(obj){
- //调用删除接口
- var user_id = $(obj).closest('.acoont_info').attr('id');
- var data = {
- type:'data_user',
- user_id:user_id,
- operate:'delete'
- }
- console.log('删除参数');
- 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);
- $(obj).closest('.acoont_info').remove();
- }else{
- console.log(data.info);
- }
- }
- });
- }
-
-
- //得到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;
- }
|