orderCompletion.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. hidden: true,
  19. reason: '',
  20. inputValue: null,
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. var that = this;
  27. that.orderSn = options.ordersn
  28. this.setData({
  29. isLogin: getMobileCache() != '',
  30. orderSn: options.ordersn,
  31. })
  32. if(this.data.isLogin){
  33. this.getOrder(that.orderSn);
  34. this.data.orderSn = options.ordersn;
  35. }
  36. },
  37. /**
  38. *
  39. * 订单数据
  40. */
  41. getOrder: function(data) {
  42. WelfareMall.getOrder({
  43. mobile: getMobileCache(),
  44. orderSn: data,
  45. }).then(res => {
  46. if (res.code == 200) {
  47. this.userOrderistView(res.data)
  48. }
  49. this.data.lock = false
  50. }).catch(_ => {
  51. console.log(_)
  52. this.data.lock = false
  53. })
  54. },
  55. userOrderistView: function(data) {
  56. if (!data) {
  57. console.log("订单详情数据为空");
  58. return
  59. }
  60. //对象转换
  61. this.data.orderDetail = data
  62. this.setData({
  63. mobileTop:getMobileCache(),
  64. orderDetail: this.data.orderDetail
  65. })
  66. },
  67. /**
  68. *
  69. * 取消订单
  70. */
  71. toCancelOrder(e) {
  72. wx.showModal({
  73. title: '取消订单',
  74. content: '',
  75. showCancel: true,//是否显示取消按钮
  76. cancelText:"取消",//默认是“取消”
  77. cancelColor:'black',//取消文字的颜色
  78. confirmText:"确定",//默认是“确定”
  79. confirmColor: 'black',//确定文字的颜色
  80. success: res => {if (res.cancel) {
  81. //点击取消,默认隐藏弹框
  82. } else {
  83. //点击确定
  84. WelfareMall.cancelOrder({
  85. mobile: getMobileCache(),
  86. orderSn: this.data.orderSn,
  87. }).then(res => {
  88. if (res.code == 200) {
  89. wx.showToast({
  90. title: '取消订单成功',
  91. icon: 'none',
  92. duration: 1500
  93. });
  94. this.onLoad(this.options);
  95. }
  96. this.data.lock = false
  97. }).catch(_ => {
  98. console.log(_)
  99. this.data.lock = false
  100. })
  101. }
  102. },
  103. fail: function (res) {
  104. console.log(res)
  105. },//接口调用失败的回调函数
  106. })
  107. },
  108. /**
  109. * 获取订单参数
  110. */
  111. async goPay() {
  112. let res = await WelfareMall.getPayParams({
  113. mobile: getMobileCache(),
  114. orderSn: this.data.orderSn,
  115. openId: wx.getStorageSync('loginInfo').openId,
  116. thirdPartyName: 'coupon-activity',
  117. payCode: "HSAY-COUPON",
  118. });
  119. console.log(res);
  120. // res = res.wxPrePayVo
  121. wx.requestPayment({
  122. timeStamp: res.wxPrePayVo.timeStamp,
  123. package: res.wxPrePayVo.pack,
  124. nonceStr: res.wxPrePayVo.nonceStr,
  125. signType: res.wxPrePayVo.signType,
  126. paySign: res.wxPrePayVo.paySign,
  127. success: function (res) {
  128. //支付成功,跳转领取成功页面
  129. wx.reLaunch({
  130. url: '/pages/couponSuccess/couponSuccess'
  131. })
  132. },
  133. fail: function (res) {
  134. console.log('payerror')
  135. console.log(res);
  136. }
  137. })
  138. },
  139. /**
  140. * 申请退款
  141. */
  142. getMode: function(){
  143. this.setData({
  144. hidden: false,
  145. inputValue: '',
  146. });
  147. },
  148. /**
  149. * 取消
  150. */
  151. cancel: function(){
  152. this.setData({
  153. hidden: true,
  154. });
  155. },
  156. /**
  157. * 提交
  158. */
  159. confirm: function(){
  160. this.setData({
  161. hidden: false
  162. });
  163. var res = this.data.reason;
  164. console.log(res);
  165. if(res == null || res =='' || res == undefined){
  166. wx.showToast({
  167. title: '退款原因必填',
  168. icon: 'none',
  169. duration: 1500
  170. })
  171. } else {
  172. this.goRefund(res);
  173. }
  174. },
  175. /**
  176. * 退款原因
  177. */
  178. getReason: function(e){
  179. this.setData({
  180. reason: e.detail.value
  181. })
  182. },
  183. /**
  184. *
  185. * 申请退款
  186. */
  187. goRefund: function(reason) {
  188. WelfareMall.orderRefund({
  189. mobile: getMobileCache(),
  190. orderSn: this.data.orderSn,
  191. reason: reason,
  192. }).then(res => {
  193. if (res.code == 200) {
  194. this.cancel();
  195. this.onLoad(this.options);
  196. const url = "../refund/refund?orderSn=" + this.data.orderSn
  197. wx.navigateTo({
  198. url
  199. })
  200. }
  201. this.data.lock = false
  202. }).catch(_ => {
  203. console.log(_)
  204. this.cancel();
  205. this.data.lock = false
  206. })
  207. },
  208. /**
  209. * 生命周期函数--监听页面初次渲染完成
  210. */
  211. onReady: function () {
  212. },
  213. /**
  214. * 生命周期函数--监听页面显示
  215. */
  216. onShow: function () {
  217. },
  218. /**
  219. * 生命周期函数--监听页面隐藏
  220. */
  221. onHide: function () {
  222. },
  223. /**
  224. * 生命周期函数--监听页面卸载
  225. */
  226. onUnload: function () {
  227. },
  228. /**
  229. * 页面相关事件处理函数--监听用户下拉动作
  230. */
  231. onPullDownRefresh: function () {
  232. },
  233. /**
  234. * 页面上拉触底事件的处理函数
  235. */
  236. onReachBottom: function () {
  237. },
  238. /**
  239. * 用户点击右上角分享
  240. */
  241. onShareAppMessage: function () {
  242. }
  243. })