index.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. const App = getApp();
  2. // 枚举类:发货方式
  3. import DeliveryTypeEnum from '../../utils/enum/DeliveryType.js';
  4. // 枚举类:支付方式
  5. import PayTypeEnum from '../../utils/enum/order/PayType'
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. dataType: 'all', // 列表类型
  12. list: [], // 订单列表
  13. scrollHeight: null, // 列表容器高度
  14. DeliveryTypeEnum, // 配送方式
  15. PayTypeEnum, // 支付方式
  16. no_more: false, // 没有更多数据
  17. isLoading: true, // 是否正在加载中
  18. page: 1, // 当前页码
  19. showQRCodePopup: false, // 核销码弹窗显示隐藏
  20. QRCodeImage: '', // 核销码图片
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad(options) {
  26. let _this = this;
  27. // 设置scroll-view高度
  28. _this.setListHeight();
  29. // 设置数据类型
  30. _this.setData({
  31. dataType: options.type || 'all'
  32. });
  33. },
  34. /**
  35. * 生命周期函数--监听页面显示
  36. */
  37. onShow() {
  38. // 获取订单列表
  39. this.getOrderList();
  40. },
  41. /**
  42. * 获取订单列表
  43. */
  44. getOrderList(isPage, page) {
  45. let _this = this;
  46. App._get('user.order/lists', {
  47. page: page || 1,
  48. dataType: _this.data.dataType
  49. }, result => {
  50. let resList = result.data.list,
  51. dataList = _this.data.list;
  52. if (isPage == true) {
  53. _this.setData({
  54. 'list.data': dataList.data.concat(resList.data),
  55. isLoading: false,
  56. });
  57. } else {
  58. _this.setData({
  59. list: resList,
  60. isLoading: false,
  61. });
  62. }
  63. });
  64. },
  65. /**
  66. * 切换标签
  67. */
  68. bindHeaderTap(e) {
  69. this.setData({
  70. dataType: e.currentTarget.dataset.type,
  71. list: {},
  72. isLoading: true,
  73. page: 1,
  74. no_more: false,
  75. });
  76. // 获取订单列表
  77. this.getOrderList(e.currentTarget.dataset.type);
  78. },
  79. /**
  80. * 取消订单
  81. */
  82. cancelOrder(e) {
  83. let _this = this;
  84. let order_id = e.currentTarget.dataset.id;
  85. wx.showModal({
  86. title: "友情提示",
  87. content: "确认要取消该订单吗?",
  88. success(o) {
  89. if (o.confirm) {
  90. App._post_form('user.order/cancel', {
  91. order_id
  92. }, result => {
  93. _this.getOrderList(_this.data.dataType);
  94. });
  95. }
  96. }
  97. });
  98. },
  99. /**
  100. * 确认收货
  101. */
  102. receipt(e) {
  103. let _this = this;
  104. let order_id = e.currentTarget.dataset.id;
  105. wx.showModal({
  106. title: "提示",
  107. content: "确认收到商品?",
  108. success(o) {
  109. if (o.confirm) {
  110. App._post_form('user.order/receipt', {
  111. order_id
  112. }, result => {
  113. _this.getOrderList(_this.data.dataType);
  114. });
  115. }
  116. }
  117. });
  118. },
  119. /**
  120. * 点击付款按钮
  121. */
  122. onPayOrder(e) {
  123. let _this = this;
  124. // 记录订单id
  125. _this.setData({
  126. payOrderId: e.currentTarget.dataset.id
  127. });
  128. // 显示支付方式弹窗
  129. _this.onTogglePayPopup();
  130. },
  131. /**
  132. * 选择支付方式
  133. */
  134. onSelectPayType(e) {
  135. let _this = this;
  136. // 隐藏支付方式弹窗
  137. _this.onTogglePayPopup();
  138. if (!_this.data.showPayPopup) {
  139. // 发起付款请求
  140. _this.payment(_this.data.payOrderId, e.currentTarget.dataset.value);
  141. }
  142. },
  143. /**
  144. * 显示/隐藏支付方式弹窗
  145. */
  146. onTogglePayPopup() {
  147. this.setData({
  148. showPayPopup: !this.data.showPayPopup
  149. });
  150. },
  151. /**
  152. * 发起付款请求
  153. */
  154. payment(orderId, payType) {
  155. // 显示loading
  156. wx.showLoading({
  157. title: '正在处理...',
  158. });
  159. App._post_form('user.order/pay', {
  160. order_id: orderId,
  161. payType: payType
  162. }, result => {
  163. if (result.code === -10) {
  164. App.showError(result.msg);
  165. return false;
  166. }
  167. // 发起微信支付
  168. if (result.data.pay_type == PayTypeEnum.WECHAT.value) {
  169. App.wxPayment({
  170. payment: result.data.payment,
  171. success() {
  172. // 跳转到已付款订单
  173. wx.navigateTo({
  174. url: '../order/detail?order_id=' + orderId
  175. });
  176. },
  177. fail() {
  178. App.showError(result.msg.error);
  179. },
  180. });
  181. }
  182. // 余额支付
  183. if (result.data.pay_type == PayTypeEnum.BALANCE.value) {
  184. App.showSuccess(result.msg.success, () => {
  185. // 跳转到已付款订单
  186. wx.navigateTo({
  187. url: '../order/detail?order_id=' + orderId
  188. });
  189. });
  190. }
  191. }, null, () => {
  192. wx.hideLoading();
  193. });
  194. },
  195. /**
  196. * 订单评价
  197. */
  198. comment(e) {
  199. let _this = this;
  200. let order_id = e.currentTarget.dataset.id;
  201. wx.navigateTo({
  202. url: './comment/comment?order_id=' + order_id,
  203. })
  204. },
  205. /**
  206. * 跳转订单详情页
  207. */
  208. navigateToDetail(e) {
  209. let order_id = e.currentTarget.dataset.id;
  210. wx.navigateTo({
  211. url: '../order/detail?order_id=' + order_id
  212. });
  213. },
  214. onPullDownRefresh() {
  215. wx.stopPullDownRefresh();
  216. },
  217. /**
  218. * 下拉到底加载数据
  219. */
  220. bindDownLoad() {
  221. // 已经是最后一页
  222. if (this.data.page >= this.data.list.last_page) {
  223. this.setData({
  224. no_more: true
  225. });
  226. return false;
  227. }
  228. // 加载下一页列表
  229. this.getOrderList(true, ++this.data.page);
  230. },
  231. /**
  232. * 设置商品列表高度
  233. */
  234. setListHeight() {
  235. let systemInfo = wx.getSystemInfoSync(),
  236. rpx = systemInfo.windowWidth / 750, // 计算rpx
  237. tapHeight = Math.floor(rpx * 88), // tap高度
  238. scrollHeight = systemInfo.windowHeight - tapHeight; // swiper高度
  239. this.setData({
  240. scrollHeight
  241. });
  242. },
  243. /**
  244. * 查看核销二维码
  245. */
  246. onExtractQRCode(e) {
  247. let _this = this,
  248. order_id = e.currentTarget.dataset.id;
  249. // 调用后台api获取核销二维码
  250. wx.showLoading({
  251. title: '加载中',
  252. });
  253. App._get('user.order/extractQrcode', {
  254. order_id
  255. }, (result) => {
  256. // 设置二维码图片路径
  257. _this.setData({
  258. QRCodeImage: result.data.qrcode
  259. });
  260. // 显示核销二维码
  261. _this.onToggleQRCodePopup();
  262. }, null, () => {
  263. wx.hideLoading();
  264. });
  265. },
  266. /**
  267. * 核销码弹出层
  268. */
  269. onToggleQRCodePopup() {
  270. let _this = this;
  271. _this.setData({
  272. showQRCodePopup: !_this.data.showQRCodePopup
  273. });
  274. },
  275. });