C端小程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

237 строки
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: "",
  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. that.payOrderUpdate(that.data.orderId, payOrderId, 1,'','',that); // 支付成功
  136. },
  137. fail: res => {
  138. that.payOrderUpdate(that.data.orderId, payOrderId, 2,'','fail',that);
  139. return;
  140. },
  141. });
  142. /// End payment --------
  143. });
  144. } else {
  145. // 免费券
  146. that.payOrderUpdate(orderId, "0", 1,'','fail') // 支付成功
  147. wx.showToast({
  148. title: "支付成功",
  149. duration: 2000,
  150. image: "./../../../assets/img/success.png",
  151. });
  152. }
  153. },
  154. /**
  155. * 支付订单更新
  156. */
  157. payOrderUpdate: (orderId, payOrderId, status, reason,type,_this) => {
  158. // 支付成功
  159. Http.post({
  160. url: config.api.payOrderUpdate,
  161. data: {
  162. payOrderId: payOrderId,
  163. orderId: orderId,
  164. status: status,
  165. reason: reason
  166. }
  167. })
  168. .then(res => {
  169. if (!type) {
  170. wx.showToast({
  171. title: "购买成功",
  172. duration: 2000,
  173. image: "./../../../assets/img/success.png",
  174. mask: false,
  175. success: function () {
  176. wx.showLoading({
  177. title: "加载中..."
  178. });
  179. setTimeout(function () {
  180. wx.hideLoading();
  181. }, 1600);
  182. setTimeout(() => {
  183. wx.redirectTo({
  184. url: `/pages/order/detail/index?orderId=${orderId}`
  185. });
  186. }, 1600);
  187. }
  188. });
  189. }
  190. })
  191. .catch(err => {
  192. console.log(err)
  193. if (!type) {
  194. setTimeout(function () {
  195. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  196. }, 1500)
  197. }
  198. });
  199. },
  200. /**
  201. * 生命周期函数--监听页面初次渲染完成
  202. */
  203. onShow: function () {
  204. let that = this;
  205. // wx.getScreenBrightness({
  206. // success: function (res) {
  207. // app.globalData.sight=res.value;
  208. // console.log(app.globalData.sight);
  209. // }
  210. // });
  211. },
  212. /**
  213. * 生命周期函数--监听页面隐藏
  214. */
  215. onHide: function () {},
  216. /**
  217. * 页面相关事件处理函数--监听用户下拉动作
  218. */
  219. onPullDownRefresh: function () {},
  220. /**
  221. * 页面上拉触底事件的处理函数
  222. */
  223. onReachBottom: function () {},
  224. /**
  225. * 用户点击右上角分享
  226. */
  227. onShareAppMessage: function () {}
  228. });