123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- import { _decorator, Component, instantiate, Label, Node, Prefab, utils } from 'cc';
- import { http } from '../http';
- import { config } from '../config';
- import { level_list_item_data, long_story_list_item_data } from '../../data/data';
- import { level_list_item } from './level_list_item';
- import { tools } from '../tools';
- const { ccclass, property } = _decorator;
- @ccclass('level_list')
- export class level_list extends Component {
- @property(Node) btn_back:Node = null;
- @property(Node) lab_title:Node = null;
- @property(Node) content:Node = null;
- @property(Prefab) item:Prefab = null;
- @property(Node) page_number:Node = null;
- @property(Node) btn_previous_page:Node = null;
- @property(Node) lab_current_page:Node = null;
- @property(Node) btn_next_page:Node = null;
-
- private m_long_story_list_data: long_story_list_item_data = null
-
- private m_back_call_back = null;
- private m_click_callback = null;
- private m_cur_page:number = 1;
- private m_every_page_count:number = 18;
- private m_total_page_count:number = 0;
- protected start(): void {
- this.btn_back.on(Node.EventType.TOUCH_END,()=>{
- if(this.m_back_call_back) {
- this.m_back_call_back()
- }
- })
- this.page_number.active = false
- let self = this
- this.btn_previous_page.on(Node.EventType.TOUCH_END, ()=> {
- if(self.m_cur_page == 1) {
- tools.showToast("已是第一页")
- return
- }
- self.m_cur_page-=1
- self.requestData()
- },this)
- this.btn_next_page.on(Node.EventType.TOUCH_END, ()=> {
- if(self.m_cur_page >= self.m_total_page_count) {
- tools.showToast("已是最后一页")
- return
- }
- self.m_cur_page+=1
- self.requestData()
- },this)
- }
- public init(long_story_list_data: long_story_list_item_data, back_call_back, call_back){
- this.m_long_story_list_data = long_story_list_data
- if(this.m_long_story_list_data) {
- this.lab_title.getComponent(Label).string = this.m_long_story_list_data.name
- }
- this.m_back_call_back = back_call_back;
- this.m_click_callback = call_back;
- this.requestData()
- }
- initView(list:level_list_item_data[]){
- for (let index = 0; index < list.length; index++) {
- const element = list[index];
- let node = instantiate(this.item)
- node.parent = this.content;
- node.getComponent(level_list_item).initView(element,this.m_click_callback)
- }
- }
- requestData() {
- this.content.removeAllChildren()
- if(this.m_long_story_list_data==null) {
- let request_data = {"page":this.m_cur_page,"limit":this.m_every_page_count}
- http.post("/tool/mysnote/levels",request_data,(err,data)=>{
- if(!err){
- // console.log(data)
- let _data = JSON.parse(data);
- let __data = _data.content
- if(this.m_cur_page == 1) {
- this.page_number.active = true
- this.m_total_page_count = Math.ceil(__data.tool_number/this.m_every_page_count)
- }
- this.setupLabNumber()
- config.last_id = parseInt(_data.content.zujian_id)
- console.log("level_list",config.last_id )
- this.initView(__data.list)
- }
- })
- } else {
- }
- }
- setupLabNumber() {
- let string = this.m_cur_page + ' / ' + this.m_total_page_count
- this.lab_current_page.getComponent(Label).string = string
- }
- }
|