import { Injectable } from '@angular/core';
import Parse from 'parse';

@Injectable({
  providedIn: 'root'
})
export class CreatedService {

  constructor() { }


 /** 册数*/
 typeNumber:any
 /** 申报类型*/
 type:any

  
 /**扩展表记录 */
 eduTextbookVolumeList: Array<any> = []
 /**获取扩展表记录 */
 async getEduTextbookVolumeList(eduTextbook:any) {
  console.log('服务获取扩展记录表')
   if (this.typeNumber && this.typeNumber > 12) {
     this.typeNumber = 12
   }
   console.log(this.type, this.typeNumber)
   let query = new Parse.Query('EduTextbookVolume')
   query.equalTo('eduTextbook', eduTextbook)
   query.select('objectId')
   query.ascending('createdAt')//小到大
   query.notEqualTo('isDeleted', true)
   if (this.type == '全册') {
     query.limit(this.typeNumber)
   } else {
     query.limit(1)
   }
   let list = await query.find()
   console.log(list)
   if (this.type == '全册') {
     this.eduTextbookVolumeList = new Array(this.typeNumber).fill({ objectId: '' })
     for (let i in list) {
       this.eduTextbookVolumeList[i] = list[i]
     }
   } else {
     this.eduTextbookVolumeList[0] = list[0]
     console.log(this.eduTextbookVolumeList)
   }
 }
}
