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.

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