C端小程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

321 líneas
9.1 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. * 跳转到成长值的页面
  77. */
  78. gotograde: function () {
  79. wx.navigateTo({
  80. url: '/pages/czdetail/czdetail',
  81. })
  82. },
  83. /**
  84. * 跳转到商场信息的页面
  85. */
  86. gomallInfo: function () {
  87. wx.navigateTo({
  88. url: '/pages/mallInfo/mallInfo',
  89. })
  90. },
  91. showVersion: function () {
  92. /**
  93. * 长按显示版本号
  94. */
  95. let that = this;
  96. if (that.data.flag == 'hidden') {
  97. that.setData({
  98. flag: 'show'
  99. });
  100. }
  101. },
  102. gotoedit: function () {
  103. this.checkUserStatus();
  104. },
  105. onLoad() {
  106. this.getLocation();
  107. this.updateScene();
  108. // this.getRoomId();
  109. // this.getRoomList();
  110. console.log(wx.getExtConfigSync())
  111. },
  112. //获取房间列表
  113. getRoomList(){
  114. debugger
  115. Http.get({
  116. url: config.api.getRoomList,
  117. data: {
  118. token: app.globalData.token,
  119. appId:config.weapp.AppId
  120. }
  121. }).then(res => {
  122. console.log(res)
  123. })
  124. },
  125. getRoomId() {
  126. let roomId = [3] // 填写具体的房间号,可通过下面【获取直播房间列表】 API 获取
  127. let customParams = encodeURIComponent(JSON.stringify({ path: 'pages/index/index', pid: 1 })) // 开发者在直播间页面路径上携带自定义参数(如示例中的path和pid参数),后续可以在分享卡片链接和跳转至商详页时获取,详见【获取自定义参数】、【直播间到商详页面携带参数】章节(上限600个字符,超过部分会被截断)
  128. console.log(customParams,777777777)
  129. this.setData({
  130. roomId,
  131. customParams
  132. })
  133. },
  134. /**
  135. * 获得经纬度
  136. */
  137. getLocation() {
  138. let that = this;
  139. wx.getLocation({
  140. type: "wgs84",
  141. success: function (res) {
  142. console.log(res)
  143. if (res && res.longitude && res.latitude) {
  144. Http.post({
  145. url: config.api.updateLBS,
  146. data: {
  147. latitude: res.latitude,
  148. longitude: res.longitude
  149. }
  150. }).then(res => {
  151. console.log(res)
  152. })
  153. }
  154. },
  155. fail: error => {
  156. console.log(error);
  157. }
  158. })
  159. },
  160. /**
  161. * 用户更新scene
  162. */
  163. updateScene() {
  164. Http.post({
  165. url: config.api.updateScene,
  166. data: {
  167. scene: app.globalData.scene
  168. }
  169. }).then(res => {
  170. console.log(res)
  171. })
  172. },
  173. /**
  174. * 生命周期函数--监听页面显示
  175. */
  176. onShow: function () {
  177. let that = this;
  178. if (typeof that.getTabBar === 'function' &&
  179. that.getTabBar()) {
  180. if (ifStoreApp == 1) {
  181. that.getTabBar().setData({
  182. selected: 1
  183. })
  184. } else if (ifStoreApp == 2) {
  185. that.getTabBar().setData({
  186. selected: 2
  187. })
  188. } else {
  189. that.getTabBar().setData({
  190. selected: 3
  191. })
  192. }
  193. }
  194. that.setData({
  195. appVersion: extConfig.appVersion,
  196. })
  197. /**
  198. * couponNum
  199. * couponNum2
  200. */
  201. let num = wx.getStorageSync('couponNum');
  202. let num1 = wx.getStorageSync('couponNum2');
  203. wx.hideTabBarRedDot({
  204. index: 3
  205. });
  206. if (num == 'couponNum1') {
  207. wx.setStorage({
  208. key: 'couponNum',
  209. data: "couponNum1",
  210. })
  211. that.setData({
  212. couponNum: "couponNum1"
  213. })
  214. } else if (num == 'couponNum') {
  215. that.setData({
  216. couponNum: "couponNum"
  217. })
  218. };
  219. if (num1 == 'couponNum3') {
  220. wx.setStorage({
  221. key: 'couponNum2',
  222. data: "couponNum3",
  223. })
  224. that.setData({
  225. couponNum2: "couponNum3"
  226. })
  227. } else if (num1 == 'couponNum2') {
  228. that.setData({
  229. couponNum2: "couponNum2"
  230. });
  231. };
  232. Http.get({
  233. url: config.api.getScore,
  234. data: {}
  235. }).then(res => {
  236. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate) {
  237. that.setData({
  238. showEdit: true
  239. })
  240. }
  241. let curPhone = res.data.phone?res.data.phone:'';
  242. if (curPhone) {
  243. let curPhoneList = curPhone.split('');
  244. let curPhoneList01 = [];
  245. curPhoneList.forEach((item,index) => {
  246. if (index>=3 && index<=6) {
  247. item = '*';
  248. }
  249. curPhoneList01.push(item);
  250. })
  251. curPhone = curPhoneList01.join('');
  252. }
  253. that.setData({
  254. score: res.data.score,
  255. curPhone: curPhone,
  256. levelName: res.data.levelName,
  257. })
  258. if (res.data.nickName) {
  259. that.setData({
  260. ismember: true,
  261. memberId: res.data.id
  262. })
  263. var size = this.setCanvasSize();
  264. var initUrl = JSON.stringify({
  265. flagid: res.data.id
  266. });
  267. }
  268. })
  269. .catch(err => {
  270. wx.showModal({
  271. title: '提示',
  272. content: err.errMsg,
  273. showCancel: false
  274. })
  275. })
  276. //暂时注释
  277. // that.getrun();
  278. //查询关于我们
  279. Http.get({
  280. url: config.api.getMallInfo,
  281. data: {}
  282. }).then(res => {
  283. console.log(res)
  284. if (res.data.businessHours !== '[]') {
  285. that.setData({
  286. aboutShow: true
  287. })
  288. } else {
  289. that.setData({
  290. aboutShow: false
  291. })
  292. }
  293. })
  294. .catch(err => {
  295. })
  296. },
  297. //适配不同屏幕大小的canvas
  298. setCanvasSize: function () {
  299. var size = {};
  300. try {
  301. var res = wx.getSystemInfoSync();
  302. var scale = 750 / 500;
  303. //不同屏幕下canvas的适配比例;设计稿是750宽
  304. var width = res.windowWidth / scale;
  305. var height = width;
  306. //canvas画布为正方形
  307. size.w = width;
  308. size.h = height;
  309. } catch (e) {
  310. // Do something when catch error
  311. console.log("获取设备信息失败" + e);
  312. }
  313. return size;
  314. },
  315. });