C端小程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

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