orderCompletion.js 5.2 KB

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