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.
 
 
 
 

446 lines
12 KiB

  1. //采购范围html
  2. var rangeHTML = '';
  3. //联系信息html
  4. var infoHTML = '';
  5. //判断是否有采购范围信息
  6. var range_count = 0;
  7. //判断是否有联系信息
  8. var contact_count = 0;
  9. window. onload = function(){
  10. rangeHTML = $('#range_info').html();
  11. infoHTML = $('#table_info_list').html();
  12. //加载省的信息
  13. reloadProvinceInfo();
  14. reloadCityInfo(1);
  15. }
  16. //添加采购范围
  17. function addRange(){
  18. var newhtml = rangeHTML;
  19. $("#range_info").prepend(newhtml);
  20. }
  21. //删除对应的采购范围
  22. function delThisInfo(obj){
  23. $(obj).parent().remove();
  24. var value = $(obj).parent().children().eq(0).val();
  25. var value1 = $(this).children().eq(1).children().eq(0).val();
  26. if (value != -1 && value1 != '') {
  27. range_count = range_count -1;
  28. }
  29. }
  30. //添加联系信息
  31. function addInfo(){
  32. var newhtml = infoHTML;
  33. $("#table_info_list").prepend(newhtml);
  34. }
  35. //联系信息的删除
  36. function delBtnDidClicked(obj){
  37. var link_id = $(obj).closest('.tabbable_info').attr('id');
  38. if(link_id == "-1"){
  39. $(obj).closest('.tabbable_info').remove();
  40. var contact = $(obj).closest('.tabbable_info').find('.contact').val();
  41. var name = $(obj).closest('.tabbable_info').find('.name').val();
  42. if (contact != '' && name != '') {
  43. contact_count = contact_count -1;
  44. }
  45. }else{
  46. $.ajax({
  47. url:base_api+'index.php', //请求地址
  48. data:{
  49. tp : "supply_dataInfo_execLink",
  50. operate:"delete",
  51. link_id:link_id
  52. },
  53. type: "post",
  54. dataType: "json",
  55. success: function (data) {
  56. console.log(data);
  57. if(data.code == "0"){
  58. $(obj).closest('.tabbable_info').remove();
  59. var contact = $(obj).closest('.tabbable_info').find('.contact').val();
  60. var name = $(obj).closest('.tabbable_info').find('.name').val();
  61. if (contact != '' && name != '') {
  62. contact_count = contact_count -1;
  63. }
  64. }else{
  65. ZZAlertInfo(data.info);
  66. }
  67. }
  68. });
  69. }
  70. }
  71. //联系信息的取消
  72. function cancelBtnDidClicked(obj){
  73. var link_id = $(obj).closest('.tabbable_info').attr('id');
  74. if (link_id == '-1') {
  75. $(obj).closest('.tabbable_info').remove();
  76. var contact = $(obj).closest('.tabbable_info').find('.contact').val();
  77. var name = $(obj).closest('.tabbable_info').find('.name').val();
  78. if (contact != '' && name != '') {
  79. contact_count = contact_count -1;
  80. }
  81. } else{
  82. $.ajax({
  83. url:base_api+'index.php', //请求地址
  84. data:{
  85. tp:"supply_dataInfo_execLink",
  86. operate:"select",
  87. link_id:link_id
  88. },
  89. type: "post",
  90. dataType: "json",
  91. success: function (data) {
  92. console.log(data);
  93. if(data.code == "0"){
  94. $(obj).closest('.tabbable_info').find('.contact').val(data.list.link_name);
  95. $(obj).closest('.tabbable_info').find('.name').val(data.list.contact_name);
  96. $(obj).closest('.tabbable_info').find('.tel').val(data.list.contact_mobile);
  97. $(obj).closest('.tabbable_info').find('.tel_short').val(data.list.contact_telphone);
  98. $(obj).closest('.tabbable_info').find('.fax').val(data.list.fax);
  99. $(obj).closest('.tabbable_info').find('.mail').val(data.list.email);
  100. $(obj).closest('.tabbable_info').find('.remarks').val(data.list.remark);
  101. $(obj).parent().parent().parent().find('input,textarea').attr('readonly','readonly');
  102. $(obj).parent().parent().parent().find('input,textarea').addClass('input_no');
  103. $(obj).closest('.tabbable_info').find('.save').hide();
  104. $(obj).closest('.tabbable_info').find('.change').show();
  105. }else{
  106. ZZAlertInfo(data.info);
  107. }
  108. }
  109. });
  110. }
  111. //
  112. // $(obj).closest('.tabbable_info').remove();
  113. // var contact = $(obj).closest('.tabbable_info').find('.contact').val();
  114. // var name = $(obj).closest('.tabbable_info').find('.name').val();
  115. // if (contact != '' && name != '') {
  116. // contact_count = contact_count -1;
  117. // }
  118. }
  119. //联系信息的小保存
  120. function saveBtnDidClicked(obj){
  121. var link_id = $(obj).closest('.tabbable_info').attr('id');
  122. var contact = $(obj).closest('.tabbable_info').find('.contact').val();
  123. var name = $(obj).closest('.tabbable_info').find('.name').val();
  124. if (contact == '' || name == '') {
  125. ZZAlertInfo('联系信息不完整!')
  126. return;
  127. } else{
  128. var contact = $(obj).closest('.tabbable_info').find('.contact').val();
  129. var name = $(obj).closest('.tabbable_info').find('.name').val();
  130. var tel = $(obj).closest('.tabbable_info').find('.tel').val();
  131. var tel_short = $(obj).closest('.tabbable_info').find('.tel_short').val();
  132. var fax = $(obj).closest('.tabbable_info').find('.fax').val();
  133. var mail = $(obj).closest('.tabbable_info').find('.mail').val();
  134. var remarks = $(obj).closest('.tabbable_info').find('.remarks').val();
  135. var data = '';
  136. if (link_id == -1) {
  137. data = {
  138. tp:"supply_dataInfo_execLink",
  139. operate:"insert",
  140. link_name:contact,
  141. contact_name:name,
  142. contact_mobile:tel,
  143. contact_telphone:tel_short,
  144. fax:fax,
  145. email:mail,
  146. remark:remarks
  147. };
  148. } else{
  149. data = {
  150. tp:"supply_dataInfo_execLink",
  151. operate:"update",
  152. link_id:link_id,
  153. link_name:contact,
  154. contact_name:name,
  155. contact_mobile:tel,
  156. contact_telphone:tel_short,
  157. fax:fax,
  158. email:mail,
  159. remark:remarks
  160. };
  161. }
  162. console.log(data);
  163. $.ajax({
  164. url:base_api+'index.php', //请求地址
  165. data:data,
  166. type: "post",
  167. dataType: "json",
  168. success: function (data) {
  169. console.log(data);
  170. if(data.code == "0"){
  171. $(obj).closest('.tabbable_info').attr('id',data.list.link_id);
  172. $(obj).parent().parent().parent().find('input,textarea').attr('readonly','readonly');
  173. $(obj).parent().parent().parent().find('input,textarea').addClass('input_no');
  174. $(obj).closest('.tabbable_info').find('.save').hide();
  175. $(obj).closest('.tabbable_info').find('.change').show();
  176. }else{
  177. ZZAlertInfo(data.info);
  178. }
  179. }
  180. });
  181. }
  182. }
  183. //联系信息的修改
  184. function changeBtnDidClicked(obj){
  185. // var link_id = $(obj).closest('.tabbable_info').attr('id');
  186. // var contact = $(obj).closest('.tabbable_info').find('.contact').val();
  187. // var name = $(obj).closest('.tabbable_info').find('.name').val();
  188. // var tel = $(obj).closest('.tabbable_info').find('.tel').val();
  189. // var tel_short = $(obj).closest('.tabbable_info').find('.tel_short').val();
  190. // var fax = $(obj).closest('.tabbable_info').find('.fax').val();
  191. // var mail = $(obj).closest('.tabbable_info').find('.mail').val();
  192. // var remarks = $(obj).closest('.tabbable_info').find('.remarks').val();
  193. // $.ajax({
  194. // url:base_path+'control.php', //请求地址
  195. // data:{
  196. // type:"data_link",
  197. // operate:"update",
  198. // link_id:link_id,
  199. // link_name:contact,
  200. // contact_name:name,
  201. // contact_mobile:tel,
  202. // contact_telphone:tel_short,
  203. // fax:fax,
  204. // email:mail,
  205. // remark:remarks
  206. // },
  207. // type: "post",
  208. // dataType: "json",
  209. // success: function (data) {
  210. // console.log(data);
  211. // if(data.code == "0"){
  212. $(obj).closest('.tabbable_info').find('input,textarea').removeAttr('readonly');
  213. $(obj).closest('.tabbable_info').find('input,textarea').removeClass('input_no');
  214. $(obj).closest('.tabbable_info').find('.change').hide();
  215. $(obj).closest('.tabbable_info').find('.save').show();
  216. // }else{
  217. // ZZAlertInfo(data.info);
  218. // }
  219. // }
  220. // });
  221. //
  222. }
  223. //总保存按钮
  224. function saveInfo(){
  225. var name_str = $('#name_str').val();
  226. var all_name = $('#all_name').val();
  227. var sale_style = $('input[name="sale_style"]:checked').val();
  228. var sale_time = $('input[name="sale_time"]:checked').val();
  229. var bank = $('#bank').val();
  230. var account_name = $('#account_name').val();
  231. var bank_id = $('#bank_id').val();
  232. var city_id = $('#cantonal').val();
  233. if (name_str == '') {
  234. ZZAlertInfo('名称不能为空!');
  235. return;
  236. }
  237. if (all_name == '') {
  238. ZZAlertInfo('公司全称不能为空!');
  239. return;
  240. }
  241. //采购范围的参数
  242. range_count = 0;
  243. var range_str = '';
  244. $('.range_every').each(function(index,dom){
  245. var value = $(this).children().eq(0).val();
  246. var value1 = $(this).children().eq(1).children().eq(0).val();
  247. if (value != -1 && value1 != '') {
  248. range_str += '{' + value + ',' + value1 + '}';
  249. range_count ++ ;
  250. }
  251. })
  252. if (range_count == 0) {
  253. ZZAlertInfo('采购信息输入不完整!');
  254. return;
  255. }
  256. console.log('采购范围参数');
  257. console.log(range_str);
  258. //联系信息的参数
  259. var submit_link_id_arr = [];
  260. $('.tabbable_info').each(function(index,dom){
  261. var link_id = $(this).closest('.tabbable_info').attr('id');
  262. submit_link_id_arr.push(link_id);
  263. })
  264. if($.inArray("-1", submit_link_id_arr)!="-1"){
  265. ZZAlertInfo("联系信息未保存");
  266. return;
  267. };
  268. // contact_count = 0;
  269. // var contact_str = '{';
  270. // $('.tabbable_info').each(function(index,dom){
  271. // var link_id = $(this).closest('.tabbable_info').attr('id');
  272. // if (link_id != -1) {
  273. // contact_str += link_id + ','
  274. // ZZAlertInfo(contact_str);
  275. // }
  276. // })
  277. // contact_str = contact_str.substring(0,contact_str.length-1);
  278. // contact_str = contact_str +'}';
  279. // console.log('联系信息参数');
  280. // console.log(contact_str);
  281. var data = {
  282. tp:'supply_supplier_addSupplier',
  283. supplier_name:name_str,
  284. area_id:city_id,
  285. company_name:all_name,
  286. purchase:range_str,
  287. sett_type:sale_style,
  288. sett_frequency:sale_time,
  289. account_bank:bank,
  290. account_num:account_name,
  291. account_name:bank_id,
  292. link_info:submit_link_id_arr.toString()
  293. }
  294. console.log('这里是data')
  295. console.log(data);
  296. $.ajax({
  297. url:base_api+'index.php', //请求地址
  298. data:data,
  299. type: "post",
  300. dataType: "json",
  301. success: function (data) {
  302. if(data.code == "0"){
  303. ZZAlertInfo(data.info,function(){
  304. window.location.href = './supplier_list.html';
  305. });
  306. }else{
  307. ZZAlertInfo(data.info);
  308. }
  309. }
  310. });
  311. }
  312. //加载省的信息
  313. function reloadProvinceInfo(){
  314. var data = {
  315. tp:"supply_dataInfo_getArea",
  316. area_id:0
  317. };
  318. console.log(data);
  319. $.ajax({
  320. url:base_api+'index.php', //请求地址
  321. type: "post", //请求方式
  322. data:data,
  323. async:false,
  324. dataType: "json",
  325. success: function (data) {
  326. if(data.code == 0){
  327. console.log(data);
  328. var HTML = "";
  329. var proList = data.list;
  330. for (var i = 0; i<proList.length;i ++) {
  331. var dict = proList[i];
  332. var tempHTML = '<option value="0">请选择省</option>';
  333. tempHTML = tempHTML.replace('请选择省',proList[i]['area_name']);
  334. tempHTML = tempHTML.replace('0',proList[i]['id']);
  335. HTML += tempHTML;
  336. }
  337. $('#province').html(HTML);
  338. }else{
  339. ZZAlertInfo(data.info);
  340. }
  341. }
  342. });
  343. }
  344. //加载市的信息
  345. function reloadCityInfo(proid){
  346. var data = {
  347. tp:"supply_dataInfo_getArea",
  348. area_id:proid
  349. };
  350. console.log(data);
  351. $.ajax({
  352. url:base_api+'index.php', //请求地址
  353. type: "post", //请求方式
  354. data:data,
  355. async:false,
  356. dataType: "json",
  357. success: function (data) {
  358. if(data.code == 0){
  359. var HTML = "";
  360. var proList = data.list;
  361. for (var i = 0; i<proList.length;i ++) {
  362. var dict = proList[i];
  363. var tempHTML = '<option value="0">请选择市</option>';
  364. tempHTML = tempHTML.replace('请选择市',proList[i]['area_name']);
  365. tempHTML = tempHTML.replace('0',proList[i]['id']);
  366. HTML += tempHTML;
  367. }
  368. $('#cantonal').html(HTML);
  369. }else{
  370. ZZAlertInfo(data.info);
  371. }
  372. }
  373. });
  374. }
  375. function selectOneProvince(selected){
  376. $("#province").find("option:selected").text();
  377. reloadCityInfo(selected.value);
  378. }
  379. //失去焦点
  380. $("#name_str").blur(function(){
  381. var value = $('#name_str').val();
  382. $.ajax({
  383. url:base_api+'index.php', //请求地址
  384. data:{
  385. tp:"supply_dataInfo_checkSupplierName",
  386. supplier_name:value,
  387. supplier_type:'187'
  388. },
  389. type: "post",
  390. dataType: "json",
  391. success: function (data) {
  392. console.log(data);
  393. if(data.code == "0"){
  394. $('#attention').text('名称可用');
  395. }else{
  396. $('#attention').text('名称已存在');
  397. }
  398. }
  399. });
  400. })