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.

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