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.

708 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. handleAgreePrivacyAuthorization() {
  429. console.log('Privacy Agreed!');
  430. this.setData({
  431. showPrivacy: true
  432. })
  433. // 用户同意隐私协议事件回调
  434. // 用户点击了同意,之后所有已声明过的隐私接口和组件都可以调用了
  435. // wx.getUserProfile()
  436. // wx.chooseMedia()
  437. // wx.getClipboardData()
  438. // wx.startRecord()
  439. },
  440. handleOpenPrivacyContract() {
  441. // 打开隐私协议页面
  442. wx.openPrivacyContract({
  443. success: () => {
  444. // this.setData({
  445. // showPrivacy: false
  446. // })
  447. }, // 打开成功
  448. fail: () => { }, // 打开失败
  449. complete: () => { }
  450. })
  451. },
  452. //获取房间列表
  453. getRoomList() {
  454. Http.get({
  455. url: config.api.getRoomList,
  456. data: {
  457. token: app.globalData.token,
  458. appId: config.weapp.AppId
  459. }
  460. }).then(res => {
  461. console.log(res)
  462. })
  463. },
  464. getRoomId() {
  465. let roomId = [3] // 填写具体的房间号,可通过下面【获取直播房间列表】 API 获取
  466. let customParams = encodeURIComponent(JSON.stringify({
  467. path: 'pages/index/index',
  468. pid: 1
  469. })) // 开发者在直播间页面路径上携带自定义参数(如示例中的path和pid参数),后续可以在分享卡片链接和跳转至商详页时获取,详见【获取自定义参数】、【直播间到商详页面携带参数】章节(上限600个字符,超过部分会被截断)
  470. console.log(customParams, 777777777)
  471. this.setData({
  472. roomId,
  473. customParams
  474. })
  475. },
  476. /**
  477. * 获得经纬度
  478. */
  479. // getLocation() {
  480. // let that = this;
  481. // wx.getLocation({
  482. // type: "wgs84",
  483. // success: function(res) {
  484. // console.log(res)
  485. // if (res && res.longitude && res.latitude) {
  486. // Http.post({
  487. // url: config.api.updateLBS,
  488. // data: {
  489. // latitude: res.latitude,
  490. // longitude: res.longitude
  491. // }
  492. // }).then(res => {
  493. // console.log(res)
  494. // })
  495. // }
  496. // },
  497. // fail: error => {
  498. // console.log(error);
  499. // }
  500. // })
  501. // },
  502. /**
  503. * 用户更新scene
  504. */
  505. updateScene() {
  506. Http.post({
  507. url: config.api.updateScene,
  508. data: {
  509. scene: app.globalData.scene
  510. }
  511. }).then(res => {
  512. console.log(res)
  513. })
  514. },
  515. /**
  516. * 生命周期函数--监听页面显示
  517. */
  518. onShow: function () {
  519. this.ifPhoneInfo()
  520. if (businessSwitch) {
  521. let openId = wx.getStorageSync("openId")
  522. this.setData({
  523. goUrl: `plugin://auto-points-plugin/index?openid=${openId}&mch_id=${this.data.mch_id}`
  524. })
  525. }
  526. console.log(this.data.goUrl)
  527. let that = this;
  528. that.userAuthorization()
  529. if (typeof that.getTabBar === 'function' &&
  530. that.getTabBar()) {
  531. if (ifStoreApp == 1) {
  532. that.getTabBar().setData({
  533. selected: 1
  534. })
  535. } else if (ifStoreApp == 2) {
  536. that.getTabBar().setData({
  537. selected: 2
  538. })
  539. } else {
  540. that.getTabBar().setData({
  541. selected: 3,
  542. })
  543. }
  544. }
  545. that.setData({
  546. appVersion: extConfig.appVersion,
  547. })
  548. /**
  549. * couponNum
  550. * couponNum2
  551. */
  552. let num = wx.getStorageSync('couponNum');
  553. let num1 = wx.getStorageSync('couponNum2');
  554. // wx.hideTabBarRedDot({
  555. // index: 3
  556. // });
  557. if (num == 'couponNum1') {
  558. wx.setStorage({
  559. key: 'couponNum',
  560. data: "couponNum1",
  561. })
  562. that.setData({
  563. couponNum: "couponNum1"
  564. })
  565. } else if (num == 'couponNum') {
  566. that.setData({
  567. couponNum: "couponNum"
  568. })
  569. };
  570. if (num1 == 'couponNum3') {
  571. wx.setStorage({
  572. key: 'couponNum2',
  573. data: "couponNum3",
  574. })
  575. that.setData({
  576. couponNum2: "couponNum3"
  577. })
  578. } else if (num1 == 'couponNum2') {
  579. that.setData({
  580. couponNum2: "couponNum2"
  581. });
  582. };
  583. Http.get({
  584. url: config.api.getScore,
  585. data: {}
  586. }).then(res => {
  587. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate) {
  588. that.setData({
  589. showEdit: true
  590. })
  591. }
  592. let curPhone = res.data.phone ? res.data.phone : '';
  593. if (curPhone) {
  594. let curPhoneList = curPhone.split('');
  595. let curPhoneList01 = [];
  596. curPhoneList.forEach((item, index) => {
  597. if (index >= 3 && index <= 6) {
  598. item = '*';
  599. }
  600. curPhoneList01.push(item);
  601. })
  602. curPhone = curPhoneList01.join('');
  603. }
  604. that.setData({
  605. score: res.data.score,
  606. credit: res.data.credit,
  607. curPhone: curPhone,
  608. levelName: res.data.levelName,
  609. userId: res.data.userId,
  610. userAvatarUrl: res.data.avatarUrl,
  611. userName: res.data.nickName
  612. })
  613. if (res.data.nickName) {
  614. that.setData({
  615. ismember: true,
  616. memberId: res.data.id
  617. })
  618. var size = this.setCanvasSize();
  619. var initUrl = JSON.stringify({
  620. flagid: res.data.id
  621. });
  622. }
  623. })
  624. .catch(err => {
  625. wx.showModal({
  626. title: '提示',
  627. content: err.errMsg,
  628. showCancel: false
  629. })
  630. })
  631. //暂时注释
  632. // that.getrun();
  633. //查询关于我们
  634. Http.get({
  635. url: config.api.getMallInfo,
  636. data: {}
  637. }).then(res => {
  638. if (res.code == 200) {
  639. this.setData({
  640. memberName: res.data.name,
  641. memberLogo: res.data.imgUrlH
  642. })
  643. }
  644. if (res.data.businessHours !== '[]') {
  645. that.setData({
  646. aboutShow: true
  647. })
  648. } else {
  649. that.setData({
  650. aboutShow: false
  651. })
  652. }
  653. })
  654. .catch(err => { })
  655. },
  656. //适配不同屏幕大小的canvas
  657. setCanvasSize: function () {
  658. var size = {};
  659. try {
  660. var res = wx.getSystemInfoSync();
  661. var scale = 750 / 500;
  662. //不同屏幕下canvas的适配比例;设计稿是750宽
  663. var width = res.windowWidth / scale;
  664. var height = width;
  665. //canvas画布为正方形
  666. size.w = width;
  667. size.h = height;
  668. } catch (e) {
  669. // Do something when catch error
  670. console.log("获取设备信息失败" + e);
  671. }
  672. return size;
  673. }
  674. });