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.

328 linhas
9.0 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. }).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. changePhoneStatus() {
  118. const isPhone = this.data.isPhone
  119. this.setData({
  120. isPhone: !isPhone
  121. })
  122. },
  123. backHome: function () {
  124. wx.switchTab({
  125. url: app.globalData.goHomeUrl,
  126. })
  127. },
  128. getPhoneNumber: function (e) {
  129. if (!this.data.isPhone) {
  130. wx.showToast({
  131. title: '请您阅读并勾选用户协议哦',
  132. icon: "none"
  133. })
  134. return
  135. }
  136. var that = this;
  137. var iv = e.detail.iv;
  138. var encryptedData = e.detail.encryptedData;
  139. Http.post({
  140. url: config.api.getUserPhone,
  141. data: {
  142. encryptedData: encryptedData,
  143. iv: iv
  144. }
  145. }).then(res => {
  146. app.globalData.phone = res.data.phone;
  147. if (that.data.skipUrl == '1') {
  148. console.log(app.globalData.skip, app.globalData.skipUrl, "跳转地址")
  149. if (app.globalData.skip == 'redirectTo') {
  150. wx.redirectTo({
  151. url: app.globalData.skipUrl,
  152. })
  153. return;
  154. } else if (app.globalData.skip == 'navigateTo') {
  155. wx.navigateTo({
  156. url: app.globalData.skipUrl,
  157. })
  158. return;
  159. } else if (app.globalData.skip == 'reLaunch') {
  160. wx.reLaunch({
  161. url: app.globalData.skipUrl,
  162. })
  163. return;
  164. } else if (app.globalData.skip == 'switchTab') {
  165. wx.switchTab({
  166. url: app.globalData.skipUrl,
  167. })
  168. return;
  169. }
  170. }
  171. //线上配送
  172. if (that.data.path == "fi") {
  173. wx.redirectTo({
  174. url: `/pages/fillIndent/fillIndent?id=${that.data.fillIndentId}&couponId=${that.data.couponId}`
  175. })
  176. }
  177. // 来着问卷
  178. if (that.data.path == "wj") {
  179. wx.redirectTo({
  180. url: `/pages/questionnaire/questionnaire?id=${that.data.wjId}`
  181. })
  182. return;
  183. }
  184. /**a
  185. * 来自我的
  186. */
  187. if (that.data.path == 'main') {
  188. wx.switchTab({
  189. url: `/index/user`
  190. })
  191. return;
  192. }
  193. /**
  194. * 来自积分兑换
  195. */
  196. if (that.data.path == 'jifen') {
  197. wx.redirectTo({
  198. url: `/pages/integralmall/payIntegcoupondetail/index?couponChannelId=${that.data.paramData.couponChannelId}&couponId=${that.data.paramData.couponId}`
  199. })
  200. return;
  201. }
  202. /**
  203. * 来自拼团详情
  204. */
  205. if (that.data.path == 'spell') {
  206. if (that.data.paramData.avatarUrl) {
  207. wx.redirectTo({
  208. 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}`
  209. })
  210. } else {
  211. wx.redirectTo({
  212. url: `/pages/spellGroup/mySpellGroup/index?couponId=${that.data.paramData.couponId}&couponChannelId=${that.data.paramData.couponChannelId}`
  213. })
  214. }
  215. return;
  216. }
  217. /**
  218. * fromId若存在来自卡转赠
  219. */
  220. if (that.data.path == 'index' && !that.data.paramData.cuserId) {
  221. wx.redirectTo({
  222. url: "/pages/game/index?url=" + that.data.paramData.url + "&id=" + that.data.paramData.id + "&gameId=" + that.data.paramData.gameId,
  223. })
  224. } else if (that.data.path == 'index' && that.data.paramData.cuserId) {
  225. wx.redirectTo({
  226. 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
  227. })
  228. }
  229. /**
  230. * 活动报名
  231. */
  232. else if (that.data.signActivity) {
  233. wx.redirectTo({
  234. url: `/pages/radetail/joinActivity/edit?activityId=${that.data.signActivity}`
  235. })
  236. } else if (that.data.mineFlag == 'mine') {
  237. wx.switchTab({
  238. url: '/index/user'
  239. });
  240. } else if (that.data.mineFlag == 'passCar') {
  241. wx.switchTab({
  242. url: '/index/passCar'
  243. });
  244. } else if (that.data.mineFlag == 'index') {
  245. wx.switchTab({
  246. url: app.globalData.goHomeUrl
  247. });
  248. } else if (that.data.path == 'exchangeCard') {
  249. wx.navigateTo({
  250. url: `/pages3/exchangeCard/exchangeCard`
  251. })
  252. } else if (that.data.path == 'searchbarDetail') {
  253. wx.navigateTo({
  254. url: `/pages/index/searchbar/detail/index?id=${that.data.id}`
  255. })
  256. } else if (that.data.path == 'activityCalendar') {
  257. wx.navigateTo({
  258. url: `/pages/activityCalendar/activityCalendar`
  259. })
  260. } else if (that.data.path == 'integralmall') {
  261. wx.navigateTo({
  262. url: `/pages/integralmall/index`
  263. })
  264. } else if (that.data.path == 'questionnaire') {
  265. wx.navigateTo({
  266. url: `/pages/questionnaire/questionnaire`
  267. })
  268. } else {
  269. wx.showToast({
  270. title: res.data.msg,
  271. icon: "success",
  272. success: function (res) {
  273. if (that.data.couponChannelId) {
  274. wx.redirectTo({
  275. url: "/pages/coupon/detail/index?couponChannelId=" + that.data.couponChannelId + "&flag=pay"
  276. })
  277. } else {
  278. if (that.data.paramData.go) {
  279. wx.navigateTo({
  280. url: '/pages3/setUserInfo/index',
  281. })
  282. } else {
  283. const ifSetUserInfo = wx.getStorageSync('ifSetUserInfo') || 0
  284. if (ifSetUserInfo) {
  285. wx.switchTab({
  286. url: '/index/user'
  287. });
  288. } else {
  289. wx.switchTab({
  290. url: '/index/passCar',
  291. })
  292. }
  293. }
  294. }
  295. }
  296. });
  297. }
  298. }).catch(err => {
  299. wx.showToast({
  300. title: '授权失败',
  301. icon: 'error',
  302. duration: 2000,
  303. mask: false
  304. });
  305. })
  306. },
  307. goCheckProtocolI() {
  308. wx.navigateTo({
  309. url: '/pages3/userProtocol/userProtocol',
  310. })
  311. },
  312. goCheckProtocolII() {
  313. wx.navigateTo({
  314. url: '/pages3/privateProtocol/privateProtocol',
  315. })
  316. },
  317. });