C端小程序
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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