orderCompletion.js 5.9 KB

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