orderCompletion.js 7.3 KB

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