orderCompletion.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. WelfareMall.getPayStatus(that.data.orderSn);
  155. that.selectOrder(that.data.orderSn);
  156. that.data.repeat = false;
  157. },
  158. fail: function (res) {
  159. console.log(res);
  160. that.data.repeat = false;
  161. },
  162. complete: function (res) {
  163. console.log(res);
  164. that.data.repeat = false;
  165. }
  166. })
  167. },
  168. /**
  169. * 申请退款
  170. */
  171. getMode: function(){
  172. this.setData({
  173. hidden: false,
  174. inputValue: '',
  175. reason: '',
  176. });
  177. },
  178. /**
  179. * 取消
  180. */
  181. cancel: function(){
  182. this.setData({
  183. hidden: true,
  184. inputValue: '',
  185. reason: '',
  186. });
  187. },
  188. /**
  189. * 提交
  190. */
  191. confirm: function(){
  192. let that = this;
  193. var res = this.data.reason;
  194. console.log(res);
  195. if(res == null || res =='' || res == undefined){
  196. wx.showToast({
  197. title: '退款原因必填',
  198. icon: 'none',
  199. duration: 1500
  200. })
  201. } else {
  202. this.setData({
  203. hidden: true
  204. });
  205. wx.showToast({
  206. title: '申请退款已提交',
  207. icon: 'none',
  208. duration: 2000,
  209. success: function(){
  210. that.goRefund(res);
  211. }
  212. });
  213. }
  214. },
  215. /**
  216. * 退款原因
  217. */
  218. getReason: function(e){
  219. this.setData({
  220. reason: e.detail.value
  221. })
  222. },
  223. /**
  224. *
  225. * 申请退款
  226. */
  227. goRefund: async function(reason) {
  228. var that = this;
  229. await WelfareMall.orderRefund({
  230. mobile: getMobileCache(),
  231. orderSn: that.data.orderSn,
  232. reason: reason,
  233. });
  234. that.cancel();
  235. await that.selectOrder(that.data.orderSn);
  236. // await wx.navigateTo({
  237. // url: "../refund/refund?orderSn=" + that.data.orderSn
  238. // })
  239. },
  240. changeOrder: function(orderSn,status,showText){
  241. var page = getCurrentPages();
  242. //获取上一个页面的页面栈
  243. var lastPage = page[page.length-2];
  244. console.log(lastPage.data)
  245. let oldOrderList = lastPage.data.orderList?lastPage.data.orderList:[];
  246. for(var i = 0;i<oldOrderList.length;i++){
  247. if(orderSn == oldOrderList[i].orderSn){
  248. oldOrderList[i].status.value = status
  249. oldOrderList[i].status.showText = showText
  250. }
  251. }
  252. wx.navigateBack({
  253. delta: 1,
  254. success:function(){
  255. lastPage.setData({
  256. orderList:oldOrderList
  257. })
  258. }
  259. })
  260. return ;
  261. },
  262. extendCouponWrap() {
  263. this.data.isExtend = !this.data.isExtend
  264. this.setData({
  265. isExtend: this.data.isExtend
  266. })
  267. },
  268. /**
  269. * 生命周期函数--监听页面初次渲染完成
  270. */
  271. onReady: function () {
  272. },
  273. /**
  274. * 生命周期函数--监听页面显示
  275. */
  276. onShow: function () {
  277. },
  278. /**
  279. * 生命周期函数--监听页面隐藏
  280. */
  281. onHide: function () {
  282. },
  283. /**
  284. * 生命周期函数--监听页面卸载
  285. */
  286. onUnload: function () {
  287. },
  288. /**
  289. * 页面相关事件处理函数--监听用户下拉动作
  290. */
  291. onPullDownRefresh: function () {
  292. },
  293. /**
  294. * 页面上拉触底事件的处理函数
  295. */
  296. onReachBottom: function () {
  297. },
  298. /**
  299. * 用户点击右上角分享
  300. */
  301. onShareAppMessage: function () {
  302. }
  303. })