import Api from "../../model/api"; import {getEventParam, showLoading} from "../../utils/utils"; import Route from "../../model/route"; import {videoTypes} from "../../model/enum"; const app = getApp(); app.Base({ dict: { "兑换课程": {method: Api.getNoScoreList, isComplete: false}, "已兑换课程": {method: Api.getScoreList, isComplete: true}, }, title: '兑换课程', data: { scoreInfos: [], active: 0, isComplete: false, show: false, item: {}, }, async onLoad(options) { await this.init(); }, async init() { const data = await Api.getScoreInfo(true); this.setData({ scoreInfos: data.data }) }, async onPullDownRefresh() { await this.init(); }, async pay(e) { await this.onPullDownRefresh(); }, async onChange(e) { this.title = getEventParam(e, "title"); this.setData({ isComplete: this.dict[this.title].isComplete }, async () => { await this.changeResetData(this); }) }, toDetail(e) { Route.toScoreDetail(); }, toNewsDetail(e) { let item = getEventParam(e, "item"); this.setData({ item: item, show: true }) }, async requestData() { let res = await this.dict[this.title].method({ pageNum: this.pageNum, pageSize: this.pageSize }); res.data.rows = res.data.rows.map(item => { let flag = this.data.scoreInfos.some(info => { return info.surplusValue >= item.score; }) return { ...item, hasScore: flag, } }); return res; }, toVideo(e) { const item = getEventParam(e, "item"); Route.toVideo(item.id, videoTypes.SCORE, "积分课") } })