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.

491 lines
20 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px'
  2. var config = require("../../config/config.js");
  3. var app = getApp();
  4. const Http = require("../../utils/HttpBasics");
  5. Page({
  6. data: {
  7. navigationBarHeight,
  8. canIUse: wx.canIUse("button.open-type.getUserInfo"),
  9. path: null,
  10. couponChannelId: null,
  11. cuserId: null,
  12. coverImg: null,
  13. couponOrderId: null,
  14. optionData: null,
  15. fromflag: '',
  16. couponChannelIdflag: '',
  17. wjId: "",
  18. composeOrderType: "",
  19. fillIndentId: "",
  20. url: null,//游戏路径
  21. id: null,//游戏id,
  22. gameId: null,//游戏gameId
  23. },
  24. //是否授权手机号
  25. judgePhonelngo() {
  26. Http.get({
  27. url: config.api.checkPhoneStatus,
  28. data: {}
  29. }).then(res => {
  30. var tempSkip = app.globalData.skip
  31. if (tempSkip == 'redirectTo') {
  32. wx.redirectTo({
  33. url: app.globalData.skipUrl,
  34. })
  35. } else if (tempSkip == 'navigateTo') {
  36. wx.navigateTo({
  37. url: app.globalData.skipUrl,
  38. })
  39. } else if (tempSkip == 'reLaunch') {
  40. wx.reLaunch({
  41. url: app.globalData.skipUrl,
  42. })
  43. } else if (tempSkip == 'switchTab') {
  44. wx.switchTab({
  45. url: app.globalData.skipUrl,
  46. })
  47. }
  48. }).catch(err => {
  49. wx.redirectTo({
  50. url: `/pages/getphoneInfo/index?skipUrl=1`
  51. });
  52. })
  53. },
  54. onLoad: function (options) {
  55. console.log(app.globalData.skip, app.globalData.skipUrl, app.globalData.type, "跳转地址")
  56. var that = this;
  57. // options.fromflag == 'coupondetail';
  58. // 游戏页面
  59. if (options && options.url && options.id && options.gameId) {
  60. that.setData({
  61. url: options.url,//游戏路径
  62. id: options.id,//游戏id,
  63. gameId: options.gameId,//游戏gameId
  64. })
  65. }
  66. // 来自优惠券详情页面
  67. if (options && options.fromflag) {
  68. that.setData({
  69. fromflag: options.fromflag
  70. })
  71. }
  72. if (options && options.composeOrderType) {
  73. that.setData({
  74. composeOrderType: options.composeOrderType
  75. })
  76. }
  77. //线上配送 填写订单
  78. if (options && options.fillIndentId && couponId && options.couponId) {
  79. that.setData({
  80. fillIndentId: options.fillIndentId,
  81. couponId: options.couponId
  82. })
  83. }
  84. // 来自优惠券列表券详情页面的 couponChannelId
  85. if (options && options.couponChannelIdflag) {
  86. that.setData({
  87. couponChannelIdflag: options.couponChannelIdflag
  88. })
  89. }
  90. //调查问卷
  91. if (options && !options.wjId || options.wjId) {
  92. this.setData({
  93. wjId: options.wjId
  94. })
  95. }
  96. if (options && options.spellGroup) {
  97. that.setData({
  98. spellGroup: options.spellGroup
  99. })
  100. } else {
  101. that.setData({
  102. spellGroup: null
  103. })
  104. }
  105. if (options.couponChannelId && !options.cuserId || options.orderId) {
  106. that.setData({
  107. couponChannelId: options.couponChannelId,
  108. orderId: options.orderId
  109. })
  110. }
  111. if (options && options.frommd && options.id) {
  112. that.setData({
  113. id: options.id,
  114. frommd: options.frommd
  115. })
  116. }
  117. // that.setData({
  118. // optionData: null
  119. // })
  120. console.log(wx.getStorageSync('options'), 6666)
  121. that.setData({
  122. optionData: wx.getStorageSync('options') ? JSON.parse(wx.getStorageSync('options')) : null
  123. })
  124. if (options && options.path == 'index') {
  125. that.setData({
  126. path: options.path
  127. })
  128. }
  129. /**
  130. * 来自转赠
  131. */
  132. if (options.couponChannelId && options.cuserId) {
  133. that.setData({
  134. couponChannelId: options.couponChannelId,
  135. cuserId: options.cuserId,
  136. updateDate: options.updateDate,
  137. coverImg: options.coverImg,
  138. userName: options.userName,
  139. avatarUrl: options.avatarUrl,
  140. couponOrderId: options.couponOrderId
  141. })
  142. }
  143. Http.get({
  144. url: config.api.marketicon,
  145. data: {
  146. appId: config.weapp.AppId
  147. }
  148. }).then(res => {
  149. that.setData({
  150. mallImgUrl: res.data.mallImgUrl
  151. });
  152. wx.setNavigationBarTitle({
  153. title: res.data.mallName
  154. })
  155. })
  156. .catch(err => {
  157. wx.showToast({
  158. title: err.errMsg,
  159. icon: 'none',
  160. duration: 2000,
  161. mask: false
  162. });
  163. })
  164. },
  165. onShow: function () {
  166. wx.checkSession({
  167. success() {
  168. //session_key 未过期,并且在本生命周期一直有效
  169. },
  170. fail() {
  171. console.log("session_key 过期")
  172. // session_key 已经失效,需要重新执行登录流程
  173. wx.login({
  174. success: (res) => {
  175. if (res.code) {
  176. let usrdata = {
  177. appId: config.weapp.AppId,
  178. code: res.code,
  179. }
  180. Http.post({
  181. url: config.api.login,
  182. data: usrdata
  183. }).then(res => {
  184. Http.setToken(res.data.token);
  185. app.globalData.token = res.data.token;
  186. })
  187. }
  188. }
  189. })
  190. }
  191. })
  192. },
  193. backHome: function () {
  194. wx.switchTab({
  195. url: app.globalData.goHomeUrl,
  196. })
  197. },
  198. bindGetUserInfo(e) {
  199. //session_key 未过期,并且在本生命周期一直有效
  200. wx.getUserProfile({
  201. title: '温馨提示',
  202. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  203. success: (res) => {
  204. let that = this;
  205. var iv = res.iv;
  206. var encryptedData = res.encryptedData;
  207. wx.getUserInfo({
  208. success: function (res) {
  209. Http.post({
  210. url: config.api.getUserInfo,
  211. data: {
  212. encryptedData: encryptedData,
  213. iv: iv
  214. }
  215. }).then(
  216. function (res) {
  217. // wx.showToast({
  218. // title: "授权个人信息成功11",
  219. // icon: "none"
  220. // });
  221. if (app.globalData.type == 'gm' && that.data.id && that.data.gameId && that.data.url) {//游戏页面
  222. app.globalData.skipUrl = '/pages/game/index?url=' + that.data.url + "&id=" + that.data.id + "&gameId=" + that.data.gameId,
  223. app.globalData.skip = 'redirectTo'
  224. that.judgePhonelngo()
  225. return;
  226. }
  227. if (that.data.wjId) {
  228. app.globalData.skipUrl = `/pages/questionnaire/questionnaire?id=${that.data.wjId}`
  229. app.globalData.skip = 'redirectTo'
  230. that.judgePhonelngo()
  231. return;
  232. }
  233. if (that.data.fromflag == 'poster') {
  234. app.globalData.skipUrl = `/pages/canvas/index?couponChannelId=${that.data.couponChannelId}`
  235. app.globalData.skip = 'redirectTo'
  236. that.judgePhonelngo()
  237. return;
  238. }
  239. //
  240. if (that.data.optionData != null && that.data.optionData.orderGroupId != null && that.data.optionData.orderGroupId != "") {
  241. app.globalData.skipUrl = `/pages/joinFrDpell/index?couponId=${that.data.optionData.couponId}&orderGroupId=${that.data.optionData.orderGroupId}&couponChannelId=${that.data.optionData.couponChannelId}&orderId=${that.data.optionData.orderId}&avatarUrl=${that.data.optionData.avatarUrl}&nickName=${that.data.optionData.nickName}`
  242. app.globalData.skip = 'reLaunch'
  243. that.judgePhonelngo()
  244. return;
  245. }
  246. if (that.data.path == 'index') {
  247. app.globalData.skipUrl = "/pages/game/index"
  248. app.globalData.skip = 'reLaunch'
  249. that.judgePhonelngo()
  250. } else {
  251. //返回主页
  252. // if (that.data.couponChannelId && !that.data.cuserId && !that.data.spellGroup||that.data.couponChannelId && !that.data.cuserId&&app.globalData.type == 'cd') {
  253. if (that.data.couponChannelId && !that.data.cuserId && !that.data.spellGroup && app.globalData.type == 'cd') {
  254. // 跳转普通券/消费卡/限时秒杀/砍价详情
  255. app.globalData.skipUrl = `/pages/coupon/detail/index?couponChannelId=${that.data.couponChannelId}`
  256. app.globalData.skip = 'navigateTo'
  257. that.judgePhonelngo()
  258. } else if (that.data.couponChannelId && that.data.cuserId && !that.data.spellGroup && app.globalData.type != 'sd') {
  259. // 来自转赠
  260. app.globalData.skipUrl = `/pages/coupon/detail/index?couponChannelId=${that.data.couponChannelId}&cuserId=${that.data.cuserId}&coverImg=${that.data.coverImg}&userName=${that.data.userName}&avatarUrl=${that.data.avatarUrl}&couponOrderId=${that.data.couponOrderId}&updateDate=${that.data.updateDate}`
  261. app.globalData.skip = 'reLaunch'
  262. that.judgePhonelngo()
  263. } else if (that.data.couponChannelId && app.globalData.type == 'sd' || that.data.couponChannelId && that.data.spellGroup) {
  264. // 拼团详情页
  265. app.globalData.skipUrl = `/pages/spellGroup/mySpellGroup/index?couponChannelId=${that.data.couponChannelId}`
  266. app.globalData.skip = 'redirectTo'
  267. that.judgePhonelngo()
  268. } else if (that.data.optionData != null && that.data.optionData.id && app.globalData.type == 'gm') {
  269. // 游戏页面
  270. that.getGameOne(app.globalData.token, that.data.optionData.id)
  271. } else if (that.data.optionData != null && that.data.optionData.id && app.globalData.type == 'td') {
  272. app.globalData.skipUrl = `/pages/topicDetail/index?id=${that.data.optionData.id}`
  273. app.globalData.skip = 'redirectTo'
  274. that.judgePhonelngo()
  275. }
  276. // 报名活动
  277. else if (that.data.optionData != null && that.data.optionData.id && app.globalData.type == 'ra') {
  278. app.globalData.skipUrl = `/pages/radetail/index?id=${that.data.optionData.id}`,
  279. app.globalData.skip = 'redirectTo'
  280. that.judgePhonelngo()
  281. }
  282. // 报名签到
  283. else if (that.data.optionData != null && that.data.optionData.id && app.globalData.type == 'si') {
  284. app.globalData.skipUrl = `/pages/acSignIn/index?id=${that.data.optionData.id}`,
  285. app.globalData.skip = 'redirectTo'
  286. that.judgePhonelngo()
  287. }
  288. // 门店详情
  289. else if (that.data.optionData != null && that.data.optionData.id && app.globalData.type == 'md') {
  290. app.globalData.skipUrl = `/pages/index/searchbar/detail/index?id=${that.data.optionData.id}`,
  291. app.globalData.skip = 'redirectTo'
  292. that.judgePhonelngo()
  293. }
  294. // 通过分享进入的门店详情页面
  295. else if (that.data.id && that.data.frommd == 'md') {
  296. app.globalData.skipUrl = `/pages/index/searchbar/detail/index?id=${that.data.id}`,
  297. app.globalData.skip = 'redirectTo'
  298. that.judgePhonelngo()
  299. } else if (that.data.optionData != null && that.data.optionData.bt && that.data.optionData.id && app.globalData.type == 'bd') {
  300. // 宣传页详情
  301. if (that.data.optionData != null && that.data.optionData.bt == '2') {
  302. // 自由图文
  303. app.globalData.skipUrl = `/pages/freeBannerDetail/index?id=${that.data.optionData.id}`,
  304. app.globalData.skip = 'redirectTo'
  305. that.judgePhonelngo()
  306. } else {
  307. // 标准格式
  308. app.globalData.skipUrl = `/pages/bannerdetail/index?id=${that.data.optionData.id}`,
  309. app.globalData.skip = 'redirectTo'
  310. that.judgePhonelngo()
  311. }
  312. } else if (that.data.orderId || that.data.orderId && app.globalData.type == 'bg') {
  313. // 参与砍价
  314. app.globalData.skipUrl = `/pages/bargain/bargainDatail/bargainDatail?orderId=${that.data.orderId}&composeOrderType=${that.composeOrderType}`,
  315. app.globalData.skip = 'navigateTo'
  316. that.judgePhonelngo()
  317. } else if (app.globalData.type == 'uc') {
  318. // 我的
  319. app.globalData.skipUrl = '/index/user',
  320. app.globalData.skip = 'switchTab'
  321. that.judgePhonelngo()
  322. } else if (app.globalData.type == 'in') {
  323. // 首页
  324. app.globalData.skipUrl = app.globalData.goHomeUrl,
  325. app.globalData.skip = 'switchTab'
  326. that.judgePhonelngo()
  327. } else if (app.globalData.type == "qd") {
  328. //每日签到
  329. app.globalData.skipUrl = "/pages/activityCalendar/activityCalendar"
  330. app.globalData.skip = 'reLaunch'
  331. that.judgePhonelngo()
  332. } else if (app.globalData.type == "hdrl") {
  333. //活动日历
  334. app.globalData.skipUrl = `/pages/radetail/index?id=${app.globalData.activityId}`
  335. app.globalData.skip = 'redirectTo'
  336. that.judgePhonelngo()
  337. }
  338. // 积分
  339. else if (app.globalData.type == 'jf') {
  340. app.globalData.skipUrl = '/pages/integralmall/index',
  341. app.globalData.skip = 'redirectTo'
  342. that.judgePhonelngo()
  343. } else if (app.globalData.type == 'pc') {
  344. // 停车
  345. app.globalData.skipUrl = '/index/passCar',
  346. app.globalData.skip = 'switchTab'
  347. that.judgePhonelngo()
  348. } else if (app.globalData.type == 'mc') {
  349. // 我的券包
  350. app.globalData.skipUrl = '/pages/couponorder/index/index',
  351. app.globalData.skip = 'redirectTo'
  352. that.judgePhonelngo()
  353. } else if (app.globalData.type == 'mo') {
  354. // 我的订单
  355. app.globalData.skipUrl = '/pages/order/index/index?id=all',
  356. app.globalData.skip = 'redirectTo'
  357. that.judgePhonelngo()
  358. } else if (app.globalData.type == 'ca') {
  359. // 我的卡包
  360. app.globalData.skipUrl = '/pages/cardorder/index/index',
  361. app.globalData.skip = 'redirectTo'
  362. that.judgePhonelngo()
  363. } else if (app.globalData.type == 'sc') {
  364. // 特享礼遇
  365. app.globalData.skipUrl = '/pages/specialcourtesy/specialcourtesy',
  366. app.globalData.skip = 'redirectTo'
  367. that.judgePhonelngo()
  368. } else if (app.globalData.type == 'rb') {
  369. // 限时秒杀
  370. app.globalData.skipUrl = '/pages/rushToBuy/index',
  371. app.globalData.skip = 'redirectTo'
  372. that.judgePhonelngo()
  373. } else if (app.globalData.type == 'bl') {
  374. // 砍价专场
  375. app.globalData.skipUrl = '/pages/bargain/bargain',
  376. app.globalData.skip = 'redirectTo'
  377. that.judgePhonelngo()
  378. } else if (app.globalData.type == 'mb') {
  379. // 我的砍价
  380. app.globalData.skipUrl = '/pages/bargain/bargain?from=myhtml',
  381. app.globalData.skip = 'redirectTo'
  382. that.judgePhonelngo()
  383. } else if (app.globalData.type == 'sl') {
  384. // 拼团专场
  385. app.globalData.skipUrl = '/pages/spellGroup/spellGroup',
  386. app.globalData.skip = 'redirectTo'
  387. that.judgePhonelngo()
  388. } else if (app.globalData.type == 'ms') {
  389. // 我的拼团
  390. app.globalData.skipUrl = '/pages/spellGroup/spellGroup?from=myhtml',
  391. app.globalData.skip = 'redirectTo'
  392. that.judgePhonelngo()
  393. } else if (app.globalData.type == 'dc') {
  394. // 消费卡
  395. app.globalData.skipUrl = '/pages/discountCardList/discountCardList',
  396. app.globalData.skip = 'redirectTo'
  397. that.judgePhonelngo()
  398. } else if (app.globalData.type == 'td') {
  399. // 专题活动页
  400. app.globalData.skipUrl = '/pages/topicDetail/index',
  401. app.globalData.skip = 'redirectTo'
  402. that.judgePhonelngo()
  403. } else if (app.globalData.type == 'ml') {
  404. // 门店
  405. app.globalData.skipUrl = '/index/searchbar',
  406. app.globalData.skip = 'switchTab'
  407. that.judgePhonelngo()
  408. } else if (that.data.fromflag == 'coupondetail' && that.data.couponChannelIdflag) {
  409. app.globalData.skipUrl = `/pages/coupon/detail/index?couponChannelId=${that.data.couponChannelIdflag}`,
  410. app.globalData.skip = 'redirectTo'
  411. that.judgePhonelngo()
  412. } else if (that.data.fromflag == 'spellcoupondetail' && that.data.couponChannelIdflag) {
  413. app.globalData.skipUrl = `/pages/spellGroup/mySpellGroup/index?couponChannelId=${that.data.couponChannelIdflag}`,
  414. app.globalData.skip = 'redirectTo'
  415. that.judgePhonelngo()
  416. } else if (that.data.fromflag == 'fillIndent' && that.data.fillIndentId && that.data.couponId) {
  417. //线上配送 填写订单
  418. app.globalData.skipUrl = `/pages/fillIndent/fillIndent?id=${that.data.fillIndentId}&couponId=${that.data.couponId}`,
  419. app.globalData.skip = 'redirectTo'
  420. that.judgePhonelngo()
  421. } else {
  422. app.globalData.skipUrl = app.globalData.goHomeUrl,
  423. app.globalData.skip = 'switchTab'
  424. that.judgePhonelngo()
  425. }
  426. }
  427. },
  428. function (error) {
  429. console.log(error)
  430. wx.showToast({
  431. title: "请授权个人信息",
  432. icon: "none"
  433. });
  434. }
  435. )
  436. .catch(err => {
  437. wx.showToast({
  438. title: err.code,
  439. icon: 'none',
  440. duration: 2000,
  441. mask: false
  442. });
  443. })
  444. }
  445. })
  446. },
  447. fail: (err => {
  448. console.log(err)
  449. })
  450. })
  451. },
  452. getGameOne: function (token, id) {
  453. let _this = this;
  454. Http.get({
  455. url: config.api.getOneGame,
  456. data: {
  457. token: token,
  458. id: id
  459. }
  460. }).then(res => {
  461. wx.redirectTo({
  462. url: '/pages/game/index?url=' + res.data.url + "&id=" + res.data.id + "&gameId=" + res.data.gameId,
  463. })
  464. })
  465. .catch(err => {
  466. wx.showModal({
  467. title: '提示',
  468. content: err.message,
  469. showCancel: false,
  470. success: function (res) {
  471. // 如果游戏下架或者找不到,重启首页
  472. if (res.confirm) {
  473. wx.reLaunch({
  474. url: '/pages/index/index',
  475. })
  476. }
  477. }
  478. })
  479. this.alphaClick();
  480. })
  481. },
  482. });