Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

595 Zeilen
20 KiB

  1. var change_id = getPar('prod_id');
  2. //采购范围html
  3. var rangeHTML = '';
  4. //联系信息html
  5. var infoHTML = '';
  6. //判断是否有采购范围信息
  7. var range_count = 0;
  8. //判断是否有联系信息
  9. var contact_count = 0;
  10. var prod_id = '';
  11. window.onload = function () {
  12. //加载采购人信息
  13. loadPurchaser();
  14. rangeHTML = $('#range_info').html();
  15. infoHTML = $('#table_info_list').html();
  16. //省市信息
  17. reloadProvinceInfo();
  18. prod_id = getPar('prod_id');
  19. var data = {
  20. type: 'supply_detail_get',
  21. supply_id: change_id
  22. };
  23. console.log(data);
  24. $.ajax({
  25. url: base_path + 'control.php', //请求地址
  26. data: data,
  27. type: "post",
  28. dataType: "json",
  29. success: function (data) {
  30. if (data.code == "0") {
  31. console.log(data);
  32. reloadData(data.list);
  33. } else {
  34. alert(data.info);
  35. }
  36. }
  37. });
  38. }
  39. //加载数据
  40. function reloadData(data) {
  41. $('#name_str').val(data.supplier_name);
  42. $('#all_name').val(data.company_name);
  43. $('input[name="sale_style"][value="' + data.sett_type + '"]').attr('checked', true);
  44. $('input[name="sale_time"][value="' + data.sett_frequency + '"]').attr('checked', true);
  45. $('#bank').val(data.account_bank);
  46. $('#account_name').val(data.account_num);
  47. $('#bank_id').val(data.account_name);
  48. $('#deduct_type').val(data.deduct_type);
  49. $('#alert_balance').val(data.alert_balance);
  50. //省份
  51. reloadCityInfo(data.province_id);
  52. $('#province').val(data.province_id);
  53. $('#cantonal').val(data.city_id);
  54. // //采购范围
  55. // var html = '';
  56. // for (var i = 0 ; i < data.purchase.length; i ++) {
  57. // var tempHTML = rangeHTML;
  58. // html += tempHTML;
  59. // }
  60. // $('#range_info').html(html);
  61. // for (var i = 0 ; i < data.purchase.length; i ++) {
  62. // $('.select_status').each(function(index,dom){
  63. // $(this).attr('value',data.purchase.product_type);
  64. // })
  65. // }
  66. //采购范围
  67. var newhtml = $('#range_info').html();
  68. $('#range_info').children().remove();
  69. for (var i = 0; i < data.purchase.length; i++) {
  70. $("#range_info").prepend(newhtml);
  71. $("#range_info").children().eq(0).attr('id', 'tt' + data.purchase[i].id);
  72. $('#tt' + data.purchase[i].id).find('.select_status').val(data.purchase[i].product_type);
  73. $('#tt' + data.purchase[i].id).find('.people').val(data.purchase[i].purchaser_name);
  74. $('#tt' + data.purchase[i].id).find('.people').removeAttr('readonly');
  75. }
  76. //联系信息
  77. var newHTML1 = $('#table_info_list').html();
  78. $('#table_info_list').children().remove();
  79. for (var i = 0; i < data.link_info.length; i++) {
  80. $("#table_info_list").prepend(newHTML1);
  81. $("#table_info_list").children().eq(0).attr('id', data.link_info[i].id);
  82. $('#' + data.link_info[i].id).find('.contact').val(data.link_info[i].link_name);
  83. $('#' + data.link_info[i].id).find('.name').val(data.link_info[i].contact_name);
  84. $('#' + data.link_info[i].id).find('.tel').val(data.link_info[i].contact_mobile);
  85. $('#' + data.link_info[i].id).find('.tel_short').val(data.link_info[i].contact_telphone);
  86. $('#' + data.link_info[i].id).find('.fax').val(data.link_info[i].fax);
  87. $('#' + data.link_info[i].id).find('.mail').val(data.link_info[i].email);
  88. $('#' + data.link_info[i].id).find('.remarks').val(data.link_info[i].remark);
  89. $('#' + data.link_info[i].id).find('input,textarea').attr('readonly', 'readonly');
  90. $('#' + data.link_info[i].id).find('input,textarea').addClass('input_no');
  91. $('#' + data.link_info[i].id).find('.save').hide();
  92. $('#' + data.link_info[i].id).find('.change').show();
  93. }
  94. }
  95. //加载采购负责人
  96. function loadPurchaser() {
  97. var data = {
  98. type: "data_purchaser"
  99. }
  100. $.ajax({
  101. url: base_path + 'control.php', //请求地址
  102. type: "post", //请求方式
  103. data: data,
  104. async: false,
  105. dataType: "json",
  106. success: function (data) {
  107. if (data.code == 0) {
  108. var HTML = '<option value="0">请选择</option>';
  109. var proList = data.list;
  110. for (var i = 0; i < proList.length; i++) {
  111. var dict = proList[i];
  112. var tempHTML = '<option value="0">请选择</option>';
  113. tempHTML = tempHTML.replace('请选择', dict['true_name']);
  114. tempHTML = tempHTML.replace('0', dict['id']);
  115. HTML += tempHTML;
  116. }
  117. $(".people").html(HTML);
  118. } else {
  119. alert(data.info);
  120. }
  121. }
  122. });
  123. }
  124. //添加采购范围
  125. function addRange() {
  126. var newhtml = rangeHTML;
  127. $("#range_info").prepend(newhtml);
  128. }
  129. //删除对应的采购范围
  130. function delThisInfo(obj) {
  131. $(obj).parent().remove();
  132. var value = $(obj).parent().children().eq(0).val();
  133. var value1 = $(this).children().eq(1).children().eq(0).val();
  134. if (value != -1 && value1 != '') {
  135. range_count = range_count - 1;
  136. }
  137. }
  138. //得到url上的参数
  139. function getPar(par) {
  140. var local_url = document.location.href;
  141. local_url = decodeURI(local_url);
  142. var get = local_url.indexOf(par + "=");
  143. if (get == -1) {
  144. return false;
  145. }
  146. var get_par = local_url.slice(par.length + get + 1);
  147. var nextPar = get_par.indexOf("&");
  148. if (nextPar != -1) {
  149. get_par = get_par.slice(0, nextPar);
  150. }
  151. return get_par;
  152. }
  153. //加载省的信息
  154. function reloadProvinceInfo() {
  155. var data = {
  156. type: "data_area",
  157. area_id: 0
  158. };
  159. console.log(data);
  160. $.ajax({
  161. url: base_path + 'control.php', //请求地址
  162. type: "post", //请求方式
  163. data: data,
  164. async: false,
  165. dataType: "json",
  166. success: function (data) {
  167. if (data.code == 0) {
  168. console.log(data);
  169. var HTML = "";
  170. var proList = data.list;
  171. for (var i = 0; i < proList.length; i++) {
  172. var dict = proList[i];
  173. var tempHTML = '<option value="0">请选择省</option>';
  174. tempHTML = tempHTML.replace('请选择省', proList[i]['area_name']);
  175. tempHTML = tempHTML.replace('0', proList[i]['id']);
  176. HTML += tempHTML;
  177. }
  178. $('#province').html(HTML);
  179. } else {
  180. alert(data.info);
  181. }
  182. }
  183. });
  184. }
  185. //加载市的信息
  186. function reloadCityInfo(proid) {
  187. var data = {
  188. type: "data_area",
  189. area_id: proid
  190. };
  191. console.log(data);
  192. $.ajax({
  193. url: base_path + 'control.php', //请求地址
  194. type: "post", //请求方式
  195. data: data,
  196. async: false,
  197. dataType: "json",
  198. success: function (data) {
  199. if (data.code == 0) {
  200. var HTML = "";
  201. var proList = data.list;
  202. for (var i = 0; i < proList.length; i++) {
  203. var dict = proList[i];
  204. var tempHTML = '<option value="0">请选择市</option>';
  205. tempHTML = tempHTML.replace('请选择市', proList[i]['area_name']);
  206. tempHTML = tempHTML.replace('0', proList[i]['id']);
  207. HTML += tempHTML;
  208. }
  209. $('#cantonal').html(HTML);
  210. } else {
  211. alert(data.info);
  212. }
  213. }
  214. });
  215. }
  216. //选择省份
  217. function selectOneProvince(selected) {
  218. $("#province").find("option:selected").text();
  219. reloadCityInfo(selected.value);
  220. }
  221. //添加采购范围
  222. function addRange() {
  223. var newhtml = rangeHTML;
  224. $("#range_info").prepend(newhtml);
  225. }
  226. //删除对应的采购范围
  227. function delThisInfo(obj) {
  228. $(obj).parent().remove();
  229. var value = $(obj).parent().children().eq(0).val();
  230. var value1 = $(this).children().eq(1).children().eq(0).val();
  231. if (value != -1 && value1 != '') {
  232. range_count = range_count - 1;
  233. }
  234. }
  235. //添加联系信息
  236. function addInfo() {
  237. var newhtml = infoHTML;
  238. $("#table_info_list").prepend(newhtml);
  239. }
  240. //联系信息的删除
  241. function delBtnDidClicked(obj) {
  242. var link_id = $(obj).closest('.tabbable_info').attr('id');
  243. if (link_id == "-1") {
  244. $(obj).closest('.tabbable_info').remove();
  245. var contact = $(obj).closest('.tabbable_info').find('.contact').val();
  246. var name = $(obj).closest('.tabbable_info').find('.name').val();
  247. if (contact != '' && name != '') {
  248. contact_count = contact_count - 1;
  249. }
  250. } else {
  251. $.ajax({
  252. url: base_path + 'control.php', //请求地址
  253. data: {
  254. type: "data_link",
  255. operate: "delete",
  256. link_id: link_id
  257. },
  258. type: "post",
  259. dataType: "json",
  260. success: function (data) {
  261. console.log(data);
  262. if (data.code == "0") {
  263. $(obj).closest('.tabbable_info').remove();
  264. var contact = $(obj).closest('.tabbable_info').find('.contact').val();
  265. var name = $(obj).closest('.tabbable_info').find('.name').val();
  266. if (contact != '' && name != '') {
  267. contact_count = contact_count - 1;
  268. }
  269. } else {
  270. alert(data.info);
  271. }
  272. }
  273. });
  274. }
  275. }
  276. //联系信息的取消
  277. function cancelBtnDidClicked(obj) {
  278. var link_id = $(obj).closest('.tabbable_info').attr('id');
  279. if (link_id == '-1') {
  280. $(obj).closest('.tabbable_info').remove();
  281. var contact = $(obj).closest('.tabbable_info').find('.contact').val();
  282. var name = $(obj).closest('.tabbable_info').find('.name').val();
  283. if (contact != '' && name != '') {
  284. contact_count = contact_count - 1;
  285. }
  286. } else {
  287. $.ajax({
  288. url: base_path + 'control.php', //请求地址
  289. data: {
  290. type: "data_link",
  291. operate: "select",
  292. link_id: link_id
  293. },
  294. type: "post",
  295. dataType: "json",
  296. success: function (data) {
  297. console.log(data);
  298. if (data.code == "0") {
  299. $(obj).closest('.tabbable_info').find('.contact').val(data.list.link_name);
  300. $(obj).closest('.tabbable_info').find('.name').val(data.list.contact_name);
  301. $(obj).closest('.tabbable_info').find('.tel').val(data.list.contact_mobile);
  302. $(obj).closest('.tabbable_info').find('.tel_short').val(data.list.contact_telphone);
  303. $(obj).closest('.tabbable_info').find('.fax').val(data.list.fax);
  304. $(obj).closest('.tabbable_info').find('.mail').val(data.list.email);
  305. $(obj).closest('.tabbable_info').find('.remarks').val(data.list.remark);
  306. $(obj).parent().parent().parent().find('input,textarea').attr('readonly', 'readonly');
  307. $(obj).parent().parent().parent().find('input,textarea').addClass('input_no');
  308. $(obj).closest('.tabbable_info').find('.save').hide();
  309. $(obj).closest('.tabbable_info').find('.change').show();
  310. } else {
  311. alert(data.info);
  312. }
  313. }
  314. });
  315. }
  316. //
  317. // $(obj).closest('.tabbable_info').remove();
  318. // var contact = $(obj).closest('.tabbable_info').find('.contact').val();
  319. // var name = $(obj).closest('.tabbable_info').find('.name').val();
  320. // if (contact != '' && name != '') {
  321. // contact_count = contact_count -1;
  322. // }
  323. }
  324. //联系信息的小保存
  325. function saveBtnDidClicked(obj) {
  326. var link_id = $(obj).closest('.tabbable_info').attr('id');
  327. var contact = $(obj).closest('.tabbable_info').find('.contact').val();
  328. var name = $(obj).closest('.tabbable_info').find('.name').val();
  329. if (contact == '' || name == '') {
  330. alert('联系信息不完整!')
  331. return;
  332. } else {
  333. var contact = $(obj).closest('.tabbable_info').find('.contact').val();
  334. var name = $(obj).closest('.tabbable_info').find('.name').val();
  335. var tel = $(obj).closest('.tabbable_info').find('.tel').val();
  336. var tel_short = $(obj).closest('.tabbable_info').find('.tel_short').val();
  337. var fax = $(obj).closest('.tabbable_info').find('.fax').val();
  338. var mail = $(obj).closest('.tabbable_info').find('.mail').val();
  339. var remarks = $(obj).closest('.tabbable_info').find('.remarks').val();
  340. var data = '';
  341. if (link_id == -1) {
  342. data = {
  343. type: "data_link",
  344. operate: "insert",
  345. link_name: contact,
  346. contact_name: name,
  347. contact_mobile: tel,
  348. contact_telphone: tel_short,
  349. fax: fax,
  350. email: mail,
  351. remark: remarks
  352. };
  353. } else {
  354. data = {
  355. type: "data_link",
  356. operate: "update",
  357. link_id: link_id,
  358. link_name: contact,
  359. contact_name: name,
  360. contact_mobile: tel,
  361. contact_telphone: tel_short,
  362. fax: fax,
  363. email: mail,
  364. remark: remarks
  365. };
  366. }
  367. console.log(data);
  368. $.ajax({
  369. url: base_path + 'control.php', //请求地址
  370. data: data,
  371. type: "post",
  372. dataType: "json",
  373. success: function (data) {
  374. console.log(data);
  375. if (data.code == "0") {
  376. $(obj).closest('.tabbable_info').attr('id', data.list.link_id);
  377. $(obj).parent().parent().parent().find('input,textarea').attr('readonly', 'readonly');
  378. $(obj).parent().parent().parent().find('input,textarea').addClass('input_no');
  379. $(obj).closest('.tabbable_info').find('.save').hide();
  380. $(obj).closest('.tabbable_info').find('.change').show();
  381. } else {
  382. alert(data.info);
  383. }
  384. }
  385. });
  386. }
  387. }
  388. //联系信息的修改
  389. function changeBtnDidClicked(obj) {
  390. // var link_id = $(obj).closest('.tabbable_info').attr('id');
  391. // var contact = $(obj).closest('.tabbable_info').find('.contact').val();
  392. // var name = $(obj).closest('.tabbable_info').find('.name').val();
  393. // var tel = $(obj).closest('.tabbable_info').find('.tel').val();
  394. // var tel_short = $(obj).closest('.tabbable_info').find('.tel_short').val();
  395. // var fax = $(obj).closest('.tabbable_info').find('.fax').val();
  396. // var mail = $(obj).closest('.tabbable_info').find('.mail').val();
  397. // var remarks = $(obj).closest('.tabbable_info').find('.remarks').val();
  398. // $.ajax({
  399. // url:base_path+'control.php', //请求地址
  400. // data:{
  401. // type:"data_link",
  402. // operate:"update",
  403. // link_id:link_id,
  404. // link_name:contact,
  405. // contact_name:name,
  406. // contact_mobile:tel,
  407. // contact_telphone:tel_short,
  408. // fax:fax,
  409. // email:mail,
  410. // remark:remarks
  411. // },
  412. // type: "post",
  413. // dataType: "json",
  414. // success: function (data) {
  415. // console.log(data);
  416. // if(data.code == "0"){
  417. $(obj).closest('.tabbable_info').find('input,textarea').removeAttr('readonly');
  418. $(obj).closest('.tabbable_info').find('input,textarea').removeClass('input_no');
  419. $(obj).closest('.tabbable_info').find('.change').hide();
  420. $(obj).closest('.tabbable_info').find('.save').show();
  421. // }else{
  422. // alert(data.info);
  423. // }
  424. // }
  425. // });
  426. //
  427. }
  428. //总保存按钮
  429. function saveInfo() {
  430. var deduct_type = $("#deduct_type").val();
  431. var alert_balance = $("#alert_balance").val();
  432. var name_str = $('#name_str').val();
  433. var all_name = $('#all_name').val();
  434. var sale_style = $('input[name="sale_style"]:checked').val();
  435. var sale_time = $('input[name="sale_time"]:checked').val();
  436. var bank = $('#bank').val();
  437. var account_name = $('#account_name').val();
  438. var bank_id = $('#bank_id').val();
  439. var city_id = $('#cantonal').val();
  440. if (name_str == '') {
  441. alert('名称不能为空!');
  442. return;
  443. }
  444. if (all_name == '') {
  445. alert('公司全称不能为空!');
  446. return;
  447. }
  448. if (deduct_type == -1) {
  449. alert('请选择扣款口径!');
  450. return;
  451. }
  452. if (alert_balance == '') {
  453. alert('请输入预警金额!');
  454. return;
  455. }
  456. //采购范围的参数
  457. range_count = 0;
  458. var range_str = '';
  459. $('.range_every').each(function (index, dom) {
  460. var value = $(this).children().eq(0).val();
  461. var value1 = $(this).children().eq(1).children().eq(0).val();
  462. var value2 = $(this).attr('id');
  463. value2 = value2.substring(2);
  464. if (value != -1 && value1 != '') {
  465. range_str += '{' + value2 + ',' + value + ',' + value1 + '}';
  466. range_count++;
  467. }
  468. })
  469. if (range_count == 0) {
  470. alert('采购信息输入不完整!');
  471. return;
  472. }
  473. console.log('采购范围参数');
  474. console.log(range_str);
  475. //联系信息的参数
  476. var submit_link_id_arr = [];
  477. $('.tabbable_info').each(function (index, dom) {
  478. var link_id = $(this).closest('.tabbable_info').attr('id');
  479. submit_link_id_arr.push(link_id);
  480. })
  481. if ($.inArray("-1", submit_link_id_arr) != "-1") {
  482. alert("联系信息未保存");
  483. return;
  484. }
  485. ;
  486. // contact_count = 0;
  487. // var contact_str = '{';
  488. // $('.tabbable_info').each(function(index,dom){
  489. // var link_id = $(this).closest('.tabbable_info').attr('id');
  490. // if (link_id != -1) {
  491. // contact_str += link_id + ','
  492. // alert(contact_str);
  493. // }
  494. // })
  495. // contact_str = contact_str.substring(0,contact_str.length-1);
  496. // contact_str = contact_str +'}';
  497. // console.log('联系信息参数');
  498. // console.log(contact_str);
  499. var data = {
  500. type: 'supply_detail_update',
  501. supplier_name: name_str,
  502. area_id: city_id,
  503. company_name: all_name,
  504. purchase: range_str,
  505. sett_type: sale_style,
  506. sett_frequency: sale_time,
  507. account_bank: bank,
  508. account_num: account_name,
  509. account_name: bank_id,
  510. link_info: submit_link_id_arr.toString(),
  511. supply_id: prod_id,
  512. deduct_type: deduct_type,
  513. alert_balance: alert_balance
  514. }
  515. console.log('这里是data')
  516. console.log(data);
  517. $.ajax({
  518. url: base_path + 'control.php', //请求地址
  519. data: data,
  520. type: "post",
  521. dataType: "json",
  522. success: function (data) {
  523. if (data.code == "0") {
  524. alert(data.info);
  525. window.location.href = './supplier_list.html';
  526. } else {
  527. alert(data.info);
  528. }
  529. }
  530. });
  531. }
  532. //失去焦点
  533. $("#name_str").blur(function () {
  534. var value = $('#name_str').val();
  535. var prod_id = getPar('prod_id');
  536. $.ajax({
  537. url: base_path + 'control.php', //请求地址
  538. data: {
  539. type: "data_check",
  540. supplier_name: value,
  541. supplier_type: '187',
  542. supplier_id: prod_id
  543. },
  544. type: "post",
  545. dataType: "json",
  546. success: function (data) {
  547. console.log(data);
  548. if (data.code == "0") {
  549. $('#attention').text('名称可用');
  550. } else {
  551. $('#attention').text('名称已存在');
  552. }
  553. }
  554. });
  555. })