orderCompletion.js 6.6 KB

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