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.

701 lines
16 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. showPrivacy: false,
  22. navigationBarHeight,
  23. ifStoreApp: ifStoreApp,
  24. aboutUs: imgurl.aboutUs.url,
  25. rqCode: imgurl.barcode.url,
  26. banneColor: bgColor.colorFirst.user2.banneColor,
  27. levelBg: bgColor.colorFirst.user.levelBg,
  28. view: bgColor.colorFirst.user2.view,
  29. fenxiang: imgurl.fenxiang1.url,
  30. redirectUrl: imgurl.redirect.url,
  31. editUrl: imgurl.edit.url,
  32. activeUrl: imgurl.active.url,
  33. dingUrl: imgurl.ding.url,
  34. duihuan: imgurl.duihuan.url,
  35. shoppingAtlas: imgurl.shoppingAtlas.url,
  36. quansUrl: imgurl.quans.url,
  37. wmintegral: imgurl.wmintegral.url,
  38. cardiconUrl: imgurl.cardicon.url,
  39. myactivitygift: imgurl.myactivitygift.url,
  40. myactivity: imgurl.myactivity.url,
  41. cheUrl: imgurl.che.url,
  42. giftUrl: imgurl.gift.url,
  43. wmbarginicon: imgurl.wmbarginicon.url,
  44. wmspellgroup: imgurl.wmspellgroup.url,
  45. canIUse: wx.canIUse('official-account'),
  46. mineFlag: "",
  47. flag: 'hidden',
  48. score: '0',
  49. credit: '0',
  50. userId: "",
  51. memberName: "",
  52. memberLogo: "",
  53. curPhone: '',
  54. name: "",
  55. birthdate: "",
  56. sex: "",
  57. showEdit: false,
  58. ismember: false,
  59. canvasHidden: false,
  60. maskHidden: true,
  61. imagePath: '',
  62. appVersion: "",
  63. placeholder: '',
  64. userAvatarUrl: "",
  65. userName: "",
  66. ifSetUserInfo: false
  67. },
  68. suerService() {
  69. console.log("打开客服")
  70. wx.openCustomerServiceChat({
  71. extInfo: { url: 'https://work.weixin.qq.com/kfid/kfc7f4a755cbb51fa99' },
  72. corpId: 'wwdc116b631d3ea35f',
  73. success(res) { },
  74. fail(res) {
  75. console.log(res);
  76. }
  77. })
  78. },
  79. checkUserStatus() {
  80. let that = this;
  81. Http.get({
  82. url: config.api.checkPhoneStatus,
  83. data: {}
  84. }).then(res => {
  85. wx.navigateTo({
  86. url: '/pages/edit/edit',
  87. })
  88. }).catch(err => {
  89. wx.navigateTo({
  90. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  91. })
  92. })
  93. },
  94. gotoPhoneInfo() {
  95. /**
  96. * 将值传到用户手机号授权的页面
  97. *
  98. */
  99. wx.navigateTo({
  100. url: `/pages/getphoneInfo/index?path=main`
  101. });
  102. },
  103. //是否授权手机号
  104. ifPhoneInfo() {
  105. const that = this
  106. Http.get({
  107. url: config.api.checkPhoneStatus,
  108. data: {}
  109. }).then(res => {
  110. console.log(res, 'res');
  111. that.setData({
  112. ifSetUserInfo: true
  113. })
  114. // 手机号未授权
  115. const ifSetUserInfo = wx.getStorageSync('ifSetUserInfo')
  116. if (ifSetUserInfo == 1) {
  117. if (!that.data.ifSetUserInfo) return
  118. wx.showModal({
  119. title: '完善个人信息',
  120. content: '请继续完成个人信息哦',
  121. showCancel: true,
  122. cancelText: "以后再说",
  123. cancelColor: '',
  124. confirmText: "去完善",
  125. confirmColor: '#FD832D',
  126. complete: (res) => {
  127. if (res.cancel) {
  128. console.log('cancel');
  129. }
  130. if (res.confirm) {
  131. wx.navigateTo({
  132. url: '/pages3/setUserInfo/index',
  133. })
  134. }
  135. // 已完成手机号授权
  136. wx.setStorageSync('ifSetUserInfo', 2)
  137. }
  138. })
  139. }
  140. return
  141. }).catch(err => {
  142. console.log(err, 'err');
  143. that.setData({
  144. ifSetUserInfo: false
  145. })
  146. const ifSetUserInfo = wx.getStorageSync('ifSetUserInfo')
  147. if (ifSetUserInfo != 2) {
  148. wx.setStorageSync('ifSetUserInfo', 1) //手机号未授权
  149. }
  150. // wx.navigateTo({
  151. // url: `/pages/getphoneInfo/index?mineFlag=mine`,
  152. // })
  153. })
  154. },
  155. /* 判断是否授权*/
  156. userAuthorization() {
  157. Http.get({
  158. url: config.api.checkUserStatus,
  159. data: {
  160. token: app.globalData.token
  161. }
  162. }).then(res => {
  163. this.ifPhoneInfo()
  164. }).catch(err => {
  165. app.globalData.type = 'uc'
  166. wx.navigateTo({
  167. url: `/pages/getuserinfo/index`,
  168. })
  169. })
  170. },
  171. /**
  172. * 跳转到成长值的页面
  173. */
  174. gotograde: function () {
  175. if (this.data.ifSetUserInfo) {
  176. wx.navigateTo({
  177. url: '/pages/czdetail/czdetail',
  178. })
  179. } else {
  180. wx.navigateTo({
  181. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  182. })
  183. }
  184. },
  185. goToOrder() {
  186. if (this.data.ifSetUserInfo) {
  187. wx.navigateTo({
  188. url: '/pages/order/index/index?id=all',
  189. })
  190. } else {
  191. wx.navigateTo({
  192. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  193. })
  194. }
  195. },
  196. goToCouponorder() {
  197. if (this.data.ifSetUserInfo) {
  198. wx.navigateTo({
  199. url: '/pages/couponorder/index/index',
  200. })
  201. } else {
  202. wx.navigateTo({
  203. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  204. })
  205. }
  206. },
  207. goToCardorder() {
  208. if (this.data.ifSetUserInfo) {
  209. wx.navigateTo({
  210. url: '/pages/cardorder/index/index',
  211. })
  212. } else {
  213. wx.navigateTo({
  214. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  215. })
  216. }
  217. },
  218. goToIntegralmall() {
  219. if (this.data.ifSetUserInfo) {
  220. wx.navigateTo({
  221. url: '/pages/integralmall/index',
  222. })
  223. } else {
  224. wx.navigateTo({
  225. url: '/pages/integralmall/index',
  226. })
  227. // wx.navigateTo({
  228. // url: `/pages/getphoneInfo/index?mineFlag=mine`,
  229. // })
  230. }
  231. },
  232. goToBargain() {
  233. if (this.data.ifSetUserInfo) {
  234. wx.navigateTo({
  235. url: '/pages/bargain/bargain?from=myhtml',
  236. })
  237. } else {
  238. wx.navigateTo({
  239. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  240. })
  241. }
  242. },
  243. goToSpellGroup() {
  244. if (this.data.ifSetUserInfo) {
  245. wx.navigateTo({
  246. url: '/pages/spellGroup/spellGroup?from=myhtml',
  247. })
  248. } else {
  249. wx.navigateTo({
  250. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  251. })
  252. }
  253. },
  254. goToMyactivity() {
  255. if (this.data.ifSetUserInfo) {
  256. wx.navigateTo({
  257. url: '/pages/user/myactivity/index',
  258. })
  259. } else {
  260. wx.navigateTo({
  261. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  262. })
  263. }
  264. },
  265. goToSetUserInfo() {
  266. if (this.data.ifSetUserInfo) {
  267. wx.navigateTo({
  268. url: '/pages3/setUserInfo/index',
  269. })
  270. } else {
  271. wx.navigateTo({
  272. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  273. })
  274. }
  275. },
  276. goToSpecialcourtesy() {
  277. if (this.data.ifSetUserInfo) {
  278. wx.navigateTo({
  279. url: '/pages/specialcourtesy/specialcourtesy',
  280. })
  281. } else {
  282. wx.navigateTo({
  283. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  284. })
  285. }
  286. },
  287. goToExchangeCard() {
  288. wx.navigateTo({
  289. url: '/pages3/exchangeCard/exchangeCard',
  290. })
  291. // if (this.data.ifSetUserInfo) {
  292. // wx.navigateTo({
  293. // url: '/pages3/exchangeCard/exchangeCard',
  294. // })
  295. // } else {
  296. // wx.navigateTo({
  297. // url: `/pages/getphoneInfo/index?mineFlag=mine`,
  298. // })
  299. // }
  300. },
  301. goToQuestionnaire() {
  302. if (this.data.ifSetUserInfo) {
  303. wx.navigateTo({
  304. url: '/pages/questionnaire/questionnaireLsit/questionnaireLsit',
  305. })
  306. } else {
  307. wx.navigateTo({
  308. url: '/pages/questionnaire/questionnaireLsit/questionnaireLsit',
  309. })
  310. // wx.navigateTo({
  311. // url: `/pages/getphoneInfo/index?mineFlag=mine`,
  312. // })
  313. }
  314. },
  315. goToComplaint() {
  316. if (this.data.ifSetUserInfo) {
  317. wx.navigateTo({
  318. url: '/pages3/complaint/complaint',
  319. })
  320. } else {
  321. wx.navigateTo({
  322. url: '/pages3/complaint/complaint',
  323. })
  324. // wx.navigateTo({
  325. // url: `/pages/getphoneInfo/index?mineFlag=mine`,
  326. // })
  327. }
  328. },
  329. goToBusinessSwitch() {
  330. if (this.data.ifSetUserInfo) {
  331. wx.navigateTo({
  332. url: this.data.goUrl,
  333. })
  334. } else {
  335. wx.navigateTo({
  336. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  337. })
  338. }
  339. },
  340. share() {
  341. if (this.data.ifSetUserInfo) {
  342. wx.navigateTo({
  343. url: '/pages/shareFriend/shareFriend',
  344. })
  345. } else {
  346. wx.navigateTo({
  347. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  348. })
  349. }
  350. },
  351. /**
  352. * 跳转到商场信息的页面
  353. */
  354. gomallInfo: function () {
  355. wx.navigateTo({
  356. url: '/pages/mallInfo/mallInfo',
  357. })
  358. },
  359. showVersion: function () {
  360. /**
  361. * 长按显示版本号
  362. */
  363. let that = this;
  364. if (that.data.flag == 'hidden') {
  365. that.setData({
  366. flag: 'show'
  367. });
  368. }
  369. },
  370. gotoedit: function () {
  371. // this.checkUserStatus();
  372. console.log('goSetAvatar');
  373. wx.navigateTo({
  374. url: '/pages3/setUserInfo/index'
  375. })
  376. },
  377. onLoad(options) {
  378. // this.getLocation();
  379. this.updateScene();
  380. // this.getRoomId();
  381. // this.getRoomList();
  382. console.log(wx.getExtConfigSync())
  383. this.getPrivacySetting()
  384. },
  385. clickPrivacy(e) {
  386. },
  387. closePrivacy() {
  388. this.setData({
  389. showPrivacy: false
  390. })
  391. },
  392. getPrivacySetting() {
  393. const canIUsePrivacy = wx.canIUse('getPrivacySetting')
  394. console.log(canIUsePrivacy, 'canIUse getPrivacySetting')
  395. if (canIUsePrivacy) {
  396. wx.getPrivacySetting({
  397. success: res => {
  398. console.log(res, 'getPrivacySetting') // 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' }
  399. if (res.needAuthorization) {
  400. // 需要弹出隐私协议
  401. this.setData({
  402. showPrivacy: false
  403. })
  404. } else {
  405. // this.setData({
  406. // showPrivacy: true
  407. // })
  408. // 用户已经同意过隐私协议,所以不需要再弹出隐私协议,也能调用已声明过的隐私接口
  409. // wx.getUserProfile()
  410. // wx.chooseMedia()
  411. // wx.getClipboardData()
  412. // wx.startRecord()
  413. // this.setData({
  414. // showPrivacy: true
  415. // })
  416. }
  417. },
  418. fail: () => { },
  419. complete: () => { }
  420. })
  421. }
  422. },
  423. handleAgreePrivacyAuthorization() {
  424. console.log('Privacy Agreed!');
  425. this.setData({
  426. showPrivacy: true
  427. })
  428. // 用户同意隐私协议事件回调
  429. // 用户点击了同意,之后所有已声明过的隐私接口和组件都可以调用了
  430. // wx.getUserProfile()
  431. // wx.chooseMedia()
  432. // wx.getClipboardData()
  433. // wx.startRecord()
  434. },
  435. handleOpenPrivacyContract() {
  436. // 打开隐私协议页面
  437. wx.openPrivacyContract({
  438. success: () => {
  439. // this.setData({
  440. // showPrivacy: false
  441. // })
  442. }, // 打开成功
  443. fail: () => { }, // 打开失败
  444. complete: () => { }
  445. })
  446. },
  447. //获取房间列表
  448. getRoomList() {
  449. Http.get({
  450. url: config.api.getRoomList,
  451. data: {
  452. token: app.globalData.token,
  453. appId: config.weapp.AppId
  454. }
  455. }).then(res => {
  456. console.log(res)
  457. })
  458. },
  459. getRoomId() {
  460. let roomId = [3] // 填写具体的房间号,可通过下面【获取直播房间列表】 API 获取
  461. let customParams = encodeURIComponent(JSON.stringify({
  462. path: 'pages/index/index',
  463. pid: 1
  464. })) // 开发者在直播间页面路径上携带自定义参数(如示例中的path和pid参数),后续可以在分享卡片链接和跳转至商详页时获取,详见【获取自定义参数】、【直播间到商详页面携带参数】章节(上限600个字符,超过部分会被截断)
  465. console.log(customParams, 777777777)
  466. this.setData({
  467. roomId,
  468. customParams
  469. })
  470. },
  471. /**
  472. * 获得经纬度
  473. */
  474. // getLocation() {
  475. // let that = this;
  476. // wx.getLocation({
  477. // type: "wgs84",
  478. // success: function(res) {
  479. // console.log(res)
  480. // if (res && res.longitude && res.latitude) {
  481. // Http.post({
  482. // url: config.api.updateLBS,
  483. // data: {
  484. // latitude: res.latitude,
  485. // longitude: res.longitude
  486. // }
  487. // }).then(res => {
  488. // console.log(res)
  489. // })
  490. // }
  491. // },
  492. // fail: error => {
  493. // console.log(error);
  494. // }
  495. // })
  496. // },
  497. /**
  498. * 用户更新scene
  499. */
  500. updateScene() {
  501. Http.post({
  502. url: config.api.updateScene,
  503. data: {
  504. scene: app.globalData.scene
  505. }
  506. }).then(res => {
  507. console.log(res)
  508. })
  509. },
  510. /**
  511. * 生命周期函数--监听页面显示
  512. */
  513. onShow: function () {
  514. this.ifPhoneInfo()
  515. if (businessSwitch) {
  516. let openId = wx.getStorageSync("openId")
  517. this.setData({
  518. goUrl: `plugin://auto-points-plugin/index?openid=${openId}&mch_id=${this.data.mch_id}`
  519. })
  520. }
  521. console.log(this.data.goUrl)
  522. let that = this;
  523. that.userAuthorization()
  524. if (typeof that.getTabBar === 'function' &&
  525. that.getTabBar()) {
  526. if (ifStoreApp == 1) {
  527. that.getTabBar().setData({
  528. selected: 1
  529. })
  530. } else if (ifStoreApp == 2) {
  531. that.getTabBar().setData({
  532. selected: 2
  533. })
  534. } else {
  535. that.getTabBar().setData({
  536. selected: 3,
  537. })
  538. }
  539. }
  540. that.setData({
  541. appVersion: extConfig.appVersion,
  542. })
  543. /**
  544. * couponNum
  545. * couponNum2
  546. */
  547. let num = wx.getStorageSync('couponNum');
  548. let num1 = wx.getStorageSync('couponNum2');
  549. // wx.hideTabBarRedDot({
  550. // index: 3
  551. // });
  552. if (num == 'couponNum1') {
  553. wx.setStorage({
  554. key: 'couponNum',
  555. data: "couponNum1",
  556. })
  557. that.setData({
  558. couponNum: "couponNum1"
  559. })
  560. } else if (num == 'couponNum') {
  561. that.setData({
  562. couponNum: "couponNum"
  563. })
  564. };
  565. if (num1 == 'couponNum3') {
  566. wx.setStorage({
  567. key: 'couponNum2',
  568. data: "couponNum3",
  569. })
  570. that.setData({
  571. couponNum2: "couponNum3"
  572. })
  573. } else if (num1 == 'couponNum2') {
  574. that.setData({
  575. couponNum2: "couponNum2"
  576. });
  577. };
  578. Http.get({
  579. url: config.api.getScore,
  580. data: {}
  581. }).then(res => {
  582. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate) {
  583. that.setData({
  584. showEdit: true
  585. })
  586. }
  587. let curPhone = res.data.phone ? res.data.phone : '';
  588. if (curPhone) {
  589. let curPhoneList = curPhone.split('');
  590. let curPhoneList01 = [];
  591. curPhoneList.forEach((item, index) => {
  592. if (index >= 3 && index <= 6) {
  593. item = '*';
  594. }
  595. curPhoneList01.push(item);
  596. })
  597. curPhone = curPhoneList01.join('');
  598. }
  599. that.setData({
  600. score: res.data.score,
  601. credit: res.data.credit,
  602. curPhone: curPhone,
  603. levelName: res.data.levelName,
  604. userId: res.data.userId,
  605. userAvatarUrl: res.data.avatarUrl,
  606. userName: res.data.nickName
  607. })
  608. if (res.data.nickName) {
  609. that.setData({
  610. ismember: true,
  611. memberId: res.data.id
  612. })
  613. var size = this.setCanvasSize();
  614. var initUrl = JSON.stringify({
  615. flagid: res.data.id
  616. });
  617. }
  618. })
  619. .catch(err => {
  620. wx.showModal({
  621. title: '提示',
  622. content: err.errMsg,
  623. showCancel: false
  624. })
  625. })
  626. //暂时注释
  627. // that.getrun();
  628. //查询关于我们
  629. Http.get({
  630. url: config.api.getMallInfo,
  631. data: {}
  632. }).then(res => {
  633. if (res.code == 200) {
  634. this.setData({
  635. memberName: res.data.name,
  636. memberLogo: res.data.imgUrlH
  637. })
  638. }
  639. if (res.data.businessHours !== '[]') {
  640. that.setData({
  641. aboutShow: true
  642. })
  643. } else {
  644. that.setData({
  645. aboutShow: false
  646. })
  647. }
  648. })
  649. .catch(err => { })
  650. },
  651. //适配不同屏幕大小的canvas
  652. setCanvasSize: function () {
  653. var size = {};
  654. try {
  655. var res = wx.getSystemInfoSync();
  656. var scale = 750 / 500;
  657. //不同屏幕下canvas的适配比例;设计稿是750宽
  658. var width = res.windowWidth / scale;
  659. var height = width;
  660. //canvas画布为正方形
  661. size.w = width;
  662. size.h = height;
  663. } catch (e) {
  664. // Do something when catch error
  665. console.log("获取设备信息失败" + e);
  666. }
  667. return size;
  668. }
  669. });