C端小程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

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