C端小程序
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

235 rader
7.5 KiB

  1. const Http = require("../../utils/HttpBasics");
  2. const imgurl = require("../../utils/imgurl");
  3. const config = require("../../config/config");
  4. const QR = require("../../utils/memberqrcode.js");
  5. let app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function(options) {
  16. console.log(options,10001)
  17. let that = this;
  18. if (decodeURIComponent(options.scene) == "undefined") {
  19. that.setData({
  20. scene: 0
  21. });
  22. } else {
  23. that.setData({
  24. scene: decodeURIComponent(options.scene)
  25. });
  26. that.setData({
  27. newArr: this.data.scene.split(':')
  28. })
  29. console.log(this.data.newArr)
  30. if (this.data.newArr[0]=='JC'){
  31. /**
  32. * 来自大屏跳转券详情
  33. */
  34. options.couponChannelId = this.data.newArr[1];
  35. }else if (this.data.newArr[0] == 'JG'){
  36. /**
  37. * 来自大屏跳转拼团详情
  38. */
  39. options.couponChannelId = this.data.newArr[1];
  40. options.path='daping'
  41. }
  42. }
  43. console.log(options.couponChannelId)
  44. wx.showToast({
  45. title: '加载中',
  46. icon: "loading",
  47. duration: 2000
  48. })
  49. wx.setStorageSync('options', JSON.stringify(options))
  50. wx.setStorageSync('imgurl', imgurl)
  51. app.getLocation();
  52. if (options.couponChannelId || options.orderId) {
  53. console.log(options,33333333333)
  54. that.userLogin(options);
  55. } else {
  56. that.userLogin()
  57. }
  58. },
  59. checkuerstatus(options) {
  60. let that = this;
  61. Http.get({
  62. url: config.api.checkUserStatus,
  63. data: {}
  64. })
  65. .then(res => {
  66. if (options && options.orderGroupId) {
  67. wx.redirectTo({
  68. url: `/pages/joinFrDpell/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  69. })
  70. return;
  71. }
  72. /**
  73. * 来自大屏的跳转拼团券详情
  74. */
  75. if (options && options.couponChannelId && options.path== 'daping'){
  76. /**
  77. * 主要是为了拿couponId
  78. */
  79. Http.get({
  80. url: config.api.couponDetail,
  81. data: {
  82. couponChannelId: options.couponChannelId
  83. }
  84. }).then(res => {
  85. let data = res.data;
  86. wx.redirectTo({
  87. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}&couponId=${data.couponId}`
  88. })
  89. });
  90. return;
  91. }
  92. if (options&&options.couponChannelId && !options.cuserId) {
  93. wx.redirectTo({
  94. url: `/pages/coupon/detail/index?couponChannelId=${options.couponChannelId}`,
  95. })
  96. } else if (options &&options.couponChannelId && options.cuserId){
  97. /**
  98. * 转赠判断
  99. */
  100. wx.redirectTo({
  101. 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}`,
  102. })
  103. } else if (options &&options.orderId) {
  104. wx.redirectTo({
  105. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${options.orderId}&from='${"discount"}`,
  106. })
  107. }else{
  108. wx.switchTab({
  109. url: '/pages/main/index'
  110. });
  111. }
  112. })
  113. .catch(err => {
  114. if (err.code == 11004) {
  115. // 用户昵称未授权
  116. if (options && options.orderGroupId) {
  117. wx.redirectTo({
  118. url: `/pages/getuserinfo/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  119. })
  120. return;
  121. }
  122. if (options && options.couponChannelId && !options.cuserId) {
  123. wx.redirectTo({
  124. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}`
  125. });
  126. } else if (options &&options.couponChannelId && options.cuserId){
  127. /**
  128. * 转赠判断
  129. */
  130. wx.redirectTo({
  131. 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}`
  132. });
  133. } else if (options && options.orderId) {
  134. wx.redirectTo({
  135. url: `/pages/getuserinfo/index?orderId=${options.orderId}&from='${"discount"}`
  136. });
  137. } else {
  138. wx.redirectTo({
  139. url: `/pages/getuserinfo/index`
  140. });
  141. }
  142. }
  143. });
  144. },
  145. /**
  146. * 用户登录
  147. */
  148. userLogin: function (options) {
  149. console.log(1111,options,2222222222)
  150. var that = this;
  151. // 获取系统信息
  152. wx.getSystemInfo({
  153. success: function (res) {
  154. var name = res.model
  155. // 检测是否为iphonex xs xr
  156. // if (name.indexOf("iPhone X") > -1) {
  157. // that.globalData.isIpx = true
  158. //}
  159. that.setData({
  160. systemInfo: JSON.stringify(res)
  161. })
  162. }
  163. })
  164. // 登录
  165. wx.login({
  166. success: ({
  167. code
  168. }) => {
  169. var usrdata = {
  170. appId: config.weapp.AppId,
  171. code: code,
  172. sceneAddress: app.globalData.sceneAddress,
  173. scene: that.data.scene,
  174. systemInfo: that.data.systemInfo
  175. };
  176. if (app.globalData.locationInfo) {
  177. usrdata = {
  178. appId: config.weapp.AppId,
  179. code: code,
  180. sceneAddress: app.globalData.sceneAddress,
  181. latitude: "" + app.globalData.locationInfo.latitude,
  182. longitude: "" + app.globalData.locationInfo.longitude,
  183. scene: that.data.scene,
  184. systemInfo: that.data.systemInfo
  185. };
  186. }
  187. Http.post({
  188. url: config.api.login,
  189. data: usrdata
  190. })
  191. .then(res => {
  192. that.setData({
  193. showPages: true
  194. })
  195. console.log(res)
  196. app.globalData.token = res.data.token;
  197. app.globalData.openId = res.data.openId;
  198. // 初始化websocket
  199. app.initSocket();
  200. // 回调发送给自己的消息
  201. app.globalData.socketReceiver = function(e) {
  202. let msgList = that.data.msgList
  203. msgList.push(e)
  204. that.setData({
  205. msgList: msgList
  206. })
  207. }
  208. Http.setToken(res.data.token);
  209. if (options&&(options.couponChannelId || options.orderId)){
  210. that.checkuerstatus(options);
  211. }else{
  212. that.checkuerstatus();
  213. }
  214. })
  215. .catch(err => {
  216. wx.showModal({
  217. title: '提示',
  218. showCancel: false,
  219. content: '登录失败,请重新尝试',
  220. success:function(res){
  221. if (res.cancel) {
  222. //点击取消,默认隐藏弹框
  223. } else {
  224. //点击确定
  225. wx.reLaunch({
  226. url: '/pages/index/index',
  227. })
  228. }
  229. }
  230. })
  231. });
  232. }
  233. });
  234. },
  235. })