orderCompletion.js 7.0 KB

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