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.
 
 
 
 

181 lines
4.3 KiB

  1. var prod_id = '';
  2. var listHTML = '';
  3. var stopListHTML = '';
  4. //停用启用的html
  5. var html_stop = '';
  6. var html_start = '';
  7. window.onload = function(){
  8. prod_id = getPar('prod_id');
  9. listHTML = $('#list_info').html();
  10. stopListHTML = $('#list_info_no').html();
  11. html_stop = $('#html_stop').html();
  12. html_start = $('#html_start').html();
  13. var data = {
  14. type:'data_user',
  15. supplier_id:prod_id,
  16. operate:'list'
  17. }
  18. console.log(data);
  19. $.ajax({
  20. url: base_path+'control.php', //请求地址
  21. type: "post", //请求方式
  22. data: data,
  23. async: false,
  24. dataType: "json",
  25. success: function(data) {
  26. if(data.code == 0) {
  27. console.log(data);
  28. reloadData(data);
  29. }else{
  30. console.log(data.info);
  31. }
  32. }
  33. });
  34. }
  35. //填充数据
  36. function reloadData(data){
  37. var list = data.list;
  38. var newHTML='';
  39. for(var i=0;i<list.length;i++){
  40. var tempHTML = '';
  41. if (list[i].status == '停用') {
  42. tempHTML = listHTML;
  43. } else{
  44. tempHTML = stopListHTML;
  45. }
  46. tempHTML=tempHTML.replace('[姓名]',list[i].true_name);
  47. tempHTML=tempHTML.replace('[id]',list[i].id);
  48. newHTML+=tempHTML;
  49. }
  50. $('#list_info').html(newHTML);
  51. }
  52. //添加账号
  53. function addAccount(){
  54. window.location.href = './add_account.html?prod_id='+prod_id;
  55. }
  56. //修改
  57. function changeDidClicked(obj){
  58. var user_id = $(obj).closest('.acoont_info').attr('id');
  59. window.location.href = './change_account.html?user_id='+user_id+'&prod_id='+prod_id;
  60. }
  61. //停用
  62. function stopDidClicked(obj){
  63. var user_id = $(obj).closest('.acoont_info').attr('id');
  64. var data = {
  65. type:'data_user',
  66. user_id:user_id,
  67. operate:'stop'
  68. }
  69. console.log('停用参数');
  70. console.log(data);
  71. $.ajax({
  72. url: base_path+'control.php', //请求地址
  73. type: "post", //请求方式
  74. data: data,
  75. async: false,
  76. dataType: "json",
  77. success: function(data) {
  78. if(data.code == 0) {
  79. console.log(data);
  80. $(obj).parent().html(html_start);
  81. }else{
  82. console.log(data.info);
  83. }
  84. }
  85. });
  86. // $(obj).closest('.acoont_info').find('.btns').removeClass('btn-primary');
  87. // $(obj).closest('.acoont_info').find('.btns').addClass('btn_stop');
  88. // $(obj).closest('.acoont_info').find('.stop_info_btn').addClass('ui_hide');
  89. // $(obj).closest('.acoont_info').find('.start_info_btn').removeClass('ui_hide');
  90. // $(obj).closest('.acoont_info').find('.change_info_btn').removeAttr('onclick');
  91. // $(obj).closest('.acoont_info').find('.del_info_btn').removeAttr('onclick');
  92. }
  93. //启用
  94. function startDidClicked(obj){
  95. var user_id = $(obj).closest('.acoont_info').attr('id');
  96. var data = {
  97. type:'data_user',
  98. user_id:user_id,
  99. operate:'start'
  100. }
  101. console.log('启用参数');
  102. console.log(data);
  103. $.ajax({
  104. url: base_path+'control.php', //请求地址
  105. type: "post", //请求方式
  106. data: data,
  107. async: false,
  108. dataType: "json",
  109. success: function(data) {
  110. if(data.code == 0) {
  111. console.log(data);
  112. $(obj).parent().html(html_stop);
  113. }else{
  114. console.log(data.info);
  115. }
  116. }
  117. });
  118. // $(obj).closest('.acoont_info').find('.btns').addClass('btn-primary');
  119. // $(obj).closest('.acoont_info').find('.btns').removeClass('btn_stop');
  120. // $(obj).closest('.acoont_info').find('.stop_info_btn').removeClass('ui_hide');
  121. // $(obj).closest('.acoont_info').find('.start_info_btn').addClass('ui_hide');
  122. // $(obj).closest('.acoont_info').find('.change_info_btn').attr('onclick','changeDidClicked(this);');
  123. // $(obj).closest('.acoont_info').find('.del_info_btn').attr('onclick','delDidClicked(this);');
  124. }
  125. //删除
  126. function delDidClicked(obj){
  127. //调用删除接口
  128. var user_id = $(obj).closest('.acoont_info').attr('id');
  129. var data = {
  130. type:'data_user',
  131. user_id:user_id,
  132. operate:'delete'
  133. }
  134. console.log('删除参数');
  135. console.log(data);
  136. $.ajax({
  137. url: base_path+'control.php', //请求地址
  138. type: "post", //请求方式
  139. data: data,
  140. async: false,
  141. dataType: "json",
  142. success: function(data) {
  143. if(data.code == 0) {
  144. console.log(data);
  145. $(obj).closest('.acoont_info').remove();
  146. }else{
  147. console.log(data.info);
  148. }
  149. }
  150. });
  151. }
  152. //得到url上的参数
  153. function getPar(par){
  154. var local_url = document.location.href;
  155. local_url = decodeURI(local_url);
  156. var get = local_url.indexOf(par +"=");
  157. if(get == -1){
  158. return false;
  159. }
  160. var get_par = local_url.slice(par.length + get + 1);
  161. var nextPar = get_par.indexOf("&");
  162. if(nextPar != -1){
  163. get_par = get_par.slice(0, nextPar);
  164. }
  165. return get_par;
  166. }