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.

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