C端小程序
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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