C端小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

367 rindas
12 KiB

  1. const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
  2. const Http = require("../../utils/HttpBasics");
  3. const imgurl = require("../../utils/imgurl");
  4. const config = require("../../config/config");
  5. const QR = require("../../utils/memberqrcode.js");
  6. let app = getApp();
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {},
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. let that = this;
  17. /**
  18. * 根据接收到的参数的值,判断跳转到哪个页面
  19. */
  20. if (options && options.type) {
  21. app.globalData.type = options.type;
  22. }
  23. if (decodeURIComponent(options.scene) == "undefined") {
  24. that.setData({
  25. scene: 0
  26. });
  27. } else {
  28. that.setData({
  29. scene: decodeURIComponent(options.scene)
  30. });
  31. that.setData({
  32. newArr: this.data.scene.split(':')
  33. })
  34. console.log(this.data.newArr)
  35. //// 大屏-二维码-start
  36. if (this.data.newArr[0] == 'JC') {
  37. // 跳转券详情
  38. options.couponChannelId = this.data.newArr[1];
  39. } else if (this.data.newArr[0] == 'JG') {
  40. // 跳转拼团详情
  41. options.couponChannelId = this.data.newArr[1];
  42. options.path = 'daping'
  43. }
  44. //// 大屏-二维码-end
  45. else if (this.data.newArr[0] == 't') {
  46. // 普通二维码
  47. options.type = this.data.newArr[1];
  48. app.globalData.type = options.type;
  49. if(options.type == 'cd') {
  50. options.couponChannelId = this.data.newArr[2];
  51. } else if (options.type == 'bd') {
  52. options.bt = this.data.newArr[2];
  53. options.id = this.data.newArr[3];
  54. } else if (options.type == 'gm') {
  55. options.id = this.data.newArr[2];
  56. } else if (options.type == 'sd') {
  57. options.couponChannelId = this.data.newArr[2];
  58. } else if (options.type == 'td') {
  59. // 专题活动页
  60. options.id = this.data.newArr[2];
  61. }
  62. }
  63. }
  64. wx.showToast({
  65. title: '加载中',
  66. icon: "loading",
  67. duration: 2000
  68. })
  69. wx.setStorageSync('options', JSON.stringify(options))
  70. wx.setStorageSync('imgurl', imgurl)
  71. app.getLocation();
  72. if (options.couponChannelId || options.orderId || options.id) {
  73. debugger;
  74. that.userLogin(options);
  75. } else {
  76. that.userLogin()
  77. }
  78. },
  79. checkuserstatus(options) {
  80. let that = this;
  81. Http.get({
  82. url: config.api.checkUserStatus,
  83. data: {}
  84. })
  85. .then(res => {
  86. /**
  87. * 参与拼团
  88. */
  89. if (options && options.orderGroupId) {
  90. wx.redirectTo({
  91. url: `/pages/joinFrDpell/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  92. })
  93. return;
  94. }
  95. /**
  96. * 来自大屏的跳转拼团券详情
  97. */
  98. if (options && options.couponChannelId && options.path == 'daping') {
  99. /**
  100. * 主要是为了拿couponId
  101. */
  102. Http.get({
  103. url: config.api.couponDetail,
  104. data: {
  105. couponChannelId: options.couponChannelId
  106. }
  107. }).then(res => {
  108. let data = res.data;
  109. wx.redirectTo({
  110. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}&couponId=${data.couponId}`
  111. })
  112. });
  113. return;
  114. }
  115. if (options && options.couponChannelId && app.globalData.type == 'cd') {
  116. // 跳转普通券/消费卡/限时秒杀/砍价详情
  117. wx.redirectTo({
  118. url: `/pages/coupon/detail/index?couponChannelId=${options.couponChannelId}`,
  119. })
  120. } else if (options && options.couponChannelId && options.cuserId) {
  121. // 转赠判断
  122. wx.redirectTo({
  123. url: `/pages/coupon/detail/index?couponChannelId=${options.couponChannelId}&cuserId=${options.cuserId}&coverImg=${options.coverImg}&userName=${options.userName}&avatarUrl=${options.avatarUrl}&couponOrderId=${options.couponOrderId}&updateDate=${options.updateDate}`,
  124. })
  125. } else if (options && options.couponChannelId && app.globalData.type == 'sd') {
  126. // 拼团详情页
  127. wx.redirectTo({
  128. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}`,
  129. })
  130. } else if (options && options.id && app.globalData.type == 'gm') {
  131. // 游戏页面
  132. that.getGameOne(app.globalData.token, options.id)
  133. } else if (options && options.bt && options.id && app.globalData.type == 'bd') {
  134. // 宣传页详情
  135. if (options.bt == '2') {
  136. // 自由图文
  137. wx.redirectTo({
  138. url: `/pages/freeBannerDetail/index?id=${options.id}`,
  139. })
  140. } else {
  141. // 标准格式
  142. wx.redirectTo({
  143. url: `/pages/bannerdetail/index?id=${options.id}`,
  144. })
  145. }
  146. } else if (options && options.id && app.globalData.type == 'td'){
  147. wx.redirectTo({
  148. url: `/pages/topicDetail/index?id=${options.id}`
  149. });
  150. }
  151. else if (options && options.orderId && app.globalData.type == 'bg') {
  152. // 参与砍价
  153. wx.redirectTo({
  154. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${options.orderId}&from=${"discount"}`,
  155. })
  156. } else if (app.globalData.type == 'uc') {
  157. // 我的
  158. wx.switchTab({
  159. url: '/pages/user/index'
  160. });
  161. } else if (app.globalData.type == 'pc') {
  162. // 停车
  163. wx.switchTab({
  164. url: '/pages/passCar/passCar'
  165. });
  166. } else if (app.globalData.type == 'mc') {
  167. // 我的券包
  168. wx.redirectTo({
  169. url: '/pages/couponorder/index/index'
  170. });
  171. } else if (app.globalData.type == 'mo') {
  172. // 我的订单
  173. wx.redirectTo({
  174. url: '/pages/order/index/index?id=all'
  175. });
  176. } else if (app.globalData.type == 'ca') {
  177. // 我的卡包
  178. wx.redirectTo({
  179. url: '/pages/cardorder/index/index'
  180. });
  181. } else if (app.globalData.type == 'sc') {
  182. // 特享礼遇
  183. wx.redirectTo({
  184. url: '/pages/specialcourtesy/specialcourtesy'
  185. });
  186. } else if (app.globalData.type == 'rb') {
  187. // 限时秒杀
  188. wx.redirectTo({
  189. url: '/pages/rushToBuy/index'
  190. });
  191. } else if (app.globalData.type == 'bl') {
  192. // 砍价专场
  193. wx.redirectTo({
  194. url: '/pages/bargain/bargain'
  195. });
  196. } else if (app.globalData.type == 'mb') {
  197. // 我的砍价
  198. wx.redirectTo({
  199. url: '/pages/bargain/bargain?from=myhtml'
  200. });
  201. } else if (app.globalData.type == 'sl') {
  202. // 拼团专场
  203. wx.redirectTo({
  204. url: '/pages/spellGroup/spellGroup'
  205. });
  206. } else if (app.globalData.type == 'ms') {
  207. // 我的拼团
  208. wx.redirectTo({
  209. url: '/pages/spellGroup/spellGroup?from=myhtml'
  210. });
  211. } else if (app.globalData.type == 'dc') {
  212. // 消费卡
  213. wx.redirectTo({
  214. url: '/pages/discountCardList/discountCardList'
  215. });
  216. } else if (app.globalData.type == 'ml') {
  217. // 门店
  218. wx.switchTab({
  219. url: '/pages/index/searchbar/index'
  220. });
  221. } else {
  222. // 主页
  223. wx.switchTab({
  224. url: '/pages/main/index'
  225. });
  226. }
  227. })
  228. .catch(err => {
  229. if (err.code == 11004) {
  230. // 用户昵称未授权
  231. if (options && options.orderGroupId) {
  232. wx.redirectTo({
  233. url: `/pages/getuserinfo/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  234. })
  235. return;
  236. }
  237. if (options && options.couponChannelId && !options.cuserId) {
  238. wx.redirectTo({
  239. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}`
  240. });
  241. } else if (options && options.couponChannelId && options.cuserId) {
  242. /**
  243. * 转赠判断
  244. */
  245. wx.redirectTo({
  246. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}&cuserId=${options.cuserId}&coverImg=${options.coverImg}&userName=${options.userName}&avatarUrl=${options.avatarUrl}&couponOrderId=${options.couponOrderId}&updateDate=${options.updateDate}`
  247. });
  248. } else if (options && options.orderId) {
  249. wx.redirectTo({
  250. url: `/pages/getuserinfo/index?orderId=${options.orderId}&from='${"discount"}`
  251. });
  252. } else {
  253. wx.redirectTo({
  254. url: `/pages/getuserinfo/index`
  255. });
  256. }
  257. }
  258. });
  259. },
  260. /**
  261. * 用户登录
  262. */
  263. userLogin: function (options) {
  264. var that = this;
  265. // 登录
  266. wx.login({
  267. success: ({
  268. code
  269. }) => {
  270. wx.getSystemInfo({
  271. success: function (res) {
  272. that.setData({
  273. systemInfo: JSON.stringify(res)
  274. })
  275. }
  276. })
  277. var usrdata = {
  278. appId: config.weapp.AppId,
  279. code: code,
  280. sceneAddress: app.globalData.sceneAddress,
  281. scene: that.data.scene,
  282. systemInfo: that.data.systemInfo
  283. };
  284. if (app.globalData.locationInfo) {
  285. usrdata = {
  286. appId: config.weapp.AppId,
  287. code: code,
  288. sceneAddress: app.globalData.sceneAddress,
  289. latitude: "" + app.globalData.locationInfo.latitude,
  290. longitude: "" + app.globalData.locationInfo.longitude,
  291. scene: that.data.scene,
  292. systemInfo: that.data.systemInfo
  293. };
  294. }
  295. Http.post({
  296. url: config.api.login,
  297. data: usrdata
  298. })
  299. .then(res => {
  300. that.setData({
  301. showPages: true
  302. })
  303. app.globalData.token = res.data.token;
  304. app.globalData.openId = res.data.openId;
  305. // 初始化websocket
  306. if (extConfig.attr.ifHaveWebSocket == 1) {
  307. app.initSocket();
  308. // 回调发送给自己的消息
  309. app.globalData.socketReceiver = function (e) {
  310. let msgList = that.data.msgList
  311. msgList.push(e)
  312. that.setData({
  313. msgList: msgList
  314. })
  315. }
  316. }
  317. if (res.data && res.data.score) {
  318. if (res.data.score != 0) {
  319. app.globalData.score = res.data.score;
  320. }
  321. }
  322. Http.setToken(res.data.token);
  323. if (options && (options.couponChannelId || options.orderId || options.id)) {
  324. that.checkuserstatus(options);
  325. } else {
  326. that.checkuserstatus();
  327. }
  328. })
  329. .catch(err => {
  330. wx.showModal({
  331. title: '提示',
  332. showCancel: false,
  333. content: '登录失败,请重新尝试',
  334. success: function (res) {
  335. if (res.cancel) {
  336. //点击取消,默认隐藏弹框
  337. } else {
  338. //点击确定
  339. wx.reLaunch({
  340. url: '/pages/index/index',
  341. })
  342. }
  343. }
  344. })
  345. });
  346. }
  347. });
  348. },
  349. getGameOne: function (token, id) {
  350. let _this = this;
  351. Http.get({
  352. url: config.api.getOneGame,
  353. data: {
  354. token: token,
  355. id: id
  356. }
  357. }).then(res => {
  358. wx.redirectTo({
  359. url: '/pages/game/index?url=' + res.data.url + "&id=" + res.data.id + "&gameId=" + res.data.gameId,
  360. })
  361. })
  362. .catch(err => {
  363. this.alphaClick();
  364. })
  365. },
  366. })