orderCompletion.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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: '',
  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.changeOrder(this.data.orderSn,4,'已取消');
  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. var that = this;
  109. let result = await WelfareMall.getOrderParams(that.data.orderSn,wx.getStorageSync('loginInfo').openId);
  110. let res = result.data
  111. wx.requestPayment({
  112. timeStamp: res.wxPrePayVo.timeStamp,
  113. package: res.wxPrePayVo.pack,
  114. nonceStr: res.wxPrePayVo.nonceStr,
  115. signType: res.wxPrePayVo.signType,
  116. paySign: res.wxPrePayVo.paySign,
  117. success: function (res) {
  118. //支付成功
  119. console.log(res);
  120. that.changeOrder(that.data.orderSn,2,'已支付');
  121. },
  122. fail: function (res) {
  123. console.log(res);
  124. }
  125. })
  126. },
  127. /**
  128. * 申请退款
  129. */
  130. getMode: function(){
  131. this.setData({
  132. hidden: false,
  133. inputValue: '',
  134. reason: '',
  135. });
  136. },
  137. /**
  138. * 取消
  139. */
  140. cancel: function(){
  141. this.setData({
  142. hidden: true,
  143. inputValue: '',
  144. reason: '',
  145. });
  146. },
  147. /**
  148. * 提交
  149. */
  150. confirm: function(){
  151. this.setData({
  152. hidden: false
  153. });
  154. var res = this.data.reason;
  155. console.log(res);
  156. if(res == null || res =='' || res == undefined){
  157. wx.showToast({
  158. title: '退款原因必填',
  159. icon: 'none',
  160. duration: 1500
  161. })
  162. } else {
  163. this.goRefund(res);
  164. }
  165. },
  166. /**
  167. * 退款原因
  168. */
  169. getReason: function(e){
  170. this.setData({
  171. reason: e.detail.value
  172. })
  173. },
  174. /**
  175. *
  176. * 申请退款
  177. */
  178. goRefund: function(reason) {
  179. var that = this;
  180. WelfareMall.orderRefund({
  181. mobile: getMobileCache(),
  182. orderSn: that.data.orderSn,
  183. reason: reason,
  184. }).then(res => {
  185. if (res.code == 200) {
  186. that.cancel();
  187. that.onLoad(that.options);
  188. that.changeOrder(that.data.orderSn,3,'已退款');
  189. const url = "../refund/refund?orderSn=" + that.data.orderSn
  190. wx.navigateTo({
  191. url
  192. })
  193. }
  194. }).catch(_ => {
  195. console.log(_)
  196. that.cancel();
  197. })
  198. },
  199. changeOrder: function(orderSn,status,showText){
  200. var page = getCurrentPages();
  201. //获取上一个页面的页面栈
  202. var lastPage = page[page.length-2];
  203. console.log(lastPage.data)
  204. let oldOrderList = lastPage.data.orderList;
  205. for(var i = 0;i<oldOrderList.length;i++){
  206. if(orderSn == oldOrderList[i].orderSn){
  207. oldOrderList[i].status.value = status
  208. oldOrderList[i].status.showText = showText
  209. }
  210. }
  211. wx.navigateBack({
  212. delta: 1,
  213. success:function(){
  214. lastPage.setData({
  215. orderList:oldOrderList
  216. })
  217. }
  218. })
  219. return;
  220. },
  221. /**
  222. * 生命周期函数--监听页面初次渲染完成
  223. */
  224. onReady: function () {
  225. },
  226. /**
  227. * 生命周期函数--监听页面显示
  228. */
  229. onShow: function () {
  230. },
  231. /**
  232. * 生命周期函数--监听页面隐藏
  233. */
  234. onHide: function () {
  235. },
  236. /**
  237. * 生命周期函数--监听页面卸载
  238. */
  239. onUnload: function () {
  240. },
  241. /**
  242. * 页面相关事件处理函数--监听用户下拉动作
  243. */
  244. onPullDownRefresh: function () {
  245. },
  246. /**
  247. * 页面上拉触底事件的处理函数
  248. */
  249. onReachBottom: function () {
  250. },
  251. /**
  252. * 用户点击右上角分享
  253. */
  254. onShareAppMessage: function () {
  255. }
  256. })