C端小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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