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.

748 lines
17 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. goToInfo() {
  156. wx.navigateTo({
  157. url: '/pages3/setUserInfo/index',
  158. })
  159. },
  160. /* 判断是否授权*/
  161. userAuthorization() {
  162. Http.get({
  163. url: config.api.checkUserStatus,
  164. data: {
  165. token: app.globalData.token
  166. }
  167. }).then(res => {
  168. this.ifPhoneInfo()
  169. }).catch(err => {
  170. app.globalData.type = 'uc'
  171. wx.navigateTo({
  172. url: `/pages/getuserinfo/index`,
  173. })
  174. })
  175. },
  176. /**
  177. * 跳转到成长值的页面
  178. */
  179. gotograde: function () {
  180. if (this.data.ifSetUserInfo) {
  181. wx.navigateTo({
  182. url: '/pages/czdetail/czdetail',
  183. })
  184. } else {
  185. wx.navigateTo({
  186. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  187. })
  188. }
  189. },
  190. goToOrder() {
  191. if (this.data.ifSetUserInfo) {
  192. wx.navigateTo({
  193. url: '/pages/order/index/index?id=all',
  194. })
  195. } else {
  196. wx.navigateTo({
  197. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  198. })
  199. }
  200. },
  201. goToCouponorder() {
  202. if (this.data.ifSetUserInfo) {
  203. wx.navigateTo({
  204. url: '/pages/couponorder/index/index',
  205. })
  206. } else {
  207. wx.navigateTo({
  208. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  209. })
  210. }
  211. },
  212. goToCardorder() {
  213. if (this.data.ifSetUserInfo) {
  214. wx.navigateTo({
  215. url: '/pages/cardorder/index/index',
  216. })
  217. } else {
  218. wx.navigateTo({
  219. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  220. })
  221. }
  222. },
  223. goToIntegralmall() {
  224. if (this.data.ifSetUserInfo) {
  225. wx.navigateTo({
  226. url: '/pages/integralmall/index',
  227. })
  228. } else {
  229. wx.navigateTo({
  230. url: '/pages/integralmall/index',
  231. })
  232. // wx.navigateTo({
  233. // url: `/pages/getphoneInfo/index?mineFlag=mine`,
  234. // })
  235. }
  236. },
  237. goToBargain() {
  238. if (this.data.ifSetUserInfo) {
  239. wx.navigateTo({
  240. url: '/pages/bargain/bargain?from=myhtml',
  241. })
  242. } else {
  243. wx.navigateTo({
  244. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  245. })
  246. }
  247. },
  248. goToSpellGroup() {
  249. if (this.data.ifSetUserInfo) {
  250. wx.navigateTo({
  251. url: '/pages/spellGroup/spellGroup?from=myhtml',
  252. })
  253. } else {
  254. wx.navigateTo({
  255. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  256. })
  257. }
  258. },
  259. goToMyactivity() {
  260. if (this.data.ifSetUserInfo) {
  261. wx.navigateTo({
  262. url: '/pages/user/myactivity/index',
  263. })
  264. } else {
  265. wx.navigateTo({
  266. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  267. })
  268. }
  269. },
  270. goToSetUserInfo() {
  271. if (this.data.ifSetUserInfo) {
  272. wx.navigateTo({
  273. url: '/pages3/setUserInfo/index',
  274. })
  275. } else {
  276. wx.navigateTo({
  277. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  278. })
  279. }
  280. },
  281. goToSpecialcourtesy() {
  282. if (this.data.ifSetUserInfo) {
  283. wx.navigateTo({
  284. url: '/pages/specialcourtesy/specialcourtesy',
  285. })
  286. } else {
  287. wx.navigateTo({
  288. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  289. })
  290. }
  291. },
  292. goToExchangeCard() {
  293. wx.navigateTo({
  294. url: '/pages3/exchangeCard/exchangeCard',
  295. })
  296. // if (this.data.ifSetUserInfo) {
  297. // wx.navigateTo({
  298. // url: '/pages3/exchangeCard/exchangeCard',
  299. // })
  300. // } else {
  301. // wx.navigateTo({
  302. // url: `/pages/getphoneInfo/index?mineFlag=mine`,
  303. // })
  304. // }
  305. },
  306. goToQuestionnaire() {
  307. if (this.data.ifSetUserInfo) {
  308. wx.navigateTo({
  309. url: '/pages/questionnaire/questionnaireLsit/questionnaireLsit',
  310. })
  311. } else {
  312. wx.navigateTo({
  313. url: '/pages/questionnaire/questionnaireLsit/questionnaireLsit',
  314. })
  315. // wx.navigateTo({
  316. // url: `/pages/getphoneInfo/index?mineFlag=mine`,
  317. // })
  318. }
  319. },
  320. goToComplaint() {
  321. if (this.data.ifSetUserInfo) {
  322. wx.navigateTo({
  323. url: '/pages3/complaint/complaint',
  324. })
  325. } else {
  326. wx.navigateTo({
  327. url: '/pages3/complaint/complaint',
  328. })
  329. // wx.navigateTo({
  330. // url: `/pages/getphoneInfo/index?mineFlag=mine`,
  331. // })
  332. }
  333. },
  334. goToBusinessSwitch() {
  335. if (this.data.ifSetUserInfo) {
  336. wx.navigateTo({
  337. url: this.data.goUrl,
  338. })
  339. } else {
  340. wx.navigateTo({
  341. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  342. })
  343. }
  344. },
  345. share() {
  346. if (this.data.ifSetUserInfo) {
  347. wx.navigateTo({
  348. url: '/pages/shareFriend/shareFriend',
  349. })
  350. } else {
  351. wx.navigateTo({
  352. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  353. })
  354. }
  355. },
  356. /**
  357. * 跳转到商场信息的页面
  358. */
  359. gomallInfo: function () {
  360. wx.navigateTo({
  361. url: '/pages/mallInfo/mallInfo',
  362. })
  363. },
  364. showVersion: function () {
  365. /**
  366. * 长按显示版本号
  367. */
  368. let that = this;
  369. if (that.data.flag == 'hidden') {
  370. that.setData({
  371. flag: 'show'
  372. });
  373. }
  374. },
  375. gotoedit: function () {
  376. // this.checkUserStatus();
  377. console.log('goSetAvatar');
  378. wx.navigateTo({
  379. url: '/pages3/setUserInfo/index'
  380. })
  381. },
  382. onLoad(options) {
  383. // this.getLocation();
  384. this.updateScene();
  385. // this.getRoomId();
  386. // this.getRoomList();
  387. console.log(wx.getExtConfigSync())
  388. this.getPrivacySetting()
  389. },
  390. clickPrivacy(e) {
  391. },
  392. closePrivacy() {
  393. this.setData({
  394. showPrivacy: false
  395. })
  396. },
  397. getPrivacySetting() {
  398. const canIUsePrivacy = wx.canIUse('getPrivacySetting')
  399. console.log(canIUsePrivacy, 'canIUse getPrivacySetting')
  400. if (canIUsePrivacy) {
  401. wx.getPrivacySetting({
  402. success: res => {
  403. console.log(res, 'getPrivacySetting') // 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' }
  404. if (res.needAuthorization) {
  405. // 需要弹出隐私协议
  406. this.setData({
  407. showPrivacy: false
  408. })
  409. } else {
  410. // this.setData({
  411. // showPrivacy: true
  412. // })
  413. // 用户已经同意过隐私协议,所以不需要再弹出隐私协议,也能调用已声明过的隐私接口
  414. // wx.getUserProfile()
  415. // wx.chooseMedia()
  416. // wx.getClipboardData()
  417. // wx.startRecord()
  418. // this.setData({
  419. // showPrivacy: true
  420. // })
  421. }
  422. },
  423. fail: () => { },
  424. complete: () => { }
  425. })
  426. }
  427. },
  428. goCanelAccount() {
  429. const that = this
  430. wx.showModal({
  431. title: '提示',
  432. content: '注销后请重新进入小程序',
  433. success(res) {
  434. if (res.confirm) {
  435. console.log('用户点击确定')
  436. that.goCancelUser()
  437. } else if (res.cancel) {
  438. console.log('用户点击取消')
  439. }
  440. }
  441. })
  442. },
  443. goCancelUser() {
  444. Http.get({
  445. url: "/user/cancelUser"
  446. }).then(res => {
  447. if (res.code == 200) {
  448. wx.showToast({
  449. title: "注销成功",
  450. icon: 'success',
  451. duration: 1500,
  452. })
  453. wx.exitMiniProgram()
  454. }
  455. }).catch(err => {
  456. console.log(err);
  457. wx.showToast({
  458. title: err.message || "注销失败",
  459. icon: 'none',
  460. duration: 1500,
  461. })
  462. })
  463. },
  464. handleAgreePrivacyAuthorization() {
  465. console.log('Privacy Agreed!');
  466. this.setData({
  467. showPrivacy: true
  468. })
  469. // 用户同意隐私协议事件回调
  470. // 用户点击了同意,之后所有已声明过的隐私接口和组件都可以调用了
  471. // wx.getUserProfile()
  472. // wx.chooseMedia()
  473. // wx.getClipboardData()
  474. // wx.startRecord()
  475. },
  476. handleOpenPrivacyContract() {
  477. // 打开隐私协议页面
  478. wx.openPrivacyContract({
  479. success: () => {
  480. // this.setData({
  481. // showPrivacy: false
  482. // })
  483. }, // 打开成功
  484. fail: () => { }, // 打开失败
  485. complete: () => { }
  486. })
  487. },
  488. //获取房间列表
  489. getRoomList() {
  490. Http.get({
  491. url: config.api.getRoomList,
  492. data: {
  493. token: app.globalData.token,
  494. appId: config.weapp.AppId
  495. }
  496. }).then(res => {
  497. console.log(res)
  498. })
  499. },
  500. getRoomId() {
  501. let roomId = [3] // 填写具体的房间号,可通过下面【获取直播房间列表】 API 获取
  502. let customParams = encodeURIComponent(JSON.stringify({
  503. path: 'pages/index/index',
  504. pid: 1
  505. })) // 开发者在直播间页面路径上携带自定义参数(如示例中的path和pid参数),后续可以在分享卡片链接和跳转至商详页时获取,详见【获取自定义参数】、【直播间到商详页面携带参数】章节(上限600个字符,超过部分会被截断)
  506. console.log(customParams, 777777777)
  507. this.setData({
  508. roomId,
  509. customParams
  510. })
  511. },
  512. /**
  513. * 获得经纬度
  514. */
  515. // getLocation() {
  516. // let that = this;
  517. // wx.getLocation({
  518. // type: "wgs84",
  519. // success: function(res) {
  520. // console.log(res)
  521. // if (res && res.longitude && res.latitude) {
  522. // Http.post({
  523. // url: config.api.updateLBS,
  524. // data: {
  525. // latitude: res.latitude,
  526. // longitude: res.longitude
  527. // }
  528. // }).then(res => {
  529. // console.log(res)
  530. // })
  531. // }
  532. // },
  533. // fail: error => {
  534. // console.log(error);
  535. // }
  536. // })
  537. // },
  538. /**
  539. * 用户更新scene
  540. */
  541. updateScene() {
  542. Http.post({
  543. url: config.api.updateScene,
  544. data: {
  545. scene: app.globalData.scene
  546. }
  547. }).then(res => {
  548. console.log(res)
  549. })
  550. },
  551. /**
  552. * 生命周期函数--监听页面显示
  553. */
  554. onShow: function () {
  555. this.ifPhoneInfo()
  556. if (businessSwitch) {
  557. let openId = wx.getStorageSync("openId")
  558. this.setData({
  559. goUrl: `plugin://auto-points-plugin/index?openid=${openId}&mch_id=${this.data.mch_id}`
  560. })
  561. }
  562. console.log(this.data.goUrl)
  563. let that = this;
  564. that.userAuthorization()
  565. if (typeof that.getTabBar === 'function' &&
  566. that.getTabBar()) {
  567. if (ifStoreApp == 1) {
  568. that.getTabBar().setData({
  569. selected: 1
  570. })
  571. } else if (ifStoreApp == 2) {
  572. that.getTabBar().setData({
  573. selected: 2
  574. })
  575. } else {
  576. that.getTabBar().setData({
  577. selected: 3,
  578. })
  579. }
  580. }
  581. that.setData({
  582. appVersion: extConfig.appVersion,
  583. })
  584. /**
  585. * couponNum
  586. * couponNum2
  587. */
  588. let num = wx.getStorageSync('couponNum');
  589. let num1 = wx.getStorageSync('couponNum2');
  590. // wx.hideTabBarRedDot({
  591. // index: 3
  592. // });
  593. if (num == 'couponNum1') {
  594. wx.setStorage({
  595. key: 'couponNum',
  596. data: "couponNum1",
  597. })
  598. that.setData({
  599. couponNum: "couponNum1"
  600. })
  601. } else if (num == 'couponNum') {
  602. that.setData({
  603. couponNum: "couponNum"
  604. })
  605. };
  606. if (num1 == 'couponNum3') {
  607. wx.setStorage({
  608. key: 'couponNum2',
  609. data: "couponNum3",
  610. })
  611. that.setData({
  612. couponNum2: "couponNum3"
  613. })
  614. } else if (num1 == 'couponNum2') {
  615. that.setData({
  616. couponNum2: "couponNum2"
  617. });
  618. };
  619. Http.get({
  620. url: config.api.getScore,
  621. data: {}
  622. }).then(res => {
  623. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate) {
  624. that.setData({
  625. showEdit: true
  626. })
  627. }
  628. let curPhone = res.data.phone ? res.data.phone : '';
  629. if (curPhone) {
  630. let curPhoneList = curPhone.split('');
  631. let curPhoneList01 = [];
  632. curPhoneList.forEach((item, index) => {
  633. if (index >= 3 && index <= 6) {
  634. item = '*';
  635. }
  636. curPhoneList01.push(item);
  637. })
  638. curPhone = curPhoneList01.join('');
  639. }
  640. that.setData({
  641. score: res.data.score,
  642. credit: res.data.credit,
  643. curPhone: curPhone,
  644. levelName: res.data.levelName,
  645. userId: res.data.userId,
  646. userAvatarUrl: res.data.avatarUrl,
  647. userName: res.data.nickName
  648. })
  649. if (res.data.nickName) {
  650. that.setData({
  651. ismember: true,
  652. memberId: res.data.id
  653. })
  654. var size = this.setCanvasSize();
  655. var initUrl = JSON.stringify({
  656. flagid: res.data.id
  657. });
  658. }
  659. })
  660. .catch(err => {
  661. wx.showModal({
  662. title: '提示',
  663. content: err.errMsg,
  664. showCancel: false
  665. })
  666. })
  667. //暂时注释
  668. // that.getrun();
  669. //查询关于我们
  670. Http.get({
  671. url: config.api.getMallInfo,
  672. data: {}
  673. }).then(res => {
  674. if (res.code == 200) {
  675. this.setData({
  676. memberName: res.data.name,
  677. memberLogo: res.data.imgUrlH
  678. })
  679. }
  680. if (res.data.businessHours !== '[]') {
  681. that.setData({
  682. aboutShow: true
  683. })
  684. } else {
  685. that.setData({
  686. aboutShow: false
  687. })
  688. }
  689. })
  690. .catch(err => { })
  691. },
  692. //适配不同屏幕大小的canvas
  693. setCanvasSize: function () {
  694. var size = {};
  695. try {
  696. var res = wx.getSystemInfoSync();
  697. var scale = 750 / 500;
  698. //不同屏幕下canvas的适配比例;设计稿是750宽
  699. var width = res.windowWidth / scale;
  700. var height = width;
  701. //canvas画布为正方形
  702. size.w = width;
  703. size.h = height;
  704. } catch (e) {
  705. // Do something when catch error
  706. console.log("获取设备信息失败" + e);
  707. }
  708. return size;
  709. }
  710. });