import { observable, action, computed } from "mobx"; import { message } from "antd"; import * as api from "../apis/blessCard"; export class HrmBlessCardStore { blessPadding = 140; blessRowHeight = 50; @observable blessing = ""; @observable createDate = ""; @observable creator = ""; @observable imgUrl = ""; @observable blessCardRef = null; @observable infoHeight = 0; @computed get blessingHeight() { if (!this.blessCardRef) return 0; return this.blessCardRef.clientWidth * 1.33 - this.blessPadding } @computed get blessRowNumber() { const h = (this.infoHeight > this.blessingHeight) ? this.infoHeight : this.blessingHeight; return Math.floor(h / this.blessRowHeight); } @action readBirthdayBlessingData = (id) => { api.readBirthdayBlessingData({ id }).then(res => { if (res.status == "1") { Object.keys(res).forEach(key => this[key] = res[key]); } else { message.error(res.message); } }) } handleLetterPaperScroll = (e) => { this.scrollRef.scroll(e.target.scrollTop); } setRef = (ref, type) => { if (type == "img" && !this.blessCardRef) { this.blessCardRef = ref; } if (type == "scroll") { this.scrollRef = ref; } } @action setInfoHeight = (height) => { this.infoHeight = height; } }