orderCompletion.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // pages/welfareMall/order/orderCompletion.js
  2. import WelfareMall from '../../../api/welfareMall'
  3. import { parseTime } from '../../../utils/util'
  4. import {getMobileCache, getPhoneNumber as getPhoneNumberSync} from '../../../utils/user'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. page: 1,
  11. pageSize: 10,
  12. lock: false,
  13. noResult: false,
  14. noMore: false,
  15. isLogin: false,
  16. orderDetail: null,
  17. orderSn: '',
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. var that = this;
  24. that.orderSn = options.ordersn
  25. this.setData({
  26. isLogin: getMobileCache() != '',
  27. orderSn: options.ordersn,
  28. })
  29. if(this.data.isLogin){
  30. this.getOrder(that.orderSn);
  31. this.data.orderSn = options.ordersn;
  32. }
  33. },
  34. // 订单数据
  35. getOrder: function(data) {
  36. WelfareMall.getOrder({
  37. mobile: getMobileCache(),
  38. orderSn: data,
  39. }).then(res => {
  40. if (res.code == 200) {
  41. this.userOrderistView(res.data)
  42. }
  43. this.data.lock = false
  44. }).catch(_ => {
  45. console.log(_)
  46. this.data.lock = false
  47. })
  48. },
  49. userOrderistView: function(data) {
  50. if (!data) {
  51. console.log("订单详情数据为空");
  52. return
  53. }
  54. //对象转换
  55. this.data.orderDetail = data
  56. this.setData({
  57. mobileTop:getMobileCache(),
  58. orderDetail: this.data.orderDetail
  59. })
  60. },
  61. // 取消订单
  62. toCancelOrder(e) {
  63. wx.showModal({
  64. title: '取消订单',
  65. content: '',
  66. showCancel: true,//是否显示取消按钮
  67. cancelText:"取消",//默认是“取消”
  68. cancelColor:'black',//取消文字的颜色
  69. confirmText:"确定",//默认是“确定”
  70. confirmColor: 'black',//确定文字的颜色
  71. success: res => {if (res.cancel) {
  72. //点击取消,默认隐藏弹框
  73. } else {
  74. //点击确定
  75. WelfareMall.cancelOrder({
  76. mobile: getMobileCache(),
  77. orderSn: this.data.orderSn,
  78. }).then(res => {
  79. if (res.code == 200) {
  80. wx.showToast({
  81. title: '取消订单成功',
  82. icon: 'none',
  83. duration: 1500
  84. })
  85. }
  86. this.data.lock = false
  87. }).catch(_ => {
  88. console.log(_)
  89. this.data.lock = false
  90. })
  91. }
  92. },
  93. fail: function (res) {
  94. console.log(res)
  95. },//接口调用失败的回调函数
  96. })
  97. },
  98. /**
  99. * 生命周期函数--监听页面初次渲染完成
  100. */
  101. onReady: function () {
  102. },
  103. /**
  104. * 生命周期函数--监听页面显示
  105. */
  106. onShow: function () {
  107. },
  108. /**
  109. * 生命周期函数--监听页面隐藏
  110. */
  111. onHide: function () {
  112. },
  113. /**
  114. * 生命周期函数--监听页面卸载
  115. */
  116. onUnload: function () {
  117. },
  118. /**
  119. * 页面相关事件处理函数--监听用户下拉动作
  120. */
  121. onPullDownRefresh: function () {
  122. },
  123. /**
  124. * 页面上拉触底事件的处理函数
  125. */
  126. onReachBottom: function () {
  127. },
  128. /**
  129. * 用户点击右上角分享
  130. */
  131. onShareAppMessage: function () {
  132. }
  133. })