C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

365 行
9.6 KiB

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