orderCompletion.js 7.1 KB

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