me.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. var status = require('../../utils/index.js');
  4. //state 0:拼团中 1:成功 2:失败
  5. //order_status_id 1:已付款 2:拼团中,已付款 3:待付款 5:交易已取消 7:退款
  6. Page({
  7. mixins: [require('../../mixin/globalMixin.js')],
  8. data: {
  9. tabs: [
  10. { id: 0, name: '全部' },
  11. { id: 1, name: '拼团中' },
  12. { id: 2, name: '拼团成功' },
  13. { id: 3, name: '拼团失败' }
  14. ],
  15. order_status: 0,
  16. showEmpty: false,
  17. list: [],
  18. loadMore: true,
  19. loadText: "加载中...",
  20. loadOver: false
  21. },
  22. pageNum: 1,
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. status.setNavBgColor();
  28. this.getData();
  29. },
  30. /**
  31. * 切换导航
  32. */
  33. changeTabs: function (e) {
  34. let that = this;
  35. let order_status = e.currentTarget.dataset.type || 0;
  36. this.pageNum = 1;
  37. this.setData({ order_status, list: [], showEmpty: false, loadMore: true, loadOver: false }, ()=>{
  38. that.getData();
  39. })
  40. },
  41. /**
  42. * 生命周期函数--监听页面显示
  43. */
  44. onShow: function () {
  45. let that = this;
  46. util.check_login_new().then((res) => {
  47. if (res) {
  48. this.setData({ needAuth: false });
  49. } else {
  50. this.setData({ needAuth: true });
  51. }
  52. })
  53. },
  54. /**
  55. * 授权成功回调
  56. */
  57. authSuccess: function () {
  58. let that = this;
  59. this.pageNum = 1;
  60. this.setData({
  61. needAuth: false,
  62. showEmpty: false,
  63. list: [],
  64. loadMore: true,
  65. loadText: "加载中...",
  66. loadOver: false
  67. }, () => {
  68. that.getData();
  69. })
  70. },
  71. authModal: function () {
  72. if (this.data.needAuth) {
  73. this.setData({
  74. showAuthModal: !this.data.showAuthModal
  75. });
  76. return false;
  77. }
  78. return true;
  79. },
  80. getData: function () {
  81. wx.showLoading();
  82. let that = this;
  83. var token = wx.getStorageSync('token');
  84. let order_id = this.orderId;
  85. let pageNum = this.pageNum;
  86. app.util.request({
  87. url: 'entry/wxapp/index',
  88. data: {
  89. controller: 'user.group_orders',
  90. token,
  91. page: pageNum,
  92. type: this.data.order_status
  93. },
  94. dataType: 'json',
  95. success: function (res) {
  96. wx.hideLoading();
  97. wx.stopPullDownRefresh();
  98. if (res.data.code == 0) {
  99. let list = res.data.data;
  100. let h = {};
  101. if (pageNum == 1 && list.length == 0) h.showEmpty = true;
  102. let oldList = that.data.list;
  103. list = list.concat(oldList);
  104. h.list = list;
  105. h.loadOver = true;
  106. h.loadText = that.data.loadMore ? "加载中..." : "没有更多商品了~";
  107. that.setData(h, function () {
  108. that.pageNum += 1;
  109. })
  110. } else {
  111. let s = { loadMore: false }
  112. if (pageNum == 1) s.showEmpty = true;
  113. that.setData( s )
  114. }
  115. }
  116. })
  117. },
  118. goLink: function (e) {
  119. var pages_all = getCurrentPages();
  120. var url = e.currentTarget.dataset.link;
  121. let type = e.currentTarget.dataset.type || '';
  122. if (type == 'ignore'){
  123. let id = e.currentTarget.dataset.id;
  124. if (type == 'ignore') url = `/lionfish_comshop/moduleA/pin/share?id=${id}`;
  125. }
  126. if (pages_all.length > 3) {
  127. wx.redirectTo({ url })
  128. } else {
  129. wx.navigateTo({ url })
  130. }
  131. },
  132. /**
  133. * 取消订单
  134. */
  135. cancelOrder: function (event) {
  136. let id = event.currentTarget.dataset.type;
  137. var token = wx.getStorageSync('token');
  138. var that = this;
  139. wx.showModal({
  140. title: '取消支付',
  141. content: '好不容易挑出来,确定要取消吗?',
  142. confirmColor: '#F75451',
  143. success(res) {
  144. if (res.confirm) {
  145. app.util.request({
  146. url: 'entry/wxapp/index',
  147. data: {
  148. controller: 'order.cancel_order',
  149. token: token,
  150. order_id: id
  151. },
  152. dataType: 'json',
  153. success: function (res) {
  154. wx.showToast({
  155. title: '取消成功',
  156. icon: 'success',
  157. duration: 1000
  158. })
  159. that.order();
  160. }
  161. })
  162. }
  163. }
  164. })
  165. },
  166. order: function (status) {
  167. var that = this;
  168. var token = wx.getStorageSync('token');
  169. this.pageNum = 1;
  170. this.setData({
  171. showEmpty: false,
  172. list: [],
  173. loadMore: true,
  174. loadText: "加载中..."
  175. }, () => {
  176. that.getData();
  177. })
  178. },
  179. /**
  180. * 付款
  181. */
  182. orderPay: function (event) {
  183. var that = this;
  184. var token = wx.getStorageSync('token');
  185. let id = event.currentTarget.dataset.type;
  186. wx.showLoading();
  187. app.util.request({
  188. url: 'entry/wxapp/index',
  189. data: {
  190. controller: 'car.wxpay',
  191. token: token,
  192. order_id: id,
  193. scene: app.globalData.scene
  194. },
  195. dataType: 'json',
  196. method: 'POST',
  197. success: function (res) {
  198. wx.hideLoading();
  199. if (res.data.code == 0) {
  200. // 交易组件
  201. if(res.data.isRequestOrderPayment==1) {
  202. wx.requestOrderPayment({
  203. orderInfo: res.data.order_info,
  204. timeStamp: res.data.timeStamp,
  205. nonceStr: res.data.nonceStr,
  206. package: res.data.package,
  207. signType: res.data.signType,
  208. paySign: res.data.paySign,
  209. success: function (wxres) {
  210. wx.redirectTo({
  211. url: '/lionfish_comshop/moduleA/pin/share?id=' + id
  212. })
  213. },
  214. fail: function (res) {
  215. console.log(res);
  216. }
  217. })
  218. } else {
  219. wx.requestPayment({
  220. appId: res.data.appId,
  221. timeStamp: res.data.timeStamp,
  222. nonceStr: res.data.nonceStr,
  223. package: res.data.package,
  224. signType: res.data.signType,
  225. paySign: res.data.paySign,
  226. success: function (wxres) {
  227. wx.redirectTo({
  228. url: '/lionfish_comshop/moduleA/pin/share?id=' + id
  229. })
  230. },
  231. fail: function (res) {
  232. console.log(res);
  233. }
  234. })
  235. }
  236. } else if (res.data.code == 2) {
  237. wx.showToast({
  238. title: res.data.msg,
  239. icon: 'none'
  240. })
  241. }
  242. }
  243. })
  244. },
  245. /**
  246. * 页面相关事件处理函数--监听用户下拉动作
  247. */
  248. onPullDownRefresh: function () {
  249. let that = this;
  250. this.pageNum = 1;
  251. this.setData({
  252. showEmpty: false,
  253. list: [],
  254. loadMore: true,
  255. loadText: "加载中..."
  256. }, () => {
  257. that.getData();
  258. })
  259. },
  260. /**
  261. * 页面上拉触底事件的处理函数
  262. */
  263. onReachBottom: function () {
  264. console.log('这是我的底线');
  265. this.data.loadMore && (this.setData({ loadOver: false }), this.getData());
  266. }
  267. })