C端小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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