import Taro from "@tarojs/taro"; import dayjs from "dayjs"; import { Component } from "react"; import { Block, View, Text, Image, RichText, ScrollView, } from "@tarojs/components"; import { Loading } from "@antmjs/vantui"; import "./integral_list.less"; /*** redux ***/ import { connect } from "react-redux"; import { userRefresh } from "../../store/features/userInfo"; import { otherSettingRefresh } from "../../store/features/otherSetting"; /*** redux end ***/ /** 自定义组件 **/ import Navbar from "../../components/navbar/navbar"; import PopupAlert from "../../components/popup/popup-alert"; /** 自定义组件 **/ import { GetOtherSetting, GetIntegralRule, GetObtainUserIntegral, GetIsAttentionOfficialAccount, GetOfficialAccount, GetCloseOfficialAccount, RefreshWxUserInfo, } from "../../utils/Interface"; import { msg } from "../../utils/traoAPI"; class IntegralList extends Component { constructor(props) { super(props); this.state = { name: "我的积分", userinfo: { ...this.props.userInfo, }, otherSetting: { // skipAppid: "", // skipPath: "", // envVersion: "", ...this.props.otherSetting, }, page: 1, list: [], isIntegral: false, // 积分规则 isOfficialAccount: false, // 是否关注公众号-一年展示一次 nodes: "", pageNum: 1, pageSize: 10, total: 0, dargState: 0, }; } async onLoad() { this.initData(); this.GetIntegralRule(); } componentDidMount() {} componentWillUnmount() {} componentDidShow() {} componentDidHide() {} async initData() { this.RefreshWxUserInfo(); this.GetObtainUserIntegral(); this.GetIsAttentionOfficialAccount(); } // 刷新用户信息 RefreshWxUserInfo = async () => { let res = await RefreshWxUserInfo(); if (res.data.code === 200) { this.props.userRefresh(res.data.data); this.setState({ userInfo: res.data.data }); } }; openShop = () => { let { otherSetting } = this.state; if (otherSetting.skipAppid) { this.goMiniProgram(); } else { this.GetOtherSetting(); // 获取小程序设置:商城地址和版本 } }; // 获取小程序设置 GetOtherSetting = async () => { let res = await GetOtherSetting(); if (res.data.code === 200) { let { otherSetting } = this.state; otherSetting.skipAppid = res.data.data.skipAppid; otherSetting.skipPath = res.data.data.skipPath; otherSetting.envVersion = res.data.data.envVersion; this.setState({ otherSetting }); this.goMiniProgram(); } }; goMiniProgram = () => { let { otherSetting } = this.state; Taro.navigateToMiniProgram({ appId: otherSetting.skipAppid, path: otherSetting.skipPath, envVersion: otherSetting.envVersion, success() { // 打开成功 // Taro.switchTab({ // url: "/pages/index/index", // }); }, fail() { // Taro.switchTab({ // url: "/pages/index/index", // }); }, }); }; // 检查是否关注公众号:只在每年的09-30号前提醒,如果没有关注则弹窗提醒 checkOfficialAccount() { let currentTime = dayjs().valueOf(); let targetTime = dayjs().month(9).day(30).valueOf(); // 仅9月30日前触发:提醒过期弹窗 if (currentTime <= targetTime) { // 检查:今年未提醒,则弹窗 this.setState({ isOfficialAccount: true }); // let isOfficialAccount = Taro.getStorageSync("isOfficialAccount"); // if (isOfficialAccount) { // let oldYear = isOfficialAccount; // let currentYear = dayjs().format("YYYY"); // if (currentYear < oldYear) { // // 检查:今年未提醒,则弹窗 // this.setState({ isOfficialAccount: true }); // } // } else { // this.setState({ isOfficialAccount: true }); // } } } // 用户是否已关闭提醒 GetOfficialAccount = async () => { Taro.showLoading({ title: "请求中...", mask: true, }); let res = await GetOfficialAccount(); if (res.data.code === 200) { if (!res.data.data) { // 如果false则是未关闭提醒 this.checkOfficialAccount(); // 检测时间,弹窗提示关注公众号 } } }; // 用户是否关注公众号 GetIsAttentionOfficialAccount = async () => { Taro.showLoading({ title: "请求中...", mask: true, }); let res = await GetIsAttentionOfficialAccount(); if (res.data.code === 200) { if (!res.data.data) { // 如果false则是没关注 this.GetOfficialAccount(); } } }; // 用户关闭提醒 GetCloseOfficialAccount = async () => { let { data } = await GetCloseOfficialAccount(); if (data.code === 200) { msg("已关闭提醒"); } else { msg("操作失败"); } }; GetObtainUserIntegral = async () => { Taro.showLoading({ title: "请求中...", mask: true, }); let { list, pageNum, pageSize } = this.state; let res = await GetObtainUserIntegral({ pageNum, pageSize, }); if (res.data.code === 200) { if (res.data.rows.length) { let data = res.data.rows.map((item: any) => { item.createTime = item.createTime ? dayjs(item.createTime).format("YYYY-MM-DD hh:mm:ss") : ""; return item; }); list = [].concat(list, data); this.setState({ list: list, total: res.data.total, dargState: 0 }); } } }; GetIntegralRule = async () => { Taro.showLoading({ title: "请求中...", mask: true, }); let res = await GetIntegralRule(); console.log("GetIntegralRule", res); if (res.data.code === 200) { let nodes = decodeURIComponent(res.data.data.value || ""); nodes = nodes.replace(/\ { this.setState({ isIntegral: true }); }; integralPopupClose = () => { this.setState({ isIntegral: false }); }; /** 关注公众号弹窗 */ officialPopupConfirm = () => { // let currentYear = dayjs().format("YYYY"); // Taro.setStorageSync("isOfficialAccount", currentYear); // 标记:本年度已提醒 this.GetCloseOfficialAccount(); this.officialPopupClose(); }; officialPopupClose = () => { this.setState({ isOfficialAccount: false }); }; /*** 上拉加载 ***/ reduction = () => { //还原初始设置 // const time = 0.5; this.setState({ scrollY: true, }); }; touchStart = (e) => { this.setState({ start_p: e.touches[0], }); }; touchmove = (e) => { let move_p = e.touches[0], //移动时的位置 deviationX = 0.3, //左右偏移量(超过这个偏移量不执行下拉操做) deviationY = 70, //拉动长度(低于这个值的时候不执行) maxY = 100; //拉动的最大高度 let start_x = this.state.start_p.clientX, start_y = this.state.start_p.clientY, move_x = move_p.clientX, move_y = move_p.clientY; //获得偏移数值 let dev = Math.abs(move_x - start_x) / Math.abs(move_y - start_y); if (dev < deviationX) { //当偏移数值大于设置的偏移数值时则不执行操做 let pY = Math.abs(move_y - start_y) / 3.5; //拖动倍率(使拖动的时候有粘滞的感受--试了不少次 这个倍率恰好) if (move_y - start_y > 0) { //下拉操做 if (pY >= deviationY) { // this.setState({ dargState: 1, downText: "释放刷新" }); } else { // this.setState({ dargState: 0, downText: "下拉刷新" }); } if (pY >= maxY) { pY = maxY; } this.setState({ scrollY: false, //拖动的时候禁用 }); } if (start_y - (move_y + 100) > 0) { //上拉操做 // console.log("上拉操做"); if (pY >= deviationY) { this.setState({ dargState: -1 }); } } } }; pull = () => { //上拉 console.log("上拉"); let { list, total, pageNum, dargState } = this.state; if (dargState === -1) { if (list.length < total) { this.setState({ pageNum: pageNum + 1 }); setTimeout(() => { this.GetObtainUserIntegral(); }, 100); } } }; down = () => { //下拉 console.log("下拉"); // this.props.onDown() }; ScrollToUpper = () => { //滚动到顶部事件 console.log("滚动到顶部事件"); // this.props.Upper() }; ScrollToLower = () => { //滚动到底部事件 console.log("滚动到底部事件"); // this.props.Lower() }; touchEnd = () => { if (this.state.dargState === 1) { this.down(); } else if (this.state.dargState === -1) { this.pull(); } // this.reduction(); }; /*** 上拉加载 ***/ render() { let { list, userinfo, isIntegral, isOfficialAccount, nodes, dargState, total, } = this.state; return ( } confirmButtonText="我知道了" textAlgin="center" close={this.integralPopupClose} confirm={this.integralPopupClose} /> // 删除测试阶段标签后,需改回700rpx 长按图片关注公众号,可以接收积分过期提醒 (测试阶段公众号为:广州云强信息科技有限公司) } confirmButtonText="我知道了" textAlgin="center" close={this.officialPopupClose} confirm={this.officialPopupConfirm} /> 积分规则 可用积分 {userinfo.credit} 前往积分商城 {/* {list.length === 0 && ( 暂无数据 )} {list.map((item: any, key: number) => { return ( {item.remarkContent} {item.createTime} {item.source === "1" ? "+" + item.floatScore : "-" + item.floatScore} ); })} */} {list.length === 0 && ( 暂无积分记录 )} {list.map((item: any, key: number) => { return ( {item.remarkContent} {item.createTime} {item.source === "1" ? "+" + item.floatScore : "-" + item.floatScore} ); })} {list.length > 0 && list.length < total && ( {dargState === 0 ? ( 上拉加载更多 ) : ( 加载中... )} )} {list.length > 0 && list.length === total && ( 已到底部 )} ); } } const mapStateToProps = (state) => ({ userInfo: state.userInfo, otherSetting: state.otherSetting, }); const mapDispatchToProps = (dispatch) => ({ userRefresh(data) { dispatch(userRefresh(data)); }, otherSettingRefresh(data) { dispatch(otherSettingRefresh(data)); }, }); export default connect(mapStateToProps, mapDispatchToProps)(IntegralList);