C端小程序
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

242 рядки
5.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. 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. showVersion: function() {
  72. /**
  73. * 长按显示版本号
  74. */
  75. let that = this;
  76. if (that.data.flag == 'hidden') {
  77. that.setData({
  78. flag: 'show'
  79. });
  80. }
  81. },
  82. gotoedit: function() {
  83. this.checkUserStatus();
  84. },
  85. onLoad() {
  86. this.getLocation();
  87. this.updateScene();
  88. },
  89. /**
  90. * 获得经纬度
  91. */
  92. getLocation() {
  93. let that = this;
  94. wx.getLocation({
  95. type: "wgs84",
  96. success: function(res) {
  97. console.log(res)
  98. if (res && res.longitude && res.latitude) {
  99. Http.post({
  100. url: config.api.updateLBS,
  101. data: {
  102. latitude: res.latitude,
  103. longitude: res.longitude
  104. }
  105. }).then(res => {
  106. console.log(res)
  107. })
  108. }
  109. },
  110. fail: error => {
  111. console.log(error);
  112. }
  113. })
  114. },
  115. /**
  116. * 用户更新scene
  117. */
  118. updateScene(){
  119. Http.post({
  120. url: config.api.updateScene,
  121. data: {
  122. scene: app.globalData.scene
  123. }
  124. }).then(res => {
  125. console.log(res)
  126. })
  127. },
  128. /**
  129. * 生命周期函数--监听页面显示
  130. */
  131. onShow: function() {
  132. let that = this;
  133. if (typeof that.getTabBar === 'function' &&
  134. that.getTabBar()) {
  135. if (ifStoreApp==1){
  136. that.getTabBar().setData({
  137. selected: 1
  138. })
  139. } else if(ifStoreApp == 2){
  140. that.getTabBar().setData({
  141. selected: 2
  142. })
  143. }else{
  144. that.getTabBar().setData({
  145. selected: 3
  146. })
  147. }
  148. }
  149. that.setData({
  150. appVersion: extConfig.appVersion,
  151. })
  152. /**
  153. * couponNum
  154. * couponNum2
  155. */
  156. let num = wx.getStorageSync('couponNum');
  157. let num1 = wx.getStorageSync('couponNum2');
  158. wx.hideTabBarRedDot({
  159. index: 3
  160. });
  161. if (num == 'couponNum1') {
  162. wx.setStorage({
  163. key: 'couponNum',
  164. data: "couponNum1",
  165. })
  166. that.setData({
  167. couponNum: "couponNum1"
  168. })
  169. } else if (num == 'couponNum') {
  170. that.setData({
  171. couponNum: "couponNum"
  172. })
  173. };
  174. if (num1 == 'couponNum3') {
  175. wx.setStorage({
  176. key: 'couponNum2',
  177. data: "couponNum3",
  178. })
  179. that.setData({
  180. couponNum2: "couponNum3"
  181. })
  182. } else if (num1 == 'couponNum2') {
  183. that.setData({
  184. couponNum2: "couponNum2"
  185. });
  186. };
  187. Http.get({
  188. url: config.api.getScore,
  189. data: {}
  190. }).then(res => {
  191. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate) {
  192. that.setData({
  193. showEdit: true
  194. })
  195. }
  196. that.setData({
  197. score: res.data.score,
  198. levelName: res.data.levelName,
  199. })
  200. if (res.data.nickName) {
  201. that.setData({
  202. ismember: true,
  203. memberId: res.data.id
  204. })
  205. var size = this.setCanvasSize();
  206. var initUrl = JSON.stringify({
  207. flagid: res.data.id
  208. });
  209. }
  210. })
  211. .catch(err => {
  212. wx.showModal({
  213. title: '提示',
  214. content: err.errMsg,
  215. showCancel: false
  216. })
  217. })
  218. //暂时注释
  219. // that.getrun();
  220. },
  221. //适配不同屏幕大小的canvas
  222. setCanvasSize: function() {
  223. var size = {};
  224. try {
  225. var res = wx.getSystemInfoSync();
  226. var scale = 750 / 500;
  227. //不同屏幕下canvas的适配比例;设计稿是750宽
  228. var width = res.windowWidth / scale;
  229. var height = width;
  230. //canvas画布为正方形
  231. size.w = width;
  232. size.h = height;
  233. } catch (e) {
  234. // Do something when catch error
  235. console.log("获取设备信息失败" + e);
  236. }
  237. return size;
  238. }
  239. });