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.

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