C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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