op.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. define(['core', 'tpl'], function(core, tpl) {
  2. var modal = {};
  3. modal.init = function(fromDetail) {
  4. if (typeof fromDetail === undefined) {
  5. fromDetail = true
  6. }
  7. modal.fromDetail = fromDetail;
  8. $('.order-cancel select').unbind('change').change(function() {
  9. var orderid = $(this).data('orderid');
  10. var val = $(this).val();
  11. if (val == '') {
  12. return
  13. }
  14. FoxUI.confirm('确认要取消该订单吗?', '提示', function() {
  15. modal.cancel(orderid, val, true)
  16. })
  17. });
  18. $('.order-delete').unbind('click').click(function() {
  19. var orderid = $(this).data('orderid');
  20. FoxUI.confirm('确认要删除该订单吗?', '提示', function() {
  21. modal.delete(orderid, 1)
  22. })
  23. });
  24. $('.order-deleted').unbind('click').click(function() {
  25. var orderid = $(this).data('orderid');
  26. FoxUI.confirm('确认要彻底删除该订单吗?', '提示', function() {
  27. modal.delete(orderid, 2)
  28. })
  29. });
  30. $('.order-recover').unbind('click').click(function() {
  31. var orderid = $(this).data('orderid');
  32. FoxUI.confirm('确认要恢复该订单吗?', '提示', function() {
  33. modal.delete(orderid, 0)
  34. })
  35. });
  36. $('.order-submoney').unbind('click').click(function() {
  37. var orderid = $(this).data('orderid');
  38. modal.submoney(orderid);
  39. });
  40. $('.order-finish').unbind('click').click(function() {
  41. var orderid = $(this).data('orderid');
  42. FoxUI.confirm('确认已收到货了吗?', '提示', function() {
  43. modal.finish(orderid)
  44. })
  45. });
  46. $('.order-verify').unbind('click').click(function() {
  47. var orderid = $(this).data('orderid');
  48. var verifycode = $(this).closest(".fui-list-group").data('verifycode');
  49. modal.verify(orderid, verifycode)
  50. })
  51. };
  52. modal.cancel = function(id, remark) {
  53. core.json('order/op/cancel', {
  54. id: id,
  55. remark: remark
  56. }, function(pay_json) {
  57. if (pay_json.status == 1) {
  58. if (modal.fromDetail) {
  59. location.href = core.getUrl('order')
  60. } else {
  61. $(".order-item[data-orderid='" + id + "']").remove()
  62. }
  63. return
  64. }
  65. FoxUI.toast.show(pay_json.result)
  66. }, true, true)
  67. };
  68. modal.delete = function(id, userdeleted) {
  69. core.json('order/op/delete', {
  70. id: id,
  71. userdeleted: userdeleted
  72. }, function(pay_json) {
  73. if (pay_json.status == 1) {
  74. if (modal.fromDetail) {
  75. location.href = core.getUrl('order')
  76. } else {
  77. $(".order-item[data-orderid='" + id + "']").remove()
  78. }
  79. return
  80. }
  81. FoxUI.toast.show(pay_json.result)
  82. }, true, true)
  83. };
  84. modal.submoney = function(id) {
  85. core.json('order/op/submoney', {
  86. id: id
  87. }, function(pay_json) {
  88. if (pay_json.status == 1) {
  89. location.href = location.href;
  90. return
  91. }
  92. FoxUI.toast.show(pay_json.result)
  93. }, true, true)
  94. };
  95. modal.finish = function(id) {
  96. core.json('order/op/finish', {
  97. id: id
  98. }, function(pay_json) {
  99. if (pay_json.status == 1) {
  100. location.href = pay_json.result.url;
  101. return
  102. }
  103. FoxUI.toast.show(pay_json.result)
  104. }, true, true)
  105. };
  106. modal.verify = function(orderid, verifycode) {
  107. console.log(verifycode);
  108. container = new FoxUIModal({
  109. content: $(".order-verify-hidden").html(),
  110. extraClass: "popup-modal",
  111. maskClick: function() {
  112. container.close()
  113. }
  114. });
  115. container.show();
  116. if ($(".code_box")) {
  117. $('.verify-pop').find('.code_box').unbind('click').click(function() {
  118. container.close()
  119. })
  120. } else {
  121. $('.verify-pop').find('.close').unbind('click').click(function() {
  122. container.close()
  123. })
  124. }
  125. core.json('verify/qrcode', {
  126. id: orderid
  127. }, function(ret) {
  128. if (ret.status == 0) {
  129. FoxUI.alert('生成出错,请刷新重试!');
  130. return
  131. }
  132. var time = +new Date();
  133. $('.verify-pop').find('.qrimg').attr('src', ret.result.url + "?timestamp=" + time).show();
  134. if (verifycode) {
  135. if (verifycode.toString().length == 9) {
  136. var verifycode1 = verifycode.toString().substr(0, 3);
  137. var verifycode2 = verifycode.toString().substr(3, 3);
  138. var verifycode3 = verifycode.toString().substr(6, 3);
  139. $('.verify-pop').find(".cav_code").html(verifycode1 + " " + verifycode2 + " " + verifycode3).show()
  140. } else {
  141. var verifycode1 = verifycode.toString().substr(0, 4);
  142. var verifycode2 = verifycode.toString().substr(4, 4);
  143. $('.verify-pop').find(".cav_code").html(verifycode1 + " " + verifycode2).show()
  144. }
  145. }
  146. }, false, true)
  147. };
  148. return modal
  149. });