C端小程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

268 lignes
7.3 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. */
  16. onLoad: function(options) {
  17. console.log(options);
  18. let that = this;
  19. /**
  20. * 根据接收到的值,判断跳转到哪个页面
  21. */
  22. if(options&&options.type){
  23. app.globalData.type = options.type;
  24. console.log(app.globalData.type)
  25. }
  26. // app.globalData.type = 'pc';
  27. if (decodeURIComponent(options.scene) == "undefined") {
  28. that.setData({
  29. scene: 0
  30. });
  31. } else {
  32. that.setData({
  33. scene: decodeURIComponent(options.scene)
  34. });
  35. that.setData({
  36. newArr: this.data.scene.split(':')
  37. })
  38. console.log(this.data.newArr)
  39. if (this.data.newArr[0]=='JC'){
  40. /**
  41. * 来自大屏跳转券详情
  42. */
  43. options.couponChannelId = this.data.newArr[1];
  44. }else if (this.data.newArr[0] == 'JG'){
  45. /**
  46. * 来自大屏跳转拼团详情
  47. */
  48. options.couponChannelId = this.data.newArr[1];
  49. options.path='daping'
  50. }
  51. }
  52. wx.showToast({
  53. title: '加载中',
  54. icon: "loading",
  55. duration: 2000
  56. })
  57. wx.setStorageSync('options', JSON.stringify(options))
  58. wx.setStorageSync('imgurl', imgurl)
  59. app.getLocation();
  60. if (options.couponChannelId || options.orderId) {
  61. console.log(options,33333333333)
  62. that.userLogin(options);
  63. } else {
  64. that.userLogin()
  65. }
  66. },
  67. checkuerstatus(options) {
  68. let that = this;
  69. Http.get({
  70. url: config.api.checkUserStatus,
  71. data: {}
  72. })
  73. .then(res => {
  74. if (options && options.orderGroupId) {
  75. wx.redirectTo({
  76. url: `/pages/joinFrDpell/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  77. })
  78. return;
  79. }
  80. /**
  81. * 来自大屏的跳转拼团券详情
  82. */
  83. if (options && options.couponChannelId && options.path== 'daping'){
  84. /**
  85. * 主要是为了拿couponId
  86. */
  87. Http.get({
  88. url: config.api.couponDetail,
  89. data: {
  90. couponChannelId: options.couponChannelId
  91. }
  92. }).then(res => {
  93. let data = res.data;
  94. wx.redirectTo({
  95. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}&couponId=${data.couponId}`
  96. })
  97. });
  98. return;
  99. }
  100. if (options && options.couponChannelId && !options.cuserId &&app.globalData.type == 'cd') {
  101. wx.redirectTo({
  102. url: `/pages/coupon/detail/index?couponChannelId=${options.couponChannelId}`,
  103. })
  104. } else if (options &&options.couponChannelId && options.cuserId){
  105. /**
  106. * 转赠判断
  107. */
  108. wx.redirectTo({
  109. 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}`,
  110. })
  111. } else if (options&&options.orderId&&app.globalData.type=='bg') {
  112. wx.redirectTo({
  113. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${options.orderId}&from='${"discount"}`,
  114. })
  115. } else if (app.globalData.type == 'uc'){
  116. wx.switchTab({
  117. url: '/pages/user/index'
  118. });
  119. } else if (app.globalData.type == 'pc') {
  120. wx.switchTab({
  121. url: '/pages/passCar/passCar'
  122. });
  123. } else if (app.globalData.type == 'co') {
  124. wx.redirectTo({
  125. url: '/pages/couponorder/index/index'
  126. });
  127. } else if (app.globalData.type == 'or') {
  128. wx.redirectTo({
  129. url: '/pages/couponorder/index/index'
  130. });
  131. } else if (app.globalData.type == 'sc') {
  132. wx.redirectTo({
  133. url: '/pages/specialcourtesy/specialcourtesy'
  134. });
  135. }else if (app.globalData.type == 'rb') {
  136. wx.redirectTo({
  137. url: '/pages/rushToBuy/index'
  138. });
  139. }else{
  140. wx.switchTab({
  141. url: '/pages/main/index'
  142. });
  143. }
  144. })
  145. .catch(err => {
  146. if (err.code == 11004) {
  147. // 用户昵称未授权
  148. if (options && options.orderGroupId) {
  149. wx.redirectTo({
  150. url: `/pages/getuserinfo/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  151. })
  152. return;
  153. }
  154. if (options && options.couponChannelId && !options.cuserId) {
  155. wx.redirectTo({
  156. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}`
  157. });
  158. } else if (options &&options.couponChannelId && options.cuserId){
  159. /**
  160. * 转赠判断
  161. */
  162. wx.redirectTo({
  163. 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}`
  164. });
  165. } else if (options && options.orderId) {
  166. wx.redirectTo({
  167. url: `/pages/getuserinfo/index?orderId=${options.orderId}&from='${"discount"}`
  168. });
  169. } else {
  170. wx.redirectTo({
  171. url: `/pages/getuserinfo/index`
  172. });
  173. }
  174. }
  175. });
  176. },
  177. /**
  178. * 用户登录
  179. */
  180. userLogin: function (options) {
  181. console.log(1111,options,2222222222)
  182. var that = this;
  183. // 登录
  184. wx.login({
  185. success: ({
  186. code
  187. }) => {
  188. wx.getSystemInfo({
  189. success: function(res) {
  190. that.setData({
  191. systemInfo: JSON.stringify(res)
  192. })
  193. }
  194. })
  195. var usrdata = {
  196. appId: config.weapp.AppId,
  197. code: code,
  198. sceneAddress: app.globalData.sceneAddress,
  199. scene: that.data.scene,
  200. systemInfo: that.data.systemInfo
  201. };
  202. if (app.globalData.locationInfo) {
  203. usrdata = {
  204. appId: config.weapp.AppId,
  205. code: code,
  206. sceneAddress: app.globalData.sceneAddress,
  207. latitude: "" + app.globalData.locationInfo.latitude,
  208. longitude: "" + app.globalData.locationInfo.longitude,
  209. scene: that.data.scene,
  210. systemInfo: that.data.systemInfo
  211. };
  212. }
  213. Http.post({
  214. url: config.api.login,
  215. data: usrdata
  216. })
  217. .then(res => {
  218. that.setData({
  219. showPages: true
  220. })
  221. app.globalData.token = res.data.token;
  222. app.globalData.openId = res.data.openId;
  223. // 初始化websocket
  224. if (extConfig.attr.ifHaveWebSocket == 1) {
  225. app.initSocket();
  226. // 回调发送给自己的消息
  227. app.globalData.socketReceiver = function (e) {
  228. let msgList = that.data.msgList
  229. msgList.push(e)
  230. that.setData({
  231. msgList: msgList
  232. })
  233. }
  234. }
  235. if (res.data && res.data.score) {
  236. if (res.data.score != 0){
  237. app.globalData.score=res.data.score;
  238. }
  239. }
  240. Http.setToken(res.data.token);
  241. if (options&&(options.couponChannelId || options.orderId)){
  242. that.checkuerstatus(options);
  243. }else{
  244. that.checkuerstatus();
  245. }
  246. })
  247. .catch(err => {
  248. wx.showModal({
  249. title: '提示',
  250. showCancel: false,
  251. content: '登录失败,请重新尝试',
  252. success:function(res){
  253. if (res.cancel) {
  254. //点击取消,默认隐藏弹框
  255. } else {
  256. //点击确定
  257. wx.reLaunch({
  258. url: '/pages/index/index',
  259. })
  260. }
  261. }
  262. })
  263. });
  264. }
  265. });
  266. },
  267. })