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.

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