index.js 7.9 KB

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