order.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. const util = require('../../../utils/util.js');
  2. const app = getApp();
  3. Page({
  4. data: {
  5. img: util.config.imgPath,
  6. queryData: {
  7. otype: 0,
  8. pageIndex: 1,
  9. pageSize: 20
  10. },
  11. stat: {},
  12. list: [],
  13. loadMore: true,
  14. modalInfo: {
  15. show: false,
  16. aid: '',
  17. orderid: ''
  18. },
  19. // ——inviteFbtn 是否显示邀请海报按钮
  20. },
  21. onLoad(options) {
  22. console.log(options)
  23. this.data.queryData.otype = options.otype || 0;
  24. this.setData({
  25. queryData: this.data.queryData
  26. });
  27. },
  28. onShow() {
  29. this.stat();
  30. this.getList(false);
  31. },
  32. setTabbar(e) {
  33. let index = e.currentTarget.dataset.index;
  34. this.data.queryData.otype = index;
  35. this.data.queryData.pageIndex = 1;
  36. this.setData({
  37. queryData: this.data.queryData,
  38. list: []
  39. });
  40. this.getList(true);
  41. },
  42. stat() {
  43. let that = this;
  44. util.ajax({
  45. func: 'v2/user/stat',
  46. load: false
  47. }, data => {
  48. if (data.code == 0) {
  49. that.setData({
  50. stat: data.data
  51. });
  52. }
  53. });
  54. },
  55. getList(load) {
  56. let that = this;
  57. util.ajax({
  58. func: "v2/order/list",
  59. data: that.data.queryData,
  60. load: load
  61. }, function (res) {
  62. if (res.code == 0) {
  63. let newData = res.data.list || [];
  64. if (newData.length > 0) {
  65. newData.forEach(el => {
  66. if (el.presellPaymentDeadline && el.presellPaymentDeadline > 0) {
  67. el.failureTime = util.formatDate(util.formatUnixtimestamp(el.presellPaymentDeadline), 'MM月dd日 hh:mm', false);
  68. }
  69. el.timeContrast = util.timeContrast(el.stopBuy);
  70. });
  71. }
  72. let loadMore = true,
  73. oldData = !load ? newData : [...that.data.list, ...newData];
  74. if (newData.length < that.data.queryData.pageSize && oldData.length > that.data.queryData.pageSize) loadMore = false;
  75. that.setData({
  76. list: oldData,
  77. loadMore
  78. });
  79. } else
  80. util.showTips(res.reason);
  81. });
  82. },
  83. cancelOrder(e) {
  84. let that = this,
  85. orderid = e.currentTarget.dataset.orderid;
  86. util.ajax({
  87. func: "order/cancel",
  88. data: {
  89. orderid
  90. }
  91. }, function (res) {
  92. if (res.code == 0) {
  93. that.data.queryData.pageIndex = 1;
  94. that.setData({
  95. queryData: that.data.queryData
  96. });
  97. that.getList(false);
  98. } else {
  99. util.showTips(res.reason);
  100. }
  101. })
  102. },
  103. cancelRefund(e) {
  104. let that = this,
  105. orderid = e.currentTarget.dataset.orderid;
  106. util.ajax({
  107. func: "order/cancel_refund",
  108. data: {
  109. orderid,
  110. password: ''
  111. }
  112. }, function (res) {
  113. if (res.code == 0) {
  114. that.data.queryData.pageIndex = 1;
  115. that.setData({
  116. queryData: that.data.queryData
  117. });
  118. that.getList(false);
  119. } else {
  120. util.showTips(res.reason);
  121. }
  122. })
  123. },
  124. comment(e) {
  125. let orderid = e.currentTarget.dataset.orderid;
  126. wx.navigateTo({
  127. url: '/pages/order/comment/comment?orderid=' + orderid + '&otype=' + this.data.queryData.otype,
  128. })
  129. },
  130. // 跳转至表单详情页(支付尾款)
  131. jumpBalancePayment(e) {
  132. console.log(e)
  133. let data = e.currentTarget.dataset;
  134. wx.navigateTo({
  135. url: '/pages/product/balancePayment/balancePayment?aid=' + data.aid + '&otype=' + data.otype + '&orderid=' + data.orderid + '&presellstatus=' + data.presellstatus + '&campsex=' + data.campsex + '&military=' + data.military,
  136. })
  137. },
  138. // 立即支付(支付尾款) --待付款状态
  139. pay(e) {
  140. let that = this;
  141. console.log(e)
  142. let presellstatus = e.currentTarget.dataset.presellstatus;
  143. util.WXPay({
  144. orderid: e.target.dataset.orderid,
  145. btype: presellstatus == 2 ? 0 : presellstatus
  146. }, that.data.aid, that.data.title).then(function () {
  147. that.getList(false);
  148. }, function (res) {
  149. if (res.code != 0) util.showTips(res.reason);
  150. });
  151. },
  152. errorImg(e) {
  153. this.data.list[e.currentTarget.dataset.index].logo = "/images/noimg.png";
  154. this.setData({
  155. list: this.data.list
  156. });
  157. },
  158. onPullDownRefresh() {
  159. var self = this;
  160. wx.showNavigationBarLoading();
  161. setTimeout(function () {
  162. self.data.queryData.pageIndex = 1;
  163. self.setData({
  164. queryData: self.data.queryData
  165. });
  166. self.getList(false);
  167. wx.hideNavigationBarLoading();
  168. wx.stopPullDownRefresh();
  169. }, 1000);
  170. },
  171. onReachBottom() {
  172. var self = this;
  173. if (self.data.loadMore == false) return false;
  174. setTimeout(function () {
  175. self.data.queryData.pageIndex = self.data.queryData.pageIndex + 1;
  176. self.setData({
  177. queryData: self.data.queryData
  178. });
  179. self.getList(true);
  180. }, 1000);
  181. },
  182. // 邀请拼团
  183. inviteGroup(ev) {
  184. console.log(ev)
  185. let data = ev.currentTarget.dataset.info;
  186. let obj = {
  187. show: true,
  188. aid: data.aid,
  189. orderid: data.orderid,
  190. sid: data.sid,
  191. pid: data.pid,
  192. logo: data.logo,
  193. title: data.atitle,
  194. status: data.status,
  195. invite: app.globalData.userInfo.code,
  196. from: 'button',
  197. sharer: app.globalData.userInfo.nickname,
  198. groupbook: data.groupbook,
  199. invitefbtn: ev.currentTarget.dataset.invitefbtn == '0' ? true : false
  200. }
  201. if (!util.isEmpty(data.groupid) && data.groupid != 'null' && data.groupid != 'undefined' && data.status != 15) {
  202. obj.groupid = data.groupid
  203. }
  204. this.setData({
  205. modalInfo: obj
  206. })
  207. },
  208. onShareAppMessage() {
  209. console.log(this.data.modalInfo)
  210. let title = '个人订单信息',
  211. url = '/pages/index/order',
  212. logo = "../images/share.png";
  213. if (this.data.modalInfo.from === 'button') {
  214. let data = this.data.modalInfo,
  215. str = [];
  216. if (!util.isEmpty(data.sid) && !util.isEmpty(data.pid) && util.isEmpty(data.groupid)) {
  217. title = data.sharer + '已报名并邀请你一起参与' + data.title;
  218. } else {
  219. title = "约吗?快来和我家孩子一起拼团挑战" + data.title;
  220. }
  221. str.push('aid=' + data.aid)
  222. str.push('orderid=' + data.orderid)
  223. str.push('invite=' + data.invite)
  224. str.push('sharesid=' + data.sid)
  225. str.push('sharepid=' + data.pid)
  226. str.push('sharer=' + data.sharer)
  227. if (!util.isEmpty(data.groupid) && data.groupid != 'null' && data.groupid != 'undefined' && data.groupbook == 1) {
  228. str.push('groupid=' + data.groupid)
  229. }
  230. url = "/pages/product/activity/index?" + str.join('&');
  231. logo = data.logo.indexOf("noimg.png") == -1 ? data.logo + '@!logo' : logo;
  232. }
  233. console.log(url)
  234. return {
  235. title: title,
  236. path: url,
  237. imageUrl: logo
  238. }
  239. },
  240. })