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.

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