order.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. var app = getApp(),
  2. api = getApp().api,
  3. is_no_more = !1,
  4. is_loading = !1,
  5. p = 2;
  6. Page({
  7. data: {
  8. status: -1,
  9. order_list: [],
  10. show_no_data_tip: !1,
  11. hide: 1,
  12. qrcode: ""
  13. },
  14. onLoad: function (t) {
  15. getApp().page.onLoad(this, t);
  16. var e = this;
  17. is_loading = is_no_more = !1, p = 2, e.setData({
  18. options: t
  19. }), e.loadOrderList(t.status || -1), getCurrentPages().length < 2 && e.setData({
  20. show_index: !0
  21. })
  22. },
  23. loadOrderList: function (t) {
  24. null == t && (t = -1);
  25. var e = this;
  26. e.setData({
  27. status: t
  28. }), getApp().core.showLoading({
  29. title: "正在加载",
  30. mask: !0
  31. });
  32. var a = {
  33. status: e.data.status
  34. };
  35. e.data.options;
  36. void 0 !== e.data.options.order_id && (a.order_id = e.data.options.order_id), getApp().request({
  37. url: getApp().api.order.list,
  38. data: a,
  39. success: function (t) {
  40. 0 == t.code && (e.setData({
  41. order_list: t.data.list,
  42. pay_type_list: t.data.pay_type_list
  43. }), getApp().core.getStorageSync(getApp().const.ITEM) && getApp().core.removeStorageSync(getApp().const.ITEM));
  44. e.setData({
  45. show_no_data_tip: 0 == e.data.order_list.length
  46. })
  47. },
  48. complete: function () {
  49. getApp().core.hideLoading()
  50. }
  51. })
  52. },
  53. onReachBottom: function () {
  54. var a = this;
  55. is_loading || is_no_more || (is_loading = !0, getApp().request({
  56. url: getApp().api.order.list,
  57. data: {
  58. status: a.data.status,
  59. page: p
  60. },
  61. success: function (t) {
  62. if (0 == t.code) {
  63. var e = a.data.order_list.concat(t.data.list);
  64. a.setData({
  65. order_list: e,
  66. pay_type_list: t.data.pay_type_list
  67. }), 0 == t.data.list.length && (is_no_more = !0)
  68. }
  69. p++
  70. },
  71. complete: function () {
  72. is_loading = !1
  73. }
  74. }))
  75. },
  76. orderPay_1: function (e) {
  77. var a = this,
  78. t = a.data.pay_type_list;
  79. 1 == t.length ? (getApp().core.showLoading({
  80. title: "正在提交",
  81. mask: !0
  82. }), 0 == t[0].payment && a.WechatPay(e), 3 == t[0].payment && a.BalancePay(e)) : getApp().core.showModal({
  83. title: "提示",
  84. content: "选择支付方式",
  85. cancelText: "余额支付",
  86. confirmText: "线上支付",
  87. success: function (t) {
  88. getApp().core.showLoading({
  89. title: "正在提交",
  90. mask: !0
  91. }), t.confirm ? a.WechatPay(e) : t.cancel && a.BalancePay(e)
  92. }
  93. })
  94. },
  95. WechatPay: function (t) {
  96. getApp().request({
  97. url: getApp().api.order.pay_data,
  98. data: {
  99. order_id: t.currentTarget.dataset.id,
  100. pay_type: "WECHAT_PAY"
  101. },
  102. complete: function () {
  103. getApp().core.hideLoading()
  104. },
  105. success: function (t) {
  106. 0 == t.code && getApp().core.requestPayment({
  107. _res: t,
  108. timeStamp: t.data.timeStamp,
  109. nonceStr: t.data.nonceStr,
  110. package: t.data.package,
  111. signType: t.data.signType,
  112. paySign: t.data.paySign,
  113. success: function (t) {},
  114. fail: function (t) {},
  115. complete: function (t) {
  116. "requestPayment:fail" != t.errMsg && "requestPayment:fail cancel" != t.errMsg ? getApp().core.redirectTo({
  117. url: "/pages/order/order?status=1"
  118. }) : getApp().core.showModal({
  119. title: "提示",
  120. content: "订单尚未支付",
  121. showCancel: !1,
  122. confirmText: "确认",
  123. success: function (t) {
  124. t.confirm && getApp().core.redirectTo({
  125. url: "/pages/order/order?status=0"
  126. })
  127. }
  128. })
  129. }
  130. }), 1 == t.code && getApp().core.showToast({
  131. title: t.msg,
  132. image: "/images/icon-warning.png"
  133. })
  134. }
  135. })
  136. },
  137. BalancePay: function (t) {
  138. getApp().request({
  139. url: getApp().api.order.pay_data,
  140. data: {
  141. order_id: t.currentTarget.dataset.id,
  142. pay_type: "BALANCE_PAY"
  143. },
  144. complete: function () {
  145. getApp().core.hideLoading()
  146. },
  147. success: function (t) {
  148. 0 == t.code && getApp().core.redirectTo({
  149. url: "/pages/order/order?status=1"
  150. }), 1 == t.code && getApp().core.showModal({
  151. title: "提示",
  152. content: t.msg,
  153. showCancel: !1
  154. })
  155. }
  156. })
  157. },
  158. orderRevoke: function (e) {
  159. var a = this;
  160. getApp().core.showModal({
  161. title: "提示",
  162. content: "是否取消该订单?",
  163. cancelText: "否",
  164. confirmText: "是",
  165. success: function (t) {
  166. if (t.cancel) return !0;
  167. t.confirm && (getApp().core.showLoading({
  168. title: "操作中"
  169. }), getApp().request({
  170. url: getApp().api.order.revoke,
  171. data: {
  172. order_id: e.currentTarget.dataset.id
  173. },
  174. success: function (t) {
  175. getApp().core.hideLoading(), getApp().core.showModal({
  176. title: "提示",
  177. content: t.msg,
  178. showCancel: !1,
  179. success: function (t) {
  180. t.confirm && a.loadOrderList(a.data.status)
  181. }
  182. })
  183. }
  184. }))
  185. }
  186. })
  187. },
  188. orderConfirm: function (e) {
  189. var a = this;
  190. getApp().core.showModal({
  191. title: "提示",
  192. content: "是否确认已收到货?",
  193. cancelText: "否",
  194. confirmText: "是",
  195. success: function (t) {
  196. if (t.cancel) return !0;
  197. t.confirm && (getApp().core.showLoading({
  198. title: "操作中"
  199. }), getApp().request({
  200. url: getApp().api.order.confirm,
  201. data: {
  202. order_id: e.currentTarget.dataset.id
  203. },
  204. success: function (t) {
  205. getApp().core.hideLoading(), getApp().core.showToast({
  206. title: t.msg
  207. }), 0 == t.code && a.loadOrderList(3)
  208. }
  209. }))
  210. }
  211. })
  212. },
  213. orderQrcode: function (t) {
  214. var e = this,
  215. a = e.data.order_list,
  216. o = t.target.dataset.index;
  217. getApp().core.showLoading({
  218. title: "正在加载",
  219. mask: !0
  220. }), e.data.order_list[o].offline_qrcode ? (e.setData({
  221. hide: 0,
  222. qrcode: e.data.order_list[o].offline_qrcode
  223. }), getApp().core.hideLoading()) : getApp().request({
  224. url: getApp().api.order.get_qrcode,
  225. data: {
  226. order_no: a[o].order_no
  227. },
  228. success: function (t) {
  229. 0 == t.code ? e.setData({
  230. hide: 0,
  231. qrcode: t.data.url
  232. }) : getApp().core.showModal({
  233. title: "提示",
  234. content: t.msg
  235. })
  236. },
  237. complete: function () {
  238. getApp().core.hideLoading()
  239. }
  240. })
  241. },
  242. hide: function (t) {
  243. this.setData({
  244. hide: 1
  245. })
  246. },
  247. onShow: function () {
  248. getApp().page.onShow(this)
  249. }
  250. });