orderCompletion.js 6.3 KB

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