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.

295 lines
8.2 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px'
  2. var config = require("../../config/config.js");
  3. const Http = require("../../utils/HttpBasics");
  4. var app = getApp();
  5. Page({
  6. data: {
  7. navigationBarHeight,
  8. canIUse: wx.canIUse("button.open-type.getPhoneNumber"),
  9. couponChannelId: "",
  10. path: null,
  11. paramData: null,
  12. signActivity: "",
  13. mineFlag: null,
  14. skipUrl: 0,
  15. fillIndentId: "",
  16. couponId: "",
  17. go: '',
  18. id: ''
  19. // skip: app.globalData.skip
  20. },
  21. onLoad: function (options) {
  22. console.log(options, 'options');
  23. var that = this;
  24. console.log(options.skipUrl, "options.skipUrl")
  25. if (options.skipUrl) {
  26. that.setData({
  27. skipUrl: options.skipUrl
  28. })
  29. }
  30. if (options.id) {
  31. that.setData({
  32. id: options.id
  33. })
  34. }
  35. if (options.go) {
  36. that.setData({
  37. go: options.go
  38. })
  39. }
  40. that.setData({
  41. path: options.path
  42. })
  43. that.setData({
  44. paramData: options
  45. })
  46. if (options && options.fillIndentId && options.couponId) {
  47. that.setData({
  48. fillIndentId: options.fillIndentId,
  49. couponId: options.couponId
  50. })
  51. }
  52. if (options && options.couponChannelId) {
  53. that.setData({
  54. couponChannelId: options.couponChannelId
  55. });
  56. }
  57. if (options && options.mineFlag) {
  58. that.setData({
  59. mineFlag: options.mineFlag
  60. })
  61. }
  62. if (options && options.signActivity) {
  63. that.setData({
  64. signActivity: options.signActivity
  65. });
  66. }
  67. Http.get({
  68. url: config.api.marketicon,
  69. data: {
  70. appId: config.weapp.AppId
  71. }
  72. }).then(res => {
  73. that.setData({
  74. mallImgUrl: res.data.mallImgUrl
  75. });
  76. wx.setNavigationBarTitle({
  77. title: res.data.mallName
  78. })
  79. })
  80. .catch(err => {
  81. wx.showToast({
  82. title: err.errMsg,
  83. icon: 'none',
  84. duration: 2000,
  85. mask: false
  86. });
  87. })
  88. },
  89. onShow: function () {
  90. wx.checkSession({
  91. success() {
  92. //session_key 未过期,并且在本生命周期一直有效
  93. },
  94. fail() {
  95. // session_key 已经失效,需要重新执行登录流程
  96. console.log("session_key 过期")
  97. wx.login({
  98. success: (res) => {
  99. if (res.code) {
  100. let usrdata = {
  101. appId: config.weapp.AppId,
  102. code: res.code,
  103. }
  104. Http.post({
  105. url: config.api.login,
  106. data: usrdata
  107. }).then(res => {
  108. Http.setToken(res.data.token);
  109. app.globalData.token = res.data.token;
  110. })
  111. }
  112. }
  113. })
  114. }
  115. })
  116. },
  117. backHome: function () {
  118. wx.switchTab({
  119. url: app.globalData.goHomeUrl,
  120. })
  121. },
  122. getPhoneNumber: function (e) {
  123. var that = this;
  124. var iv = e.detail.iv;
  125. var encryptedData = e.detail.encryptedData;
  126. Http.post({
  127. url: config.api.getUserPhone,
  128. data: {
  129. encryptedData: encryptedData,
  130. iv: iv
  131. }
  132. }).then(res => {
  133. app.globalData.phone = res.data.phone;
  134. if (that.data.skipUrl == '1') {
  135. console.log(app.globalData.skip, app.globalData.skipUrl, "跳转地址")
  136. if (app.globalData.skip == 'redirectTo') {
  137. wx.redirectTo({
  138. url: app.globalData.skipUrl,
  139. })
  140. return;
  141. } else if (app.globalData.skip == 'navigateTo') {
  142. wx.navigateTo({
  143. url: app.globalData.skipUrl,
  144. })
  145. return;
  146. } else if (app.globalData.skip == 'reLaunch') {
  147. wx.reLaunch({
  148. url: app.globalData.skipUrl,
  149. })
  150. return;
  151. } else if (app.globalData.skip == 'switchTab') {
  152. wx.switchTab({
  153. url: app.globalData.skipUrl,
  154. })
  155. return;
  156. }
  157. }
  158. //线上配送
  159. if (that.data.path == "fi") {
  160. wx.redirectTo({
  161. url: `/pages/fillIndent/fillIndent?id=${that.data.fillIndentId}&couponId=${that.data.couponId}`
  162. })
  163. }
  164. // 来着问卷
  165. if (that.data.path == "wj") {
  166. wx.redirectTo({
  167. url: `/pages/questionnaire/questionnaire?id=${that.data.wjId}`
  168. })
  169. return;
  170. }
  171. /**a
  172. * 来自我的
  173. */
  174. if (that.data.path == 'main') {
  175. wx.switchTab({
  176. url: `/index/user`
  177. })
  178. return;
  179. }
  180. /**
  181. * 来自积分兑换
  182. */
  183. if (that.data.path == 'jifen') {
  184. wx.redirectTo({
  185. url: `/pages/integralmall/payIntegcoupondetail/index?couponChannelId=${that.data.paramData.couponChannelId}&couponId=${that.data.paramData.couponId}`
  186. })
  187. return;
  188. }
  189. /**
  190. * 来自拼团详情
  191. */
  192. if (that.data.path == 'spell') {
  193. if (that.data.paramData.avatarUrl) {
  194. wx.redirectTo({
  195. url: `/pages/joinFrDpell/index?couponId=${that.data.paramData.couponId}&orderGroupId=${that.data.paramData.orderGroupId}&couponChannelId=${that.data.paramData.couponChannelId}&orderId=${that.data.paramData.orderId}&avatarUrl=${that.data.paramData.avatarUrl}&nickName=${that.data.paramData.nickName}`
  196. })
  197. } else {
  198. wx.redirectTo({
  199. url: `/pages/spellGroup/mySpellGroup/index?couponId=${that.data.paramData.couponId}&couponChannelId=${that.data.paramData.couponChannelId}`
  200. })
  201. }
  202. return;
  203. }
  204. /**
  205. * fromId若存在来自卡转赠
  206. */
  207. if (that.data.path == 'index' && !that.data.paramData.cuserId) {
  208. wx.redirectTo({
  209. url: "/pages/game/index?url=" + that.data.paramData.url + "&id=" + that.data.paramData.id + "&gameId=" + that.data.paramData.gameId,
  210. })
  211. } else if (that.data.path == 'index' && that.data.paramData.cuserId) {
  212. wx.redirectTo({
  213. url: "/pages/coupon/detail/index?cuserId=" + that.data.paramData.cuserId + '&couponChannelId=' + that.data.paramData.couponChannelId + '&coverImg=' + that.data.paramData.coverImg + '&avatarUrl=' + that.data.paramData.avatarUrl + '&userName=' + that.data.paramData.userName + '&couponOrderId=' + that.data.paramData.couponOrderId + "&updateDate=" + that.data.paramData.updateDate
  214. })
  215. }
  216. /**
  217. * 活动报名
  218. */
  219. else if (that.data.signActivity) {
  220. wx.redirectTo({
  221. url: `/pages/radetail/joinActivity/edit?activityId=${that.data.signActivity}`
  222. })
  223. } else if (that.data.mineFlag == 'mine') {
  224. wx.switchTab({
  225. url: '/index/user'
  226. });
  227. } else if (that.data.mineFlag == 'passCar') {
  228. wx.switchTab({
  229. url: '/index/passCar'
  230. });
  231. } else if (that.data.mineFlag == 'index') {
  232. wx.switchTab({
  233. url: app.globalData.goHomeUrl
  234. });
  235. } else if (that.data.path == 'exchangeCard') {
  236. wx.navigateTo({
  237. url: `/pages/exchangeCard/exchangeCard`
  238. })
  239. } else if (that.data.path == 'searchbarDetail') {
  240. wx.navigateTo({
  241. url: `/pages/index/searchbar/detail/index?id=${that.data.id}`
  242. })
  243. } else {
  244. wx.showToast({
  245. title: res.data.msg,
  246. icon: "success",
  247. success: function (res) {
  248. if (that.data.couponChannelId) {
  249. wx.redirectTo({
  250. url: "/pages/coupon/detail/index?couponChannelId=" + that.data.couponChannelId + "&flag=pay"
  251. })
  252. } else {
  253. if (that.data.paramData.go) {
  254. wx.navigateTo({
  255. url: '/pages3/setUserInfo/index',
  256. })
  257. } else {
  258. const ifSetUserInfo = wx.getStorageSync('ifSetUserInfo') || 0
  259. if (ifSetUserInfo) {
  260. wx.switchTab({
  261. url: '/index/user'
  262. });
  263. } else {
  264. wx.switchTab({
  265. url: '/index/passCar',
  266. })
  267. }
  268. }
  269. }
  270. }
  271. });
  272. }
  273. }).catch(err => {
  274. wx.showToast({
  275. title: '授权失败',
  276. icon: 'error',
  277. duration: 2000,
  278. mask: false
  279. });
  280. })
  281. },
  282. goCheckProtocol() {
  283. wx.navigateTo({
  284. url: '/pages3/userProtocol/userProtocol',
  285. })
  286. }
  287. });