C端小程序
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.

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