C端小程序
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

360 рядки
9.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.new1.url,
  15. weixinTitle: imgurl.weixinTitle.url,
  16. showModalStatus: false,
  17. flag: 0,
  18. order: null,
  19. orderId: null,
  20. //存储计时器
  21. setInter: "",
  22. mystatus: '',
  23. staticGamedata: {},
  24. showIf: false,
  25. showPage:false,
  26. showButton:false,
  27. cardDetail:null,
  28. supportTransfer:'',
  29. cardIf:false
  30. },
  31. phone: function (e) {
  32. let that = this;
  33. console.log(e);
  34. wx.makePhoneCall({
  35. phoneNumber: e.currentTarget.dataset.merchantlinkphone
  36. });
  37. },
  38. /**
  39. * 跳转到门店列表的详情页面
  40. */
  41. gotoDetail(e) {
  42. wx.navigateTo({
  43. url: `/pages/index/searchbar/detail/index?id=${e.currentTarget.dataset.id}`
  44. })
  45. },
  46. getUserInfo: function () {
  47. let that = this;
  48. // 获取用户信息
  49. Http.get({
  50. url: config.api.getScore,
  51. data: {}
  52. })
  53. .then(res => {
  54. console.log(res)
  55. that.setData({
  56. userName: res.data.nickName,
  57. avatarUrl: res.data.avatarUrl
  58. })
  59. })
  60. },
  61. onShareAppMessage: function (res) {
  62. if (res.from === 'button') {
  63. console.log(res, 3333333333333333333333)
  64. // 来自页面内转发按钮
  65. let _this = this;
  66. return {
  67. title: _this.data.userName+'赠送您一张' + _this.data.order.title,
  68. path: '/pages/index/index?couponChannelId=' + this.data.order.couponChannelId + '&cuserId=' + this.data.order.cuserId + '&couponId=' + this.data.order.productId + '&coverImg=' + this.data.order.coverImg + '&userName=' + this.data.userName + '&avatarUrl=' + this.data.avatarUrl + '&couponOrderId=' + this.data.order.couponOrderId + '&updateDate=' + this.data.order.updateDate,
  69. imageUrl: this.data.order.coverImg,
  70. success: function (res) {
  71. // 转发成功
  72. },
  73. fail: function (res) {
  74. // 转发失败
  75. }
  76. }
  77. } else {
  78. console.log(res, 444444444444444444)
  79. }
  80. },
  81. powerDrawer: function (e) {
  82. let that = this;
  83. console.log(e)
  84. // couponOrderStatus
  85. // 0 未使用
  86. // 1 已使用
  87. // 2 已过期
  88. // 3 已经退款
  89. if (that.data.mystatus == "" || that.data.mystatus == undefined) {
  90. wx.navigateTo({
  91. url: `/pages/orderquanma/index?quancode=${
  92. e.currentTarget.dataset.quancode
  93. }&title=${e.currentTarget.dataset.title}&subtitle=${
  94. e.currentTarget.dataset.subtitle
  95. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${
  96. e.currentTarget.dataset.couponorderstatus}&validstatus=${e.currentTarget.dataset.validstatus}`
  97. });
  98. } else {
  99. wx.navigateTo({
  100. url: `/pages/orderquanma/index?quancode=${
  101. e.currentTarget.dataset.quancode
  102. }&title=${e.currentTarget.dataset.title}&subtitle=${
  103. e.currentTarget.dataset.subtitle
  104. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${
  105. that.data.mystatus}&validstatus=${e.currentTarget.dataset.validstatus}`
  106. });
  107. }
  108. },
  109. gotogame: function () {
  110. let that = this;
  111. wx.navigateTo({
  112. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  113. })
  114. },
  115. // 买完卡跳转到立即使用页面
  116. gotoUse:function(){
  117. wx.navigateTo({
  118. url: '/pages/cardorder/index/index'
  119. })
  120. },
  121. // 获取游戏
  122. getStaticGame(token) {
  123. let _this = this;
  124. Http.get({
  125. url: config.api.getGame,
  126. data: {
  127. triggleAction: 3 // 购买触发
  128. }
  129. }).then(res => {
  130. if (res.data.id) {
  131. _this.setData({
  132. showIf: true
  133. })
  134. }
  135. _this.setData({
  136. staticGamedata: res.data
  137. })
  138. })
  139. .catch(err => {
  140. console.log(err);
  141. })
  142. },
  143. /**
  144. * 生命周期函数--监听页面加载
  145. */
  146. onLoad: function (options) {
  147. let that = this;
  148. that.setData({
  149. orderId: options.orderId
  150. });
  151. wx.hideShareMenu()
  152. if(options.cardIf){
  153. that.setData({
  154. cardIf:true
  155. })
  156. }
  157. wx.showLoading({
  158. title: "加载中"
  159. });
  160. Http.get({
  161. url: config.api.orderDetail,
  162. data: {
  163. orderId: options.orderId
  164. }
  165. })
  166. .then(res => {
  167. wx.hideLoading();
  168. if(res.code == 200){
  169. that.getUserInfo()
  170. that.setData({
  171. showPage:true
  172. })
  173. }
  174. that.setData({
  175. order: res.data,
  176. supportTransfer: res.data.supportTransfer
  177. });
  178. that.getStaticGame()
  179. //createDate 创建时间
  180. var createDate = util.formatTime(res.data.createDate, "yyyy-MM-dd hh:mm:ss");
  181. that.setData({
  182. createDate: createDate
  183. });
  184. })
  185. .catch(error=>{
  186. wx.hideLoading();
  187. wx.showModal({
  188. title: '提示',
  189. content: error.errMsg,
  190. showCancel:false
  191. })
  192. })
  193. },
  194. onShow:function(){
  195. let that = this;
  196. that.setData({
  197. showButton: false
  198. })
  199. },
  200. /**
  201. * 去拼团
  202. */
  203. goToOrderGroup(orderId, orderGroupId, _this) {
  204. let that = this;
  205. // 支付成功
  206. Http.post({
  207. url: config.api.toOrderGroup,
  208. data: {
  209. id: orderGroupId,
  210. orderId,
  211. couponId: _this.data.order.productId
  212. }
  213. })
  214. .then(res => {
  215. wx.redirectTo({
  216. url: `/pages/spellDetail/index?orderId=${orderId}&couponId=${_this.data.order.productId}&orderGroupId=${res.data.orderGroupId}`
  217. });
  218. })
  219. .catch(err => {
  220. console.log(err);
  221. })
  222. // return;
  223. },
  224. /**
  225. * 发起支付
  226. */
  227. orderFunc(e) {
  228. var that = this;
  229. that.setData({
  230. showButton: true
  231. })
  232. wx.showLoading({
  233. title: "加载中..."
  234. });
  235. const orderId = "" + that.data.orderId;
  236. if (that.data.order.payment > 0) {
  237. // 支付金额不为0
  238. Http.post({
  239. url: config.api.payOrderCreate,
  240. data: {
  241. orderId: orderId
  242. }
  243. }).then(res => {
  244. var payOrderId = "" + res.data.payOrderId;
  245. wx.hideLoading();
  246. wx.requestPayment({
  247. timeStamp: res.data.timeStamp,
  248. nonceStr: res.data.nonceStr,
  249. package: res.data.package,
  250. signType: (res.data.signType) ? res.data.signType : "MD5",
  251. paySign: res.data.paySign,
  252. success: res => {
  253. wx.showLoading({
  254. title: '订单正在处理中...',
  255. })
  256. setTimeout(function () {
  257. wx.hideLoading()
  258. }, 5000)
  259. that.payOrderUpdate(that.data.orderId, payOrderId, 1,'','',that); // 支付成功
  260. if (res.errMsg == "requestPayment:ok") {
  261. if (that.data.order.type == 100) {
  262. wx.setStorage({
  263. key: 'couponNum2',
  264. data: "couponNum2"
  265. })
  266. } else if (that.data.order.type != 5) {
  267. wx.setStorage({
  268. key: 'couponNum',
  269. data: "couponNum"
  270. })
  271. }
  272. }
  273. },
  274. fail: res => {
  275. that.setData({
  276. showButton:false
  277. })
  278. that.payOrderUpdate(that.data.orderId, payOrderId, 2,'','fail',that);
  279. return;
  280. },
  281. });
  282. });
  283. } else {
  284. // 免费券
  285. that.payOrderUpdate(orderId, "0", 1,'','free') // 支付成功
  286. if (that.data.order.type == 100) {
  287. wx.setStorage({
  288. key: 'couponNum2',
  289. data: "couponNum2"
  290. })
  291. } else if (that.data.order.type != "5") {
  292. wx.setStorage({
  293. key: 'couponNum',
  294. data: "couponNum"
  295. })
  296. }
  297. wx.showToast({
  298. title: "支付成功",
  299. duration: 2000,
  300. image: imgurl.success.url,
  301. });
  302. }
  303. },
  304. /**
  305. * 支付订单更新
  306. */
  307. payOrderUpdate: (orderId, payOrderId, status, reason,type,_this) => {
  308. // 支付成功
  309. Http.post({
  310. url: config.api.payOrderUpdate,
  311. data: {
  312. payOrderId: payOrderId,
  313. orderId: orderId,
  314. status: status,
  315. reason: reason
  316. }
  317. })
  318. .then(res => {
  319. wx.hideLoading();
  320. _this.setData({
  321. showButton: false
  322. })
  323. if (!type&&type!='free') {
  324. wx.showToast({
  325. title: "购买成功",
  326. duration: 2000,
  327. image: imgurl.success.url,
  328. mask: false,
  329. success: function () {
  330. wx.showLoading({
  331. title: "加载中..."
  332. });
  333. setTimeout(function () {
  334. wx.hideLoading();
  335. }, 1600);
  336. setTimeout(() => {
  337. wx.redirectTo({
  338. url: `/pages/order/detail/index?orderId=${orderId}`
  339. });
  340. }, 1600);
  341. }
  342. });
  343. } else if (type == 'free'){
  344. wx.redirectTo({
  345. url: `/pages/order/detail/index?orderId=${orderId}`
  346. });
  347. }
  348. })
  349. .catch(err => {
  350. console.log(err)
  351. if (!type) {
  352. setTimeout(function () {
  353. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  354. }, 1500)
  355. }
  356. });
  357. },
  358. });