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.

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