Basket.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { User } from 'src/models/User.js'
  2. import { Model, Collection } from 'js-abstract-model'
  3. import { RegistrationList } from 'src/models/Registration.js'
  4. class Basket extends Model {
  5. constructor (data) {
  6. super(data, [
  7. { key: 'id' },
  8. // -----------------
  9. { key: 'unit_price' },
  10. { key: 'title' },
  11. { key: 'thumbnail' },
  12. { key: 'slug' },
  13. { key: 'slug' },
  14. { key: 'product_type' },
  15. { key: 'description' },
  16. { key: 'capacity' },
  17. // -----------------
  18. { key: 'creator' },
  19. {
  20. key: 'creator_info',
  21. relatedModel: User
  22. },
  23. { key: 'owner' },
  24. {
  25. key: 'owner_info',
  26. relatedModel: User
  27. },
  28. {
  29. key: 'registrations_info',
  30. relatedModel: RegistrationList
  31. },
  32. { key: 'status' },
  33. { key: 'amount' },
  34. { key: 'description' },
  35. { key: 'creation_time' },
  36. { key: 'last_modification_time' },
  37. { key: 'is_active' },
  38. { key: 'is_deleted' }
  39. ])
  40. this.statusEnums = [
  41. {
  42. label: 'باز',
  43. value: 'OPEN'
  44. },
  45. {
  46. label: 'لغو شده',
  47. value: 'CANCELED'
  48. },
  49. {
  50. label: 'بسته شده',
  51. value: 'CLOSED'
  52. },
  53. {
  54. label: 'پرداخت شده',
  55. value: 'PAID'
  56. }
  57. ]
  58. this.loadStatusInfo()
  59. }
  60. loadStatusInfo () {
  61. const target = this.statusEnums.find(type => type.value === this.status)
  62. if (!target) {
  63. this.status_info = {
  64. label: null,
  65. value: null
  66. }
  67. } else {
  68. this.status_info = target
  69. }
  70. }
  71. }
  72. class BasketList extends Collection {
  73. model() {
  74. return Basket
  75. }
  76. }
  77. export { Basket, BasketList }