C端小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

244 linhas
5.9 KiB

  1. let config = require("../../../config/config.js");
  2. let util = require("../../../utils/util");
  3. let Http = require("../../../utils/HttpBasics");
  4. let app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. showModalStatus: false,
  11. flag: 0,
  12. order: null,
  13. orderId: null,
  14. //存储计时器
  15. setInter: "",
  16. mystatus: '',
  17. staticGamedata: {},
  18. showIf: false
  19. },
  20. powerDrawer: function (e) {
  21. let that = this;
  22. // couponOrderStatus
  23. // 0 未使用
  24. // 1 已使用
  25. // 2 已过期
  26. // 3 已经退款
  27. if (that.data.mystatus == "" || that.data.mystatus == undefined) {
  28. wx.navigateTo({
  29. url: `/pages/orderquanma/index?quancode=${
  30. e.currentTarget.dataset.quancode
  31. }&title=${e.currentTarget.dataset.title}&subtitle=${
  32. e.currentTarget.dataset.subtitle
  33. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${
  34. e.currentTarget.dataset.couponorderstatus
  35. }`
  36. });
  37. } else {
  38. wx.navigateTo({
  39. url: `/pages/orderquanma/index?quancode=${
  40. e.currentTarget.dataset.quancode
  41. }&title=${e.currentTarget.dataset.title}&subtitle=${
  42. e.currentTarget.dataset.subtitle
  43. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${
  44. that.data.mystatus
  45. }`
  46. });
  47. }
  48. },
  49. gotogame: function () {
  50. let that = this;
  51. wx.navigateTo({
  52. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  53. })
  54. },
  55. // 获取游戏
  56. getStaticGame(token) {
  57. let _this = this;
  58. Http.get({
  59. url: config.api.getGame,
  60. data: {
  61. triggleAction: 3
  62. }
  63. }).then(res => {
  64. if (res.data.id) {
  65. _this.setData({
  66. showIf: true
  67. })
  68. }
  69. _this.setData({
  70. staticGamedata: res.data
  71. })
  72. })
  73. .catch(err => {
  74. console.log(err);
  75. })
  76. },
  77. /**
  78. * 生命周期函数--监听页面加载
  79. */
  80. onLoad: function (options) {
  81. let that = this;
  82. this.setData({
  83. orderId: options.orderId
  84. });
  85. wx.showLoading({
  86. title: "加载中"
  87. });
  88. setTimeout(function () {
  89. wx.hideLoading();
  90. }, 1500);
  91. Http.get({
  92. url: config.api.orderDetail,
  93. data: {
  94. orderId: options.orderId
  95. }
  96. }).then(res => {
  97. that.setData({
  98. order: res.data
  99. });
  100. that.getStaticGame()
  101. //createDate 创建时间
  102. var createDate = util.formatTime(res.data.createDate, "yyyy-MM-dd hh:mm:ss");
  103. that.setData({
  104. createDate: createDate
  105. });
  106. });
  107. },
  108. /**
  109. * 发起支付
  110. */
  111. orderFunc(e) {
  112. var that = this;
  113. wx.showLoading({
  114. title: "加载中..."
  115. });
  116. const orderId = "" + that.data.orderId;
  117. if (that.data.order.payment > 0) {
  118. // 支付金额不为0
  119. Http.post({
  120. url: config.api.payOrderCreate,
  121. data: {
  122. orderId: orderId
  123. }
  124. }).then(res => {
  125. /// Begin payment ----
  126. var payOrderId = "" + res.data.payOrderId;
  127. wx.hideLoading();
  128. wx.requestPayment({
  129. timeStamp: res.data.timeStamp,
  130. nonceStr: res.data.nonceStr,
  131. package: res.data.package,
  132. signType: (res.data.signType) ? res.data.signType : "MD5",
  133. paySign: res.data.paySign,
  134. success: res => {
  135. wx.showLoading({
  136. title: '订单正在处理中...',
  137. })
  138. setTimeout(function () {
  139. wx.hideLoading()
  140. }, 5000)
  141. that.payOrderUpdate(that.data.orderId, payOrderId, 1,'','',that); // 支付成功
  142. },
  143. fail: res => {
  144. that.payOrderUpdate(that.data.orderId, payOrderId, 2,'','fail',that);
  145. return;
  146. },
  147. });
  148. /// End payment --------
  149. });
  150. } else {
  151. // 免费券
  152. that.payOrderUpdate(orderId, "0", 1,'','fail') // 支付成功
  153. wx.showToast({
  154. title: "支付成功",
  155. duration: 2000,
  156. image: "./../../../assets/img/success.png",
  157. });
  158. }
  159. },
  160. /**
  161. * 支付订单更新
  162. */
  163. payOrderUpdate: (orderId, payOrderId, status, reason,type,_this) => {
  164. // 支付成功
  165. Http.post({
  166. url: config.api.payOrderUpdate,
  167. data: {
  168. payOrderId: payOrderId,
  169. orderId: orderId,
  170. status: status,
  171. reason: reason
  172. }
  173. })
  174. .then(res => {
  175. wx.hideLoading()
  176. if (!type) {
  177. wx.showToast({
  178. title: "购买成功",
  179. duration: 2000,
  180. image: "./../../../assets/img/success.png",
  181. mask: false,
  182. success: function () {
  183. wx.showLoading({
  184. title: "加载中..."
  185. });
  186. setTimeout(function () {
  187. wx.hideLoading();
  188. }, 1600);
  189. setTimeout(() => {
  190. wx.redirectTo({
  191. url: `/pages/order/detail/index?orderId=${orderId}`
  192. });
  193. }, 1600);
  194. }
  195. });
  196. }
  197. })
  198. .catch(err => {
  199. console.log(err)
  200. if (!type) {
  201. setTimeout(function () {
  202. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  203. }, 1500)
  204. }
  205. });
  206. },
  207. /**
  208. * 生命周期函数--监听页面初次渲染完成
  209. */
  210. onShow: function () {
  211. let that = this;
  212. // wx.getScreenBrightness({
  213. // success: function (res) {
  214. // app.globalData.sight=res.value;
  215. // console.log(app.globalData.sight);
  216. // }
  217. // });
  218. },
  219. /**
  220. * 生命周期函数--监听页面隐藏
  221. */
  222. onHide: function () {},
  223. /**
  224. * 页面相关事件处理函数--监听用户下拉动作
  225. */
  226. onPullDownRefresh: function () {},
  227. /**
  228. * 页面上拉触底事件的处理函数
  229. */
  230. onReachBottom: function () {},
  231. /**
  232. * 用户点击右上角分享
  233. */
  234. onShareAppMessage: function () {}
  235. });