charge-dialog.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { config } from "../../config/config";
  2. import { user_data } from "../../data/data";
  3. import { http } from "../../framework/http";
  4. import { log } from "../../framework/log";
  5. import { tools } from "../../framework/tools";
  6. import { util } from "../../framework/util";
  7. import { UserData } from "../../stores/userDataManager";
  8. import { UserStatus } from "../../stores/userStatusManager";
  9. const novelPlugin = requirePlugin('novel-plugin');
  10. Component({
  11. properties: {
  12. novelManagerId: {
  13. type: Number,
  14. value: -1
  15. },
  16. bookId: {
  17. type: String,
  18. value: ''
  19. },
  20. chapterIndex: {
  21. type: Number,
  22. value: -1
  23. },
  24. },
  25. data: {
  26. loading: false,
  27. status_name: "解锁",
  28. chapter_data:null,
  29. },
  30. lifetimes:{
  31. attached(){
  32. let chapterIndex = this.properties.chapterIndex
  33. setTimeout(()=>{
  34. UserStatus().getSelectBookDirectoryList((list)=>{
  35. if(list!=null){
  36. for (var i = 0; i < list.length; i++) {
  37. if((list[i].id-1) == chapterIndex){
  38. this.data.chapter_data = list[i]
  39. break
  40. }
  41. }
  42. console.log("chapter_data",this.data.chapter_data)
  43. if(this.data.chapter_data!=null){
  44. this.data.status_name = `解锁需要${this.data.chapter_data.coin}书币`
  45. this.setData({status_name:this.data.status_name})
  46. }
  47. }
  48. })
  49. },100)
  50. }
  51. },
  52. pageLifetimes:{
  53. show() {
  54. },
  55. },
  56. methods: {
  57. get_status_name(){
  58. return this.data.status_name
  59. },
  60. BuyBookChapter(chapter_id,coin){
  61. const novelManager = novelPlugin.getNovelManager(this.properties.novelManagerId);
  62. if(UserData().getData().coin>=coin){
  63. util.showLoading('正在购买...',true)
  64. let book_data = UserStatus().getUserSelectBook()
  65. http.DynamicRequest(config.url_confg.Dynamic.buy_chapter,{'book_id':book_data.book_id,'chapter_id':chapter_id},(err,d)=>{
  66. if(!err){
  67. log.Debug(d)
  68. if(d.code==config.url_confg.StatesCode.SUCCESS){
  69. // d.content.includes(chapter_id)
  70. UserData().update_user_info(()=>{
  71. util.hideLoading()
  72. util.showInfoToast('购买成功!')
  73. novelManager.paymentCompleted()
  74. })
  75. }else{
  76. }
  77. }else{
  78. log.Error(err)
  79. }
  80. })
  81. }else{
  82. util.showModal("书币不足","是否充值?",()=>{
  83. novelManager.switchTab({url:'/pages/mine/mine'})
  84. // util.reLaunch('/pages/mine/mine')
  85. })
  86. }
  87. },
  88. // 这里实现自己的付费逻辑
  89. async pay() {
  90. // novelManagerId 句柄 用来获取novelManager实例
  91. const novelManager = novelPlugin.getNovelManager(this.properties.novelManagerId);
  92. // getId() 返回当前manager对应的Id(即句柄)
  93. console.log('id:', novelManager.getId());
  94. // getBookId() 返回当前manager对应的bookId
  95. console.log('bookId:', novelManager.getBookId());
  96. if(this.data.chapter_data!=null){
  97. this.BuyBookChapter(this.properties.chapterIndex+1,this.data.chapter_data.coin)
  98. }
  99. // wx.showModal({
  100. // title: '付费逻辑',
  101. // content: '请到components/charge-dialog/charge-dialog.js中完善付费逻辑',
  102. // showCancel: false,
  103. // });
  104. },
  105. },
  106. })