123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- import { prefixPagePath } from "../../../../core/utils";
- import { createSubscribe } from 'applet-page-component';
- import { reportCmPV_YL } from '../../utils/cloudMonitorHelper';
- const app = getApp();
- const getRect = id => new Promise(resolve => {
- my.createSelectorQuery().select(`#${id}`).boundingClientRect().exec(resolve);
- });
- const getExtInfo = item => {
- const {
- componentExtInfo
- } = item;
- return componentExtInfo;
- };
- Component(createSubscribe({
- // eslint-disable-next-line no-unused-vars
- async onPageScroll(_, {
- scrollTop
- }) {
- const {
- id,
- isScrollOver
- } = this.data;
- let contentHeight = 0;
- if (this.contentHeight) {
- // eslint-disable-next-line prefer-destructuring
- contentHeight = this.contentHeight;
- } else {
- const res = await getRect(id);
- const [rect] = res;
- const {
- height = 0
- } = rect || {};
- contentHeight = height;
- }
- /* 这里动态设置标题栏 */
- if (scrollTop > contentHeight) {
- if (!isScrollOver) {
- const {
- componentData
- } = this.props;
- const {
- title
- } = getExtInfo(componentData);
- my.setNavigationBar({
- title
- });
- this.setData({
- isScrollOver: true
- });
- }
- } else if (isScrollOver) {
- my.setNavigationBar({
- title: ' '
- });
- this.setData({
- isScrollOver: false
- });
- }
- }
- })({
- props: {
- componentData: {}
- },
- data: {
- navHeight: 72,
- /* 消息通知是否显示 */
- showMsg: true,
- isScrollOver: false,
- id: `index_heart_${Date.now()}`,
- imgSrcPrefix: app.globalData.imgSrcPrefix
- },
- didMount() {},
- methods: {
- /**
- * 关闭消息通知
- */
- closeMsgBtn() {
- this.setData({
- showMsg: false
- });
- },
- /**
- * 跳转到医院特色
- */
- goToDetail() {
- const pageCode = 'hospital-characteristics';
- my.navigateTo({
- url: `${prefixPagePath}/one/index?pageCode=${pageCode}`
- });
- /* 服务预警,医院介绍 */
- reportCmPV_YL({
- title: '医院介绍'
- });
- },
- /**
- * 获取头部初始头部初始padding-top
- */
- onCallback({
- height
- }) {
- this.setData({
- navHeight: height
- });
- }
- }
- }));
|