C端小程序
Não pode escolher mais do que 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.

243 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. }&sight=${that.data.sight}`
  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. }&sight=${that.data.sight}`
  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. wx.showToast({
  75. title: err.errMsg,
  76. icon: 'none',
  77. duration: 2000,
  78. mask: false
  79. });
  80. })
  81. },
  82. /**
  83. * 生命周期函数--监听页面加载
  84. */
  85. onLoad: function (options) {
  86. let that = this;
  87. this.setData({
  88. orderId: options.orderId
  89. });
  90. wx.showLoading({
  91. title: "加载中"
  92. });
  93. setTimeout(function () {
  94. wx.hideLoading();
  95. }, 1500);
  96. Http.get({
  97. url: config.api.orderDetail,
  98. data: {
  99. orderId: options.orderId
  100. }
  101. }).then(res => {
  102. that.setData({
  103. order: res.data
  104. });
  105. that.getStaticGame()
  106. //createDate 创建时间
  107. var createDate = util.formatTime(res.data.createDate, "yyyy-MM-dd hh:mm:ss");
  108. that.setData({
  109. createDate: createDate
  110. });
  111. });
  112. },
  113. /**
  114. * 发起支付
  115. */
  116. orderFunc(e) {
  117. var that = this;
  118. wx.showLoading({
  119. title: "加载中..."
  120. });
  121. const orderId = "" + that.data.orderId;
  122. if (that.data.order.payment > 0) {
  123. // 支付金额不为0
  124. Http.post({
  125. url: config.api.payOrderCreate,
  126. data: {
  127. orderId: orderId
  128. }
  129. }).then(res => {
  130. /// Begin payment ----
  131. var payOrderId = "" + res.data.payOrderId;
  132. wx.hideLoading();
  133. wx.requestPayment({
  134. timeStamp: res.data.timeStamp,
  135. nonceStr: res.data.nonceStr,
  136. package: res.data.package,
  137. signType: (res.data.signType) ? res.data.signType : "MD5",
  138. paySign: res.data.paySign,
  139. success: res => {
  140. that.payOrderUpdate(that.data.orderId, payOrderId, 1,'','',that); // 支付成功
  141. },
  142. fail: res => {
  143. that.payOrderUpdate(that.data.orderId, payOrderId, 2,'','fail',that);
  144. return;
  145. },
  146. });
  147. /// End payment --------
  148. });
  149. } else {
  150. // 免费券
  151. that.payOrderUpdate(orderId, "0", 1,'','fail') // 支付成功
  152. wx.showToast({
  153. title: "支付成功",
  154. duration: 2000,
  155. image: "./../../../assets/img/success.png",
  156. });
  157. }
  158. },
  159. /**
  160. * 支付订单更新
  161. */
  162. payOrderUpdate: (orderId, payOrderId, status, reason,type,_this) => {
  163. // 支付成功
  164. Http.post({
  165. url: config.api.payOrderUpdate,
  166. data: {
  167. payOrderId: payOrderId,
  168. orderId: orderId,
  169. status: status,
  170. reason: reason
  171. }
  172. })
  173. .then(res => {
  174. if (!type) {
  175. wx.showToast({
  176. title: "购买成功",
  177. duration: 2000,
  178. image: "./../../../assets/img/success.png",
  179. mask: false,
  180. success: function () {
  181. wx.showLoading({
  182. title: "加载中..."
  183. });
  184. setTimeout(function () {
  185. wx.hideLoading();
  186. }, 1600);
  187. setTimeout(() => {
  188. wx.redirectTo({
  189. url: `/pages/order/detail/index?orderId=${orderId}`
  190. });
  191. }, 1600);
  192. }
  193. });
  194. }
  195. })
  196. .catch(err => {
  197. console.log(err)
  198. if (!type) {
  199. setTimeout(function () {
  200. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  201. }, 1500)
  202. }
  203. });
  204. },
  205. /**
  206. * 生命周期函数--监听页面初次渲染完成
  207. */
  208. onShow: function () {
  209. let that = this;
  210. wx.getScreenBrightness({
  211. success: function (res) {
  212. that.setData({
  213. sight: res.value
  214. })
  215. }
  216. });
  217. },
  218. /**
  219. * 生命周期函数--监听页面隐藏
  220. */
  221. onHide: function () {},
  222. /**
  223. * 页面相关事件处理函数--监听用户下拉动作
  224. */
  225. onPullDownRefresh: function () {},
  226. /**
  227. * 页面上拉触底事件的处理函数
  228. */
  229. onReachBottom: function () {},
  230. /**
  231. * 用户点击右上角分享
  232. */
  233. onShareAppMessage: function () {}
  234. });