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.

237 lines
5.4 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. navigationBarHeight,
  15. ifStoreApp:ifStoreApp,
  16. banneColor: bgColor.colorFirst.user.banneColor,
  17. levelBg: bgColor.colorFirst.user.levelBg,
  18. view: bgColor.colorFirst.user.view,
  19. redirectUrl: imgurl.redirect.url,
  20. editUrl: imgurl.edit.url,
  21. activeUrl: imgurl.active.url,
  22. dingUrl: imgurl.ding.url,
  23. quansUrl: imgurl.quans.url,
  24. wmintegral: imgurl.wmintegral.url,
  25. cardiconUrl: imgurl.cardicon.url,
  26. myactivitygift: imgurl.myactivitygift.url,
  27. myactivity: imgurl.myactivity.url,
  28. cheUrl: imgurl.che.url,
  29. giftUrl: imgurl.gift.url,
  30. wmbarginicon: imgurl.wmbarginicon.url,
  31. wmspellgroup: imgurl.wmspellgroup.url,
  32. canIUse: wx.canIUse('official-account'),
  33. mineFlag:"",
  34. flag: 'hidden',
  35. score: '0',
  36. name: "",
  37. birthdate: "",
  38. sex: "",
  39. showEdit: false,
  40. ismember: false,
  41. canvasHidden: false,
  42. maskHidden: true,
  43. imagePath: '',
  44. appVersion: "",
  45. placeholder: ''
  46. },
  47. checkUserStatus() {
  48. let that = this;
  49. Http.get({
  50. url: config.api.checkPhoneStatus,
  51. data: {}
  52. }).then(res => {
  53. }).catch(err => {
  54. wx.navigateTo({
  55. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  56. })
  57. })
  58. },
  59. /**
  60. * 跳转到成长值的页面
  61. */
  62. gotograde: function() {
  63. wx.navigateTo({
  64. url: '/pages/czdetail/czdetail',
  65. })
  66. },
  67. showVersion: function() {
  68. /**
  69. * 长按显示版本号
  70. */
  71. let that = this;
  72. if (that.data.flag == 'hidden') {
  73. that.setData({
  74. flag: 'show'
  75. });
  76. }
  77. },
  78. gotoedit: function() {
  79. wx.navigateTo({
  80. url: '/pages/edit/edit',
  81. })
  82. },
  83. onLoad() {
  84. this.getLocation();
  85. this.updateScene();
  86. },
  87. /**
  88. * 获得经纬度
  89. */
  90. getLocation() {
  91. let that = this;
  92. wx.getLocation({
  93. type: "wgs84",
  94. success: function(res) {
  95. console.log(res)
  96. if (res && res.longitude && res.latitude) {
  97. Http.post({
  98. url: config.api.updateLBS,
  99. data: {
  100. latitude: res.latitude,
  101. longitude: res.longitude
  102. }
  103. }).then(res => {
  104. console.log(res)
  105. })
  106. }
  107. },
  108. fail: error => {
  109. console.log(error);
  110. }
  111. })
  112. },
  113. /**
  114. * 用户更新scene
  115. */
  116. updateScene(){
  117. Http.post({
  118. url: config.api.updateScene,
  119. data: {
  120. scene: app.globalData.scene
  121. }
  122. }).then(res => {
  123. console.log(res)
  124. })
  125. },
  126. /**
  127. * 生命周期函数--监听页面显示
  128. */
  129. onShow: function() {
  130. let that = this;
  131. if (typeof that.getTabBar === 'function' &&
  132. that.getTabBar()) {
  133. if (ifStoreApp==1){
  134. that.getTabBar().setData({
  135. selected: 1
  136. })
  137. }else{
  138. that.getTabBar().setData({
  139. selected: 3
  140. })
  141. }
  142. }
  143. that.checkUserStatus();
  144. that.setData({
  145. appVersion: extConfig.appVersion,
  146. })
  147. /**
  148. * couponNum
  149. * couponNum2
  150. */
  151. let num = wx.getStorageSync('couponNum');
  152. let num1 = wx.getStorageSync('couponNum2');
  153. wx.hideTabBarRedDot({
  154. index: 3
  155. });
  156. if (num == 'couponNum1') {
  157. wx.setStorage({
  158. key: 'couponNum',
  159. data: "couponNum1",
  160. })
  161. that.setData({
  162. couponNum: "couponNum1"
  163. })
  164. } else if (num == 'couponNum') {
  165. that.setData({
  166. couponNum: "couponNum"
  167. })
  168. };
  169. if (num1 == 'couponNum3') {
  170. wx.setStorage({
  171. key: 'couponNum2',
  172. data: "couponNum3",
  173. })
  174. that.setData({
  175. couponNum2: "couponNum3"
  176. })
  177. } else if (num1 == 'couponNum2') {
  178. that.setData({
  179. couponNum2: "couponNum2"
  180. });
  181. };
  182. Http.get({
  183. url: config.api.getScore,
  184. data: {}
  185. }).then(res => {
  186. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate) {
  187. that.setData({
  188. showEdit: true
  189. })
  190. }
  191. that.setData({
  192. score: res.data.score,
  193. levelName: res.data.levelName,
  194. })
  195. if (res.data.nickName) {
  196. that.setData({
  197. ismember: true,
  198. memberId: res.data.id
  199. })
  200. var size = this.setCanvasSize();
  201. var initUrl = JSON.stringify({
  202. flagid: res.data.id
  203. });
  204. }
  205. })
  206. .catch(err => {
  207. wx.showModal({
  208. title: '提示',
  209. content: err.errMsg,
  210. showCancel: false
  211. })
  212. })
  213. //暂时注释
  214. // that.getrun();
  215. },
  216. //适配不同屏幕大小的canvas
  217. setCanvasSize: function() {
  218. var size = {};
  219. try {
  220. var res = wx.getSystemInfoSync();
  221. var scale = 750 / 500;
  222. //不同屏幕下canvas的适配比例;设计稿是750宽
  223. var width = res.windowWidth / scale;
  224. var height = width;
  225. //canvas画布为正方形
  226. size.w = width;
  227. size.h = height;
  228. } catch (e) {
  229. // Do something when catch error
  230. console.log("获取设备信息失败" + e);
  231. }
  232. return size;
  233. }
  234. });