Package.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { ProductList } from 'src/models/Product'
  2. import { Collection, Model } from 'js-abstract-model'
  3. class Package 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: 'store_category_info' },
  12. { key: 'content_category' },
  13. { key: 'content_category_info' },
  14. {
  15. key: 'unit_price',
  16. default: 0
  17. },
  18. { key: 'sellable_price' },
  19. { key: 'discount_percent' },
  20. { key: 'description' },
  21. { key: 'is_physical' },
  22. { key: 'is_hidden' },
  23. { key: 'maximum_order_count' },
  24. { key: 'weight' },
  25. {
  26. key: 'is_add_to_basket_disabled',
  27. default: false
  28. },
  29. {
  30. key: 'is_purchased',
  31. default: false
  32. },
  33. { key: 'specification' },
  34. { key: 'products' },
  35. {
  36. key: 'products_info',
  37. relatedModel: ProductList
  38. }
  39. ], {
  40. is_physical: {
  41. infoKey: 'is_physical_info',
  42. enumListKey: 'is_physicalEnums',
  43. enums: [
  44. {
  45. label: 'فیزیکی',
  46. value: true
  47. },
  48. {
  49. label: 'مجازی',
  50. value: false
  51. }
  52. ]
  53. },
  54. is_hidden: {
  55. infoKey: 'is_hidden_info',
  56. enumListKey: 'is_hiddenEnums',
  57. enums: [
  58. {
  59. label: 'پنهان',
  60. value: true
  61. },
  62. {
  63. label: 'نمایان',
  64. value: false
  65. }
  66. ]
  67. }
  68. })
  69. if (!this.thumbnail) {
  70. this.thumbnail = '/img/sample-post-thumbnail.jpg'
  71. }
  72. }
  73. getFinalPrice () {
  74. return parseInt(this.unit_price * (100 - this.discount_percent)).toLocaleString('fa')
  75. }
  76. }
  77. class PackageList extends Collection {
  78. model () {
  79. return Package
  80. }
  81. }
  82. export { Package, PackageList }