C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

345 line
8.1 KiB

  1. var app = getApp();
  2. const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px'
  3. const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
  4. let ifStoreApp = extConfig.attr.ifStoreApp;
  5. const Http = require("../utils/HttpBasics");
  6. const imgurl = require("../utils/imgurl");
  7. var config = require("../config/config.js");
  8. const bgColor = require("../utils/bgColor.js")
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. templateId: [],
  15. aboutShow: false,
  16. navigationBarHeight,
  17. ifStoreApp: ifStoreApp,
  18. aboutUs: imgurl.aboutUs.url,
  19. banneColor: bgColor.colorFirst.user.banneColor,
  20. levelBg: bgColor.colorFirst.user.levelBg,
  21. view: bgColor.colorFirst.user.view,
  22. fenxiang: imgurl.fenxiang1.url,
  23. redirectUrl: imgurl.redirect.url,
  24. editUrl: imgurl.edit.url,
  25. activeUrl: imgurl.active.url,
  26. dingUrl: imgurl.ding.url,
  27. duihuan: imgurl.duihuan.url,
  28. shoppingAtlas: imgurl.shoppingAtlas.url,
  29. quansUrl: imgurl.quans.url,
  30. wmintegral: imgurl.wmintegral.url,
  31. cardiconUrl: imgurl.cardicon.url,
  32. myactivitygift: imgurl.myactivitygift.url,
  33. myactivity: imgurl.myactivity.url,
  34. cheUrl: imgurl.che.url,
  35. giftUrl: imgurl.gift.url,
  36. wmbarginicon: imgurl.wmbarginicon.url,
  37. wmspellgroup: imgurl.wmspellgroup.url,
  38. canIUse: wx.canIUse('official-account'),
  39. mineFlag: "",
  40. flag: 'hidden',
  41. score: '0',
  42. curPhone: '',
  43. name: "",
  44. birthdate: "",
  45. sex: "",
  46. showEdit: false,
  47. ismember: false,
  48. canvasHidden: false,
  49. maskHidden: true,
  50. imagePath: '',
  51. appVersion: "",
  52. placeholder: ''
  53. },
  54. checkUserStatus() {
  55. let that = this;
  56. Http.get({
  57. url: config.api.checkPhoneStatus,
  58. data: {}
  59. }).then(res => {
  60. wx.navigateTo({
  61. url: '/pages/edit/edit',
  62. })
  63. }).catch(err => {
  64. wx.navigateTo({
  65. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  66. })
  67. })
  68. },
  69. gotoPhoneInfo() {
  70. /**
  71. * 将值传到用户手机号授权的页面
  72. *
  73. */
  74. wx.redirectTo({
  75. url: `/pages/getphoneInfo/index?path=main`
  76. });
  77. },
  78. /* 判断是否授权*/
  79. userAuthorization() {
  80. Http.get({
  81. url: config.api.checkUserStatus,
  82. data: {
  83. token: app.globalData.token
  84. }
  85. }).then(res => {
  86. // this.getUserInfo()
  87. }).catch(err => {
  88. wx.navigateTo({
  89. url: `/pages/getuserinfo/index`,
  90. })
  91. })
  92. },
  93. /**
  94. * 跳转到成长值的页面
  95. */
  96. gotograde: function() {
  97. wx.navigateTo({
  98. url: '/pages/czdetail/czdetail',
  99. })
  100. },
  101. /**
  102. * 跳转到商场信息的页面
  103. */
  104. gomallInfo: function() {
  105. wx.navigateTo({
  106. url: '/pages/mallInfo/mallInfo',
  107. })
  108. },
  109. showVersion: function() {
  110. /**
  111. * 长按显示版本号
  112. */
  113. let that = this;
  114. if (that.data.flag == 'hidden') {
  115. that.setData({
  116. flag: 'show'
  117. });
  118. }
  119. },
  120. gotoedit: function() {
  121. this.checkUserStatus();
  122. },
  123. onLoad() {
  124. this.getLocation();
  125. this.updateScene();
  126. // this.getRoomId();
  127. // this.getRoomList();
  128. console.log(wx.getExtConfigSync())
  129. },
  130. //获取房间列表
  131. getRoomList() {
  132. debugger
  133. Http.get({
  134. url: config.api.getRoomList,
  135. data: {
  136. token: app.globalData.token,
  137. appId: config.weapp.AppId
  138. }
  139. }).then(res => {
  140. console.log(res)
  141. })
  142. },
  143. getRoomId() {
  144. let roomId = [3] // 填写具体的房间号,可通过下面【获取直播房间列表】 API 获取
  145. let customParams = encodeURIComponent(JSON.stringify({
  146. path: 'pages/index/index',
  147. pid: 1
  148. })) // 开发者在直播间页面路径上携带自定义参数(如示例中的path和pid参数),后续可以在分享卡片链接和跳转至商详页时获取,详见【获取自定义参数】、【直播间到商详页面携带参数】章节(上限600个字符,超过部分会被截断)
  149. console.log(customParams, 777777777)
  150. this.setData({
  151. roomId,
  152. customParams
  153. })
  154. },
  155. /**
  156. * 获得经纬度
  157. */
  158. getLocation() {
  159. let that = this;
  160. wx.getLocation({
  161. type: "wgs84",
  162. success: function(res) {
  163. console.log(res)
  164. if (res && res.longitude && res.latitude) {
  165. Http.post({
  166. url: config.api.updateLBS,
  167. data: {
  168. latitude: res.latitude,
  169. longitude: res.longitude
  170. }
  171. }).then(res => {
  172. console.log(res)
  173. })
  174. }
  175. },
  176. fail: error => {
  177. console.log(error);
  178. }
  179. })
  180. },
  181. /**
  182. * 用户更新scene
  183. */
  184. updateScene() {
  185. Http.post({
  186. url: config.api.updateScene,
  187. data: {
  188. scene: app.globalData.scene
  189. }
  190. }).then(res => {
  191. console.log(res)
  192. })
  193. },
  194. /**
  195. * 生命周期函数--监听页面显示
  196. */
  197. onShow: function() {
  198. let that = this;
  199. that.userAuthorization()
  200. if (typeof that.getTabBar === 'function' &&
  201. that.getTabBar()) {
  202. if (ifStoreApp == 1) {
  203. that.getTabBar().setData({
  204. selected: 1
  205. })
  206. } else if (ifStoreApp == 2) {
  207. that.getTabBar().setData({
  208. selected: 2
  209. })
  210. } else {
  211. that.getTabBar().setData({
  212. selected: 3
  213. })
  214. }
  215. }
  216. that.setData({
  217. appVersion: extConfig.appVersion,
  218. })
  219. /**
  220. * couponNum
  221. * couponNum2
  222. */
  223. let num = wx.getStorageSync('couponNum');
  224. let num1 = wx.getStorageSync('couponNum2');
  225. wx.hideTabBarRedDot({
  226. index: 3
  227. });
  228. if (num == 'couponNum1') {
  229. wx.setStorage({
  230. key: 'couponNum',
  231. data: "couponNum1",
  232. })
  233. that.setData({
  234. couponNum: "couponNum1"
  235. })
  236. } else if (num == 'couponNum') {
  237. that.setData({
  238. couponNum: "couponNum"
  239. })
  240. };
  241. if (num1 == 'couponNum3') {
  242. wx.setStorage({
  243. key: 'couponNum2',
  244. data: "couponNum3",
  245. })
  246. that.setData({
  247. couponNum2: "couponNum3"
  248. })
  249. } else if (num1 == 'couponNum2') {
  250. that.setData({
  251. couponNum2: "couponNum2"
  252. });
  253. };
  254. Http.get({
  255. url: config.api.getScore,
  256. data: {}
  257. }).then(res => {
  258. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate) {
  259. that.setData({
  260. showEdit: true
  261. })
  262. }
  263. let curPhone = res.data.phone ? res.data.phone : '';
  264. if (curPhone) {
  265. let curPhoneList = curPhone.split('');
  266. let curPhoneList01 = [];
  267. curPhoneList.forEach((item, index) => {
  268. if (index >= 3 && index <= 6) {
  269. item = '*';
  270. }
  271. curPhoneList01.push(item);
  272. })
  273. curPhone = curPhoneList01.join('');
  274. }
  275. that.setData({
  276. score: res.data.score,
  277. curPhone: curPhone,
  278. levelName: res.data.levelName,
  279. })
  280. if (res.data.nickName) {
  281. that.setData({
  282. ismember: true,
  283. memberId: res.data.id
  284. })
  285. var size = this.setCanvasSize();
  286. var initUrl = JSON.stringify({
  287. flagid: res.data.id
  288. });
  289. }
  290. })
  291. .catch(err => {
  292. wx.showModal({
  293. title: '提示',
  294. content: err.errMsg,
  295. showCancel: false
  296. })
  297. })
  298. //暂时注释
  299. // that.getrun();
  300. //查询关于我们
  301. Http.get({
  302. url: config.api.getMallInfo,
  303. data: {}
  304. }).then(res => {
  305. console.log(res)
  306. if (res.data.businessHours !== '[]') {
  307. that.setData({
  308. aboutShow: true
  309. })
  310. } else {
  311. that.setData({
  312. aboutShow: false
  313. })
  314. }
  315. })
  316. .catch(err => {})
  317. },
  318. //适配不同屏幕大小的canvas
  319. setCanvasSize: function() {
  320. var size = {};
  321. try {
  322. var res = wx.getSystemInfoSync();
  323. var scale = 750 / 500;
  324. //不同屏幕下canvas的适配比例;设计稿是750宽
  325. var width = res.windowWidth / scale;
  326. var height = width;
  327. //canvas画布为正方形
  328. size.w = width;
  329. size.h = height;
  330. } catch (e) {
  331. // Do something when catch error
  332. console.log("获取设备信息失败" + e);
  333. }
  334. return size;
  335. },
  336. });