index.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. var canpay = true;
  4. Page({
  5. mixins: [require('../../mixin/globalMixin.js')],
  6. data: {
  7. tablebar: 4,
  8. page: 1,
  9. theme_type: '',
  10. order_status: -1,
  11. no_order: 0,
  12. hide_tip: true,
  13. order: [],
  14. tip: '正在加载',
  15. is_empty: false,
  16. tabs: [
  17. { id: -1, name: '全部' },
  18. { id: 3, name: '待付款' },
  19. { id: 1, name: '待配送' },
  20. { id: 14, name: '配送中' },
  21. { id: 4, name: '待提货' },
  22. { id: 6, name: '已提货' }
  23. ],
  24. hexiaoStatus: ['','','','待付款','待使用','','','','','','','已完成']
  25. },
  26. onLoad: function(options) {
  27. let { order_status, is_show_tip, isfail } = options;
  28. wx.showLoading();
  29. if (order_status == undefined) {
  30. order_status = -1;
  31. }
  32. this.setData({
  33. order_status: order_status,
  34. })
  35. if (is_show_tip != undefined && is_show_tip == 1) {
  36. wx.showToast({
  37. title: '支付成功',
  38. })
  39. } else if (isfail != undefined && isfail == 1) {
  40. wx.showToast({
  41. title: '支付失败',
  42. icon: 'none'
  43. })
  44. }
  45. this.getData();
  46. },
  47. getData: function() {
  48. this.setData({ isHideLoadMore: true })
  49. this.data.no_order = 1
  50. let that = this;
  51. var token = wx.getStorageSync('token');
  52. app.util.request({
  53. 'url': 'entry/wxapp/index',
  54. 'data': {
  55. controller: 'order.orderlist',
  56. token: token,
  57. page: that.data.page,
  58. order_status: that.data.order_status
  59. },
  60. dataType: 'json',
  61. success: function(res) {
  62. wx.hideLoading();
  63. if (res.data.code == 0) {
  64. let rushList = that.data.order.concat(res.data.data);
  65. that.setData({
  66. order: rushList,
  67. hide_tip: true,
  68. no_order: 0
  69. });
  70. } else {
  71. if(that.data.page == 1 && that.data.order.length <= 0) that.setData({is_empty: true});
  72. that.setData({
  73. isHideLoadMore: true
  74. })
  75. return false;
  76. }
  77. }
  78. })
  79. },
  80. goOrder: function(event) {
  81. let id = event.currentTarget.dataset.type;
  82. var pages_all = getCurrentPages();
  83. let delivery = event.currentTarget.dataset.delivery || '';
  84. let url = `/lionfish_comshop/pages/order/order?id=${id}&delivery=${delivery}`;
  85. if (pages_all.length > 3) {
  86. wx.redirectTo({ url })
  87. } else {
  88. wx.navigateTo({ url })
  89. }
  90. },
  91. receivOrder: function(event) {
  92. let id = event.currentTarget.dataset.type;
  93. let delivery = event.currentTarget.dataset.delivery;
  94. var token = wx.getStorageSync('token');
  95. if (delivery == "pickup") content = "确认提货";
  96. var that = this;
  97. wx.showModal({
  98. title: '提示',
  99. content: '确认收到',
  100. confirmColor: '#F75451',
  101. success(res) {
  102. if (res.confirm) {
  103. app.util.request({
  104. 'url': 'entry/wxapp/index',
  105. 'data': {
  106. controller: 'order.receive_order',
  107. token: token,
  108. order_id: id
  109. },
  110. dataType: 'json',
  111. success: function(res) {
  112. if (res.data.code == 0) {
  113. wx.showToast({
  114. title: '收货成功',
  115. icon: 'success',
  116. duration: 1000
  117. })
  118. that.order(that.data.order_status);
  119. }
  120. }
  121. })
  122. }
  123. }
  124. })
  125. },
  126. cancelOrder: function(event) {
  127. let id = event.currentTarget.dataset.type;
  128. var token = wx.getStorageSync('token');
  129. var that = this;
  130. wx.showModal({
  131. title: '取消支付',
  132. content: '好不容易挑出来,确定要取消吗?',
  133. confirmColor: '#F75451',
  134. success(res) {
  135. if (res.confirm) {
  136. app.util.request({
  137. 'url': 'entry/wxapp/index',
  138. 'data': {
  139. controller: 'order.cancel_order',
  140. token: token,
  141. order_id: id
  142. },
  143. dataType: 'json',
  144. success: function (res) {
  145. wx.showToast({
  146. title: '取消成功',
  147. icon: 'success',
  148. duration: 1000
  149. })
  150. that.order(that.data.order_status);
  151. }
  152. })
  153. }
  154. }
  155. })
  156. },
  157. getOrder: function(event) {
  158. this.setData({ is_empty: false })
  159. wx.showLoading();
  160. let starus = event.currentTarget.dataset.type;
  161. this.order(starus);
  162. },
  163. order: function(starus) {
  164. var that = this;
  165. that.setData({
  166. order_status: starus,
  167. order: [],
  168. no_order: 0,
  169. page: 1
  170. })
  171. this.getData();
  172. },
  173. /**
  174. * 支付防抖
  175. */
  176. preOrderPay: util.debounce(function(event) {
  177. console.log('lijizhifuy')
  178. canpay&&this.orderPay(event);
  179. }),
  180. orderPay: function(event) {
  181. wx.showLoading({
  182. title: '支付中',
  183. })
  184. canpay = false;
  185. let that = this;
  186. var token = wx.getStorageSync('token');
  187. let id = event[0].currentTarget.dataset.type;
  188. let delivery = event[0].currentTarget.dataset.delivery;
  189. app.util.request({
  190. 'url': 'entry/wxapp/index',
  191. 'data': {
  192. controller: 'car.wxpay',
  193. token: token,
  194. order_id: id,
  195. pay_method:'fypay',
  196. scene: app.globalData.scene
  197. },
  198. dataType: 'json',
  199. method: 'POST',
  200. success: function(res) {
  201. wx.hideLoading();
  202. if(res.data.code ==0)
  203. {
  204. var is_pin = res.data.is_pin;
  205. // 交易组件
  206. if(res.data.isRequestOrderPayment==1) {
  207. wx.requestOrderPayment({
  208. orderInfo: res.data.order_info,
  209. timeStamp: res.data.timeStamp,
  210. nonceStr: res.data.nonceStr,
  211. package: res.data.package,
  212. signType: res.data.signType,
  213. paySign: res.data.paySign,
  214. success: function (wxres) {
  215. wx.redirectTo({
  216. url: '/lionfish_comshop/pages/order/order?id=' + id + '&is_show=1&delivery='+delivery
  217. })
  218. },
  219. fail: function (res) {
  220. console.log(res);
  221. },
  222. complete: ()=>{
  223. canpay = true;
  224. }
  225. })
  226. } else {
  227. wx.requestPayment({
  228. appId: res.data.appId,
  229. timeStamp: res.data.timeStamp,
  230. nonceStr: res.data.nonceStr,
  231. package: res.data.package,
  232. signType: res.data.signType,
  233. paySign: res.data.paySign,
  234. success: function (wxres) {
  235. wx.redirectTo({
  236. url: '/lionfish_comshop/pages/order/order?id=' + id + '&is_show=1&delivery='+delivery
  237. })
  238. },
  239. fail: function (res) {
  240. console.log(res);
  241. },
  242. complete: ()=>{
  243. canpay = true;
  244. }
  245. })
  246. }
  247. } else if (res.data.code == 1) {
  248. wx.showToast({
  249. title: res.data.RETURN_MSG || '支付错误',
  250. icon: 'none'
  251. })
  252. canpay = true;
  253. } else if (res.data.code == 2) {
  254. wx.showToast({
  255. title: res.data.msg,
  256. icon:'none'
  257. })
  258. canpay = true;
  259. setTimeout(() => {
  260. that.setData({
  261. page: 1,
  262. no_order: 0,
  263. order: [],
  264. tip: '正在加载',
  265. is_empty: false
  266. }, ()=>{
  267. that.getData();
  268. })
  269. }, 1500);
  270. }
  271. },
  272. fail: ()=>{
  273. wx.hideLoading();
  274. canpay = true;
  275. }
  276. })
  277. },
  278. onReachBottom: function() {
  279. if (this.data.no_order == 1) return false;
  280. this.data.page += 1;
  281. this.getData();
  282. this.setData({
  283. isHideLoadMore: false
  284. })
  285. },
  286. onPullDownRefresh: function () {
  287. this.setData({
  288. is_empty: false,
  289. page: 1,
  290. order: []
  291. })
  292. wx.showLoading();
  293. this.getData();
  294. wx.stopPullDownRefresh();
  295. }
  296. })