Product.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { Collection, Model } from 'js-abstract-model'
  2. import { MediaList } from 'src/models/Media.js'
  3. class Product extends Model {
  4. constructor (data) {
  5. super(data, [
  6. { key: 'id' },
  7. { key: 'thumbnail' },
  8. { key: 'title' },
  9. { key: 'inventory' },
  10. { key: 'store_category' },
  11. { key: 'content_category' },
  12. { key: 'unit_price' },
  13. { key: 'sellable_price' },
  14. {
  15. key: 'discount_percent',
  16. default: 0
  17. },
  18. { key: 'description' },
  19. { key: 'maximum_order_count' },
  20. { key: 'is_physical' },
  21. { key: 'weight' },
  22. { key: 'physical_type' },
  23. { key: 'specification' },
  24. {
  25. key: 'medias',
  26. defalut: []
  27. },
  28. {
  29. key: 'medias_info',
  30. relatedModel: MediaList
  31. }
  32. ], {
  33. is_physical: {
  34. infoKey: 'is_physical_info',
  35. enumListKey: 'is_physicalEnums',
  36. enums: [
  37. {
  38. label: 'فیزیکی',
  39. value: true
  40. },
  41. {
  42. label: 'مجازی',
  43. value: false
  44. }
  45. ]
  46. },
  47. physical_type: {
  48. infoKey: 'physical_type_info',
  49. enumListKey: 'physical_typeEnums',
  50. enums: [
  51. {
  52. label: 'لوح فشرده',
  53. value: 'CD'
  54. },
  55. {
  56. label: 'کتاب',
  57. value: 'BOOK'
  58. },
  59. {
  60. label: 'جزوه',
  61. value: 'MANUSCRIPT'
  62. }
  63. ]
  64. }
  65. })
  66. if (!this.thumbnail) {
  67. this.thumbnail = '/img/sample-post-thumbnail.jpg'
  68. }
  69. }
  70. getFinalPrice () {
  71. return parseInt(this.unit_price * (100 - this.discount_percent)).toLocaleString('fa')
  72. }
  73. }
  74. class ProductList extends Collection {
  75. model () {
  76. return Product
  77. }
  78. }
  79. export { Product, ProductList }