123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- import { config } from "../../config/config";
- import { user_data } from "../../data/data";
- import { http } from "../../framework/http";
- import { log } from "../../framework/log";
- import { tools } from "../../framework/tools";
- import { util } from "../../framework/util";
- import { UserData } from "../../stores/userDataManager";
- import { UserStatus } from "../../stores/userStatusManager";
- const novelPlugin = requirePlugin('novel-plugin');
- Component({
- properties: {
- novelManagerId: {
- type: Number,
- value: -1
- },
- bookId: {
- type: String,
- value: ''
- },
- chapterIndex: {
- type: Number,
- value: -1
- },
- },
- data: {
- loading: false,
- status_name: "解锁",
- chapter_data:null,
- },
- lifetimes:{
- attached(){
- let chapterIndex = this.properties.chapterIndex
- setTimeout(()=>{
- UserStatus().getSelectBookDirectoryList((list)=>{
- if(list!=null){
- for (var i = 0; i < list.length; i++) {
- if((list[i].id-1) == chapterIndex){
- this.data.chapter_data = list[i]
- break
- }
- }
- console.log("chapter_data",this.data.chapter_data)
- if(this.data.chapter_data!=null){
- this.data.status_name = `解锁需要${this.data.chapter_data.coin}书币`
- this.setData({status_name:this.data.status_name})
- }
- }
-
- })
- },100)
-
- }
- },
- pageLifetimes:{
- show() {
-
- },
- },
- methods: {
- get_status_name(){
- return this.data.status_name
- },
-
- BuyBookChapter(chapter_id,coin){
- const novelManager = novelPlugin.getNovelManager(this.properties.novelManagerId);
- if(UserData().getData().coin>=coin){
- util.showLoading('正在购买...',true)
- let book_data = UserStatus().getUserSelectBook()
- http.DynamicRequest(config.url_confg.Dynamic.buy_chapter,{'book_id':book_data.book_id,'chapter_id':chapter_id},(err,d)=>{
- if(!err){
- log.Debug(d)
- if(d.code==config.url_confg.StatesCode.SUCCESS){
- // d.content.includes(chapter_id)
- UserData().update_user_info(()=>{
- util.hideLoading()
- util.showInfoToast('购买成功!')
- novelManager.paymentCompleted()
- })
- }else{
-
- }
- }else{
- log.Error(err)
- }
-
- })
- }else{
- util.showModal("书币不足","是否充值?",()=>{
- novelManager.switchTab({url:'/pages/mine/mine'})
- // util.reLaunch('/pages/mine/mine')
- })
- }
-
- },
- // 这里实现自己的付费逻辑
- async pay() {
- // novelManagerId 句柄 用来获取novelManager实例
- const novelManager = novelPlugin.getNovelManager(this.properties.novelManagerId);
- // getId() 返回当前manager对应的Id(即句柄)
- console.log('id:', novelManager.getId());
- // getBookId() 返回当前manager对应的bookId
- console.log('bookId:', novelManager.getBookId());
-
- if(this.data.chapter_data!=null){
- this.BuyBookChapter(this.properties.chapterIndex+1,this.data.chapter_data.coin)
- }
- // wx.showModal({
- // title: '付费逻辑',
- // content: '请到components/charge-dialog/charge-dialog.js中完善付费逻辑',
- // showCancel: false,
- // });
- },
- },
- })
|