Package.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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: 'content_category' },
  12. { key: 'unit_price' },
  13. { key: 'discount_percent' },
  14. { key: 'description' },
  15. { key: 'is_physical' },
  16. { key: 'maximum_order_count' },
  17. { key: 'weight' },
  18. { key: 'specification' },
  19. { key: 'products' },
  20. {
  21. key: 'products_info',
  22. relatedModel: ProductList
  23. }
  24. ], {
  25. is_physical: {
  26. infoKey: 'is_physical_info',
  27. enumListKey: 'is_physicalEnums',
  28. enums: [
  29. {
  30. label: 'فیزیکی',
  31. value: true
  32. },
  33. {
  34. label: 'مجازی',
  35. value: false
  36. }
  37. ]
  38. }
  39. })
  40. if (!this.thumbnail) {
  41. this.thumbnail = '/img/sample-post-thumbnail.jpg'
  42. }
  43. }
  44. getFinalPrice () {
  45. return parseInt(this.unit_price * (100 - this.discount_percent)).toLocaleString('fa')
  46. }
  47. }
  48. class PackageList extends Collection {
  49. model () {
  50. return Package
  51. }
  52. }
  53. export { Package, PackageList }