orderList.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. // pages/goods/orderList/orderList.js
  2. import { get, post } from '../../../utils/http'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. current: 4,
  9. list: [],
  10. total: 0,
  11. page: 1,
  12. statusTexts: {
  13. // 状态-1已取消,0待支付,1已支付待取货,2.已完成
  14. s_0: '待支付',
  15. s_1: '待取货',
  16. s_3: '已取消',
  17. s_2: '已取货'
  18. },
  19. pay_methon: 1,
  20. payNow: false,
  21. },
  22. pay_methonw() {
  23. this.setData({
  24. pay_methon: 1
  25. })
  26. },
  27. pay_methonc() {
  28. this.setData({
  29. pay_methon: 2
  30. })
  31. },
  32. onClosePay() {
  33. this.setData({
  34. payNow: false
  35. })
  36. },
  37. /**
  38. * 获取我的储值
  39. * api/user
  40. */
  41. getAmount() {
  42. get('api/user/amount', {}, (res) => {
  43. if (res.data) {
  44. this.setData({
  45. inserllAmount: res.data.amount
  46. })
  47. }
  48. })
  49. },
  50. /**
  51. * 生命周期函数--监听页面加载
  52. */
  53. onLoad: function (options) {
  54. if (options.current) {
  55. this.setData({ current: options.current })
  56. }
  57. },
  58. /**
  59. * 生命周期函数--监听页面初次渲染完成
  60. */
  61. onReady: function () {},
  62. /**
  63. * 生命周期函数--监听页面显示
  64. */
  65. onShow: function () {
  66. this.getAmount()
  67. this.getOrder(1)
  68. },
  69. /**
  70. * 生命周期函数--监听页面隐藏
  71. */
  72. onHide: function () {},
  73. /**
  74. * 生命周期函数--监听页面卸载
  75. */
  76. onUnload: function () {},
  77. /**
  78. * 页面相关事件处理函数--监听用户下拉动作
  79. */
  80. onPullDownRefresh: function () {},
  81. /**
  82. * 页面上拉触底事件的处理函数
  83. */
  84. onReachBottom: function () {
  85. if (this.data.page * 10 < this.data.total) {
  86. this.getOrder(++this.data.page)
  87. }
  88. },
  89. /**
  90. * 用户点击右上角分享
  91. */
  92. onShareAppMessage: function () {},
  93. /**
  94. * 切换tabs
  95. */
  96. onTabsChange(e) {
  97. let current = e.currentTarget.dataset.id
  98. if (current == this.data.current) {
  99. return
  100. }
  101. this.setData(
  102. {
  103. current,
  104. page: 1
  105. },
  106. () => {
  107. this.getOrder()
  108. }
  109. )
  110. },
  111. /**
  112. * 取消订单
  113. */
  114. onCancelOrder(e) {
  115. let that = this
  116. wx.showModal({
  117. title: '提示',
  118. content: '是否取消当前订单',
  119. success(res) {
  120. if (res.confirm) {
  121. console.log('用户点击确定')
  122. get(
  123. 'v2/api/goods_order/cancel',
  124. {
  125. order_id: e.currentTarget.dataset.id
  126. },
  127. (res) => {
  128. wx.showToast({
  129. title: res.msg,
  130. icon: 'success',
  131. duration: 2000
  132. })
  133. that.getOrder(1)
  134. }
  135. )
  136. } else if (res.cancel) {
  137. console.log('用户点击取消')
  138. }
  139. }
  140. })
  141. },
  142. onPay: function (e) {
  143. this.setData({
  144. order_id: e.currentTarget.dataset.id,
  145. payMoney: e.currentTarget.dataset.money,
  146. // payNow: true
  147. })
  148. wx.navigateTo({
  149. url: `/pages/goods/orderDetail/orderDetail?id=${ e.currentTarget.dataset.id}`,
  150. })
  151. },
  152. /**
  153. * 去支付
  154. */
  155. payNow(e) {
  156. let that = this
  157. post(
  158. 'v2/api/order/goods/pay',
  159. {
  160. pay_way: this.data.pay_methon == 1 ? 'weixin' : 'amount',
  161. order_id: this.data.order_id
  162. },
  163. (res) => {
  164. that.setData({
  165. payNow: false
  166. })
  167. if (that.data.pay_methon == 2) {
  168. wx.showToast({
  169. title: '支付成功',
  170. icon: 'success'
  171. })
  172. setTimeout(() => {
  173. that.getOrder(1)
  174. }, 1000)
  175. return
  176. }
  177. wx.requestPayment({
  178. timeStamp: res.data.pay_data.timeStamp,
  179. nonceStr: res.data.pay_data.nonceStr,
  180. package: res.data.pay_data.package,
  181. signType: res.data.pay_data.signType,
  182. paySign: res.data.pay_data.paySign,
  183. success(res) {
  184. if (res.errMsg == 'requestPayment:ok') {
  185. wx.showToast({
  186. title: '支付成功',
  187. icon: 'success'
  188. })
  189. setTimeout(() => {
  190. that.getOrder(1)
  191. }, 1000)
  192. }
  193. },
  194. fail(res) {
  195. wx.showToast({
  196. title: '支付失败',
  197. icon: 'error'
  198. })
  199. }
  200. })
  201. }
  202. )
  203. },
  204. /**
  205. * 获取订单列表
  206. * api/order
  207. */
  208. getOrder(_page) {
  209. let { list, current, page, statusTexts } = this.data
  210. get(
  211. '/v2/api/goods_order/list',
  212. {
  213. type: Number(current),
  214. page: _page || page,
  215. limit: 10
  216. },
  217. (res) => {
  218. console.log(res);
  219. if (_page == 1 || page == 1) {
  220. list = []
  221. this.data.page = 1
  222. }
  223. res.data.list.map((item) => {
  224. // 状态,-3已退款,-2退款中,-1已取消,0待支付,1已支付,待取货,2已取货
  225. if(item.status==-1){
  226. item.status=3
  227. }
  228. item['status_text'] = statusTexts['s_' + item.status]
  229. let sum = 0
  230. item.good.map(item1=>{
  231. sum += item1.num
  232. })
  233. // 加上加购产品数量
  234. sum = item.plus.length+sum
  235. item.sum = sum
  236. })
  237. list.push(...res.data.list)
  238. this.setData({ list, total: res.data.total })
  239. }
  240. )
  241. },
  242. /**
  243. * 用户允许消息通知
  244. * /api/message/agree
  245. */
  246. messageAgree(ids, order_id) {
  247. post(
  248. 'api/message/agree',
  249. {
  250. order_id,
  251. ids
  252. },
  253. () => {}
  254. )
  255. }
  256. })