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.

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