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.

228 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. token: token
  99. }
  100. }).then(res => {
  101. if (res.data.id){
  102. _this.setData({
  103. showIf:true
  104. })
  105. }
  106. _this.setData({
  107. staticGamedata: res.data
  108. })
  109. })
  110. },
  111. /**
  112. * 发起支付
  113. */
  114. orderFunc(e) {
  115. var that = this;
  116. wx.showLoading({
  117. title: "加载中..."
  118. });
  119. const orderId = "" + that.data.orderId;
  120. if (that.data.order.payment > 0) {
  121. // 支付金额不为0
  122. Http.post({
  123. url: config.api.payOrderCreate,
  124. data: {
  125. orderId: orderId
  126. }
  127. }).then(res => {
  128. console.log(res);
  129. /// Begin payment ----
  130. var payOrderId = "" + res.data.payOrderId;
  131. wx.hideLoading();
  132. wx.requestPayment({
  133. timeStamp: res.data.timeStamp,
  134. nonceStr: res.data.nonceStr,
  135. package: res.data.package,
  136. signType: (res.data.signType) ? res.data.signType : "MD5",
  137. paySign: res.data.paySign,
  138. success: res => {
  139. console.log(res);
  140. that.payOrderUpdate(that.data.orderId, payOrderId, 1); // 支付成功
  141. /**
  142. * @Meo
  143. * 更新订单的状态
  144. */
  145. console.log(res);
  146. if (res.errMsg == "requestPayment:ok") {
  147. wx.showToast({
  148. title: "购买成功",
  149. duration: 2000,
  150. image: "./../../../assets/img/success.png",
  151. mask: false,
  152. success: function () {
  153. wx.showLoading({
  154. title: "加载中..."
  155. });
  156. setTimeout(function () {
  157. wx.hideLoading();
  158. }, 1600);
  159. setTimeout(() => {
  160. wx.navigateTo({
  161. url: `/pages/order/detail/index?orderId=${
  162. that.data.orderId
  163. }`
  164. });
  165. }, 1600);
  166. }
  167. });
  168. }
  169. },
  170. fail: res => {
  171. that.payOrderUpdate(that.data.orderId, payOrderId, 2);
  172. console.log(res);
  173. return;
  174. },
  175. });
  176. /// End payment --------
  177. });
  178. } else {
  179. // 免费券
  180. that.payOrderUpdate(orderId, "0", 1) // 支付成功
  181. wx.showToast({
  182. title: "支付成功",
  183. duration: 2000,
  184. image: "./../../../assets/img/success.png",
  185. });
  186. }
  187. },
  188. /**
  189. * 支付订单更新
  190. */
  191. payOrderUpdate: (orderId, payOrderId, status, reason) => {
  192. // 支付成功
  193. Http.post({
  194. url: config.api.payOrderUpdate,
  195. data: {
  196. payOrderId: payOrderId,
  197. orderId: orderId,
  198. status: status,
  199. reason: reason
  200. }
  201. })
  202. .then(res => {
  203. console.log("payOrderUpdate then", res);
  204. })
  205. .catch(err => {
  206. console.log("payOrderUpdate catch", err);
  207. });
  208. },
  209. /**
  210. * 生命周期函数--监听页面初次渲染完成
  211. */
  212. onShow: function () {
  213. let that = this;
  214. wx.getScreenBrightness({
  215. success: function (res) {
  216. that.setData({
  217. sight: res.value
  218. })
  219. }
  220. })
  221. }
  222. });