orderCompletion.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. // pages/welfareMall/order/orderCompletion.js
  2. import WelfareMall from '../../../api/welfareMall'
  3. import {getMobileCache, getPhoneNumber as getPhoneNumberSync} from '../../../utils/user'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. page: 1,
  10. pageSize: 10,
  11. lock: false,
  12. noResult: false,
  13. noMore: false,
  14. orderDetail: null,
  15. orderSn: '',
  16. hidden: true,
  17. reason: '',
  18. inputValue: '',
  19. repeat: false,
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. // var that = this;
  26. // that.orderSn = options.ordersn
  27. if(!options.ordersn){
  28. return;
  29. }
  30. this.setData({
  31. orderSn: options.ordersn,
  32. })
  33. this.getOrder(options.ordersn);
  34. // this.data.orderSn = options.ordersn;
  35. },
  36. /**
  37. *
  38. * 订单数据
  39. */
  40. getOrder: function(data) {
  41. WelfareMall.getOrder({
  42. mobile: getMobileCache(),
  43. orderSn: data,
  44. }).then(res => {
  45. if (res.code == 200) {
  46. this.userOrderistView(res.data)
  47. }
  48. this.data.lock = false
  49. }).catch(_ => {
  50. console.log(_)
  51. this.data.lock = false
  52. })
  53. },
  54. /**
  55. *
  56. * 订单数据--查询
  57. */
  58. selectOrder: async function(orderSn) {
  59. let res = await WelfareMall.getOrder({
  60. mobile: getMobileCache(),
  61. orderSn: orderSn,
  62. })
  63. this.userOrderistView(res.data)
  64. await this.changeOrder(res.data.orderSn,res.data.status.value,res.data.status.showText);
  65. },
  66. userOrderistView: function(data) {
  67. if (!data) {
  68. console.log("订单详情数据为空");
  69. return
  70. }
  71. // 构建券包传参参数
  72. const couponList = []
  73. if (data.goodsList && Array.isArray(data.goodsList)) {
  74. data.goodsList.forEach(v => {
  75. const coupons = v.couponList
  76. if (coupons && coupons.length > 0) {
  77. coupons.forEach(coupon => {
  78. coupon.isSn = true
  79. coupon.payStatus = data.status.value
  80. couponList.push(coupon)
  81. })
  82. }
  83. })
  84. }
  85. //对象转换
  86. this.data.orderDetail = data
  87. this.setData({
  88. mobileTop:getMobileCache(),
  89. orderDetail: this.data.orderDetail,
  90. couponList,
  91. })
  92. },
  93. /**
  94. *
  95. * 取消订单
  96. */
  97. toCancelOrder(e) {
  98. var that = this;
  99. wx.showModal({
  100. title: '取消订单',
  101. content: '',
  102. showCancel: true,//是否显示取消按钮
  103. cancelText:"取消",//默认是“取消”
  104. cancelColor:'#00000',//取消文字的颜色
  105. confirmText:"确定",//默认是“确定”
  106. confirmColor: '#00000',//确定文字的颜色
  107. success: res => {if (res.cancel) {
  108. //点击取消,默认隐藏弹框
  109. } else {
  110. //点击确定
  111. WelfareMall.cancelOrder({
  112. mobile: getMobileCache(),
  113. orderSn: that.data.orderSn,
  114. }).then(res => {
  115. if (res.code == 200) {
  116. wx.showToast({
  117. title: '取消订单成功',
  118. icon: 'none',
  119. duration: 1500
  120. });
  121. that.selectOrder(that.data.orderSn);
  122. }
  123. }).catch(_ => {
  124. console.log(_)
  125. })
  126. }
  127. },
  128. fail: function (res) {
  129. console.log(res)
  130. },//接口调用失败的回调函数
  131. })
  132. },
  133. /**
  134. * 获取订单参数
  135. */
  136. async goPay() {
  137. var that = this;
  138. if(that.data.repeat){
  139. return;
  140. }
  141. that.data.repeat = true;
  142. let result = await WelfareMall.getOrderParams(that.data.orderSn,wx.getStorageSync('loginInfo').openId,true);
  143. let res = result.data
  144. wx.requestOrderPayment({
  145. timeStamp: res.wxPrePayVo.timeStamp,
  146. package: res.wxPrePayVo.pack,
  147. nonceStr: res.wxPrePayVo.nonceStr,
  148. signType: res.wxPrePayVo.signType,
  149. paySign: res.wxPrePayVo.paySign,
  150. orderInfo:res.orderInfo,
  151. success: function (res) {
  152. //支付成功
  153. console.log(res);
  154. that.selectOrder(that.data.orderSn);
  155. that.data.repeat = false;
  156. },
  157. fail: function (res) {
  158. console.log(res);
  159. that.data.repeat = false;
  160. },
  161. complete: function (res) {
  162. console.log(res);
  163. that.data.repeat = false;
  164. }
  165. })
  166. },
  167. /**
  168. * 申请退款
  169. */
  170. getMode: function(){
  171. this.setData({
  172. hidden: false,
  173. inputValue: '',
  174. reason: '',
  175. });
  176. },
  177. /**
  178. * 取消
  179. */
  180. cancel: function(){
  181. this.setData({
  182. hidden: true,
  183. inputValue: '',
  184. reason: '',
  185. });
  186. },
  187. /**
  188. * 提交
  189. */
  190. confirm: function(){
  191. let that = this;
  192. var res = this.data.reason;
  193. console.log(res);
  194. if(res == null || res =='' || res == undefined){
  195. wx.showToast({
  196. title: '退款原因必填',
  197. icon: 'none',
  198. duration: 1500
  199. })
  200. } else {
  201. this.setData({
  202. hidden: true
  203. });
  204. wx.showToast({
  205. title: '申请退款已提交',
  206. icon: 'none',
  207. duration: 2000,
  208. success: function(){
  209. that.goRefund(res);
  210. }
  211. });
  212. }
  213. },
  214. /**
  215. * 退款原因
  216. */
  217. getReason: function(e){
  218. this.setData({
  219. reason: e.detail.value
  220. })
  221. },
  222. /**
  223. *
  224. * 申请退款
  225. */
  226. goRefund: async function(reason) {
  227. var that = this;
  228. await WelfareMall.orderRefund({
  229. mobile: getMobileCache(),
  230. orderSn: that.data.orderSn,
  231. reason: reason,
  232. });
  233. that.cancel();
  234. await that.selectOrder(that.data.orderSn);
  235. // await wx.navigateTo({
  236. // url: "../refund/refund?orderSn=" + that.data.orderSn
  237. // })
  238. },
  239. changeOrder: function(orderSn,status,showText){
  240. var page = getCurrentPages();
  241. //获取上一个页面的页面栈
  242. var lastPage = page[page.length-2];
  243. console.log(lastPage.data)
  244. let oldOrderList = lastPage.data.orderList;
  245. for(var i = 0;i<oldOrderList.length;i++){
  246. if(orderSn == oldOrderList[i].orderSn){
  247. oldOrderList[i].status.value = status
  248. oldOrderList[i].status.showText = showText
  249. }
  250. }
  251. wx.navigateBack({
  252. delta: 1,
  253. success:function(){
  254. lastPage.setData({
  255. orderList:oldOrderList
  256. })
  257. }
  258. })
  259. return ;
  260. },
  261. extendCouponWrap() {
  262. this.data.isExtend = !this.data.isExtend
  263. this.setData({
  264. isExtend: this.data.isExtend
  265. })
  266. },
  267. /**
  268. * 生命周期函数--监听页面初次渲染完成
  269. */
  270. onReady: function () {
  271. },
  272. /**
  273. * 生命周期函数--监听页面显示
  274. */
  275. onShow: function () {
  276. },
  277. /**
  278. * 生命周期函数--监听页面隐藏
  279. */
  280. onHide: function () {
  281. },
  282. /**
  283. * 生命周期函数--监听页面卸载
  284. */
  285. onUnload: function () {
  286. },
  287. /**
  288. * 页面相关事件处理函数--监听用户下拉动作
  289. */
  290. onPullDownRefresh: function () {
  291. },
  292. /**
  293. * 页面上拉触底事件的处理函数
  294. */
  295. onReachBottom: function () {
  296. },
  297. /**
  298. * 用户点击右上角分享
  299. */
  300. onShareAppMessage: function () {
  301. }
  302. })