trade.js 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081
  1. define(['bootstrap'], function($){
  2. var trade = {};
  3. var reg_credit = /^[+-]?(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/i;
  4. var reg_int = /^[0-9]\d*$/i;
  5. trade.init = function() {
  6. $('.modal-trade').on('click', function(){
  7. $('#consume-Modal, #credit-Modal, #card-Modal, #card-edit-Modal, #group-Modal').remove();
  8. var type = $(this).data('type');
  9. var uid = parseInt($(this).data('uid'));
  10. if(type == 'consume') {
  11. trade.consume(uid);
  12. } else if(type == 'credit1' || type == 'credit2') {
  13. trade.credit(type, uid);
  14. } else if(type == 'card') {
  15. trade.card(uid);
  16. } else if(type == 'cardsn') {
  17. trade.card_edit(uid);
  18. }
  19. });
  20. };
  21. trade.consume = function(uid) {
  22. var html = '<div class="modal fade" id="consume-Modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">'+
  23. ' <div class="modal-dialog modal-lg" role="document">'+
  24. ' <div class="modal-content">'+
  25. ' <form class="table-responsive form-inline" method="post" action="" id="form-consume">'+
  26. ' <div class="modal-header">'+
  27. ' <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>'+
  28. ' <h4 class="modal-title" id="myModalLabel">会员消费</h4>'+
  29. ' </div>'+
  30. ' <div class="modal-body">'+
  31. ' <table class="table table-hover table-bordered">'+
  32. ' <tr>'+
  33. ' <th width="150">'+
  34. ' <select name="type" id="type" class="form-control">'+
  35. ' <option value="mobile">手机号</option>'+
  36. ' <option value="uid">会员UID</option>'+
  37. ' </select>'+
  38. ' </th>'+
  39. ' <td>'+
  40. ' <div class="form-group">'+
  41. ' <input type="text" value="" name="username" id="username" class="form-control"/>'+
  42. ' </div>'+
  43. ' </td>'+
  44. ' </tr>'+
  45. ' <tr id="user" style="display: none">'+
  46. ' <th>会员信息</th>'+
  47. ' <td>'+
  48. ' <div class="form-group">'+
  49. ' <div class="input-group">'+
  50. ' <strong class="form-control-static"></strong>'+
  51. ' </div>'+
  52. ' </div>'+
  53. ' </td>'+
  54. ' </tr>'+
  55. ' <tr>'+
  56. ' <th>消费总计</th>'+
  57. ' <td>'+
  58. ' <div class="form-group">'+
  59. ' <div class="input-group">'+
  60. ' <input type="text" value="" name="total" id="total" class="form-control"/>'+
  61. ' <span class="input-group-addon">元</span>'+
  62. ' </div>'+
  63. ' </div>'+
  64. ' </td>'+
  65. ' </tr>'+
  66. ' <tr>'+
  67. ' <th>实收金额</th>'+
  68. ' <td>'+
  69. ' <div class="input-group">'+
  70. ' <input type="text" value="" name="money" id="money" class="form-control" readonly/>'+
  71. ' <span class="input-group-addon">元</span>'+
  72. ' </div>'+
  73. ' </td>'+
  74. ' </tr>'+
  75. ' <tr>'+
  76. ' <th rowspan="3">支付方式</th>'+
  77. ' <td>'+
  78. ' <label class="checkbox-inline">'+
  79. ' <input type="checkbox" name="is_credit2_pay" id="is_credit2_pay" value="1" /> 余额支付'+
  80. ' </label>'+
  81. ' <div class="form-group">'+
  82. ' <div class="input-group">'+
  83. ' <input type="text" value="0" name="credit2" id="credit2" disabled class="form-control"/>'+
  84. ' <span class="input-group-addon">元</span>'+
  85. ' </div>'+
  86. ' </div>'+
  87. ' </td>'+
  88. ' </tr>'+
  89. ' <tr>'+
  90. ' <td>'+
  91. ' <label class="checkbox-inline">'+
  92. ' <input type="checkbox" name="is_credit1_pay" id="is_credit1_pay" value="1" /> 积分抵现'+
  93. ' </label>'+
  94. ' <div class="form-group">'+
  95. ' <div class="input-group">'+
  96. ' <input type="text" value="0" name="credit1" id="credit1" disabled class="form-control"/>'+
  97. ' <span class="input-group-addon">积分 抵消</span>'+
  98. ' <input type="text" value="0" name="offset_money" id="offset_money" disabled class="form-control"/>'+
  99. ' <span class="input-group-addon">元</span>'+
  100. ' </div>'+
  101. ' </div>'+
  102. ' </td>'+
  103. ' </tr>'+
  104. ' <tr>'+
  105. ' <td>'+
  106. ' <label class="checkbox-inline">'+
  107. ' <input type="checkbox" value="1" name="is_cash_pay" id="is_cash_pay" /> 现金支付'+
  108. ' </label>'+
  109. ' <div class="form-group">'+
  110. ' <div class="input-group">'+
  111. ' <input type="text" value="0" name="cash" id="cash" disabled class="form-control"/>'+
  112. ' <span class="input-group-addon">元  找零</span>'+
  113. ' <input type="text" value="0" name="return_cash" id="return_cash" disabled class="form-control"/>'+
  114. ' <span class="input-group-addon">元</span>'+
  115. ' </div>'+
  116. ' </div>'+
  117. ' </td>'+
  118. ' </tr>'+
  119. ' <tr>'+
  120. ' <th>备注</th>'+
  121. ' <td>'+
  122. ' <textarea name="remark" class="form-control" cols="81"></textarea>'+
  123. ' </td>'+
  124. ' </tr>'+
  125. ' </table>'+
  126. ' </div>'+
  127. ' <div class="modal-footer">'+
  128. ' <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>'+
  129. ' <input type="button" class="btn btn-primary" id="submit-form" value="提交">'+
  130. ' </div>'+
  131. ' </form>'+
  132. ' </div>'+
  133. ' </div>'+
  134. '</div>';
  135. require(['validator'], function($){
  136. $('#consume-Modal').remove();
  137. $(document.body).append(html);
  138. var dialog = $('#consume-Modal');
  139. dialog.modal('show');
  140. $('#username').focus();
  141. $('#form-consume').bootstrapValidator({
  142. fields: {
  143. username: {
  144. validators: {
  145. notEmpty: {
  146. message: '请填写用户手机或UID'
  147. }
  148. }
  149. },
  150. total: {
  151. validators: {
  152. notEmpty: {
  153. message: '请填写消费总计'
  154. },
  155. regexp: {
  156. regexp: reg_credit,
  157. message: '最多只保留小数点后2位的正数'
  158. }
  159. }
  160. },
  161. credit2: {
  162. validators: {
  163. notEmpty: {
  164. message: '请填写余额支付金额'
  165. },
  166. regexp: {
  167. regexp: reg_credit,
  168. message: '最多只保留小数点后2位的正数'
  169. },
  170. between: {
  171. min: 0,
  172. max: 100000000,
  173. money: 0,
  174. message : '超出可用余额'
  175. }
  176. }
  177. },
  178. credit1: {
  179. validators: {
  180. notEmpty: {
  181. message: '请填写积分数量'
  182. },
  183. regexp: {
  184. regexp: reg_int,
  185. message: '积分数量只能是正整数'
  186. },
  187. between: {
  188. min: 0,
  189. max: 1000000000,
  190. message : '超出会员所拥有的积分或超出最多可抵消金额'
  191. }
  192. }
  193. },
  194. cash: {
  195. validators: {
  196. notEmpty: {
  197. message: '请填写现金支付金额'
  198. },
  199. regexp: {
  200. regexp: reg_credit,
  201. message: '最多只保留小数点后2位的正数'
  202. }
  203. }
  204. }
  205. }
  206. });
  207. var Validator = $('#form-consume').data('bootstrapValidator');
  208. var consume = {
  209. 'user': {},
  210. 'card': {},
  211. 'total': 0,
  212. 'money': 0,
  213. 'last_money': 0,
  214. 'return_cash':0,
  215. 'is_credit1_pay': false,
  216. 'is_credit2_pay': false,
  217. 'is_cash_pay': false,
  218. 'credit1': 0,
  219. 'credit2': 0,
  220. 'cash': 0,
  221. 'offset_money': 0,
  222. 'password': '',
  223. 'init': function(uid) {
  224. Validator.enableFieldValidators('credit2');
  225. Validator.enableFieldValidators('credit1');
  226. Validator.enableFieldValidators('cash');
  227. this.getuser();
  228. if(uid > 0) {
  229. $('#type').val('uid');
  230. $('#username').val(uid);
  231. $('#username').trigger('blur');
  232. $('#username, #type').attr('disabled', true);
  233. }
  234. this.initmoney();
  235. this.initconsume();
  236. this.submit();
  237. },
  238. 'checkuser': function() {
  239. if(this.user.uid == undefined || !this.user.uid) {
  240. this.user = {};
  241. this.card = {};
  242. $('#username').focus();
  243. Validator.updateMessage('username', 'notEmpty', '未找到对应会员');
  244. Validator.updateStatus('username', 'INVALID', 'notEmpty');
  245. //util.message('未找到对应会员');
  246. return false;
  247. }
  248. return true;
  249. },
  250. 'getuser': function(){
  251. var _this = this;
  252. $('#username').blur(function(){
  253. Validator.validateField('username');
  254. var username = $.trim($('#username').val());
  255. var type = $('#type').val();
  256. if(username) {
  257. $.post('./index.php?c=mc&a=trade&do=user&', {'type':type, 'username':username}, function(data){
  258. var data = $.parseJSON(data);
  259. if(data.error != 'none') {
  260. _this.user = {};
  261. _this.card = {};
  262. $('#user').hide();
  263. Validator.updateMessage('username', 'notEmpty', data.message);
  264. Validator.updateStatus('username', 'INVALID', 'notEmpty');
  265. return false;
  266. } else {
  267. _this.user = data.user;
  268. _this.card = data.card;
  269. $('#user strong').html(data.html);
  270. $('#user').show();
  271. }
  272. });
  273. }
  274. });
  275. },
  276. 'initmoney': function() {
  277. var _this = this;
  278. $('#total').blur(function(){
  279. if(!_this.checkuser()) {
  280. return false;
  281. }
  282. var total = parseFloat($(this).val());
  283. _this.total = total;
  284. money = total;
  285. if(_this.user.discount && total >= _this.user.discount.condition) {
  286. if(_this.card.discount_type == 1) {
  287. money = total - _this.user.discount.discount;
  288. } else {
  289. if(!_this.user.discount.discount) {
  290. _this.user.discount.discount = 1;
  291. }
  292. money = total * _this.user.discount.discount;
  293. }
  294. if(money < 0) {
  295. money = 0;
  296. }
  297. }
  298. $('#money').val(money);
  299. _this.money = money;
  300. _this.last_money = money;
  301. });
  302. },
  303. 'initcredit1': function() {
  304. var _this = this;
  305. $('#credit1').keyup(function(){
  306. if(!_this.checkuser()) {
  307. return false;
  308. }
  309. _this.credit1 = parseInt($(this).val());
  310. if(isNaN(_this.credit1)) {
  311. _this.credit1 = 0;
  312. }
  313. if(_this.credit1 >= 0 && _this.card.offset_rate > 0 && _this.card.offset_max > 0) {
  314. $('#offset_money').val(_this.credit1 / _this.card.offset_rate);
  315. _this.offset_money = _this.credit1/_this.card.offset_rate;
  316. }
  317. var credit1 = parseInt($(this).val());
  318. if(_this.user.credit1 < credit1) {
  319. Validator.updateOption('credit1', 'between', 'max', _this.user.credit1);
  320. Validator.updateMessage('credit1', 'between', '超出会员账户可用积分');
  321. Validator.updateStatus('credit1', 'INVALID', 'between');
  322. } else if(_this.card && (_this.card.offset_rate > 0) && (_this.card.offset_max > 0) && (credit1 > (_this.card.offset_rate * _this.card.offset_max))) {
  323. Validator.updateOption('credit1', 'between', 'max', _this.card.offset_rate * _this.card.offset_max);
  324. Validator.updateMessage('credit1', 'between', '积分最多可抵消'+_this.card.offset_max);
  325. Validator.updateStatus('credit1', 'INVALID', 'between');
  326. }
  327. _this.updatereturn();
  328. });
  329. },
  330. 'initcredit2': function() {
  331. var _this = this;
  332. $('#credit2').keyup(function(){
  333. if(!_this.checkuser()) {
  334. return false;
  335. }
  336. var money = $('#money').val();
  337. if(money > 0) {
  338. var credit2 = parseFloat($('#credit2').val());
  339. if(_this.user.credit2 < credit2) {
  340. Validator.updateOption('credit2', 'between', 'max', _this.user.credit2);
  341. Validator.updateMessage('credit2', 'between', '超出会员账户可用余额');
  342. Validator.updateStatus('credit2', 'INVALID', 'between');
  343. } else if(credit2 > money) {
  344. Validator.updateOption('credit2', 'between', 'max', money);
  345. Validator.updateMessage('credit2', 'between', '使用余额不能大于应付金额');
  346. Validator.updateStatus('credit2', 'INVALID', 'between');
  347. }
  348. _this.credit2 = credit2;
  349. _this.updatereturn();
  350. }
  351. });
  352. },
  353. 'initcash': function() {
  354. var _this = this;
  355. $('#cash').keyup(function(){
  356. if(!_this.checkuser()) {
  357. return false;
  358. }
  359. var money = $('#money').val();
  360. if(money > 0) {
  361. var cash = parseFloat($('#cash').val());
  362. _this.cash = cash;
  363. _this.updatereturn();
  364. }
  365. });
  366. },
  367. 'updatereturn': function() {
  368. var _this = this;
  369. _this.return_cash = _this.money - _this.credit2 - _this.offset_money - _this.cash;
  370. if(_this.return_cash > 0) {
  371. _this.last_money = _this.return_cash;
  372. $('#return_cash').val(0);
  373. } else {
  374. _this.last_money = 0;
  375. $('#return_cash').val(Math.abs(_this.return_cash));
  376. }
  377. },
  378. 'updatecredit1': function(){
  379. var _this = this;
  380. if(_this.card.offset_rate >= 0 || _this.card.offset_max >= 0 && _this.last_money > 0) {
  381. var min = Math.min.apply(null, [_this.user.credit1, _this.card.offset_rate * _this.card.offset_max, _this.card.offset_rate * _this.last_money]);
  382. $('#credit1').val(min).focus().select();
  383. $('#offset_money').val(min/_this.card.offset_rate);
  384. _this.credit1 = min;
  385. _this.offset_money = min/_this.card.offset_rate;
  386. }
  387. },
  388. 'updatecredit2': function(){
  389. var _this = this;
  390. var min = Math.min(_this.user.credit2, _this.last_money);
  391. $('#credit2').val(min);
  392. _this.credit2 = min;
  393. },
  394. 'updatecash': function(){
  395. var _this = this;
  396. $('#cash').val(_this.last_money);
  397. _this.cash = _this.last_money;
  398. },
  399. 'initconsume': function() {
  400. var _this = this;
  401. _this.is_credit1_pay = $('#is_credit1_pay').prop('checked');
  402. _this.is_credit2_pay = $('#is_credit2_pay').prop('checked');
  403. _this.is_cash_pay = $('#is_cash_pay').prop('checked');
  404. _this.credit1 = parseInt($('#credit1').val());
  405. _this.credit2 = parseFloat($('#credit2').val());
  406. _this.cash = parseFloat($('#cash').val());
  407. _this.initcredit1();
  408. _this.initcredit2();
  409. _this.initcash();
  410. $('#is_credit1_pay').click(function(){
  411. if(!_this.checkuser()) {
  412. return false;
  413. }
  414. if(!_this.money) {
  415. Validator.updateStatus('total', 'INVALID', 'regexp');
  416. $('#total').focus().select();
  417. return false;
  418. }
  419. if(!$(this).prop('checked')) {
  420. //如果是非选中状态
  421. Validator.updateStatus('credit1', 'VALID');
  422. $('#credit1').attr('disabled', true);
  423. Validator.enableFieldValidators('credit1', false);
  424. $('#credit1').val(0);
  425. $('#offset_money').val(0);
  426. $(this).prop('checked', false);
  427. _this.is_credit1_pay = false;
  428. _this.credit1 = 0;
  429. _this.offset_money = 0;
  430. } else if(_this.last_money >= 0) {
  431. if(_this.last_money == 0) {
  432. return false;
  433. }
  434. _this.is_credit1_pay = true;
  435. $('#credit1').removeAttr('disabled');
  436. Validator.enableFieldValidators('credit1', true);
  437. _this.updatecredit1();
  438. }
  439. _this.updatereturn();
  440. });
  441. $('#is_credit2_pay').click(function(){
  442. if(!_this.checkuser()) {
  443. return false;
  444. }
  445. if(!_this.money) {
  446. Validator.updateStatus('total', 'INVALID', 'regexp');
  447. $('#total').focus().select();
  448. return false;
  449. }
  450. if(!$(this).prop('checked')) {
  451. //如果是非选中状态
  452. Validator.updateStatus('credit2', 'VALID');
  453. $('#credit2').attr('disabled', true);
  454. Validator.enableFieldValidators('credit2', false);
  455. $('#credit2').val(0);
  456. $(this).prop('checked', false);
  457. _this.is_credit2_pay = false;
  458. _this.credit2 = 0;
  459. } else if(_this.last_money >= 0) {
  460. if(_this.last_money == 0) {
  461. return false;
  462. }
  463. $('#credit2').removeAttr('disabled');
  464. Validator.enableFieldValidators('credit2', true);
  465. _this.is_credit2_pay = true;
  466. _this.updatecredit2();
  467. }
  468. _this.updatereturn();
  469. });
  470. $('#is_cash_pay').click(function(){
  471. if(!_this.checkuser()) {
  472. return false;
  473. }
  474. if(!_this.money) {
  475. Validator.updateStatus('total', 'INVALID', 'regexp');
  476. $('#total').focus().select();
  477. return false;
  478. }
  479. if(!$(this).prop('checked')) {
  480. //如果是非选中状态
  481. Validator.updateStatus('cash', 'VALID');
  482. $('#cash').attr('disabled', true);
  483. Validator.enableFieldValidators('cash', false);
  484. $('#cash').val(0);
  485. $(this).prop('checked', false);
  486. _this.is_cash_pay = false;
  487. _this.cash = 0;
  488. } else if(_this.last_money >= 0) {
  489. if(_this.last_money == 0) {
  490. return false;
  491. }
  492. $('#cash').removeAttr('disabled');
  493. Validator.enableFieldValidators('cash', true);
  494. _this.is_cash_pay = true;
  495. _this.updatecash();
  496. }
  497. _this.updatereturn();
  498. });
  499. },
  500. 'submit': function() {
  501. var _this = this;
  502. _this.updatereturn();
  503. $('#form-consume #submit-form').click(function(){
  504. Validator.validate();
  505. if(Validator.isValid()) {
  506. if(_this.last_money > 0) {
  507. util.message('支付金额小于实收金额,请检查表单');
  508. return false;
  509. }
  510. _this.password = $.trim($(':input[name="password"]').val());
  511. _this.remark = $.trim($('textarea[name="remark"]').val());
  512. var param = {
  513. 'uid': _this.user.uid,
  514. 'total': _this.total,
  515. 'money': _this.money,
  516. 'credit2': _this.credit2,
  517. 'credit1': _this.credit1,
  518. 'cash': _this.cash,
  519. 'offset_money': _this.offset_money,
  520. 'return_cash': _this.return_cash,
  521. 'password': _this.password,
  522. 'remark': _this.remark
  523. }
  524. $.post('./index.php?c=mc&a=trade&do=consume', param, function(data){
  525. if(data != 'success') {
  526. util.message(data, '', 'error');
  527. return false;
  528. } else {
  529. dialog.modal('hide');
  530. util.message('交易成功', 'refresh', 'success');
  531. return false;
  532. }
  533. });
  534. }
  535. });
  536. }
  537. };
  538. consume.init(uid);
  539. });
  540. };
  541. trade.credit = function(type, uid) {
  542. var types = {'credit1': '积分', 'credit2': '余额'};
  543. var html = '<div class="modal fade" id="credit-Modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">'+
  544. ' <div class="modal-dialog modal-lg" role="document">'+
  545. ' <div class="modal-content">'+
  546. ' <form class="table-responsive form-inline" method="post" action="" id="form-credit">'+
  547. ' <div class="modal-header">'+
  548. ' <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>'+
  549. ' <h4 class="modal-title" id="myModalLabel">会员'+types[type]+'操作</h4>'+
  550. ' </div>'+
  551. ' <div class="modal-body">'+
  552. ' <table class="table table-hover table-bordered">'+
  553. ' <tr>'+
  554. ' <th width="150">'+
  555. ' <select name="type" id="type" class="form-control">'+
  556. ' <option value="mobile">手机号</option>'+
  557. ' <option value="uid">会员UID</option>'+
  558. ' </select>'+
  559. ' </th>'+
  560. ' <td>'+
  561. ' <div class="form-group">'+
  562. ' <input type="text" value="" name="username" id="username" class="form-control"/>'+
  563. ' </div>'+
  564. ' </td>'+
  565. ' </tr>'+
  566. ' <tr id="user" style="display: none">'+
  567. ' <th>会员信息</th>'+
  568. ' <td>'+
  569. ' <div class="form-group">'+
  570. ' <div class="input-group">'+
  571. ' <strong class="form-control-static"></strong>'+
  572. ' </div>'+
  573. ' </div>'+
  574. ' </td>'+
  575. ' </tr>'+
  576. ' <tr>'+
  577. ' <th>修改'+types[type]+'(增减)</th>'+
  578. ' <td>'+
  579. ' <div class="form-group">'+
  580. ' <input type="text" value="" name="num" id="total" class="form-control"/>'+
  581. ' <div class="help-block">输入500,则标识增加500;输入-500则表示减少500</div>'+
  582. ' </div>'+
  583. ' </td>'+
  584. ' </tr>'+
  585. ' <tr>'+
  586. ' <th>备注</th>'+
  587. ' <td>'+
  588. ' <textarea name="remark" class="form-control" cols="81"></textarea>'+
  589. ' </td>'+
  590. ' </tr>'+
  591. ' </table>'+
  592. ' </div>'+
  593. ' <div class="modal-footer">'+
  594. ' <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>'+
  595. ' <input type="submit" class="btn btn-primary" id="submit" name="提交"value="提交">'+
  596. ' </div>'+
  597. ' </form>'+
  598. ' </div>'+
  599. ' </div>'+
  600. '</div>';
  601. require(['validator'], function($){
  602. $('#credit-Modal').remove();
  603. $(document.body).append(html);
  604. var dialog = $('#credit-Modal');
  605. dialog.modal('show');
  606. $('#form-credit').bootstrapValidator({
  607. fields: {
  608. username: {
  609. validators: {
  610. notEmpty: {
  611. message: '请填写用户手机或UID'
  612. }
  613. }
  614. },
  615. num: {
  616. validators: {
  617. notEmpty: {
  618. message: '请填写数量'
  619. },
  620. regexp: {
  621. regexp: /^[+-]?(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/i,
  622. message: '最多只保留小数点后2位的正数'
  623. }
  624. }
  625. }
  626. }
  627. });
  628. var Validator = $('#form-credit').data('bootstrapValidator');
  629. var credit = {
  630. 'user': {},
  631. 'card': {},
  632. 'init': function(type, uid) {
  633. this.type = type,
  634. this.getuser();
  635. if(uid > 0) {
  636. $('#type').val('uid');
  637. $('#username').val(uid);
  638. $('#username').trigger('blur');
  639. $('#username, #type').attr('disabled', true);
  640. }
  641. this.submit();
  642. },
  643. getuser: function() {
  644. var _this = this;
  645. $('#username').blur(function(){
  646. Validator.validateField('username');
  647. var username = $.trim($('#username').val());
  648. var type = $('#type').val();
  649. if(username) {
  650. $.post('./index.php?c=mc&a=trade&do=user&', {'type':type, 'username':username}, function(data){
  651. var data = $.parseJSON(data);
  652. if(data.error != 'none') {
  653. _this.user = {};
  654. _this.card = {};
  655. $('#user').hide();
  656. Validator.updateMessage('username', 'notEmpty', data.message);
  657. Validator.updateStatus('username', 'INVALID', 'notEmpty');
  658. return false;
  659. } else {
  660. _this.user = data.user;
  661. _this.card = data.card;
  662. $('#user strong').html(data.html);
  663. $('#user').show();
  664. }
  665. });
  666. }
  667. });
  668. },
  669. 'checkuser': function() {
  670. if(this.user.uid == undefined || !this.user.uid) {
  671. this.user = {};
  672. this.card = {};
  673. $('#username').focus();
  674. Validator.updateMessage('username', 'notEmpty', '未找到对应会员');
  675. Validator.updateStatus('username', 'INVALID', 'notEmpty');
  676. //util.message('未找到对应会员');
  677. return false;
  678. }
  679. return true;
  680. },
  681. 'submit': function() {
  682. var _this = this;
  683. $('#form-credit .btn-primary').click(function(){
  684. _this.checkuser();
  685. Validator.validate();
  686. if(Validator.isValid()) {
  687. _this.password = $.trim($(':input[name="password"]').val());
  688. _this.num = $.trim($(':text[name="num"]').val());
  689. _this.remark = $.trim($('textarea[name="remark"]').val());
  690. var param = {
  691. 'uid': _this.user.uid,
  692. 'num': _this.num,
  693. 'password': _this.password,
  694. 'remark': _this.remark,
  695. 'type': _this.type
  696. }
  697. $.post('./index.php?c=mc&a=trade&do=credit', param, function(data){
  698. if(data != 'success') {
  699. util.message(data, '', 'error');
  700. return false;
  701. } else {
  702. dialog.modal('hide');
  703. util.message('操作成功', 'refresh', 'success');
  704. return false;
  705. }
  706. });
  707. }
  708. });
  709. }
  710. };
  711. credit.init(type, uid);
  712. });
  713. };
  714. trade.card = function(uid) {
  715. var html = '<div class="modal fade" id="card-Modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">'+
  716. ' <div class="modal-dialog modal-lg" role="document">'+
  717. ' <div class="modal-content">'+
  718. ' <form class="table-responsive form-inline" method="post" action="" id="form-card">'+
  719. ' <div class="modal-header">'+
  720. ' <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>'+
  721. ' <h4 class="modal-title" id="myModalLabel">发放会员卡</h4>'+
  722. ' </div>'+
  723. ' <div class="modal-body">'+
  724. ' <table class="table table-hover table-bordered">'+
  725. ' <tr>'+
  726. ' <th width="150">'+
  727. ' <select name="type" id="type" class="form-control">'+
  728. ' <option value="mobile">手机号</option>'+
  729. ' <option value="uid">会员UID</option>'+
  730. ' </select>'+
  731. ' </th>'+
  732. ' <td>'+
  733. ' <div class="form-group">'+
  734. ' <input type="text" value="" name="username" id="username" class="form-control"/>'+
  735. ' </div>'+
  736. ' </td>'+
  737. ' </tr>'+
  738. ' <tr id="user" style="display: none">'+
  739. ' <th>会员信息</th>'+
  740. ' <td>'+
  741. ' <div class="form-group">'+
  742. ' <div class="input-group">'+
  743. ' <strong class="form-control-static"></strong>'+
  744. ' </div>'+
  745. ' </div>'+
  746. ' </td>'+
  747. ' </tr>'+
  748. ' </table>'+
  749. ' </div>'+
  750. ' <div class="modal-footer">'+
  751. ' <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>'+
  752. ' <input type="submit" class="btn btn-primary" id="submit" name="提交"value="提交">'+
  753. ' </div>'+
  754. ' </form>'+
  755. ' </div>'+
  756. ' </div>'+
  757. '</div>';
  758. require(['validator'], function($){
  759. $('#card-Modal').remove();
  760. $(document.body).append(html);
  761. var dialog = $('#card-Modal');
  762. dialog.modal('show');
  763. $('#form-card').bootstrapValidator({
  764. fields: {
  765. username: {
  766. validators: {
  767. notEmpty: {
  768. message: '请填写用户手机或UID'
  769. }
  770. }
  771. }
  772. }
  773. });
  774. var Validator = $('#form-card').data('bootstrapValidator');
  775. var card = {
  776. 'user': {},
  777. 'card': {},
  778. 'init': function(uid) {
  779. this.getuser();
  780. if(uid > 0) {
  781. $('#type').val('uid');
  782. $('#username').val(uid);
  783. $('#username').trigger('blur');
  784. if(this.user.uid > 0) {
  785. $('#username, #type').attr('disabled', true);
  786. }
  787. }
  788. this.submit();
  789. },
  790. getuser: function() {
  791. var _this = this;
  792. $('#username').blur(function(){
  793. Validator.validateField('username');
  794. var username = $.trim($('#username').val());
  795. var type = $('#type').val();
  796. if(username) {
  797. $.post('./index.php?c=mc&a=trade&do=user&', {'type':type, 'username':username}, function(data){
  798. var data = $.parseJSON(data);
  799. if(data.error != 'none') {
  800. _this.user = {};
  801. _this.card = {};
  802. $('#user').hide();
  803. Validator.updateMessage('username', 'notEmpty', data.message);
  804. Validator.updateStatus('username', 'INVALID', 'notEmpty');
  805. return false;
  806. } else {
  807. _this.user = data.user;
  808. _this.card = data.card;
  809. $('#user strong').html(data.html);
  810. $('#user').show();
  811. }
  812. });
  813. }
  814. });
  815. },
  816. 'checkuser': function() {
  817. if(this.user.uid == undefined || !this.user.uid) {
  818. this.user = {};
  819. this.card = {};
  820. $('#username').focus();
  821. Validator.updateMessage('username', 'notEmpty', '未找到对应会员');
  822. Validator.updateStatus('username', 'INVALID', 'notEmpty');
  823. return false;
  824. }
  825. if(this.card.id > 0) {
  826. util.message('该会员已领取会员卡');
  827. return false;
  828. }
  829. return true;
  830. },
  831. 'submit': function() {
  832. var _this = this;
  833. $('#form-card .btn-primary').click(function(){
  834. _this.checkuser();
  835. Validator.validate();
  836. if(Validator.isValid()) {
  837. _this.password = $.trim($(':input[name="password"]').val());
  838. var param = {
  839. 'uid': _this.user.uid,
  840. 'password': _this.password,
  841. }
  842. $.post('./index.php?c=mc&a=trade&do=card', param, function(data){
  843. if(data != 'success') {
  844. util.message(data, '', 'error');
  845. return false;
  846. } else {
  847. dialog.modal('hide');
  848. util.message('发放会员卡成功', 'refresh', 'success');
  849. return false;
  850. }
  851. });
  852. }
  853. });
  854. }
  855. };
  856. card.init(uid);
  857. });
  858. }
  859. trade.card_edit = function(uid) {
  860. var html = '<div class="modal fade" id="card-edit-Modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">'+
  861. ' <div class="modal-dialog modal-lg" role="document">'+
  862. ' <div class="modal-content">'+
  863. ' <form class="table-responsive form-inline" method="post" action="" id="form-card">'+
  864. ' <div class="modal-header">'+
  865. ' <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>'+
  866. ' <h4 class="modal-title" id="myModalLabel">更改会员卡号</h4>'+
  867. ' </div>'+
  868. ' <div class="modal-body">'+
  869. ' <table class="table table-hover table-bordered">'+
  870. ' <tr>'+
  871. ' <th width="150">'+
  872. ' <select name="type" id="type" class="form-control">'+
  873. ' <option value="mobile">手机号</option>'+
  874. ' <option value="uid">会员UID</option>'+
  875. ' </select>'+
  876. ' </th>'+
  877. ' <td>'+
  878. ' <div class="form-group">'+
  879. ' <input type="text" value="" name="username" id="username" class="form-control"/>'+
  880. ' </div>'+
  881. ' </td>'+
  882. ' </tr>'+
  883. ' <tr id="user" style="display: none">'+
  884. ' <th>会员信息</th>'+
  885. ' <td>'+
  886. ' <div class="form-group">'+
  887. ' <div class="input-group">'+
  888. ' <strong class="form-control-static"></strong>'+
  889. ' </div>'+
  890. ' </div>'+
  891. ' </td>'+
  892. ' </tr>'+
  893. ' <tr>'+
  894. ' <th>原卡号</th>'+
  895. ' <td>'+
  896. ' <div class="form-group">'+
  897. ' <p class="label label-danger" id="old_cardsn"></p>'+
  898. ' </div>'+
  899. ' </td>'+
  900. ' </tr>'+
  901. ' <tr>'+
  902. ' <th>设置新卡号</th>'+
  903. ' <td>'+
  904. ' <div class="form-group">'+
  905. ' <input type="text" name="cardsn" id="cardsn" value="" class="form-control">'+
  906. ' </div>'+
  907. ' </td>'+
  908. ' </tr>'+
  909. ' </table>'+
  910. ' </div>'+
  911. ' <div class="modal-footer">'+
  912. ' <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>'+
  913. ' <input type="submit" class="btn btn-primary" id="submit" name="提交"value="提交">'+
  914. ' </div>'+
  915. ' </form>'+
  916. ' </div>'+
  917. ' </div>'+
  918. '</div>';
  919. require(['validator'], function($){
  920. $('#card-edit-Modal').remove();
  921. $(document.body).append(html);
  922. var dialog = $('#card-edit-Modal');
  923. dialog.modal('show');
  924. $('#form-card').bootstrapValidator({
  925. fields: {
  926. username: {
  927. validators: {
  928. notEmpty: {
  929. message: '请填写用户手机或UID'
  930. }
  931. }
  932. },
  933. cardsn: {
  934. validators: {
  935. notEmpty: {
  936. message: '新卡号不能为空'
  937. },
  938. remote: {
  939. url: "./index.php?c=mc&a=trade&do=cardsn&type=check",
  940. data: function(validator) {
  941. return {
  942. data: validator.getFieldElements('cardsn').val()
  943. };
  944. },
  945. message: '卡号已经被其他用户使用'
  946. }
  947. }
  948. }
  949. }
  950. });
  951. var Validator = $('#form-card').data('bootstrapValidator');
  952. var card_edit = {
  953. 'user': {},
  954. 'card': {},
  955. 'init': function(uid) {
  956. this.getuser();
  957. if(uid > 0) {
  958. $('#type').val('uid');
  959. $('#username').val(uid);
  960. $('#username').trigger('blur');
  961. if(this.user.uid > 0) {
  962. $('#username, #type').attr('disabled', true);
  963. }
  964. }
  965. this.submit();
  966. },
  967. getuser: function() {
  968. var _this = this;
  969. $('#username').blur(function(){
  970. Validator.validateField('username');
  971. var username = $.trim($('#username').val());
  972. var type = $('#type').val();
  973. if(username) {
  974. $.post('./index.php?c=mc&a=trade&do=user&', {'type':type, 'username':username}, function(data){
  975. var data = $.parseJSON(data);
  976. if(data.error != 'none') {
  977. _this.user = {};
  978. _this.card = {};
  979. $('#user').hide();
  980. Validator.updateMessage('username', 'notEmpty', data.message);
  981. Validator.updateStatus('username', 'INVALID', 'notEmpty');
  982. return false;
  983. } else {
  984. _this.user = data.user;
  985. _this.card = data.card;
  986. $('#user strong').html(data.html);
  987. $('#old_cardsn').html(data.user.cardsn);
  988. $('#user').show();
  989. }
  990. });
  991. }
  992. });
  993. },
  994. 'checkuser': function() {
  995. if(this.user.uid == undefined || !this.user.uid) {
  996. this.user = {};
  997. this.card = {};
  998. $('#username').focus();
  999. Validator.updateMessage('username', 'notEmpty', '未找到对应会员');
  1000. Validator.updateStatus('username', 'INVALID', 'notEmpty');
  1001. return false;
  1002. }
  1003. return true;
  1004. },
  1005. 'submit': function() {
  1006. var _this = this;
  1007. $('#form-card .btn-primary').click(function(){
  1008. _this.checkuser();
  1009. Validator.validate();
  1010. if(Validator.isValid()) {
  1011. var param = {
  1012. 'uid': _this.user.uid,
  1013. 'cardsn': $.trim($('#cardsn').val()),
  1014. 'password': $.trim($(':input[name="password"]').val())
  1015. }
  1016. $.post('./index.php?c=mc&a=trade&do=cardsn', param, function(data){
  1017. if(data != 'success') {
  1018. util.message(data, '', 'error');
  1019. return false;
  1020. } else {
  1021. dialog.modal('hide');
  1022. util.message('更改卡号成功', 'refresh', 'success');
  1023. return false;
  1024. }
  1025. });
  1026. }
  1027. });
  1028. }
  1029. };
  1030. card_edit.init(uid);
  1031. });
  1032. }
  1033. return trade;
  1034. });