You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
4.8 KiB

  1. var app = getApp();
  2. const config = require('../../../config/config.js')
  3. const util = require('../../../utils/util.js')
  4. const Http = require('../../../utils/http.js')
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. billTypeValue: '',
  11. billId: '',
  12. flag: false,
  13. detailData: {},
  14. list: []
  15. },
  16. onLoad: function (options) {
  17. let that = this;
  18. console.log(options, 'options');
  19. that.setData({
  20. billTypeValue: options.billTypeValue,
  21. billId: options.billId,
  22. flag: options.flag === 'mall'
  23. })
  24. this.getData()
  25. },
  26. getData() {
  27. Http.getRequest(this.data.flag ? config.api.mallbillDetail : config.api.billDetail, app.globalData.token, '', {
  28. billId: this.data.billId,
  29. billTypeValue: this.data.billTypeValue,
  30. }, (res) => {
  31. if (res.code === 200) {
  32. res.data.starttime = res.data.starttime ? util.formatTime(Number(res.data.starttime), "yyyy.MM.dd ") : '';
  33. res.data.endtime = res.data.starttime ? util.formatTime(Number(res.data.endtime), "yyyy.MM.dd ") : '';
  34. this.setData({
  35. detailData: res.data
  36. })
  37. }
  38. })
  39. Http.getRequest(config.api.billActionlist, app.globalData.token, '', {
  40. billId: this.data.billId,
  41. pageNum: 1,
  42. pageSize: 1000,
  43. }, (res) => {
  44. if (res.code === 200) {
  45. res.data.list.forEach(ele => {
  46. ele.createtime = ele.createtime ? util.formatTime(Number(ele.createtime), "yyyy.MM.dd ") : '';
  47. })
  48. this.setData({
  49. list: res.data.list
  50. })
  51. }
  52. })
  53. },
  54. goBack() {
  55. wx.navigateBack({
  56. delta: 1
  57. })
  58. },
  59. /**
  60. * 查看结算单详情
  61. */
  62. godetail() {
  63. wx.navigateTo({
  64. url: `/pages/statementsDetail/index?id=${this.data.billId}`,
  65. })
  66. },
  67. makePhoneCall(e) {
  68. const phone = e.currentTarget.dataset.phone
  69. wx.makePhoneCall({
  70. phoneNumber: phone
  71. })
  72. },
  73. /**
  74. * 更新订单的状态
  75. */
  76. updatePayBill: function (billId, status, reason, type) {
  77. let that = this;
  78. Http.postRequest(config.api.updatePayBill, app.globalData.token, '', {
  79. billId: billId,
  80. status: status,
  81. reason: reason
  82. }, (res) => {
  83. })
  84. },
  85. /**
  86. * @去支付
  87. */
  88. gotopay: function () {
  89. let that = this;
  90. wx.showLoading({
  91. title: '加载中',
  92. })
  93. let bUserId = wx.getStorageSync("bUserId") ? wx.getStorageSync("bUserId") : app.globalData.bUserId;
  94. if (bUserId && that.data.billId && app.globalData.openId && config.weapp.appId) {
  95. Http.postRequest(config.api.createorder, app.globalData.token, '', {
  96. bUserId: bUserId,
  97. billId: that.data.billId,
  98. openId: app.globalData.openId,
  99. appId: config.weapp.appId,
  100. billTypeValue: that.data.billTypeValue,
  101. merchantId: that.data.merchantId
  102. }, (res) => {
  103. console.log(res);
  104. if (res.code == 200) {
  105. // that.setData({
  106. // payBillId: res.data.payBillId
  107. // })
  108. wx.requestPayment({
  109. timeStamp: res.data.timeStamp,
  110. nonceStr: res.data.nonceStr,
  111. package: res.data.package,
  112. signType: res.data.signType ? res.data.signType : 'MD5',
  113. paySign: res.data.paySign,
  114. success(res) {
  115. console.log(res);
  116. wx.hideLoading();
  117. that.updatePayBill(that.data.billId, 1, res.errMsg, "fail");
  118. wx.showModal({
  119. title: '提示',
  120. content: '支付成功',
  121. showCancel: false,
  122. success: function (res) {
  123. if (res.confirm) {
  124. wx.switchTab({
  125. url: '/pages/bill/bill',
  126. })
  127. }
  128. }
  129. })
  130. },
  131. fail(res) {
  132. console.log(res);
  133. wx.hideLoading();
  134. that.updatePayBill(that.data.billId, 2, res.errMsg, "cancel");
  135. wx.showModal({
  136. title: '支付消息',
  137. showCancel: false,
  138. content: "支付取消",
  139. success: function (res) {
  140. console.log(res);
  141. wx.switchTab({
  142. url: '/pages/bill/bill',
  143. })
  144. },
  145. fail: function (res) {
  146. console.log(res);
  147. }
  148. })
  149. }
  150. })
  151. } else {
  152. wx.hideLoading();
  153. wx.showModal({
  154. title: '支付失败',
  155. showCancel: false,
  156. content: res.message,
  157. success: function (res) {
  158. console.log(res);
  159. wx.switchTab({
  160. url: '/pages/bill/bill',
  161. })
  162. },
  163. fail: function (res) {
  164. console.log(res);
  165. }
  166. })
  167. }
  168. })
  169. } else {
  170. wx.hideLoading();
  171. }
  172. }
  173. })