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.

368 lines
8.6 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. templateId: [],
  15. aboutShow: false,
  16. navigationBarHeight,
  17. ifStoreApp: ifStoreApp,
  18. aboutUs: imgurl.aboutUs.url,
  19. rqCode: imgurl.barcode.url,
  20. banneColor: bgColor.colorFirst.user.banneColor,
  21. levelBg: bgColor.colorFirst.user.levelBg,
  22. view: bgColor.colorFirst.user.view,
  23. fenxiang: imgurl.fenxiang1.url,
  24. redirectUrl: imgurl.redirect.url,
  25. editUrl: imgurl.edit.url,
  26. activeUrl: imgurl.active.url,
  27. dingUrl: imgurl.ding.url,
  28. duihuan: imgurl.duihuan.url,
  29. shoppingAtlas: imgurl.shoppingAtlas.url,
  30. quansUrl: imgurl.quans.url,
  31. wmintegral: imgurl.wmintegral.url,
  32. cardiconUrl: imgurl.cardicon.url,
  33. myactivitygift: imgurl.myactivitygift.url,
  34. myactivity: imgurl.myactivity.url,
  35. cheUrl: imgurl.che.url,
  36. giftUrl: imgurl.gift.url,
  37. wmbarginicon: imgurl.wmbarginicon.url,
  38. wmspellgroup: imgurl.wmspellgroup.url,
  39. canIUse: wx.canIUse('official-account'),
  40. mineFlag: "",
  41. flag: 'hidden',
  42. score: '0',
  43. userId:"",
  44. memberName:"",
  45. memberLogo:"",
  46. curPhone: '',
  47. name: "",
  48. birthdate: "",
  49. sex: "",
  50. showEdit: false,
  51. ismember: false,
  52. canvasHidden: false,
  53. maskHidden: true,
  54. imagePath: '',
  55. appVersion: "",
  56. placeholder: ''
  57. },
  58. checkUserStatus() {
  59. let that = this;
  60. Http.get({
  61. url: config.api.checkPhoneStatus,
  62. data: {}
  63. }).then(res => {
  64. wx.navigateTo({
  65. url: '/pages/edit/edit',
  66. })
  67. }).catch(err => {
  68. wx.navigateTo({
  69. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  70. })
  71. })
  72. },
  73. gotoPhoneInfo() {
  74. /**
  75. * 将值传到用户手机号授权的页面
  76. *
  77. */
  78. wx.navigateTo({
  79. url: `/pages/getphoneInfo/index?path=main`
  80. });
  81. },
  82. //是否授权手机号
  83. ifPhoneInfo() {
  84. let that = this;
  85. Http.get({
  86. url: config.api.checkPhoneStatus,
  87. data: {}
  88. }).then(res => {
  89. return
  90. }).catch(err => {
  91. wx.navigateTo({
  92. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  93. })
  94. })
  95. },
  96. /* 判断是否授权*/
  97. userAuthorization() {
  98. Http.get({
  99. url: config.api.checkUserStatus,
  100. data: {
  101. token: app.globalData.token
  102. }
  103. }).then(res => {
  104. this.ifPhoneInfo()
  105. }).catch(err => {
  106. wx.navigateTo({
  107. url: `/pages/getuserinfo/index`,
  108. })
  109. })
  110. },
  111. /**
  112. * 跳转到成长值的页面
  113. */
  114. gotograde: function() {
  115. wx.navigateTo({
  116. url: '/pages/czdetail/czdetail',
  117. })
  118. },
  119. /**
  120. * 跳转到商场信息的页面
  121. */
  122. gomallInfo: function() {
  123. wx.navigateTo({
  124. url: '/pages/mallInfo/mallInfo',
  125. })
  126. },
  127. showVersion: function() {
  128. /**
  129. * 长按显示版本号
  130. */
  131. let that = this;
  132. if (that.data.flag == 'hidden') {
  133. that.setData({
  134. flag: 'show'
  135. });
  136. }
  137. },
  138. gotoedit: function() {
  139. this.checkUserStatus();
  140. },
  141. onLoad() {
  142. this.getLocation();
  143. this.updateScene();
  144. // this.getRoomId();
  145. // this.getRoomList();
  146. console.log(wx.getExtConfigSync())
  147. },
  148. //获取房间列表
  149. getRoomList() {
  150. debugger
  151. Http.get({
  152. url: config.api.getRoomList,
  153. data: {
  154. token: app.globalData.token,
  155. appId: config.weapp.AppId
  156. }
  157. }).then(res => {
  158. console.log(res)
  159. })
  160. },
  161. getRoomId() {
  162. let roomId = [3] // 填写具体的房间号,可通过下面【获取直播房间列表】 API 获取
  163. let customParams = encodeURIComponent(JSON.stringify({
  164. path: 'pages/index/index',
  165. pid: 1
  166. })) // 开发者在直播间页面路径上携带自定义参数(如示例中的path和pid参数),后续可以在分享卡片链接和跳转至商详页时获取,详见【获取自定义参数】、【直播间到商详页面携带参数】章节(上限600个字符,超过部分会被截断)
  167. console.log(customParams, 777777777)
  168. this.setData({
  169. roomId,
  170. customParams
  171. })
  172. },
  173. /**
  174. * 获得经纬度
  175. */
  176. getLocation() {
  177. let that = this;
  178. wx.getLocation({
  179. type: "wgs84",
  180. success: function(res) {
  181. console.log(res)
  182. if (res && res.longitude && res.latitude) {
  183. Http.post({
  184. url: config.api.updateLBS,
  185. data: {
  186. latitude: res.latitude,
  187. longitude: res.longitude
  188. }
  189. }).then(res => {
  190. console.log(res)
  191. })
  192. }
  193. },
  194. fail: error => {
  195. console.log(error);
  196. }
  197. })
  198. },
  199. /**
  200. * 用户更新scene
  201. */
  202. updateScene() {
  203. Http.post({
  204. url: config.api.updateScene,
  205. data: {
  206. scene: app.globalData.scene
  207. }
  208. }).then(res => {
  209. console.log(res)
  210. })
  211. },
  212. /**
  213. * 生命周期函数--监听页面显示
  214. */
  215. onShow: function() {
  216. let that = this;
  217. that.userAuthorization()
  218. if (typeof that.getTabBar === 'function' &&
  219. that.getTabBar()) {
  220. if (ifStoreApp == 1) {
  221. that.getTabBar().setData({
  222. selected: 1
  223. })
  224. } else if (ifStoreApp == 2) {
  225. that.getTabBar().setData({
  226. selected: 2
  227. })
  228. } else {
  229. that.getTabBar().setData({
  230. selected: 3,
  231. })
  232. }
  233. }
  234. that.setData({
  235. appVersion: extConfig.appVersion,
  236. })
  237. /**
  238. * couponNum
  239. * couponNum2
  240. */
  241. let num = wx.getStorageSync('couponNum');
  242. let num1 = wx.getStorageSync('couponNum2');
  243. wx.hideTabBarRedDot({
  244. index: 3
  245. });
  246. if (num == 'couponNum1') {
  247. wx.setStorage({
  248. key: 'couponNum',
  249. data: "couponNum1",
  250. })
  251. that.setData({
  252. couponNum: "couponNum1"
  253. })
  254. } else if (num == 'couponNum') {
  255. that.setData({
  256. couponNum: "couponNum"
  257. })
  258. };
  259. if (num1 == 'couponNum3') {
  260. wx.setStorage({
  261. key: 'couponNum2',
  262. data: "couponNum3",
  263. })
  264. that.setData({
  265. couponNum2: "couponNum3"
  266. })
  267. } else if (num1 == 'couponNum2') {
  268. that.setData({
  269. couponNum2: "couponNum2"
  270. });
  271. };
  272. Http.get({
  273. url: config.api.getScore,
  274. data: {}
  275. }).then(res => {
  276. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate) {
  277. that.setData({
  278. showEdit: true
  279. })
  280. }
  281. let curPhone = res.data.phone ? res.data.phone : '';
  282. if (curPhone) {
  283. let curPhoneList = curPhone.split('');
  284. let curPhoneList01 = [];
  285. curPhoneList.forEach((item, index) => {
  286. if (index >= 3 && index <= 6) {
  287. item = '*';
  288. }
  289. curPhoneList01.push(item);
  290. })
  291. curPhone = curPhoneList01.join('');
  292. }
  293. that.setData({
  294. score: res.data.score,
  295. curPhone: curPhone,
  296. levelName: res.data.levelName,
  297. userId: res.data.userId
  298. })
  299. if (res.data.nickName) {
  300. that.setData({
  301. ismember: true,
  302. memberId: res.data.id
  303. })
  304. var size = this.setCanvasSize();
  305. var initUrl = JSON.stringify({
  306. flagid: res.data.id
  307. });
  308. }
  309. })
  310. .catch(err => {
  311. wx.showModal({
  312. title: '提示',
  313. content: err.errMsg,
  314. showCancel: false
  315. })
  316. })
  317. //暂时注释
  318. // that.getrun();
  319. //查询关于我们
  320. Http.get({
  321. url: config.api.getMallInfo,
  322. data: {}
  323. }).then(res => {
  324. if(res.code==200){
  325. this.setData({
  326. memberName:res.data.name,
  327. memberLogo:res.data.imgUrlH
  328. })
  329. }
  330. if (res.data.businessHours !== '[]') {
  331. that.setData({
  332. aboutShow: true
  333. })
  334. } else {
  335. that.setData({
  336. aboutShow: false
  337. })
  338. }
  339. })
  340. .catch(err => {})
  341. },
  342. //适配不同屏幕大小的canvas
  343. setCanvasSize: function() {
  344. var size = {};
  345. try {
  346. var res = wx.getSystemInfoSync();
  347. var scale = 750 / 500;
  348. //不同屏幕下canvas的适配比例;设计稿是750宽
  349. var width = res.windowWidth / scale;
  350. var height = width;
  351. //canvas画布为正方形
  352. size.w = width;
  353. size.h = height;
  354. } catch (e) {
  355. // Do something when catch error
  356. console.log("获取设备信息失败" + e);
  357. }
  358. return size;
  359. },
  360. });