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.

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