C端小程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

383 wiersze
9.1 KiB

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