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.

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