C端小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

432 rindas
10 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. userAvatarUrl: "",
  64. userName: "",
  65. },
  66. suerService() {
  67. console.log("打开客服")
  68. wx.openCustomerServiceChat({
  69. extInfo: { url: 'https://work.weixin.qq.com/kfid/kfc7f4a755cbb51fa99' },
  70. corpId: 'wwdc116b631d3ea35f',
  71. success(res) { },
  72. fail(res) {
  73. console.log(res);
  74. }
  75. })
  76. },
  77. checkUserStatus() {
  78. let that = this;
  79. Http.get({
  80. url: config.api.checkPhoneStatus,
  81. data: {}
  82. }).then(res => {
  83. wx.navigateTo({
  84. url: '/pages/edit/edit',
  85. })
  86. }).catch(err => {
  87. wx.navigateTo({
  88. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  89. })
  90. })
  91. },
  92. gotoPhoneInfo() {
  93. /**
  94. * 将值传到用户手机号授权的页面
  95. *
  96. */
  97. wx.navigateTo({
  98. url: `/pages/getphoneInfo/index?path=main`
  99. });
  100. },
  101. //是否授权手机号
  102. ifPhoneInfo() {
  103. Http.get({
  104. url: config.api.checkPhoneStatus,
  105. data: {}
  106. }).then(res => {
  107. return
  108. }).catch(err => {
  109. wx.setStorageSync('ifSetUserInfo', 1) //手机号未授权
  110. wx.navigateTo({
  111. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  112. })
  113. })
  114. },
  115. /* 判断是否授权*/
  116. userAuthorization() {
  117. Http.get({
  118. url: config.api.checkUserStatus,
  119. data: {
  120. token: app.globalData.token
  121. }
  122. }).then(res => {
  123. this.ifPhoneInfo()
  124. }).catch(err => {
  125. app.globalData.type = 'uc'
  126. wx.navigateTo({
  127. url: `/pages/getuserinfo/index`,
  128. })
  129. })
  130. },
  131. /**
  132. * 跳转到成长值的页面
  133. */
  134. gotograde: function () {
  135. wx.navigateTo({
  136. url: '/pages/czdetail/czdetail',
  137. })
  138. },
  139. gotointegralmall: function () {
  140. wx.navigateTo({
  141. url: '/pages/integralmall/integraHistory/index',
  142. })
  143. },
  144. /**
  145. * 跳转到商场信息的页面
  146. */
  147. gomallInfo: function () {
  148. wx.navigateTo({
  149. url: '/pages/mallInfo/mallInfo',
  150. })
  151. },
  152. showVersion: function () {
  153. /**
  154. * 长按显示版本号
  155. */
  156. let that = this;
  157. if (that.data.flag == 'hidden') {
  158. that.setData({
  159. flag: 'show'
  160. });
  161. }
  162. },
  163. gotoedit: function () {
  164. // this.checkUserStatus();
  165. console.log('goSetAvatar');
  166. wx.navigateTo({
  167. url: '/pages3/setUserInfo/index'
  168. })
  169. },
  170. onLoad(options) {
  171. // this.getLocation();
  172. this.updateScene();
  173. // this.getRoomId();
  174. // this.getRoomList();
  175. console.log(wx.getExtConfigSync())
  176. },
  177. //获取房间列表
  178. getRoomList() {
  179. Http.get({
  180. url: config.api.getRoomList,
  181. data: {
  182. token: app.globalData.token,
  183. appId: config.weapp.AppId
  184. }
  185. }).then(res => {
  186. console.log(res)
  187. })
  188. },
  189. getRoomId() {
  190. let roomId = [3] // 填写具体的房间号,可通过下面【获取直播房间列表】 API 获取
  191. let customParams = encodeURIComponent(JSON.stringify({
  192. path: 'pages/index/index',
  193. pid: 1
  194. })) // 开发者在直播间页面路径上携带自定义参数(如示例中的path和pid参数),后续可以在分享卡片链接和跳转至商详页时获取,详见【获取自定义参数】、【直播间到商详页面携带参数】章节(上限600个字符,超过部分会被截断)
  195. console.log(customParams, 777777777)
  196. this.setData({
  197. roomId,
  198. customParams
  199. })
  200. },
  201. /**
  202. * 获得经纬度
  203. */
  204. // getLocation() {
  205. // let that = this;
  206. // wx.getLocation({
  207. // type: "wgs84",
  208. // success: function(res) {
  209. // console.log(res)
  210. // if (res && res.longitude && res.latitude) {
  211. // Http.post({
  212. // url: config.api.updateLBS,
  213. // data: {
  214. // latitude: res.latitude,
  215. // longitude: res.longitude
  216. // }
  217. // }).then(res => {
  218. // console.log(res)
  219. // })
  220. // }
  221. // },
  222. // fail: error => {
  223. // console.log(error);
  224. // }
  225. // })
  226. // },
  227. /**
  228. * 用户更新scene
  229. */
  230. updateScene() {
  231. Http.post({
  232. url: config.api.updateScene,
  233. data: {
  234. scene: app.globalData.scene
  235. }
  236. }).then(res => {
  237. console.log(res)
  238. })
  239. },
  240. /**
  241. * 生命周期函数--监听页面显示
  242. */
  243. onShow: function () {
  244. const ifSetUserInfo = wx.getStorageSync('ifSetUserInfo') || 2
  245. // 手机号未授权
  246. if (ifSetUserInfo == 1) {
  247. wx.showModal({
  248. title: '完善个人信息',
  249. content: '请继续完成个人信息哦',
  250. showCancel: true,
  251. cancelText: "以后再说",
  252. cancelColor: '',
  253. confirmText: "去完善",
  254. confirmColor: '#FD832D',
  255. complete: (res) => {
  256. if (res.cancel) {
  257. console.log('cancel');
  258. }
  259. if (res.confirm) {
  260. wx.setStorageSync('ifSetUserInfo', 2) // 已完成手机号授权
  261. wx.navigateTo({
  262. url: '/pages3/setUserInfo/index',
  263. })
  264. }
  265. }
  266. })
  267. }
  268. if (businessSwitch) {
  269. let openId = wx.getStorageSync("openId")
  270. this.setData({
  271. goUrl: `plugin://auto-points-plugin/index?openid=${openId}&mch_id=${this.data.mch_id}`
  272. })
  273. }
  274. console.log(this.data.goUrl)
  275. let that = this;
  276. that.userAuthorization()
  277. if (typeof that.getTabBar === 'function' &&
  278. that.getTabBar()) {
  279. if (ifStoreApp == 1) {
  280. that.getTabBar().setData({
  281. selected: 1
  282. })
  283. } else if (ifStoreApp == 2) {
  284. that.getTabBar().setData({
  285. selected: 2
  286. })
  287. } else {
  288. that.getTabBar().setData({
  289. selected: 3,
  290. })
  291. }
  292. }
  293. that.setData({
  294. appVersion: extConfig.appVersion,
  295. })
  296. /**
  297. * couponNum
  298. * couponNum2
  299. */
  300. let num = wx.getStorageSync('couponNum');
  301. let num1 = wx.getStorageSync('couponNum2');
  302. // wx.hideTabBarRedDot({
  303. // index: 3
  304. // });
  305. if (num == 'couponNum1') {
  306. wx.setStorage({
  307. key: 'couponNum',
  308. data: "couponNum1",
  309. })
  310. that.setData({
  311. couponNum: "couponNum1"
  312. })
  313. } else if (num == 'couponNum') {
  314. that.setData({
  315. couponNum: "couponNum"
  316. })
  317. };
  318. if (num1 == 'couponNum3') {
  319. wx.setStorage({
  320. key: 'couponNum2',
  321. data: "couponNum3",
  322. })
  323. that.setData({
  324. couponNum2: "couponNum3"
  325. })
  326. } else if (num1 == 'couponNum2') {
  327. that.setData({
  328. couponNum2: "couponNum2"
  329. });
  330. };
  331. Http.get({
  332. url: config.api.getScore,
  333. data: {}
  334. }).then(res => {
  335. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate) {
  336. that.setData({
  337. showEdit: true
  338. })
  339. }
  340. let curPhone = res.data.phone ? res.data.phone : '';
  341. if (curPhone) {
  342. let curPhoneList = curPhone.split('');
  343. let curPhoneList01 = [];
  344. curPhoneList.forEach((item, index) => {
  345. if (index >= 3 && index <= 6) {
  346. item = '*';
  347. }
  348. curPhoneList01.push(item);
  349. })
  350. curPhone = curPhoneList01.join('');
  351. }
  352. that.setData({
  353. score: res.data.score,
  354. credit: res.data.credit,
  355. curPhone: curPhone,
  356. levelName: res.data.levelName,
  357. userId: res.data.userId,
  358. userAvatarUrl: res.data.avatarUrl,
  359. userName: res.data.nickName
  360. })
  361. if (res.data.nickName) {
  362. that.setData({
  363. ismember: true,
  364. memberId: res.data.id
  365. })
  366. var size = this.setCanvasSize();
  367. var initUrl = JSON.stringify({
  368. flagid: res.data.id
  369. });
  370. }
  371. })
  372. .catch(err => {
  373. wx.showModal({
  374. title: '提示',
  375. content: err.errMsg,
  376. showCancel: false
  377. })
  378. })
  379. //暂时注释
  380. // that.getrun();
  381. //查询关于我们
  382. Http.get({
  383. url: config.api.getMallInfo,
  384. data: {}
  385. }).then(res => {
  386. if (res.code == 200) {
  387. this.setData({
  388. memberName: res.data.name,
  389. memberLogo: res.data.imgUrlH
  390. })
  391. }
  392. if (res.data.businessHours !== '[]') {
  393. that.setData({
  394. aboutShow: true
  395. })
  396. } else {
  397. that.setData({
  398. aboutShow: false
  399. })
  400. }
  401. })
  402. .catch(err => { })
  403. },
  404. //适配不同屏幕大小的canvas
  405. setCanvasSize: function () {
  406. var size = {};
  407. try {
  408. var res = wx.getSystemInfoSync();
  409. var scale = 750 / 500;
  410. //不同屏幕下canvas的适配比例;设计稿是750宽
  411. var width = res.windowWidth / scale;
  412. var height = width;
  413. //canvas画布为正方形
  414. size.w = width;
  415. size.h = height;
  416. } catch (e) {
  417. // Do something when catch error
  418. console.log("获取设备信息失败" + e);
  419. }
  420. return size;
  421. }
  422. });