review.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. const app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. item: [],
  8. active: 0,
  9. steps: [{text: '待付款'},{text: '已付款'},{text: '已发货'},{text: '已完成'}],
  10. order_no: null,
  11. disabled:false,
  12. actions: [],
  13. orderParams: {}, // 支付参数
  14. chickPayBtn: false, //点击了支付按钮(订单信息交由古德云组件)
  15. chickOnPay: false, // 用户是否已经点击了「支付」并成功跳转到 古德云收银台 小程序
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载 */
  19. onLoad: function (options) {
  20. let order_no = options.order_no;
  21. this.setData({
  22. order_no: order_no
  23. })
  24. this.getOrder(order_no);
  25. },
  26. /**
  27. * 读取订单信息
  28. */
  29. getOrder: function (order_no) {
  30. let that = this;
  31. app.api().Get("api/v3/fastshop/cart/review", {order_no:order_no}, function (rel) {
  32. var item = rel.data;
  33. var active = 0;
  34. for (let i in item) {
  35. if (item[i]['status'] == 1) {
  36. active = 3;
  37. } else {
  38. if (item[i]['paid_at'] == 0) {
  39. active = 0;
  40. } else {
  41. if (item[i]['express_status'] == 0) {
  42. active = 1;
  43. } else {
  44. active = 2;
  45. }
  46. }
  47. }
  48. }
  49. that.setData({
  50. item: rel.data,
  51. active: active,
  52. })
  53. })
  54. },
  55. /**
  56. * 唤起微信支付
  57. */
  58. wchatPayment: function (buytype) {
  59. let that = this;
  60. var param = {
  61. order_no: that.data.order_no,
  62. buytype: buytype,
  63. }
  64. app.api().Post('api/v3/fastshop/cart/retryPay',param,function (rel) {
  65. if (200 == rel.code) {
  66. if (rel.data.type == 1) {
  67. that.setData({
  68. chickPayBtn: true,
  69. orderParams: rel.data.order
  70. })
  71. } else {
  72. app.doWechatPay(rel.data.orde,function (res) {
  73. that.getOrder(onderNo);
  74. }, function (res) {
  75. wx.showModal({
  76. content: '支付失败或取消',
  77. showCancel: false
  78. })
  79. })
  80. }
  81. }
  82. })
  83. },
  84. //关闭订单
  85. closeOrder: function (event) {
  86. let that = this;
  87. var onderNo = that.data.order_no;
  88. wx.showModal({
  89. content: '请确认要关闭订单?',
  90. success: function (res) {
  91. if (res.confirm) {
  92. app.api().Post("api/v3/fastshop/cart/closeorder", { order_no: onderNo }, function (rel) {
  93. wx.showModal({
  94. content: rel.msg,
  95. showCancel: false,
  96. success: function () {
  97. wx.navigateBack({
  98. delta: 1
  99. })
  100. }
  101. })
  102. })
  103. }
  104. }
  105. })
  106. },
  107. //确认收货
  108. okOrder: function (event) {
  109. let that = this;
  110. var onderNo = that.data.order_no;
  111. wx.showModal({
  112. content: '确认要签收当前商品?',
  113. success: function (res) {
  114. if (res.confirm) {
  115. app.api().Post("api/v3/fastshop/cart/signOrder", { order_no: onderNo }, function (rel) {
  116. wx.showModal({
  117. content: rel.msg,
  118. showCancel: false,
  119. success: function () {
  120. that.getOrder(onderNo)
  121. }
  122. })
  123. })
  124. }
  125. }
  126. })
  127. },
  128. //查询快递
  129. getMaps: function (event) {
  130. let that = this;
  131. var onderNo = that.data.order_no;
  132. let config = app.globalData.wechat_config;
  133. wx.navigateTo({
  134. url: '/pages/helper/webview?src=' + app.api_root + '/api-' + config.app_id + '/v3/fastshop-webview-express&ids=' + onderNo,
  135. })
  136. },
  137. //支付方式
  138. payTypes: function () {
  139. let that = this;
  140. that.setData({
  141. show: true,
  142. disabled: true
  143. });
  144. if (that.data.show) {
  145. app.api().Get('api/v3/fastshop/index/shopBuyTypes', { 'signkey': 'shopBuyTypes' }, function (result) {
  146. that.setData({
  147. actions: result.data
  148. });
  149. })
  150. }
  151. },
  152. //是否弹出支付菜单
  153. onClose() {
  154. this.setData({
  155. show: false,
  156. disabled: false
  157. });
  158. },
  159. //选择支付方式
  160. onSelect(event) {
  161. let that = this;
  162. var payTypes = event.detail.types;
  163. that.setData({
  164. disabled: true
  165. });
  166. switch (payTypes) {
  167. case 1:
  168. that.wchatPayment("wepay");
  169. break;
  170. case 2:
  171. that.wchatPayment("point");
  172. break;
  173. default:
  174. that.onClose();
  175. }
  176. },
  177. /**
  178. * 支付成功的事件处理函数
  179. * res.detail 为 payjs 小程序返回的订单信息
  180. * 可通过 res.detail.payjsOrderId 拿到 payjs 订单号
  181. * 可通过 res.detail.responseData 拿到详细支付信息
  182. */
  183. goodPaySuccess: function (res) {
  184. if (res.detail.return_code = "SUCCESS") {
  185. that.getOrder(this.data.order_no);
  186. }
  187. },
  188. /**
  189. * 支付失败的事件处理函数
  190. * res.detail.error 为 true 代表传入小组件的参数存在问题
  191. * res.detail.navigateSuccess 代表了是否成功跳转到 PAYJS 小程序
  192. * res.detail.event 可能存有失败的原因
  193. * 如果下单成功但是用户取消支付则 res.detail.event.return_code == FAIL
  194. */
  195. goodPayFail: function (res) {
  196. this.setData({
  197. chickPayBtn: false,
  198. })
  199. },
  200. /**
  201. * 支付完毕的事件处理函数
  202. * 无论支付成功或失败均会执行
  203. */
  204. goodPayComplete: function () {
  205. this.setData({
  206. chickPayBtn: false,
  207. })
  208. },
  209. /**
  210. * 组件内部数据被修改时的事件
  211. * 当用户跳转到 云收银台 小程序并等待返回的过程中 chickOnPay 值为 true
  212. */
  213. goodPayChange(res) {
  214. if (res.detail.chickOnPay) {
  215. this.setData({
  216. chickOnPay: res.detail.chickOnPay
  217. })
  218. }
  219. }
  220. })